/* Layout: barra superior com abas; cada aba é uma tela de trabalho (tabelas densas, mapa grande). */
:root {
  --bg: #f4f5f6;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --ink: #1b2127;
  --muted: #5d6670;
  --line: #dde1e5;
  --accent: #d0161e;      /* vermelho FIEL */
  --accent-ink: #ffffff;
  --accent-soft: #fbe8e9;
  --good: #2f7d4a;
  --good-soft: #e3f2e8;
  --warn: #a8660c;
  --warn-soft: #fbf0dc;
  --bad: #b8322a;
  --bad-soft: #f9e2e0;
  --land: #e8ebee;
  --land-line: #b9c1c9;
  --sea: #d9e3ec;
  --shadow: 0 10px 30px rgba(20, 26, 32, .16);
  --f-display: "Archivo", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", Roboto, Arial, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --r: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111518; --surface: #1a1f24; --surface-2: #222830; --ink: #e5e8eb; --muted: #9aa3ad; --line: #2d343c;
    --accent: #ff4d53; --accent-ink: #1a0607; --accent-soft: #3b1d1f;
    --good: #5cc283; --good-soft: #1c3226; --warn: #e3a64a; --warn-soft: #3a2c15; --bad: #ff7b70; --bad-soft: #3d1f1d;
    --land: #232a31; --land-line: #46505b; --sea: #161b20; --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111518; --surface: #1a1f24; --surface-2: #222830; --ink: #e5e8eb; --muted: #9aa3ad; --line: #2d343c;
  --accent: #ff4d53; --accent-ink: #1a0607; --accent-soft: #3b1d1f;
  --good: #5cc283; --good-soft: #1c3226; --warn: #e3a64a; --warn-soft: #3a2c15; --bad: #ff7b70; --bad-soft: #3d1f1d;
  --land: #232a31; --land-line: #46505b; --sea: #161b20; --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--f-body); }
h1, h2, h3 { font-family: var(--f-display); font-stretch: 88%; line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 750; }
h2 { font-size: 1.12rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.label { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }

/* ---- Barra superior ---- */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 1000; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 20px; padding-inline: 16px; min-height: 54px; }
.brand { display: flex; align-items: baseline; gap: 8px; flex-shrink: 0; }
.brand b { font: 800 1.35rem/1 var(--f-display); font-stretch: 85%; letter-spacing: .04em; color: var(--accent); }
.brand span { font: 600 .78rem/1 var(--f-display); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; padding: 16px 11px 14px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 3px solid transparent; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.aviso { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 8px 16px; background: var(--warn-soft); color: var(--ink); border-bottom: 1px solid var(--line); font-size: .86rem; }
.aviso b { color: var(--warn); }

main { padding-block: 22px 60px; padding-inline: 16px; max-width: 1280px; margin: 0 auto; }
.view { display: grid; gap: 18px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.head p { color: var(--muted); max-width: 70ch; margin-top: 4px; }

/* ---- Blocos ---- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.panel > h2 + *, .panel > .ph + * { margin-top: 12px; }
.ph { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 18px; }

/* Indicadores: faixa única com divisórias, sem cartões soltos */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.kpi { padding: 14px 16px; border-right: 1px solid var(--line); min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi .v { font: 750 1.65rem/1.1 var(--f-display); font-stretch: 90%; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi .d { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* ---- Controles ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: var(--r); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--muted); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.pri:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: .76rem; color: var(--muted); font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], input[type="email"], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); min-width: 0;
}
textarea { resize: vertical; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.check { display: flex; gap: 6px; align-items: center; cursor: pointer; font-size: .88rem; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }

/* ---- Tabelas ---- */
.tw { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.emp b { display: block; font-weight: 600; }
.emp span { font-size: .78rem; color: var(--muted); }

/* ---- Marcadores de estado ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 99px; font-size: .76rem; font-weight: 500; background: var(--surface-2); white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.score { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 600; }
.cls { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 4px; font: 800 .8rem/1 var(--f-display); }
.cls.A { background: var(--good-soft); color: var(--good); }
.cls.B { background: var(--warn-soft); color: var(--warn); }
.cls.C { background: var(--surface-2); color: var(--muted); }
.etapa { font-size: .78rem; padding: 2px 8px; border-radius: 4px; background: var(--surface-2); white-space: nowrap; }
.etapa.GANHO { background: var(--good-soft); color: var(--good); font-weight: 600; }
.etapa.PERDIDO { background: var(--bad-soft); color: var(--bad); }
.etapa.NEGOCIACAO, .etapa.PROPOSTA { background: var(--accent-soft); color: var(--accent); }
.late { color: var(--bad); font-weight: 600; }

/* Barras horizontais (funil, segmentos, composição do score) */
.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto; gap: 10px; align-items: center; font-size: .86rem; }
.hbar .t { height: 18px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.hbar .f { height: 100%; background: var(--accent); border-radius: 3px; min-width: 2px; }
.hbar .f.soft { background: var(--muted); opacity: .55; }
.hbar .n { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; min-width: 92px; text-align: right; }

/* ---- Mapa ---- */
.mapwrap { display: grid; grid-template-columns: 280px 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.mapside { padding: 14px; border-right: 1px solid var(--line); display: grid; gap: 14px; align-content: start; max-height: 74vh; overflow-y: auto; }
.map { height: 74vh; min-height: 420px; background: var(--sea); }
.map.sm { height: 440px; min-height: 0; }
.legend { display: grid; gap: 4px; font-size: .82rem; }
.legend label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.leaflet-container { font-family: var(--f-body); background: var(--sea); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; font-size: .86rem; line-height: 1.45; }
.leaflet-popup-content b { font-size: .95rem; }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--line); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.fab-icon { width: 22px; height: 22px; background: var(--ink); border: 3px solid var(--surface); border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.4); display: grid; place-items: center; color: var(--surface); font: 800 11px/1 var(--f-display); }
.stop-icon { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 700 11px/1 var(--f-body); border: 2px solid var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.mapmode { position: absolute; z-index: 800; top: 10px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 6px 12px; border-radius: var(--r); font-size: .85rem; }

/* ---- Funil (kanban) ---- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--r); padding: 10px; display: grid; gap: 8px; align-content: start; min-height: 200px; }
.col.over { outline: 2px dashed var(--accent); }
.colh { display: grid; gap: 2px; padding: 2px 2px 6px; border-bottom: 2px solid var(--line); }
.colh h3 { display: flex; justify-content: space-between; }
.colh.GANHO { border-bottom-color: var(--good); }
.colh.PERDIDO { border-bottom-color: var(--bad); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 9px 10px; display: grid; gap: 5px; cursor: grab; font-size: .84rem; }
.card:hover { border-color: var(--muted); }
.card b { font-weight: 600; line-height: 1.25; }
.card .row { display: flex; justify-content: space-between; gap: 6px; align-items: center; color: var(--muted); font-size: .78rem; }
.card select { padding: 3px 5px; font-size: .78rem; }

/* ---- Janela de detalhes ---- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 18, .45); z-index: 2000; display: flex; justify-content: flex-end; }
.drawer { width: min(860px, 100%); height: 100%; background: var(--bg); box-shadow: var(--shadow); overflow-y: auto; padding-block: calc(env(safe-area-inset-top, 0px) + 18px) 40px; padding-inline: 20px; display: grid; gap: 16px; align-content: start; }
.drawer .top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.form .wide { grid-column: 1 / -1; }
.timeline { display: grid; gap: 8px; }
.timeline div { border-left: 2px solid var(--line); padding-left: 10px; font-size: .85rem; }
.pitch { background: var(--accent-soft); border-radius: var(--r); padding: 12px 14px; font-size: .88rem; }
.factrow { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .87rem; }
.factrow:last-child { border-bottom: 0; }
.factrow b { font-variant-numeric: tabular-nums; }

/* ---- Diversos ---- */
.empty { padding: 28px; text-align: center; color: var(--muted); }
.toast { position: fixed; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 9px 16px; border-radius: var(--r); z-index: 3000; font-size: .9rem; box-shadow: var(--shadow); }
.code { font-family: var(--f-mono); font-size: .8rem; background: var(--surface-2); padding: 1px 5px; border-radius: 3px; }
pre.code { padding: 10px; overflow-x: auto; white-space: pre; }
.steps { display: grid; gap: 10px; counter-reset: s; padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.steps li::before { content: counter(s); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 700 .85rem/1 var(--f-display); }
.confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--bad-soft); padding: 8px 10px; border-radius: var(--r); font-size: .86rem; }

/* ---- Login e conta ---- */
.deslogado .topbar, .deslogado main { display: none; }
.deslogado #login { min-height: 100%; display: grid; }
.login { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.login-brand { background: var(--accent); color: var(--accent-ink); padding-block: 48px; padding-inline: clamp(20px, 6vw, 72px); display: grid; align-content: center; gap: 22px; }
.login-brand .brand b, .login-brand .brand span { color: var(--accent-ink); }
.login-brand .brand b { font-size: 2.4rem; }
.login-brand .brand span { font-size: 1rem; opacity: .85; }
.login-brand h1 { font-size: clamp(1.6rem, 3.2vw, 2.5rem); font-stretch: 80%; max-width: 18ch; }
.login-brand ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; max-width: 46ch; }
.login-brand li { border-top: 1px solid color-mix(in srgb, var(--accent-ink) 30%, transparent); padding-top: 10px; }
.login-form { background: var(--bg); padding-block: 48px; padding-inline: clamp(16px, 5vw, 64px); display: grid; align-content: center; gap: 22px; }
.login-form form { display: grid; gap: 12px; max-width: 380px; width: 100%; }
.login-form form h2 { font-size: 1.5rem; }
.login-form form .btn.pri { justify-content: center; padding-block: 10px; }
.login-erro { color: var(--bad); min-height: 1.2em; font-size: .88rem; }
.login-demo { max-width: 380px; border: 1px dashed var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 8px; }
.login-demo table td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-family: var(--f-mono); font-size: .85rem; text-decoration: underline; }
.userbox { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.userchip { display: grid; text-align: right; background: none; border: 0; cursor: pointer; padding: 4px 6px; border-radius: var(--r); line-height: 1.2; }
.userchip:hover { background: var(--surface-2); }
.userchip b { font-size: .86rem; }
.userchip span { font-size: .72rem; color: var(--muted); }

@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { padding-block: 28px; }
  .login-brand ul { display: none; }
  .userbox { justify-content: space-between; padding-bottom: 6px; }
  .userchip { text-align: left; }
  .topbar-in { flex-direction: column; align-items: stretch; gap: 0; padding-top: 10px; }
  .tab { padding: 10px 10px 9px; }
  .mapwrap { grid-template-columns: 1fr; }
  .mapside { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; }
  .map { height: 62vh; }
  .kpi { border-right: 0; border-bottom: 1px solid var(--line); }
  .hbar { grid-template-columns: 100px 1fr; }
  .hbar .n { grid-column: 2; text-align: left; }
  .drawer { padding-inline: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
