/* ============================================================
   SHAVIT CRM — design tokens + base styles
   Editorial monochrome with single warm accent.
   ============================================================ */

:root {
  /* Light theme tokens (default — overridden by .theme-dark) */
  --bg:        #F4F1EA;
  --bg-2:      #ECE7DC;
  --surface:   #FFFFFF;
  --surface-2: #FAF7F0;
  --surface-3: #F1EDE3;
  --line:      rgba(20,18,14,.10);
  --line-2:    rgba(20,18,14,.06);
  --ink:       #14120E;
  --ink-2:     rgba(20,18,14,.78);
  --ink-3:     rgba(20,18,14,.55);
  --ink-4:     rgba(20,18,14,.36);
  --accent:    #E8623D;
  --accent-ink:#FFFFFF;
  --good:      #4A7C3A;
  --warn:      #C77A1F;
  --bad:       #B23A2E;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --row-h: 44px;
  --pad: 16px;

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Poppins', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --serif:'Instrument Serif', Georgia, serif;
}

.theme-dark {
  --bg:        #0B0B0A;
  --bg-2:      #131311;
  --surface:   #161614;
  --surface-2: #1C1C19;
  --surface-3: #232320;
  --line:      rgba(255,253,245,.10);
  --line-2:    rgba(255,253,245,.05);
  --ink:       #F4F1EA;
  --ink-2:     rgba(244,241,234,.78);
  --ink-3:     rgba(244,241,234,.55);
  --ink-4:     rgba(244,241,234,.34);
  --accent-ink:#0B0B0A;
}

/* density */
.density-compact  { --row-h: 36px; --pad: 12px; }
.density-regular  { --row-h: 44px; --pad: 16px; }
.density-comfy    { --row-h: 56px; --pad: 22px; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea {
  font: inherit; color: inherit;
}
/* Estilo-base de todos os controles de formulário tipo-texto, para que um
   <input> "pelado" (fora de .field) nunca renderize como caixa branca padrão
   do browser no tema escuro. O :where() exclui checkbox/radio/range/file
   (que têm render próprio, ex.: .twk-slider) SEM somar especificidade — a
   regra fica em (0,0,1), então .field/.search/.mobile-search-bar e os ajustes
   mobile (height 44px, font-size 16px anti-zoom iOS) continuam vencendo. */
input:not(:where([type=checkbox], [type=radio], [type=range], [type=file])),
select, textarea {
  height: 36px; padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  font-size: 13px;
}
textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
input:not(:where([type=checkbox], [type=radio], [type=range], [type=file])):focus,
select:focus, textarea:focus { border-color: var(--ink-3); }
input:not(:where([type=checkbox], [type=radio], [type=range], [type=file]))::placeholder,
textarea::placeholder { color: var(--ink-4); }
button { cursor: default; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }

::selection { background: var(--accent); color: var(--accent-ink); }

/* ===== Layout shell ===== */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  background: var(--bg);
}
.app.nav-rail   { grid-template-columns: 176px 1fr; }
.app.nav-hidden { grid-template-columns: 0 1fr; }

/* ===== Sidebar ===== */
.side {
  border-right: 1px solid var(--line);
  background: var(--bg);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 10;
}
.side .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-2);
}
.side.rail .brand { padding: 18px 14px 14px; justify-content: flex-start; }
.side .brand-mark {
  width: 28px; height: 28px; flex: none;
  display: grid; place-items: center;
  color: var(--ink);
}
.side .brand-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  letter-spacing: -0.01em;
  line-height: 1;
}
.side.rail .brand-name { display: block; }

.nav {
  display: flex; flex-direction: column;
  padding: 10px 8px;
  gap: 1px;
  flex: 1; min-height: 0;
  overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13px;
  position: relative;
  transition: background .12s, color .12s;
}
.nav-item .ico { width: 16px; height: 16px; flex: none; opacity: .85; }
.nav-item .lbl { flex: 1; }
.nav-item .badge {
  font-family: var(--mono); font-size: 10px;
  color: var(--ink-3);
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}
.theme-dark .nav-item.active { background: var(--surface-2); }
.nav-item.active::before {
  content: ''; position: absolute; left: -8px; top: 8px; bottom: 8px;
  width: 2px; background: var(--accent); border-radius: 2px;
}
.side.rail .nav-item { justify-content: flex-start; padding: 9px 10px; }
.side.rail .nav-item .lbl { display: block; }
.side.rail .nav-item .badge { display: block; }
.side.rail .nav-item.active::before { left: -8px; }

.nav-section {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: 16px 12px 6px;
}
.side.rail .nav-section { display: block; }

.side-foot {
  border-top: 1px solid var(--line-2);
  padding: 12px;
  display: flex; align-items: center; gap: 10px;
}
.side.rail .side-foot { justify-content: flex-start; padding: 12px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3);
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  color: var(--ink-2);
  flex: none;
}
.side-foot .who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.side-foot .who b { font-size: 12.5px; font-weight: 600; }
.side-foot .who span { font-size: 11px; color: var(--ink-3); }
.side.rail .side-foot .who { display: flex; }

/* ===== Main area ===== */
.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 100vh;
}
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: saturate(140%) blur(10px);
}
.crumbs {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .06em;
}
.crumbs b { color: var(--ink); font-weight: 600; }
.crumbs .dot { opacity: .35; }

.topbar .grow { flex: 1; }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px; height: 32px;
  width: 280px;
}
.search input {
  background: transparent; border: 0; outline: 0;
  height: auto; padding: 0; border-radius: 0;
  flex: 1; min-width: 0;
  font-size: 12.5px;
}
.search input::placeholder { color: var(--ink-4); }
.search .kbd {
  font-family: var(--mono); font-size: 10px;
  color: var(--ink-4);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--ink-2);
  border: 1px solid transparent;
}
.icon-btn:hover { background: var(--surface); border-color: var(--line); color: var(--ink); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 8px;
  font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary {
  background: var(--ink); color: var(--bg);
  border-color: var(--ink);
}
.btn.primary:hover { background: var(--ink-2); }
.btn.accent {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.ghost { background: transparent; }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }

/* ===== Page ===== */
.page {
  padding: 28px 32px 56px;
  max-width: 100%;
  flex: 1;
  min-width: 0;
}
.density-compact .page { padding: 18px 22px 36px; }
.density-comfy   .page { padding: 36px 44px 64px; }

.h-display {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 56px;
  line-height: 1.0;
  letter-spacing: -0.02em;
  margin: 0;
}
.h-eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 10px;
}
.text-mono { font-family: var(--mono); }
.text-mute { color: var(--ink-3); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ===== Cards / Panels ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card.flat { background: transparent; }
.card-pad { padding: var(--pad); }

.divider { height: 1px; background: var(--line); margin: 14px 0; }
.divider.vert { width: 1px; height: 100%; background: var(--line); }

/* ===== Stat tile ===== */
.stat {
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.stat .lbl {
  font-family: var(--mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-3);
}
.stat .val {
  font-family: var(--serif); font-style: italic;
  font-size: 44px; line-height: 1;
  letter-spacing: -0.02em;
}
.stat .sub {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
}
.stat .delta { display: inline-flex; align-items: center; gap: 3px; }
.stat .delta.up { color: var(--good); }
.stat .delta.dn { color: var(--bad); }

/* ===== Pills / chips ===== */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  border-radius: 11px;
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: .04em;
  background: var(--surface-3); color: var(--ink-2);
  border: 1px solid var(--line-2);
  white-space: nowrap;
}
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-3);
}
.pill.accent { background: color-mix(in oklch, var(--accent) 14%, transparent); color: var(--accent); border-color: color-mix(in oklch, var(--accent) 25%, transparent); }
.pill.accent .dot { background: var(--accent); }
.pill.good   { background: color-mix(in oklch, var(--good) 14%, transparent); color: var(--good); }
.pill.good .dot { background: var(--good); }
.pill.warn   { background: color-mix(in oklch, var(--warn) 14%, transparent); color: var(--warn); }
.pill.warn .dot { background: var(--warn); }
.pill.bad    { background: color-mix(in oklch, var(--bad) 14%, transparent); color: var(--bad); }
.pill.bad .dot { background: var(--bad); }
.pill.line { background: transparent; border-color: var(--line); }

/* ===== Tables ===== */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; font-size: 13px; }
.tbl th {
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500;
  border-bottom: 1px solid var(--line);
}
.tbl tbody tr { border-bottom: 1px solid var(--line-2); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child { border-bottom: 0; }
.tbl td.right { text-align: right; }
.tbl .r-avatar { display: flex; align-items: center; gap: 10px; }

/* ===== Kanban ===== */
.kb {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(280px, 1fr);
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
}
.kb-col {
  display: flex; flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 480px;
  scroll-snap-align: start;
}
.kb-col.drop { background: color-mix(in oklch, var(--accent) 8%, var(--surface-2)); border-color: var(--accent); }
.kb-col header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.kb-col header .name { font-size: 12.5px; font-weight: 600; }
.kb-col header .count { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.kb-col header .total {
  margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--ink-3);
}
.kb-col .body {
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
  flex: 1;
}
.deal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  cursor: grab;
  display: flex; flex-direction: column; gap: 8px;
}
.deal:active { cursor: grabbing; }
.deal.dragging { opacity: .35; }
.deal .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.deal .co { font-size: 13px; font-weight: 600; line-height: 1.2; }
.deal .svc { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.deal .val { font-family: var(--serif); font-style: italic; font-size: 22px; line-height: 1; }
.deal .meta { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.deal .meta .sep { opacity: .35; }
.deal .bar {
  display: flex; gap: 2px; height: 3px;
}
.deal .bar i {
  flex: 1; background: var(--line); border-radius: 1px;
}
.deal .bar i.on { background: var(--accent); }

/* ===== Drawer ===== */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.42);
  z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(640px, 92vw);
  background: var(--bg);
  border-left: 1px solid var(--line);
  z-index: 51;
  transform: translateX(100%);
  transition: transform .26s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.drawer.open { transform: translateX(0); }
.drawer header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.drawer .body { flex: 1; overflow-y: auto; padding: 0; }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(0,0,0,.42);
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
  overflow-y: auto;
  padding: 20px 0;
}
.modal.open { opacity: 1; pointer-events: auto; }
.modal .sheet {
  width: min(560px, 92vw);
  max-height: min(88vh, 840px);
  display: flex; flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transform: translateY(8px) scale(.98);
  transition: transform .2s;
}
.modal.open .sheet { transform: translateY(0) scale(1); }

/* ── Modais: header e footer ficam fixos, só o corpo (miolo) rola.
   Aplicado em qualquer modal com estrutura 3-divs: header / body / footer.
   Sem classes — usamos a posição dos children. */
.modal .sheet > div:first-child { flex-shrink: 0; }
.modal .sheet > div:last-child  { flex-shrink: 0; }
.modal .sheet > div:not(:first-child):not(:last-child) {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== Forms ===== */
.field {
  display: flex; flex-direction: column; gap: 4px;
}
.field label {
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3);
}
.field input, .field select, .field textarea {
  height: 36px; padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  font-size: 13px;
}
.field textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink-3); }

/* ===== Tag bar / segmented ===== */
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.seg button {
  height: 26px; padding: 0 10px;
  border-radius: 6px; font-size: 12px; color: var(--ink-3);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 0 var(--line); }
.theme-dark .seg button.on { background: var(--surface-3); }

/* ===== Sparkline / mini bars ===== */
.bars {
  display: flex; align-items: flex-end; gap: 3px;
  height: 56px;
}
.bars i {
  width: 6px; background: var(--ink-4);
  border-radius: 1px;
}
.bars i.hi { background: var(--accent); }

/* ===== Filter bar ===== */
.fbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 0;
  flex-wrap: wrap;
}

/* Custom scrollbar (subtle) */
.app *::-webkit-scrollbar { width: 10px; height: 10px; }
.app *::-webkit-scrollbar-track { background: transparent; }
.app *::-webkit-scrollbar-thumb {
  background: var(--ink-4); border-radius: 8px;
  border: 3px solid transparent; background-clip: content-box;
  opacity: .4;
}
.app *::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: content-box; border: 3px solid transparent; }

/* ===== Calendar ===== */
.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  /* meses com 6 semanas geram uma linha extra implícita — mantém altura uniforme */
  grid-template-rows: auto repeat(5, 1fr);
  grid-auto-rows: 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.cal .head {
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.cal .day {
  min-height: 110px;
  padding: 8px 10px;
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}
.cal .day.dim { background: var(--surface-2); color: var(--ink-4); }
.cal .day.today .num { color: var(--accent); font-weight: 600; }
.cal .day .num { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.cal .ev {
  font-size: 11px; padding: 3px 6px; border-radius: 4px;
  background: var(--surface-3); color: var(--ink-2);
  border-left: 2px solid var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal .ev.t1 { border-left-color: var(--good); }
.cal .ev.t2 { border-left-color: var(--warn); }
.cal .ev.t3 { border-left-color: var(--bad); }

/* ===== Inbox layout ===== */
.inbox {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - 130px);
  min-height: 560px;
}
.inbox .list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-y: auto;
}
.inbox .list .it {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-2);
  display: flex; flex-direction: column; gap: 4px;
  cursor: default;
}
.inbox .list .it:hover { background: var(--surface-2); }
.inbox .list .it.on { background: var(--surface-3); border-left: 2px solid var(--accent); padding-left: 12px; }
.inbox .thread {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.inbox .thread header { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.inbox .thread .msgs { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 78%; }
.msg .who { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); margin-bottom: 4px; }
.msg .bubble {
  background: var(--surface-2); border: 1px solid var(--line-2);
  padding: 10px 12px; border-radius: 12px;
  font-size: 13.5px; line-height: 1.5;
}
.msg.me { align-self: flex-end; }
.msg.me .bubble { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* small helpers */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.right { margin-left: auto; }

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

/* ── Settings two-col layout (nav 200px + content) ── */
.settings-grid { display: grid; grid-template-columns: 200px 1fr; gap: 28px; }

/* ── Calendar two-col layout (1fr + sidebar 320px) ── */
.cal-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}

/* ── Reports 4-col KPI cells ── */
.report-kpi {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

/* ── Finance editorial heading ── */
.finance-h1 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 48px;
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 8px 0 0;
}

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2,1fr); }
  .grid-3 { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; }
}

/* fade-in transitions */
.fade-in { animation: fadeIn .26s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toasts ===== */
.toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; gap: 11px; align-items: flex-start;
  min-width: 280px; max-width: 380px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.22);
  animation: toastIn .24s ease both;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast-success { border-left-color: var(--good); }
.toast-error   { border-left-color: var(--bad); }
.toast-info    { border-left-color: var(--accent); }
.toast-warn    { border-left-color: var(--warn); }
.toast-success .toast-icon { color: var(--good); }
.toast-error   .toast-icon { color: var(--bad); }
.toast-info    .toast-icon { color: var(--accent); }
.toast-warn    .toast-icon { color: var(--warn); }
.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; min-width: 0; }
.toast-msg {
  font-size: 13px; font-weight: 500; color: var(--ink);
  line-height: 1.35;
}
.toast-detail {
  font-size: 11px; color: var(--ink-3);
  font-family: var(--mono);
  margin-top: 3px; line-height: 1.4;
  word-break: break-word;
}
.toast-close {
  flex-shrink: 0;
  background: none; border: none;
  color: var(--ink-4); cursor: pointer;
  padding: 2px; display: flex;
  align-items: center; justify-content: center;
  transition: color .15s;
}
.toast-close:hover { color: var(--ink); }
@media (max-width: 720px) {
  .toast-container {
    left: 12px; right: 12px; bottom: auto;
    top: calc(12px + env(safe-area-inset-top, 0px));
  }
  .toast { min-width: 0; max-width: none; }
}

/* progress meter */
.meter {
  height: 4px; background: var(--line); border-radius: 2px; overflow: hidden;
}
.meter > i { display: block; height: 100%; background: var(--accent); }
.meter.line > i { background: var(--ink); }

/* Logo svg */
.brand-mark svg { width: 100%; height: 100%; display: block; }

/* report cells */
.cell {
  padding: 16px 18px;
  border-right: 1px solid var(--line);
}
.cell:last-child { border-right: 0; }
.cell .lbl {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 8px;
}

/* bottom shadow on sticky header in dark */
.theme-dark .topbar { background: rgba(11,11,10,.78); }

/* selection box (kanban dragging hint) */
.deal[draggable="true"]:hover { border-color: var(--ink-3); }

/* Mobile-only back button — hidden by default, shown via media query */
.mobile-back-btn { display: none !important; }

/* Thread header: barra mobile (back + ações rápidas) — oculta no desktop */
.thread-hd-bar { display: none; }

/* ============================================================
   MOBILE — max-width 768px
   App-like experience: bottom tab bar, no sidebar,
   touch-friendly sizes, bottom-sheet drawers.
   ============================================================ */

/* ── Mobile-only / desktop-only toggles ─────────────────── */
.mobile-nav        { display: none; }
.mobile-title      { display: none; }
.mobile-search-btn { display: none; }

@media (max-width: 768px) {

  /* ── Layout shell ── */
  .app,
  .app.nav-rail,
  .app.nav-full,
  .app.nav-hidden {
    grid-template-columns: 1fr;
  }
  .side { display: none !important; }

  /* ── Main content ── */
  .main { min-height: 100svh; padding-bottom: 0; }
  .page {
    padding: 16px 16px calc(80px + env(safe-area-inset-bottom, 0px));
  }
  .density-compact .page { padding: 12px 12px calc(76px + env(safe-area-inset-bottom, 0px)); }
  .density-comfy   .page { padding: 20px 20px calc(84px + env(safe-area-inset-bottom, 0px)); }

  /* ── Top bar ── */
  .topbar {
    padding: 0 12px;
    height: 54px;
    gap: 8px;
  }
  .crumbs { display: none; }
  .topbar .grow { flex: 1; }
  .mobile-title {
    display: block;
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
  }
  .mobile-search-btn { display: grid; }
  /* Hide desktop search on mobile */
  .search-wrap { display: none; }
  /* Shrink topbar buttons */
  .icon-btn { width: 38px; height: 38px; }
  .btn.primary { height: 36px; padding: 0 14px; }

  /* ── Typography ── */
  .h-display {
    font-size: 30px;
    line-height: 1.1;
  }
  .stat .val { font-size: 28px; }

  /* ── Settings layout stacked ── */
  .settings-grid { grid-template-columns: 1fr; gap: 0; }
  .settings-grid > nav {
    flex-direction: row !important;
    overflow-x: auto;
    padding-bottom: 4px;
    gap: 4px !important;
    margin-bottom: 20px;
    flex-wrap: nowrap;
  }
  .settings-grid > nav .nav-item {
    flex-shrink: 0;
    padding: 7px 12px;
    white-space: nowrap;
  }
  .settings-grid > nav .nav-item .ico { display: none; }

  /* ── Settings webhook row: empilha no mobile ── */
  .webhook-row { flex-wrap: wrap; }
  .webhook-row input { flex: 1 1 100%; min-width: 0; }
  .webhook-row .btn  { flex-shrink: 0; }

  /* ── Grids → single column ── */
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid-3 { grid-template-columns: 1fr; gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; gap: 10px; }

  /* ── Cards ── */
  .card-pad { padding: 14px; }

  /* ── Dashboard specific ── */
  .dash-grid-main  { grid-template-columns: 1fr !important; }
  .dash-grid-lower { grid-template-columns: 1fr !important; }

  /* ── Stat tile compact ── */
  .stat { padding: 14px 14px 10px; gap: 6px; }
  .stat .sub { font-size: 10px; }

  /* ── Pipeline / Kanban ── */
  .kb {
    grid-auto-columns: 82vw;
    gap: 12px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Drawer → bottom sheet ── */
  .drawer {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 92svh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.32,.72,0,1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .drawer.open { transform: translateY(0); }
  /* drag handle */
  .drawer::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--ink-4);
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
  }
  .drawer header { padding: 12px 16px; }
  .drawer .body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* ── Modal → bottom sheet ── */
  .modal { align-items: flex-end; }
  .modal .sheet {
    width: 100%;
    max-height: 92svh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    transform: translateY(100%);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    /* overflow: hidden + header/footer fixos vem do bloco geral acima */
  }
  .modal.open .sheet { transform: translateY(0); }

  /* ── Forms / inputs ── */
  .field input,
  .field select { height: 44px; font-size: 16px; /* prevent iOS zoom */ }
  .field textarea { font-size: 16px; }

  /* ── Buttons ── */
  .btn { height: 40px; font-size: 13px; }
  .btn.sm { height: 34px; }

  /* ── Inbox stacked — overridden below by flex rules ── */

  /* ── Calendar ── */
  .cal .day { min-height: 56px; padding: 4px 6px; }
  .cal .head { padding: 8px 4px; font-size: 9px; }
  .cal .ev { font-size: 9.5px; padding: 2px 4px; }

  /* ── Scrollbar hidden on mobile ── */
  .app *::-webkit-scrollbar { display: none; }

  /* ── Tables: scroll only inside table-cards (não afeta outros cards) ── */
  /* !important: telas usam inline style={{overflow:'hidden'}} para clipar rounded
     corners no desktop. Sobrescrevemos apenas overflow-x, mantendo overflow-y. */
  .card:has(.tbl) { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .card:has(.tbl) .tbl { min-width: 540px; }

  /* ── Defensive: quebra de palavra em conteúdo longo (URLs, emails, tokens) ── */
  .card-pad, .modal .sheet, .drawer .body, .toast-detail {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* ── Conversor de moeda (FxScreen): selects de moeda mais estreitos ── */
  .main select[style*="width:120"],
  .main select[style*="width: 120"] {
    width: 90px !important;
    flex-shrink: 0 !important;
  }
  /* Inputs/divs inline com height 48 do FxScreen continuam OK */

  /* ── Inbox: thread header não pode estourar com ações em linha ── */
  .inbox .thread header { flex-wrap: wrap; }

  /* ── Pipeline: lead-intake rows wrappam ── */
  .pipeline-lead { flex-wrap: wrap; }

  /* ── Header da página: pega .row.between mesmo se houver wrappers ──
     Cobre estruturas onde o título e botões ficam em níveis ligeiramente
     diferentes de aninhamento. */
  .page > .fade-in > .row.between:first-child,
  .page > .row.between:first-child,
  .fade-in > .row.between:first-child {
    flex-wrap: wrap !important;
    gap: 10px;
  }

  /* ── Seg: scrollável horizontalmente (sem quebrar layout) ── */
  .seg {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-shrink: 1;
    min-width: 0;
  }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex-shrink: 0; }

  /* ── Filter bar: mantém horizontal, permite wrap ── */
  .fbar { flex-wrap: wrap; gap: 10px; padding: 10px 0; }
  .fbar .search { flex: 1; min-width: 200px; width: auto !important; }

  /* ── Calendar layout → coluna única no mobile ── */
  .cal-layout { grid-template-columns: 1fr; }
  /* Permite scroll horizontal no week/day view */
  .cal-layout > div:first-child { overflow-x: auto; }
  /* WeekView: 7 colunas legíveis com scroll lateral em vez de espremer */
  .cal-week { min-width: 560px; }

  /* ── Reports KPI → 2 colunas no mobile ── */
  .report-kpi { grid-template-columns: 1fr 1fr; }

  /* ── Finance heading menor no mobile ── */
  .finance-h1 { font-size: 30px; }

  /* ── Inbox: um painel de cada vez ── */
  .inbox {
    display: flex !important;
    flex-direction: column;
    height: calc(100svh - 54px - 52px - env(safe-area-inset-bottom, 0px));
    min-height: 0;
    gap: 0;
    overflow: hidden;
  }
  .inbox .list,
  .inbox .thread {
    flex: 1 1 auto;
    min-height: 0;
    border-radius: 0 !important;
    width: 100%;
  }
  .inbox.show-thread .list   { display: none; }
  .inbox.show-list   .thread { display: none; }

  /* ── Composer mobile ── */
  /* Textarea: fonte 16px evita zoom automático no iOS */
  .composer-ta { font-size: 16px !important; min-height: 46px !important; padding: 12px !important; }
  /* Botão enviar: só ícone, sem texto */
  .send-label  { display: none; }
  /* Botão enviar vira quadrado como icon-btn */
  .composer-send { width: 44px; height: 44px; padding: 0 !important; justify-content: center; }
  /* Icon buttons do composer um pouco maiores para toque */
  .inbox .thread .composer-ta ~ button.icon-btn,
  .inbox .thread button.icon-btn { width: 40px; height: 40px; }

  /* ── Thread header mobile: 2 linhas ── */
  .inbox .thread header {
    padding: 8px 12px 10px;
  }
  /* Linha 1 (mobile): back btn + ações rápidas */
  .thread-hd-bar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
  }
  /* Esconde ações desktop no mobile */
  .thread-hd-actions { display: none !important; }

  /* ── Botão voltar (mobile only) ── */
  .mobile-back-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
    padding: 2px 6px 2px 0;
    flex-shrink: 0;
  }

  /* ── Topbar: esconde texto "Novo" em telas pequenas ── */
  .topbar-new-text { display: none; }

  /* ── Mobile tab bar ── */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 40;
    background: var(--bg);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    backdrop-filter: saturate(140%) blur(14px);
    -webkit-backdrop-filter: saturate(140%) blur(14px);
  }
  .theme-dark .mobile-nav { background: rgba(11,11,10,.88); }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    color: var(--ink-4);
    font-size: 10px;
    font-family: var(--sans);
    font-weight: 500;
    border-radius: 0;
    min-height: 52px;
    transition: color .15s;
    position: relative;
  }
  .mobile-nav-item .ico { opacity: 1; }
  .mobile-nav-item span { line-height: 1; letter-spacing: 0; }
  .mobile-nav-item.active { color: var(--ink); }
  .mobile-nav-item.active::after {
    content: '';
    position: absolute;
    top: 0; left: 25%; right: 25%;
    height: 2px;
    background: var(--accent);
    border-radius: 0 0 2px 2px;
  }
  .mobile-nav-item .m-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 16px);
    min-width: 16px; height: 16px;
    padding: 0 4px;
    background: var(--accent);
    color: var(--accent-ink);
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    display: grid; place-items: center;
  }

  /* ── Mobile search overlay ── */
  .mobile-search-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 60;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    display: flex; align-items: center; gap: 10px;
    backdrop-filter: blur(14px);
  }
  .mobile-search-bar input {
    flex: 1;
    height: 40px;
    padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 16px;
    outline: none;
  }
  .mobile-search-bar .cancel-btn {
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
    white-space: nowrap;
  }
  .mobile-search-results {
    position: fixed;
    top: 64px; left: 0; right: 0; bottom: 0;
    z-index: 59;
    background: var(--bg);
    overflow-y: auto;
    padding: 0 0 80px;
  }
  .mobile-search-results .sr-item {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-2);
  }
  .mobile-search-results .sr-item:active { background: var(--surface-2); }
}

/* ============================================================
   AGENTES — sub-tabs por agente + actions + task grid
   ============================================================ */
.task-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
@media (max-width: 720px) {
  .task-grid { grid-template-columns: 1fr; }
}

.task-button {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: background .12s, border-color .12s, transform .08s;
  color: var(--ink);
  cursor: pointer;
}
.task-button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--ink-4);
}
.task-button:active:not(:disabled) { transform: translateY(1px); }
.task-button:disabled { opacity: 0.5; cursor: not-allowed; }

.task-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  flex-shrink: 0;
  color: var(--accent);
}
.task-text { flex: 1; min-width: 0; }
.task-label {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
}
.task-desc {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 4px;
  line-height: 1.4;
}
.task-note {
  font-size: 10.5px;
  color: var(--warn);
  margin-top: 4px;
  font-family: var(--mono);
}


.agent-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  flex-wrap: nowrap;
}
.agent-tabs::-webkit-scrollbar { display: none; }
.agent-tabs button {
  flex-shrink: 0;
  height: 34px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* ============================================================
   MOBILE MENU — bottom sheet com todas as seções
   ============================================================ */
.mobile-menu-scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.42);
  display: flex; align-items: flex-end;
  animation: fadeIn .18s ease both;
}
.mobile-menu-sheet {
  width: 100%;
  max-height: 86svh;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  animation: sheetUp .26s cubic-bezier(.32,.72,0,1) both;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.mobile-menu-grip {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--ink-4);
  margin: 10px auto 2px;
  flex-shrink: 0;
}
.mobile-menu-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px 10px 16px;
  font-size: 15px; font-weight: 600;
  border-bottom: 1px solid var(--line-2);
  flex-shrink: 0;
}
.mobile-menu-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 12px 8px;
  flex: 1; min-height: 0;
}
.mobile-menu-section {
  font-family: var(--mono); font-size: 9px;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-4);
  padding: 14px 8px 6px;
}
.mobile-menu-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px 10px;
  border-radius: 10px;
  font-size: 14px; color: var(--ink-2);
  text-align: left;
}
.mobile-menu-item:active { background: var(--surface-2); }
.mobile-menu-item.active {
  background: var(--surface);
  color: var(--ink); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--line);
}
.mobile-menu-item span { flex: 1; }
.mobile-menu-item .m-badge-inline {
  font-family: var(--mono); font-size: 11px;
  color: var(--ink-3); flex: none;
}
.mobile-menu-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 6px 16px 0;
  padding: 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 14px; font-weight: 500;
  color: var(--bad);
  flex-shrink: 0;
}
.mobile-menu-logout:active { background: var(--surface-2); }

/* ============================================================
   VERY SMALL PHONES — max-width 400px
   ============================================================ */
@media (max-width: 400px) {
  .stat .val { font-size: 24px; }
  .h-display { font-size: 24px; }
  .page { padding: 12px 12px calc(76px + env(safe-area-inset-bottom, 0px)); }
  .topbar { padding: 0 8px; gap: 4px; }
  .deal .val { font-size: 18px; }
}

/* ============================================================
   AUTH SHELL — tela de login/cadastro
   ============================================================ */
.auth-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
  color: var(--ink);
}
.auth-shell-right {
  display: grid;
  place-items: center;
  padding: 40px;
}

@media (max-width: 768px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }
  .auth-shell-left {
    display: none !important;
  }
  .auth-shell-right {
    padding: 32px 24px;
    align-items: flex-start;
    padding-top: 56px;
  }
}

/* ============================================================
   DASHBOARD — hero + grids responsivos
   ============================================================ */
.dash-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}
.dash-hero-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .dash-hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
  }
  .dash-hero-pills { align-items: flex-start; }
  .dash-hero .h-display,
  .dash-hero h1 { font-size: 28px !important; line-height: 1.15; }

  /* Grids do dashboard → coluna única */
  .dash-grid-main  { grid-template-columns: 1fr !important; }
  .dash-grid-lower { grid-template-columns: 1fr !important; }

  /* Pipeline chart: ajuste de larguras fixas */
  .dash-pipe-label { width: 80px !important; font-size: 11.5px !important; }
  .dash-pipe-val   { width: 64px !important; font-size: 11px !important; }
}

/* ============================================================
   GLOBAL: impede scroll lateral em todos os tamanhos
   ============================================================ */
html, body { overflow-x: hidden; max-width: 100%; }
/* mídia nunca estoura a largura do container */
img, video, canvas { max-width: 100%; }
