:root {
  --bg: #07111f;
  --surface: #0a1a33;
  --card: #101b2d;
  --text: #eaf0ff;
  --muted: #94a3b8;
  --blue: #0052ff;
  --green: #22c55e;
  --danger: #ef4444;
  --border: rgba(255,255,255,.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: radial-gradient(circle at top left, rgba(0, 82, 255, .25), transparent 34%), var(--bg);
  color: var(--text);
}

a { color: inherit; }

.container {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--blue);
  color: white;
  font-weight: 900;
}

h1, h2, h3, p { margin-top: 0; }

.muted { color: var(--muted); }

.card {
  background: rgba(16, 27, 45, .86);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .24);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

label {
  color: var(--muted);
  font-size: 14px;
}

input, select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  background: rgba(7, 17, 31, .88);
  color: var(--text);
  border-radius: 14px;
  outline: none;
  font-size: 16px;
}

button, .button {
  border: none;
  border-radius: 14px;
  padding: 13px 16px;
  background: var(--blue);
  color: white;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.secondary, .button.secondary {
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.status.ok { color: #bbf7d0; background: rgba(34,197,94,.12); }
.status.error { color: #fecaca; background: rgba(239,68,68,.12); }

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.dashboard {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 32px;
}

.dashboard-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.dashboard-title h1 {
  font-size: clamp(36px, 5vw, 76px);
  letter-spacing: -0.06em;
  margin-bottom: 4px;
}

.big-card {
  margin-top: 28px;
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 24px;
}

.main-number {
  font-size: clamp(68px, 10vw, 170px);
  line-height: .88;
  font-weight: 950;
  letter-spacing: -0.08em;
  margin: 16px 0 24px;
}

.progress-wrap {
  width: 100%;
  height: 28px;
  background: rgba(255,255,255,.08);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  border-radius: 999px;
  transition: width .4s ease;
}

.kpis {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.kpi {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}

.kpi strong {
  font-size: clamp(26px, 3vw, 44px);
  letter-spacing: -0.04em;
}

.footer-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  margin-top: 24px;
}

.error-box {
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .3);
  color: #fecaca;
  padding: 16px;
  border-radius: 16px;
  margin-bottom: 16px;
  display: none;
}

@media (max-width: 900px) {
  .grid, .big-card { grid-template-columns: 1fr; }
  .dashboard { padding: 18px; }
  .dashboard-top, .footer-line { flex-direction: column; align-items: flex-start; }
}

.debug-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.debug-table th,
.debug-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.debug-table th {
  color: var(--muted);
  font-size: 13px;
}

.sales-feed-card {
  max-height: 315px;
  overflow: hidden;
}

.sales-feed-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sales-feed-title span {
  margin-bottom: 0;
}

.sales-feed-title small {
  color: #bbf7d0;
  background: rgba(34, 197, 94, .12);
  border: 1px solid rgba(34, 197, 94, .25);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.sales-feed-list {
  display: grid;
  gap: 8px;
  max-height: 250px;
  overflow: hidden;
}

.sale-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: rgba(7, 17, 31, .58);
  border-radius: 14px;
}

.sale-row.new-sale {
  animation: saleFlash 2.4s ease-out;
}

.sale-main {
  min-width: 0;
}

.sale-number {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 14px;
}

.sale-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(34, 197, 94, .12);
  flex: 0 0 auto;
}

.sale-customer {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sale-value {
  font-size: 18px;
  font-weight: 950;
  letter-spacing: -0.03em;
  text-align: right;
  white-space: nowrap;
}

.sale-date {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
  margin-top: 3px;
}

.sale-empty {
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 14px;
}

@keyframes saleFlash {
  0% {
    border-color: rgba(34, 197, 94, .75);
    background: rgba(34, 197, 94, .18);
    transform: translateY(-3px);
  }
  100% {
    border-color: var(--border);
    background: rgba(7, 17, 31, .58);
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .big-card { grid-template-columns: 1fr; }
  .sales-feed-card { max-height: none; }
  .sales-feed-list { max-height: none; }
}

.top-actions { margin-top: 0; }

.reconciliation-page {
  width: min(1480px, calc(100% - 32px));
}

.reconciliation-filters {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 16px;
  align-items: end;
}

.reconciliation-filters .form-group { margin-bottom: 0; }
.reconciliation-filters button { min-height: 48px; }
.reconciliation-filters button:disabled { cursor: wait; opacity: .65; }
.reconciliation-filters + .status { margin-top: 20px; }
.reconciliation-results { margin-top: 20px; }

.reconciliation-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.reconciliation-kpis .kpi strong { font-size: clamp(28px, 3vw, 42px); }
.kpi-paid { border-color: rgba(34, 197, 94, .42); }
.kpi-unpaid { border-color: rgba(239, 68, 68, .48); }
.kpi-awaiting { border-color: rgba(59, 130, 246, .42); }
.kpi-overdue { border-color: rgba(239, 68, 68, .64); }
.kpi-divergent { border-color: rgba(245, 158, 11, .46); }
.kpi-missing { border-color: rgba(239, 68, 68, .48); }
.kpi-fatura { border-color: rgba(249, 115, 22, .42); }

.reconciliation-table-card { padding: 20px; }
.result-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.result-toolbar h2 { margin-bottom: 6px; }
.result-toolbar p { margin-bottom: 0; }
.result-actions { display: flex; align-items: end; gap: 10px; flex: 0 0 auto; }
.compact-filter { width: min(220px, 100%); margin-bottom: 0; flex: 0 0 auto; }
.export-button { min-height: 48px; white-space: nowrap; }
.print-metadata { display: none; }
.table-scroll { overflow: auto; margin-top: 16px; }
.reconciliation-table { margin-top: 0; min-width: 1180px; }
.reconciliation-table td { vertical-align: top; }
.reconciliation-table td small { display: block; color: var(--muted); margin-top: 4px; }
.reconciliation-table th { padding: 0; }

.sort-button {
  width: 100%;
  min-height: 44px;
  padding: 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  justify-content: flex-start;
  white-space: nowrap;
  font-size: 13px;
}

.sort-button:hover,
.sort-button:focus-visible {
  color: var(--text);
  background: rgba(255, 255, 255, .05);
}

.sort-button span {
  color: #93c5fd;
  font-size: 15px;
}
.company-cell { min-width: 230px; white-space: normal !important; }
.observation-cell { min-width: 240px; white-space: normal !important; color: var(--muted); }

.reconciliation-badge {
  display: inline-flex;
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-paid { color: #bbf7d0; background: rgba(34, 197, 94, .15); border-color: rgba(34, 197, 94, .3); }
.badge-unpaid { color: #fecaca; background: rgba(239, 68, 68, .15); border-color: rgba(239, 68, 68, .3); }
.badge-awaiting { color: #bfdbfe; background: rgba(59, 130, 246, .15); border-color: rgba(59, 130, 246, .3); }
.badge-overdue { color: #fecaca; background: rgba(239, 68, 68, .2); border-color: rgba(239, 68, 68, .42); }
.badge-divergent { color: #fde68a; background: rgba(245, 158, 11, .15); border-color: rgba(245, 158, 11, .3); }
.badge-missing { color: #fecaca; background: rgba(239, 68, 68, .15); border-color: rgba(239, 68, 68, .3); }
.badge-cell { white-space: normal !important; min-width: 210px; }
.payment-badge { margin-left: 6px; }
.row-missing { background: rgba(239, 68, 68, .035); }
.row-overdue { background: rgba(239, 68, 68, .055); }
.row-awaiting { background: rgba(59, 130, 246, .025); }
.row-divergent { background: rgba(245, 158, 11, .035); }
.empty-table { text-align: center !important; color: var(--muted); padding: 32px !important; }
.security-note { color: var(--muted); font-size: 13px; margin: 18px 4px 0; }
.security-note code { color: var(--text); }

@media (max-width: 1000px) {
  .reconciliation-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .reconciliation-filters { grid-template-columns: 1fr; }
  .result-toolbar { align-items: stretch; flex-direction: column; }
  .compact-filter { width: 100%; }
  .result-actions { width: 100%; align-items: stretch; flex-direction: column; }
  .reconciliation-kpis { grid-template-columns: 1fr; }
}

/* Menu superior */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px max(16px, calc((100% - 1400px) / 2));
  background: rgba(7, 17, 31, .92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.app-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.app-nav-brand .logo-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }

.app-nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.app-nav-links a {
  padding: 9px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.app-nav-links a:hover { color: var(--text); background: rgba(255,255,255,.06); }
.app-nav-links a.active { color: var(--text); background: rgba(0, 82, 255, .28); }

.app-nav-user { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }
.app-nav-user button { padding: 8px 14px; border-radius: 10px; font-size: 14px; }

@media (max-width: 760px) {
  .app-nav { flex-wrap: wrap; gap: 8px 16px; }
  .app-nav-links { order: 3; flex-basis: 100%; }
  .app-nav-user { margin-left: auto; }
  .app-nav-user #navUsername { display: none; }
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card { width: min(400px, 100%); }
.login-card .logo { margin-bottom: 24px; }
.login-card h1 { margin-bottom: 2px; font-size: 24px; }
.login-card p { margin-bottom: 0; }
.login-card button { width: 100%; margin-top: 8px; }
.login-card button:disabled { cursor: wait; opacity: .65; }

/* Faturas */
textarea {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  background: rgba(7, 17, 31, .88);
  color: var(--text);
  border-radius: 14px;
  outline: none;
  font: inherit;
  font-size: 15px;
  resize: vertical;
}

a.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 14px;
  font-weight: 800;
  text-decoration: none;
  background: var(--blue);
  color: white;
}
a.button-link.secondary { background: rgba(255,255,255,.08); border: 1px solid var(--border); }
button.danger { color: #fecaca; border-color: rgba(239, 68, 68, .4); }

.faturas-page { width: min(1240px, calc(100% - 32px)); }
.fatura-editor { margin-bottom: 20px; border-color: rgba(0, 82, 255, .45); }
.fatura-grid { display: grid; grid-template-columns: 180px 180px 1fr; gap: 0 16px; }
.fatura-grid-wide { grid-column: 1 / -1; }
.fatura-section-title { margin: 8px 0 4px; }
.fatura-help { font-size: 13px; margin-bottom: 0; }
.fatura-items-table { min-width: 760px; }
.fatura-items-table td { white-space: normal; vertical-align: middle; padding: 8px; }
.fatura-items-table input { padding: 10px 12px; font-size: 15px; }
.fatura-items-table td:nth-child(2) { width: 120px; }
.fatura-items-table td:nth-child(3) { width: 150px; }
.fatura-items-table td:nth-child(4) { width: 150px; }
.fatura-items-table td:nth-child(5) { width: 56px; }
.fatura-items-table tfoot td { border-bottom: 0; }
.item-remove { padding: 8px 12px; }
.fatura-notes { margin-top: 16px; }
.debug-table .num { text-align: right; }
.faturas-table { min-width: 860px; }
.faturas-table small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.row-actions { display: flex; gap: 6px; }
.row-actions button, .row-actions a.button-link { padding: 8px 12px; font-size: 13px; }
.badge-fatura { color: #fed7aa; background: rgba(249, 115, 22, .15); border-color: rgba(249, 115, 22, .35); }
.portal-only-card { margin-top: 20px; }

@media (max-width: 760px) {
  .fatura-grid { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4 landscape; margin: 9mm; }

  :root { --text: #111827; --muted: #475569; --border: #cbd5e1; }

  body {
    min-height: auto;
    background: #fff;
    color: #111827;
    font-family: Arial, sans-serif;
  }

  .reconciliation-page {
    width: 100%;
    padding: 0;
  }

  .header { margin-bottom: 12px; }
  .header h1 { font-size: 24px; margin-bottom: 4px; }
  .app-nav,
  .header nav,
  .query-card,
  .result-actions,
  .security-note { display: none !important; }

  .reconciliation-results { margin-top: 0; }
  .reconciliation-kpis { grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 12px; }
  .reconciliation-kpis .kpi { padding: 8px; border: 1px solid #cbd5e1; background: #f8fafc; }
  .reconciliation-kpis .kpi span { color: #475569; font-size: 9px; margin-bottom: 3px; }
  .reconciliation-kpis .kpi strong { color: #111827; font-size: 19px; }

  .card {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
    box-shadow: none;
  }

  .result-toolbar { display: block; }
  .result-toolbar h2 { font-size: 17px; margin-bottom: 3px; }
  .result-toolbar .muted { color: #475569; font-size: 9px; }
  .print-metadata { display: block !important; color: #475569; font-size: 9px; margin-top: 3px; }
  .table-scroll { overflow: visible; margin-top: 8px; }

  .reconciliation-table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
    font-size: 7.5px;
  }

  .reconciliation-table th,
  .reconciliation-table td {
    padding: 4px;
    border-bottom: 1px solid #cbd5e1;
    white-space: normal;
    color: #111827;
  }

  .reconciliation-table th:nth-child(1) { width: 7%; }
  .reconciliation-table th:nth-child(2) { width: 8%; }
  .reconciliation-table th:nth-child(3) { width: 18%; }
  .reconciliation-table th:nth-child(4) { width: 9%; }
  .reconciliation-table th:nth-child(5) { width: 17%; }
  .reconciliation-table th:nth-child(6) { width: 9%; }
  .reconciliation-table th:nth-child(7) { width: 9%; }
  .reconciliation-table th:nth-child(8) { width: 23%; }

  .sort-button {
    min-height: 0;
    padding: 4px;
    color: #111827;
    font-size: 8px;
  }

  .sort-button span { display: none; }
  .reconciliation-table td small { color: #475569; font-size: 6.5px; }
  .company-cell,
  .observation-cell,
  .badge-cell { min-width: 0; }

  .reconciliation-badge {
    padding: 2px 4px;
    font-size: 6.5px;
    color: #111827;
    background: #fff;
    border-color: #94a3b8;
  }

  .reconciliation-row { break-inside: avoid; }
}

/* Resumo do período */
.period-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.period-presets button { min-height: 36px; padding: 6px 14px; font-size: 14px; }
.summary-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.summary-kpi strong { display: block; font-size: clamp(24px, 2.6vw, 36px); }
.summary-kpi small { display: block; color: var(--muted); font-size: 13px; margin-top: 8px; line-height: 1.4; }
.kpi-taxes { border-color: rgba(245, 158, 11, .46); }
.summary-alerts { display: grid; gap: 8px; margin-bottom: 20px; }
.summary-alerts:empty { display: none; }
.summary-alert { border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; font-size: 14px; }
.alert-danger { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .35); color: #fecaca; }
.alert-warning { background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .35); color: #fde68a; }
.alert-info { background: rgba(59, 130, 246, .1); border-color: rgba(59, 130, 246, .3); color: #bfdbfe; }
.summary-section { margin-top: 20px; }
.summary-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.value-danger { color: #fca5a5; }
.month-bars {
  display: flex;
  align-items: stretch;
  gap: 12px;
  height: 220px;
  margin: 20px 0;
  overflow-x: auto;
}
.month-bars:empty { display: none; }
.month-bar { flex: 0 1 110px; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 64px; }
.month-bar-value { font-size: 12px; color: var(--muted); white-space: nowrap; }
.month-bar-track {
  flex: 1;
  width: 100%;
  max-width: 72px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(255,255,255,.03);
  border-radius: 10px;
  overflow: hidden;
}
.month-bar-paid { background: var(--green); }
.month-bar-pending { background: var(--danger); opacity: .8; }
.month-bar-label { font-size: 13px; }

@media (max-width: 1000px) {
  .summary-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .summary-kpis { grid-template-columns: 1fr; }
}
