/* ============================================================
   GERADOR DE DECLARAÇÃO DE FATURAMENTO — DESIGN SYSTEM
   Paleta e tipografia fixas — não alterar valores das variáveis.
   ============================================================ */

:root {
  /* Base */
  --bg: #0A1016;
  --panel: #121B23;
  --panel-2: #17222B;
  --line: #223140;

  /* Texto */
  --text: #E7EEF3;
  --muted: #8AA0B3;
  --muted-2: #5C7386;

  /* Status e ação */
  --cyan: #4FD1E8;
  --green: #34D399;
  --red: #F87171;
  --avulsa: #FFD400;

  /* Tipografia */
  --font-sans: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  /* Métrica */
  --radius: 10px;
  --radius-sm: 8px;
  --radius-lg: 12px;
}

/* ============================================================
   RESET / BASE
   ============================================================ */

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  color: var(--text);
}

.mono { font-family: var(--font-mono); }

::selection { background: var(--cyan); color: var(--bg); }

/* Foco visível sempre presente para acessibilidade */
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ============================================================
   TOPBAR
   ============================================================ */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}

.brand-text h1 {
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
}

.brand-text p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--avulsa);
  flex: 0 0 auto;
}

.status-dot.saved { background: var(--green); }
.status-dot.error { background: var(--red); }

.topbar-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

/* ============================================================
   BOTÕES
   ============================================================ */

.btn {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  transition: filter 0.12s ease, transform 0.05s ease;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #06181F;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--muted-2);
  cursor: not-allowed;
  filter: none;
}

.btn-secondary {
  background: var(--panel-2);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--cyan); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text); border-color: var(--line); }

.btn-success {
  background: var(--green);
  border-color: var(--green);
  color: #06231A;
}
.btn-success:hover { filter: brightness(1.08); }

.btn-danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

/* ============================================================
   LAYOUT
   ============================================================ */

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 69px);
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 69px;
  height: calc(100vh - 69px);
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.step-item:hover {
  background: var(--panel-2);
  color: var(--text);
}

.step-item.active {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--cyan);
}

.step-num {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted-2);
}

.step-item.active .step-num {
  border-color: var(--cyan);
  color: var(--cyan);
}

.step-item.complete .step-num {
  background: var(--green);
  border-color: var(--green);
  color: #06231A;
}

.step-label { flex: 1; }

.step-flag {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.step-flag.ok { background: var(--green); }
.step-flag.pending { background: var(--avulsa); }

.sidebar-total {
  margin-top: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-total-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.sidebar-total-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--cyan);
}

.sidebar-total-hint {
  font-size: 11px;
  color: var(--muted-2);
}

.build-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted-2);
  text-align: center;
  opacity: 0.6;
  margin-top: 10px;
}

/* ============================================================
   CONTENT / PANELS
   ============================================================ */

.content {
  padding: 28px 32px 60px;
  max-width: 980px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: panel-in 0.15s ease;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-header {
  margin-bottom: 22px;
}

.panel-header h2 {
  font-size: 19px;
  color: var(--text);
}

.panel-header p {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* ============================================================
   FORMULÁRIOS
   ============================================================ */

.cnpj-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  background: var(--panel);
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 30px 24px;
  margin-bottom: 18px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cnpj-dropzone:hover {
  border-color: var(--cyan);
}

.cnpj-dropzone.dragover {
  border-color: var(--cyan);
  background: rgba(79, 209, 232, 0.06);
}

.cnpj-dropzone.success {
  border-color: var(--green);
}

.cnpj-dropzone.error {
  border-color: var(--red);
}

.cnpj-dropzone-compact {
  padding: 16px 22px;
  margin-bottom: 18px;
  gap: 6px;
}

.cnpj-dropzone-icon {
  width: 34px;
  height: 34px;
  color: var(--cyan);
}

.cnpj-dropzone-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
}

.cnpj-dropzone-subtitle {
  font-size: 12.5px;
  color: var(--muted);
  max-width: 480px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-span-2 { grid-column: span 2; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.req { color: var(--red); }

.field input,
.field select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--text);
  transition: border-color 0.12s ease;
}

.field input::placeholder { color: var(--muted-2); }

.field input:focus,
.field select:focus {
  border-color: var(--cyan);
  outline: none;
}

.field input.invalid,
.field select.invalid {
  border-color: var(--red);
}

.field-error {
  font-size: 11px;
  color: var(--red);
  min-height: 14px;
}

.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2px 0;
}

.hint {
  font-size: 12px;
  color: var(--muted-2);
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.footer-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

/* ============================================================
   FATURAMENTO — CONTROLES E TABELA
   ============================================================ */

.fat-controls {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.fat-controls .field { width: 220px; }

.fat-controls input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 13.5px;
}

.csv-hint {
  font-size: 12px;
  color: var(--muted-2);
  margin: -6px 0 18px;
  line-height: 1.6;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.fat-table {
  width: 100%;
  border-collapse: collapse;
}

.fat-table thead th {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.th-valor { text-align: right; }

.fat-table tbody tr {
  border-bottom: 1px solid var(--line);
}

.fat-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

.fat-table tbody tr:last-child { border-bottom: none; }

.fat-table td {
  padding: 10px 18px;
  font-size: 13.5px;
}

.fat-month-cell {
  color: var(--text);
  font-weight: 500;
  text-transform: capitalize;
}

.fat-value-cell { text-align: right; }

.fat-value-cell input {
  width: 160px;
  text-align: right;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}

.fat-value-cell input:focus {
  border-color: var(--cyan);
  outline: none;
}

.fat-value-cell input.invalid {
  border-color: var(--red);
}

.fat-empty-row td {
  text-align: center;
  color: var(--muted-2);
  padding: 30px;
  font-size: 13px;
}

.fat-total-row td {
  background: var(--panel-2);
  font-weight: 700;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.fat-total-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.fat-total-value {
  text-align: right;
  color: var(--cyan);
  font-size: 17px;
}

.fat-warning {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(255, 212, 0, 0.08);
  border: 1px solid var(--avulsa);
  border-radius: var(--radius-sm);
  color: var(--avulsa);
  font-size: 12.5px;
}

/* ============================================================
   VALIDATION BANNER (preview)
   ============================================================ */

.validation-banner {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  color: var(--text);
  font-size: 13px;
}

.validation-banner strong { color: var(--red); }

.validation-banner ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.validation-banner li { margin-bottom: 3px; }

/* ============================================================
   DOCUMENTO — PRÉ-VISUALIZAÇÃO / IMPRESSÃO
   ============================================================ */

.doc-frame {
  display: flex;
  justify-content: center;
  padding: 20px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.doc-a4 {
  width: 210mm;
  max-width: 100%;
  background: #FFFFFF;
  color: #14202B;
  padding: 20mm 18mm;
  font-family: var(--font-sans);
  font-size: 15px;
  box-shadow: 0 0 0 1px var(--line);
  box-sizing: border-box;
}

.doc-header {
  text-align: center;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 2.5px solid #14202B;
}

.doc-header h3 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #14202B;
}

.doc-paragraph {
  font-size: 15.5px;
  line-height: 1.75;
  text-align: justify;
  color: #1B2A38;
  margin-bottom: 18px;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
  font-size: 15px;
}

.doc-table th,
.doc-table td {
  border: 1px solid #C7D2DA;
  padding: 9px 14px;
}

.doc-table th {
  background: #EEF3F6;
  text-align: left;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #33475A;
}

.doc-table td:last-child,
.doc-table th:last-child {
  text-align: right;
  font-family: var(--font-mono);
}

.doc-total-row td {
  font-weight: 700;
  font-size: 15.5px;
  background: #EEF3F6;
}

.doc-local {
  font-size: 15.5px;
  margin-bottom: 22px;
  color: #1B2A38;
}

.doc-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 6px;
}

.doc-sign-block {
  text-align: center;
  min-width: 0;
}

.doc-sign-slot {
  height: 38px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.doc-sign-image {
  display: block;
  height: 36px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

.doc-sign-line {
  border-top: 1.5px solid #14202B;
  margin-bottom: 8px;
}

.doc-sign-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #14202B;
}

.doc-sign-role {
  font-size: 13px;
  color: #4A5D6E;
  margin-top: 3px;
}

.doc-sign-doc {
  font-size: 12.5px;
  font-family: var(--font-mono);
  color: #4A5D6E;
  margin-top: 4px;
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text);
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toast-in 0.18s ease;
}

.toast.error { border-left-color: var(--red); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   RESPONSIVIDADE
   ============================================================ */

@media (max-width: 980px) {
  .content { max-width: 100%; }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px 14px;
  }

  .steps {
    flex-direction: row;
    gap: 6px;
  }

  .step-label { display: none; }

  .sidebar-total {
    margin-top: 0;
    margin-left: auto;
    flex: 0 0 auto;
  }

  .content { padding: 20px 16px 60px; }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .topbar-status { order: 3; margin-left: 0; }
  .topbar-actions { order: 4; flex-wrap: wrap; }

  .brand-text p { display: none; }

  .form-grid {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .field-span-2 { grid-column: span 1; }

  .fat-controls { flex-direction: column; align-items: stretch; }
  .fat-controls .field { width: 100%; }

  .fat-value-cell input { width: 120px; }

  .doc-a4 { padding: 14mm 10mm; }

  .doc-signatures { grid-template-columns: 1fr; gap: 30px; }

  .panel-footer { flex-wrap: wrap; }
  .footer-actions { width: 100%; justify-content: flex-end; }
}

@media (max-width: 420px) {
  .fat-table thead th:first-child,
  .fat-table td.fat-month-cell { padding-left: 12px; }
  .fat-table th, .fat-table td { padding: 8px 10px; }
  .fat-value-cell input { width: 100px; font-size: 12px; }
}

/* ============================================================
   IMPRESSÃO
   ============================================================ */

@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 210mm;
    max-height: 297mm;
    overflow: hidden;
    box-shadow: none;
  }
  @page { size: A4; margin: 0; }
}
