/* Painel Funil Tracker — tokens claro/escuro, sem dependências externas. */

:root {
  color-scheme: light;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b2330;
  --muted: #5b6577;
  --border: #d5dae3;
  --accent: #1f5fbf;
  --accent-contrast: #ffffff;
  --accent-soft: #e7effc;
  --danger: #b3261e;
  --danger-soft: #fbeae9;
  --ok: #1a7f4b;
  --ok-soft: #e6f4ec;
  --warn: #8a6100;
  --warn-soft: #fdf3dd;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12161d;
    --surface: #1a202a;
    --surface-2: #222a36;
    --text: #e8ecf3;
    --muted: #9aa5b5;
    --border: #313a48;
    --accent: #6ea3f5;
    --accent-contrast: #10151d;
    --accent-soft: #1e2c44;
    --danger: #f2857c;
    --danger-soft: #3a1f1d;
    --ok: #63d19a;
    --ok-soft: #163226;
    --warn: #e8bd63;
    --warn-soft: #3a2f14;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161d;
  --surface: #1a202a;
  --surface-2: #222a36;
  --text: #e8ecf3;
  --muted: #9aa5b5;
  --border: #313a48;
  --accent: #6ea3f5;
  --accent-contrast: #10151d;
  --accent-soft: #1e2c44;
  --danger: #f2857c;
  --danger-soft: #3a1f1d;
  --ok: #63d19a;
  --ok-soft: #163226;
  --warn: #e8bd63;
  --warn-soft: #3a2f14;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

.muted { color: var(--muted); }
.num { text-align: right; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Layout */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.footer {
  text-align: center;
  padding: 14px 16px 28px;
  font-size: 0.85rem;
}

/* Botões */
.btn {
  font: inherit;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-outline {
  background: transparent;
  border-color: var(--border);
}

.btn-outline:hover:not(:disabled) { background: var(--surface-2); }

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

.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn-block { width: 100%; }

/* Filtros */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

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

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

.field input,
.field select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}

.field input:focus-visible,
.field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-action { justify-content: flex-end; }

.field input:disabled,
.field select:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.toggle-caption {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  cursor: pointer;
  min-height: 38px;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Status */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}

.status-bar.is-stale { color: var(--warn); }
.status-bar.is-loading { color: var(--muted); }

.error-box {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.9rem;
  font-weight: 700;
  margin-top: 6px;
}

.kpi-note {
  font-size: 0.78rem;
  margin-top: 6px;
}

/* Painéis e tabelas */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.table-wrap { overflow-x: auto; min-width: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tbody tr:hover { background: var(--surface-2); }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

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

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-muted { background: var(--surface-2); color: var(--muted); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.empty {
  color: var(--muted);
  padding: 14px 4px 4px;
  margin: 0;
  font-size: 0.92rem;
}

/* Paginação */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-top: 14px;
}

/* Diálogo de histórico */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 18px;
  width: min(860px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  overflow: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

dialog::backdrop { background: rgba(10, 14, 20, 0.55); }

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.dialog-head h2 { margin: 0; font-size: 1.1rem; }

.history-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin: 10px 0 14px;
  font-size: 0.9rem;
  min-width: 0;
}

.history-meta div {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-wrap: anywhere;
  min-width: 0;
}

.history-meta .k {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

/* Login */
.login-body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-main { width: 100%; max-width: 380px; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 22px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}

.login-card .error-box { margin: 0; }

/* Responsivo */
@media (max-width: 720px) {
  .container { padding: 14px 16px 32px; }
  .kpi-value { font-size: 1.55rem; }
  .filters { grid-template-columns: 1fr 1fr; }
  .field-action { grid-column: 1 / -1; }
  .field-action .btn { width: 100%; }
  th, td { padding: 8px 7px; }
}

@media (max-width: 460px) {
  .filters { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; }
}
