/* Modernizado e ajustado para nunca ultrapassar a altura da tela */

html, body {
  height: 100%;
  width: 100vw;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  min-width: 100vw;
  margin: 0;
  padding: 0;
  background-color: #181828;
  color: #f7f7fb;
  font-family: 'Inter', 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  height: 100vh;
  overflow: hidden; /* não deixa ultrapassar o vertical */
}

/* Layout centralizado responsivo com espaço para header/footer */
.app-wrapper {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  width: 100vw;
  max-height: 100vh;
  overflow-y: auto;
  padding: 2.5vh 0 2.5vh 0;
}

header {
  width: 100%;
  max-width: 560px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  background: transparent;
}

#qr-section {
  background-color: #23233b;
  border-radius: 18px;
  box-shadow: 0 4px 32px 8px rgba(48, 41, 78, 0.09);
  padding: 32px 24px;
  text-align: center;
  width: 100%;
  max-width: 560px;
  /* Impede ultrapassar a altura da tela: */
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  margin-bottom: 20px;
}

.msg {
  color: #10101a;
}

form {
  margin-top: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #a0a4c1;
}

input, textarea, select {
  width: 100%;
  padding: 10px 14px;
  box-sizing: border-box;
  border-radius: 7px;
  background: #272742;
  color: #fff;
  border: 1px solid #363652;
  margin-bottom: 12px;
  font-size: 16px;
  transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
  border-color: #7a78e6;
  outline: none;
}

button {
  background-color: #6a5cff;
  color: #fff;
  padding: 12px 18px;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 2px 12px 0 rgba(106, 92, 255, 0.1);
  transition: background 0.18s, box-shadow 0.18s;
}

button:hover, button:focus-visible {
  background-color: #564ec9;
}

#qrcode-container {
  margin-top: 28px;
  text-align: center;
  position: relative;
  padding: 0;
}

#qrcode {
  display: inline-flex;
  border: 7px solid #f7f7fb;
  background-color: #fff;
  border-radius: 10px;
  padding: 12px;
}

footer {
  flex-shrink: 0;
  color: #15aca5;
  margin-top: auto;
  margin-bottom: 12px;
  width: 100vw;
  text-align: center;
  font-size: 15px;
  background: transparent;
}

/* Modern Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0 0 0 0;
  width: 100vw;
  height: 100vh;
  background: rgba(24, 24, 40, 0.83);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.33s cubic-bezier(.4,0,.2,1);
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
}

.spinner {
  border: 5px solid #363652;
  border-top: 5px solid #6a5cff;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 15px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
  from { transform: rotate(0deg); }
}

/* Message Container moderno no topo */
.message-container {
  position: fixed;
  top: 32px;
  right: 32px;
  z-index: 1001;
  max-width: 420px;
  width: auto;
}

.message {
  background-color: #23233b;
  color: #fff;
  padding: 17px 22px;
  margin-bottom: 12px;
  border-radius: 8px;
  border-left: 5px solid #6a5cff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  opacity: 0;
  transform: translateY(-12px);
  transition: all 0.36s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 2px 16px rgba(48, 41, 78, 0.20);
}

.message.show {
  opacity: 1;
  transform: translateY(0);
}

.message-success {
  border-left-color: #4caf50;
}

.message-error {
  border-left-color: #f44336;
}

.message-warning {
  border-left-color: #ff9800;
}

.message-info {
  border-left-color: #2196f3;
}

.message-text {
  flex: 1;
  margin-right: 18px;
  color: #fff;
  font-weight: 500;
  font-size: 16px;
}

.message-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  min-width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 40%;
  transition: background 0.15s;
}

.message-close:hover {
  background-color: rgba(106, 92, 255, 0.18);
}

.error {
  border-color: #f44336 !important;
  background: rgba(244,67,54,0.125) !important;
  color: #f44336;
  font-style: italic;
  padding: 16px;
}

.field-error {
  color: #f44336;
  font-size: 13px;
  margin-top: 5px;
  text-align: left;
}

/* Loading states for QR container */
.loading {
  color: #6a5cff;
  font-style: italic;
  padding: 20px;
}

/* RESPONSIVIDADE E PREVENÇÃO DE OVERFLOW */

@media (max-width: 650px) {
  #qr-section,
  .app-wrapper {
    max-width: 98vw;
    border-radius: 0;
    box-shadow: none;
    padding-left: 6px;
    padding-right: 6px;
  }
  header {
    max-width: 98vw;
    padding: 0 6px;
  }
  .message-container {
    right: 8px;
    left: 8px;
    top: 10px;
    max-width: 96vw;
  }
}

@media (max-width: 500px) {
  #qr-section {
    padding: 14px 4px;
    font-size: 98%;
    max-height: calc(100vh - 94px);
  }
  .app-wrapper {
    padding: 6px 0 6px 0;
    max-height: 100vh;
  }
  label {
    font-size: 97%;
  }
  .message-container {
    top: 4px;
  }
  button, input, textarea, select {
    font-size: 16px !important;
  }
}

/* Mobile:
 * Remove overflow de body, deixa rolável só o wrapper, e ajusta o footer 
 * para nunca ficar para fora da viewport. 
 */

@media (max-width: 480px) {
  body {
    overflow: hidden;
    padding: 0;
  }
  .app-wrapper {
    min-height: 0;
    max-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom, 6px);
  }
  #qr-section {
    max-height: calc(100vh - 84px);
  }
  footer {
    font-size: 13px;
    padding-bottom: 1px;
  }
}

::-webkit-scrollbar {
  width: 8px;
  background: #22223d;
}
::-webkit-scrollbar-thumb {
  background: #363652;
}

/* Acessibilidade */
*:focus {
  outline: 2px solid #6a5cff;
  outline-offset: 1.5px;
}

/* Compatibilidade para content overflow evitado */
.app-wrapper,
#qr-section,
.content-form,
.history-list {
  overflow-y: auto;
}

@media print {
  body {
    background: white;
    color: black;
    overflow: auto !important;
  }
  #qr-section {
    background: white;
    box-shadow: none;
    max-height: unset;
  }
  header, .message-container, .loading-overlay {
    display: none !important;
  }
  #qrcode {
    border: 1px solid black;
    border-radius: 0;
  }
}