/* VELTIS Gestão — layout adaptativo: celular primeiro, expandido no PC. */

:root {
  --text-scale: 1;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eceff7;
  --text: #0b0e18;
  --muted: #3b4256;
  --border: #aab1c4;
  --primary: #2c3cb0;
  --primary-text: #ffffff;
  --ok: #0f6a3e;
  --warn: #9a6200;
  --danger: #b3261e;
  --critical-bg: #fde8e6;
  --warn-bg: #fff4d6;
  --ok-bg: #e4f5ec;
  --radius: 12px;
  --logo-bg: #0b0e18;
  --logo-border: #aab1c4;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 4px 14px rgba(20, 24, 40, 0.05);
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1119;
    --surface: #181b27;
    --surface-2: #222636;
    --text: #e9ecf5;
    --muted: #c9cfe2;
    --border: #4d5474;
    --primary: #8394ff;
    --primary-text: #0c0f1e;
    --ok: #6fd69a;
    --warn: #f2c35e;
    --danger: #ff8d84;
    --critical-bg: #3a1c1a;
    --warn-bg: #3a2f14;
    --ok-bg: #16301f;
    --shadow: none;
    --logo-bg: transparent;
    --logo-border: transparent;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1119;
  --surface: #181b27;
  --surface-2: #222636;
  --text: #e9ecf5;
  --muted: #c9cfe2;
  --border: #4d5474;
  --primary: #8394ff;
  --primary-text: #0c0f1e;
  --ok: #6fd69a;
  --warn: #f2c35e;
  --danger: #ff8d84;
  --critical-bg: #3a1c1a;
  --warn-bg: #3a2f14;
  --ok-bg: #16301f;
  --shadow: none;
  --logo-bg: transparent;
  --logo-border: transparent;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--text-scale, 1)); }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 1.375rem; }
h2 { font-size: 1.0625rem; }
h3 { font-size: 0.9375rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Barra superior e navegação ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; letter-spacing: 0.04em; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand span { color: var(--primary); font-weight: 600; }
.nav { display: none; gap: 4px; }
.nav a, .bottom-nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted);
  min-height: 40px;
}
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me-name { font-size: 0.8125rem; color: var(--muted); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 0.75rem; font-weight: 700; text-align: center; line-height: 20px;
}

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex-direction: column; justify-content: center; gap: 0;
  font-size: 0.75rem; min-height: 52px; padding: 4px; border-radius: 10px;
}
.bottom-nav a[aria-current="page"] { color: var(--primary); font-weight: 700; background: var(--surface-2); }

/* ---------- Estrutura ---------- */
.container {
  max-width: 1280px; margin: 0 auto;
  padding: 16px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin-right: auto; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.grid-kpi { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 18px 0 8px; }

@media (min-width: 900px) {
  .topbar { padding: 10px 24px; }
  .nav { display: flex; margin-left: 12px; }
  .bottom-nav { display: none !important; }
  .container { padding: 24px 24px 40px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
  .grid-kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
  .me-name { max-width: 240px; }
  .card { padding: 18px; }
}

/* ---------- Formulários e botões (alvo de toque >= 44px) ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8125rem; color: var(--muted); min-width: 0; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
  max-width: 100%;
}
textarea { resize: vertical; min-height: 88px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn {
  font: inherit; cursor: pointer; border-radius: 10px; padding: 10px 16px; min-height: 44px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.form-error { color: var(--danger); margin: 0; font-size: 0.875rem; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-items: end; }
@media (min-width: 900px) { .inline-form { grid-template-columns: 2fr 1fr 1fr auto; } }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto;
}
dialog::backdrop { background: rgba(10, 12, 20, 0.55); }

/* ---------- Login ---------- */
.auth-wrap { min-height: 80vh; display: grid; place-items: center; }
.auth-card { width: min(380px, 100%); }

/* ---------- Painel ---------- */
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .value { font-size: 1.625rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.kpi .label { font-size: 0.8125rem; color: var(--muted); }
.kpi.danger .value { color: var(--danger); }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }

.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
}
.alert.critico { background: var(--critical-bg); border-color: transparent; }
.alert.atencao { background: var(--warn-bg); border-color: transparent; }
.alert .sev { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.alert.critico .sev { color: var(--danger); }
.alert.atencao .sev { color: var(--warn); }
.alert .msg { font-weight: 600; }
.alert a { text-decoration: none; color: var(--text); }
.alert a:hover { text-decoration: underline; }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 130px) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 0.8125rem; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--primary); width: 0; transition: width 0.4s ease; }
.bar-fill.ok { background: var(--ok); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }

.columns-chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 6px; }
.columns-chart .col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.columns-chart .pair { flex: 1 1 0; min-height: 0; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.columns-chart .stack-bar { width: 45%; max-width: 14px; background: var(--primary); border-radius: 6px 6px 2px 2px; height: 0; transition: height 0.4s ease; }
.columns-chart .stack-bar.delivered { background: var(--ok); }
.columns-chart .day { font-size: 0.625rem; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 12px; font-size: 0.75rem; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; background: var(--primary); }
.legend i.delivered { background: var(--ok); }

/* ---------- Tabelas que viram cartões no celular ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: var(--surface); }
  .table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 0.75rem; }
}

/* ---------- Funil (quadro) ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; width: 100%; }
.toolbar input[type="search"] { flex: 1 1 200px; }
.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: 78vw;
  gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; -webkit-overflow-scrolling: touch;
}
@media (min-width: 900px) {
  .board { grid-auto-columns: minmax(230px, 1fr); overflow-x: visible; scroll-snap-type: none; }
}
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; scroll-snap-align: start; }
.column-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.column-head h3 { margin: 0; font-size: 0.875rem; }
.count { font-size: 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; }
.column.lost { opacity: 0.75; }
.cards { display: flex; flex-direction: column; gap: 8px; }
.deal {
  display: block; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
}
.deal:hover { border-color: var(--primary); }
.deal-client { font-size: 0.75rem; color: var(--muted); }
.deal-title { font-weight: 600; margin: 2px 0 6px; }
.deal-meta { font-size: 0.75rem; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); width: 0; }
.sla-chip { font-size: 0.6875rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.sla-chip.ok { background: var(--ok-bg); color: var(--ok); }
.sla-chip.atencao { background: var(--warn-bg); color: var(--warn); }
.sla-chip.critico { background: var(--critical-bg); color: var(--danger); }
.empty { color: var(--muted); font-size: 0.875rem; padding: 10px; text-align: center; }

/* ---------- Listas, passos e linha do tempo ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.list-item .main { min-width: 0; flex: 1 1 220px; }
.list-item a { text-decoration: none; color: var(--text); font-weight: 600; }
.tag {
  display: inline-block; font-size: 0.75rem; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.tag.stage { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.tag.overdue { background: var(--critical-bg); color: var(--danger); border-color: transparent; }
.step.done .step-title { text-decoration: line-through; color: var(--muted); }
.step-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; width: 100%; }
.step-ctrl { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; width: 100%; }
@media (min-width: 560px) { .step-ctrl { grid-template-columns: 1fr 1fr 1fr; } }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { border-left: 3px solid var(--border); padding: 2px 0 2px 12px; }
.timeline li.nota { border-left-color: var(--primary); }
.timeline li.etapa { border-left-color: var(--ok); }
.timeline li.passo { border-left-color: var(--warn); }
.timeline li.formulario { border-left-color: var(--danger); }
.timeline .who { font-size: 0.8125rem; color: var(--muted); }
.timeline .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.sla-bar { margin-top: 6px; }

.people { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 900px) { .people { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; } }
.person-stat { font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }

/* ---------- Notificações ---------- */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px;
  box-shadow: var(--shadow); max-width: calc(100vw - 28px); font-size: 0.875rem; z-index: 50;
}
.toast.error { background: var(--danger); color: #fff; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

:focus:not(:focus-visible) { outline: none; }

/* ---------- Preferências de leitura: tema e tamanho do texto ---------- */
.prefs { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.prefs select { width: auto; min-width: 7.5rem; min-height: 40px; padding: 6px 10px; font-size: 0.875rem; }
.prefs .btn { min-width: 44px; min-height: 40px; padding: 6px 10px; font-weight: 700; }
.prefs .btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.topbar .prefs { margin-left: auto; }
.topbar .me { margin-left: 0; }
.login-prefs { display: flex; justify-content: flex-end; padding: 12px 14px 0; }
@media (min-width: 900px) { .topbar .prefs { margin-left: 0; } }
@media (max-width: 899px) {
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px; }
  .topbar .me { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .topbar .me-name { display: none; }
  .prefs select { flex: 1 1 9rem; }
}

/* ---------- Identidade visual: Grupo VELTIS ---------- */
.brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.brand-icon {
  height: 2.25rem; width: auto; padding: 3px; border-radius: 8px;
  background: var(--logo-bg); border: 1px solid var(--logo-border);
}
.login-logo {
  display: block; width: min(240px, 70%); height: auto; margin: 0 auto 12px;
  padding: 10px; border-radius: 16px;
  background: var(--logo-bg); border: 1px solid var(--logo-border);
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 380px) { .brand-text { font-size: 0.9rem; } }
