:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --line: #e2e2dd;
  --text: #17181a;
  --muted: #6b6d72;
  --accent: #c98a0c;
  --accent-ink: #ffffff;
  --accent-soft: #fbf0d8;
  --red: #c0392b;
  --red-soft: #fbe5e2;
  --green: #2e8b57;
  --green-soft: #e0f2e8;
  --blue: #2f6fb3;
  --blue-soft: #e2edf8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1a1b1e;
    --surface-2: #232428;
    --line: #2d2f33;
    --text: #ececec;
    --muted: #9a9ca2;
    --accent: #f5b83d;
    --accent-ink: #1a1405;
    --accent-soft: #3a2e14;
    --red: #ff6b5b;
    --red-soft: #3a1e1b;
    --green: #4cc38a;
    --green-soft: #17301f;
    --blue: #6aa8ec;
    --blue-soft: #18283a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40vh 16px; text-align: center; color: var(--muted); }

/* Topo e navegação */
header.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; }
.brand small { color: var(--muted); font-weight: 500; }
nav.tabs { display: flex; gap: 4px; margin-left: 12px; }
nav.tabs button {
  border: 0; background: none; padding: 8px 12px; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 600;
}
nav.tabs button.on { background: var(--surface-2); color: var(--text); }
nav.tabs .badge { margin-left: 4px; }
.spacer { flex: 1; }
.iconbtn { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 18px; }

main { max-width: 1180px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }

.fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 30;
  border: 0; border-radius: 999px; padding: 14px 20px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); cursor: pointer;
}

nav.tabs.mob { display: none; }
.stagechips { display: none; }
@media (max-width: 760px) {
  nav.tabs.desk { display: none; }
  nav.tabs.mob { display: flex; }
  nav.tabs {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 25;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around;
  }
  nav.tabs button { flex: 1; padding: 10px 4px; font-size: 13px; }
  .brand small { display: none; }
}
@media (min-width: 761px) {
  .fab { bottom: 24px; right: 24px; }
  main { padding-bottom: 48px; }
}

/* Blocos */
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; font-weight: 700; }
h2:first-child { margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); text-align: center; }
.badge.red { background: var(--red); color: #fff; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }

/* Resumo do topo da tela Hoje */
.strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 600; }
@media (max-width: 760px) { .strip { grid-template-columns: repeat(2, 1fr); } }

.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; position: relative; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar i.green { background: var(--green); }
.bar i.ghost { position: absolute; top: 0; left: 0; background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* Itens de ação */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; }
.item .main { flex: 1; min-width: 0; cursor: pointer; }
.item .title { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.item .act { margin-top: 2px; }
.item .meta { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item .btns { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.item.late { border-left: 4px solid var(--red); }
@media (max-width: 560px) {
  .item { flex-direction: column; }
  .item .btns { width: 100%; justify-content: stretch; }
  .item .btns .btn { flex: 1; }
}

.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 8px 12px; border-radius: 10px;
  cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

/* Funil */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { flex: 1; min-width: 140px; }
.board { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.col { flex: 0 0 280px; scroll-snap-align: start; display: flex; flex-direction: column; gap: 8px; }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 2px; }
.col-head b { font-size: 14px; }
.col-head span { font-size: 12px; color: var(--muted); }
.deal { padding: 10px 12px; cursor: pointer; }
.deal .title { font-weight: 700; }
.deal .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.deal .next { font-size: 13px; color: var(--muted); margin-top: 6px; }
.deal .next.late { color: var(--red); font-weight: 600; }
@media (max-width: 760px) {
  .toolbar input { flex-basis: 100%; }
  .toolbar select { min-width: 0; flex: 1 1 30%; font-size: 14px; padding: 8px; }
  .stagechips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 4px; scrollbar-width: none; }
  .stagechips button { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 600; cursor: pointer; }
  .stagechips button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .stagechips button.on .badge { background: rgba(0,0,0,.15); color: inherit; }
  .board { display: block; margin: 0; padding: 0; overflow: visible; }
  .col { display: none; }
  .col.sel { display: flex; }
}

/* Números */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 760px) { .grid3 { grid-template-columns: 1fr; } .grid4 { grid-template-columns: repeat(2, 1fr); } }
.big { padding: 14px; }
.big .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big .sub { font-size: 13px; color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); }
table.t th { font-size: 12px; color: var(--muted); font-weight: 700; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; }

/* Formulários */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px;
  font-size: 16px; color: var(--text);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fgrid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .fgrid { grid-template-columns: 1fr; } }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* Modal / folha */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 18px; }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 16px; }
.sheet-foot { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; padding: 12px; }
@media (max-width: 560px) {
  .overlay { padding: 0; align-items: flex-end; }
  .sheet { max-height: 100%; height: 100%; border-radius: 0; }
}
.stagepick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stagepick button { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 4px; cursor: pointer; font-size: 12px; line-height: 1.2; }
.stagepick button b { display: block; font-size: 13px; }
.stagepick button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
@media (max-width: 420px) { .stagepick { grid-template-columns: repeat(2, 1fr); } }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.hist { font-size: 13px; color: var(--muted); }
.hist div { padding: 3px 0; }

/* Login */
.login { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.login .card { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 22px; margin: 0; display: flex; align-items: center; gap: 10px; }
.login h1 img { width: 34px; height: 34px; }
.err { color: var(--red); font-size: 14px; min-height: 1em; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  table.t { font-size: 13px; }
  table.t th, table.t td { padding: 8px 6px; }
  table.t th:first-child, table.t td:first-child { padding-left: 10px; }
  table.t th:last-child, table.t td:last-child { padding-right: 10px; }
  .hide-m { display: none; }
}
@media (max-width: 560px) {
  table.t.compact { font-size: 12px; }
  table.t.compact th, table.t.compact td { padding-left: 4px; padding-right: 4px; }
  table.t.compact .chip { padding: 2px 5px; }
}
.show-m { display: none; }
@media (max-width: 560px) { .show-m { display: inline; } }
