/* --- 1. CONFIGURAÇÕES VISUAIS GERAIS (MINIMALISTA) --- */
:root {
  --primary: #0f172a;
  --primary-dark: #020617;
  --bg-page: #f8fafc;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-border: rgba(255, 255, 255, 0.4);
  --text-main: #334155;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

/* --- VARIÁVEIS DO TEMA NOTURNO --- */
body.dark-mode {
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --bg-page: #0f172a;
  --surface: rgba(30, 41, 59, 0.75);
  --surface-border: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
}

body {
  font-family: "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-page);
  min-height: 100vh;
  margin: 0;
  padding: 20px 15px 50px 15px;
  color: var(--text-main);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- TELA DE CARREGAMENTO (LOADING) --- */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-page);
  opacity: 0.9;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s ease;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* --- 2. PAINEL DE CONTROLE (MODERNO) --- */
.app-container {
  max-width: 950px;
  margin: 0 auto;
}

.control-panel {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 25px 30px;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.08);
  margin-bottom: 30px;
  border: 1px solid var(--surface-border);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

h1 {
  margin: 0 0 20px 0;
  color: var(--primary);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: color 0.3s ease;
}
.tag {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* --- TOGGLE SWITCH MODERNO (MODO NOTURNO) --- */
.theme-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: 0.4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
input:checked + .slider {
  background-color: var(--primary);
}
input:checked + .slider:before {
  transform: translateX(20px);
}
.slider.round {
  border-radius: 24px;
}
.slider.round:before {
  border-radius: 50%;
}

/* --- RELÓGIO (LIMPO) --- */
.premium-clock-container {
  background: transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border-color);
  transition: border-color 0.3s ease;
}

.p-time {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
  transition: color 0.3s ease;
}
.p-date-box {
  text-align: right;
}
.p-day {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.p-full-date {
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 500;
}

/* GRID DO FORMULÁRIO */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 25px;
}
@media (min-width: 768px) {
  .form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    align-items: end;
  }
}

.input-box {
  display: flex;
  flex-direction: column;
}
.input-box label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.input-box input,
.input-box select {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: transparent;
  color: var(--text-main);
  box-sizing: border-box;
  transition: all 0.2s ease;
}
.input-box input:focus,
.input-box select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  outline: none;
}

body.dark-mode .input-box input,
body.dark-mode .input-box select {
  background: rgba(15, 23, 42, 0.5);
}

/* --- BOTÕES (FLAT) --- */
.actions-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
}
.btn {
  flex: 1;
  min-width: 140px;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  transition: all 0.2s ease;
  text-decoration: none;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.btn-success {
  background: #10b981;
  color: white;
}
.btn-success:hover {
  background: #059669;
}
.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background: var(--border-color);
}

body.dark-mode .btn-success {
  background: #059669;
}

/* --- RESPONSIVIDADE MOBILE --- */
@media (max-width: 767px) {
  .control-panel {
    padding: 20px;
  }
  .premium-clock-container {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  .p-date-box {
    text-align: left;
  }
  .actions-bar {
    flex-direction: column;
  }
  .btn {
    width: 100%;
  }
  .toggle-box {
    align-items: flex-start !important;
  }
}

/* --- 3. CONFIGURAÇÃO DE IMPRESSÃO --- */
@media print {
  @page {
    size: A4;
    margin: 0;
  }
  body {
    background: white !important;
    padding: 0;
    margin: 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .no-print {
    display: none !important;
  }
  .app-container {
    max-width: 100%;
    width: 100%;
    margin: 0;
  }

  .recibo-wrapper {
    height: 99mm;
    width: 100%;
    box-sizing: border-box;
    padding: 5mm 8mm;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-bottom: 1px dashed #9ca3af;
  }
  .cortar-container {
    display: none !important;
  }

  .recibo-box {
    min-height: 0 !important;
    height: 100%;
    padding: 10px 20px 15px 20px !important;
    box-shadow: none !important;
    border: 1px solid #000;
    display: flex;
    flex-direction: column;
    background: white !important;
    box-sizing: border-box;
  }

  .r-header {
    margin-bottom: 5px;
  }
  .r-title {
    font-size: 12pt;
    margin-bottom: 0;
  }
  .r-valor {
    font-size: 14pt;
  }
  .r-body {
    font-size: 10pt;
    line-height: 1.2;
    margin-bottom: 5px;
    flex-grow: 1;
  }
  .r-footer {
    margin-top: auto;
    padding-bottom: 0;
    display: flex;
    align-items: flex-end;
  }
  .r-assinatura {
    padding-top: 5px;
    width: 230px;
    font-size: 8.5pt;
    line-height: 1.1;
  }

  .recibo-wrapper:nth-child(3n) {
    border-bottom: none;
  }
  .recibo-wrapper:nth-child(3n) {
    page-break-after: always;
  }

  /* Esconder botão de baixar imagem na impressão */
  .btn-download-img {
    display: none !important;
  }
}

/* --- 4. RECIBOS (VISUAL TELA) --- */
#output {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: transparent;
  border-radius: var(--radius-md);
}
.recibo-wrapper {
  position: relative;
  page-break-inside: avoid !important;
  break-inside: avoid !important;
}

/* Botão de download individual da imagem */
.btn-download-img {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(15, 23, 42, 0.85);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.2s ease;
  z-index: 10;
  backdrop-filter: blur(4px);
}
.btn-download-img:hover {
  background: rgba(15, 23, 42, 1);
}
.recibo-wrapper:hover .btn-download-img {
  opacity: 1;
}

.recibo-box {
  padding: 50px;
  position: relative;
  color: #000;
  min-height: 380px;
  display: flex;
  flex-direction: column;
}

.r-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 35px;
}
.r-title {
  font-weight: 900;
  text-transform: uppercase;
  font-size: 1.1em;
  letter-spacing: 2px;
  color: var(--ink-color);
}
.r-valor-box {
  text-align: right;
}
.r-valor {
  font-weight: 800;
  font-size: 1.8em;
  white-space: nowrap;
  line-height: 1;
  color: var(--ink-color);
}
.r-extenso {
  font-size: 0.85em;
  font-style: italic;
  opacity: 0.7;
  margin-top: 5px;
  max-width: 350px;
}
.r-body {
  font-size: 1.15em;
  line-height: 1.8;
  text-align: justify;
  margin-bottom: 40px;
  flex-grow: 1;
}
.r-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: auto;
}
.r-data {
  font-size: 1em;
  color: #555;
  text-align: left;
  white-space: nowrap;
  margin-bottom: 5px;
}

/* CORREÇÃO DO VAZAMENTO DA ASSINATURA */
.r-assinatura {
  border-top: 1px solid #000;
  width: 280px;
  max-width: 100%;
  text-align: center;
  padding-top: 10px;
  font-size: 0.85em;
  transition: font-family 0.3s ease;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}
.r-assinatura strong {
  display: block;
  line-height: 1.2;
  margin-bottom: 2px;
}

/* Fonte Cursiva */
.f-cursive strong {
  font-family: "Dancing Script", cursive;
  font-size: 1.8em;
  font-weight: 700;
  line-height: 1;
  display: inline-block;
  margin-bottom: 5px;
}

.cortar-container {
  padding: 0;
  text-align: center;
  background: transparent;
}
.cortar {
  border-top: 1px dashed var(--border-color);
  height: 0;
  width: 100%;
  position: relative;
  margin: 10px 0;
}
.cortar span {
  background: var(--bg-page);
  padding: 0 10px;
  position: relative;
  top: -8px;
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  transition: background 0.3s ease, color 0.3s ease;
}

/* --- 5. TEMAS E VARIAÇÕES --- */
.ink-black {
  --ink-color: #000000;
}
.ink-navy {
  --ink-color: #1e3a8a;
}
.ink-forest {
  --ink-color: #14532d;
}
.ink-wine {
  --ink-color: #881337;
}
.ink-slate {
  --ink-color: #334155;
}
.ink-gold {
  --ink-color: #b45309;
}
.ink-blue {
  --ink-color: #2563eb;
}
.ink-grey {
  --ink-color: #4b5563;
}
.ink-cyan {
  --ink-color: #0891b2;
}
.ink-brown {
  --ink-color: #78350f;
}
.ink-dark {
  --ink-color: #0f172a;
}

.paper-white {
  background-color: #ffffff;
}
.paper-warm {
  background-color: #fafaf9;
}
.paper-blue {
  background-color: #f0f9ff;
}
.paper-gray {
  background-color: #f8fafc;
}
.paper-grid {
  background-color: #f0f9ff;
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
}
.paper-cream {
  background-color: #fefce8;
}
.paper-pastel {
  background-color: #fdf4ff;
}
.paper-vintage {
  background-color: #fef3c7;
}

.f-sans {
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.f-serif {
  font-family: "Georgia", "Times New Roman", serif;
}
.f-mono {
  font-family: "Courier New", monospace;
  letter-spacing: -0.5px;
}

.b-simple {
  border: 1px solid #000;
}
.b-double {
  border: 4px double var(--ink-color);
}
.b-thick-left {
  border-left: 12px solid var(--ink-color);
  background: linear-gradient(90deg, #fafafa 0%, #fff 100%);
}
.b-modern {
  border-top: 6px solid var(--ink-color);
  border-bottom: 1px solid #ddd;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.04);
}
.b-corner {
  border: 2px solid var(--ink-color);
  border-radius: 16px;
}
.b-gold-frame {
  border: 4px solid #fcd34d;
  border-radius: 0;
  outline: 2px solid #b45309;
  outline-offset: -8px;
}
.b-ticket {
  border: 2px solid var(--ink-color);
  border-left: 8px dotted var(--ink-color);
  border-right: 8px dotted var(--ink-color);
  border-radius: 12px;
}
.b-left-bar {
  border-left: 15px solid var(--ink-color);
  background: #fff;
}

.b-bw-classic {
  border: 3px double #000;
}
.b-bw-bold {
  border: 4px solid #000;
}
.b-bw-dotted {
  border: 2px dashed #000;
  border-radius: 8px;
}
.b-bw-minimal {
  border: 1px solid #000;
  border-top: 8px solid #000;
}
.b-bw-retro {
  border: 2px solid #000;
  border-radius: 0;
  box-shadow: 5px 5px 0px #ccc;
}
.b-bw-clean {
  border: 1px solid #000;
  border-left: 5px solid #000;
}
.b-bw-sharp {
  border: 2px solid #000;
  border-radius: 0;
  outline: 1px solid #000;
  outline-offset: 4px;
}

.b-neon {
  border: 2px solid var(--ink-color);
  box-shadow: 0 0 10px rgba(8, 145, 178, 0.3);
}
.b-pastel {
  border: 3px solid #fbcfe8;
  border-radius: 20px;
}
.b-vintage {
  border: 4px double var(--ink-color);
  background-image: radial-gradient(#d4d4d8 1px, transparent 1px);
  background-size: 15px 15px;
}
.b-corporate {
  border-top: 8px solid var(--ink-color);
  border-bottom: 2px solid var(--ink-color);
}

.v-box {
  border: 1px solid var(--ink-color);
  padding: 5px 15px;
  border-radius: 6px;
}
.v-fill {
  background: var(--ink-color);
  color: #fff;
  padding: 5px 15px;
  border-radius: 6px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact; /* Padrão moderno */
}
.v-lines {
  border-top: 1px solid var(--ink-color);
  border-bottom: 1px solid var(--ink-color);
  padding: 2px 0;
}
.v-plain {
  /* Intencionalmente vazio - remove qualquer estilo anterior */
  background: transparent;
  padding: 0;
  border: none;
}
.v-bw {
  background: #000;
  color: #fff !important;
  padding: 2px 10px;
  font-family: monospace;
}

#statusMsg {
  width: 100%;
  margin-top: 15px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}
.dev-footer {
  text-align: center;
  margin-top: 40px;
  padding-top: 20px;
  color: var(--text-muted);
  font-size: 12px;
}
.dev-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
