:root {
  --bg: #f4f6f9; --panel: #ffffff; --panel-2: #f8fafc; --border: #e2e8f0; --text: #1e293b; --muted: #64748b;
  --accent: #2563eb; --accent-fg: #ffffff; --accent-soft: #e8f0fe; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 10px; --sel: #eaf1ff;
  --st-novo: #2563eb; --st-em_atendimento: #d97706; --st-aguardando: #7c3aed; --st-resolvido: #16a34a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --panel: #161b22; --panel-2: #1c2330; --border: #2b3441; --text: #e6edf3; --muted: #8b98a9;
    --accent: #4c8dff; --accent-fg: #0b1220; --accent-soft: #16233f; --sel: #17233d; --shadow: 0 1px 2px rgba(0,0,0,.4);
    --st-novo: #58a6ff; --st-em_atendimento: #f0a13a; --st-aguardando: #b392f0; --st-resolvido: #3fb950;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #161b22; --panel-2: #1c2330; --border: #2b3441; --text: #e6edf3; --muted: #8b98a9;
  --accent: #4c8dff; --accent-fg: #0b1220; --accent-soft: #16233f; --sel: #17233d; --shadow: 0 1px 2px rgba(0,0,0,.4);
  --st-novo: #58a6ff; --st-em_atendimento: #f0a13a; --st-aguardando: #b392f0; --st-resolvido: #3fb950;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- controles ---------- */
.btn { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--panel-2); border-color: color-mix(in srgb, var(--border), var(--text) 18%); }
.btn:focus-visible, .input:focus-visible, .list-item:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 10px; }
.input.sm { padding: 5px 8px; font-size: 13px; width: auto; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.field .input { color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- login ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo img { width: 28px; height: 28px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-rows: 52px 1fr; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar .search { max-width: 460px; }
.nav-link { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.nav-link:hover { background: var(--panel-2); color: var(--text); }
.nav-link.active { color: var(--text); background: var(--accent-soft); font-weight: 600; }
.banner { padding: 8px 14px; background: color-mix(in srgb, var(--warn), var(--panel) 85%); border-bottom: 1px solid var(--warn); color: var(--text); font-size: 13px; }

.view-host { min-height: 0; display: flex; overflow: hidden; }
.view-host > .mail { flex: 1; min-width: 0; }
.view-host > .page { overflow: auto; }
.mail { display: grid; grid-template-columns: 232px 380px minmax(0, 1fr); min-height: 0; }
.pane { min-height: 0; overflow: auto; }
.side { background: var(--panel); border-right: 1px solid var(--border); padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.side h4 { margin: 12px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; cursor: pointer; border: 0; background: transparent; text-align: left; width: 100%; }
.side-item:hover { background: var(--panel-2); }
.side-item.active { background: var(--accent-soft); font-weight: 600; }
.badge { margin-left: auto; background: var(--accent); color: var(--accent-fg); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; }
.list { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.list-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-scroll { overflow: auto; flex: 1; }
.list-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: var(--panel); padding: 10px 12px 10px 16px; cursor: pointer; position: relative; }
.list-item:hover { background: var(--panel-2); }
.list-item.selected { background: var(--sel); }
.list-item.unread::before { content: ""; position: absolute; left: 6px; top: 16px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.list-item.unread .l-from, .list-item.unread .l-subject { font-weight: 700; }
.l-top { display: flex; gap: 8px; align-items: baseline; }
.l-from { flex: 1; min-width: 0; }
.l-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.l-addr { margin-top: 1px; }
.l-subject { margin-top: 1px; }
.l-snip { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.l-meta { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.detail { background: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.detail-empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 24px; }

/* ---------- chips / avatares ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 1px 8px; border: 1px solid currentColor; }
.chip.st-novo { color: var(--st-novo); } .chip.st-em_atendimento { color: var(--st-em_atendimento); }
.chip.st-aguardando { color: var(--st-aguardando); } .chip.st-resolvido { color: var(--st-resolvido); }
.chip.plain { color: var(--muted); font-weight: 500; }
.avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; flex: none; border: 2px solid var(--panel); }
.avatar.lg { width: 30px; height: 30px; font-size: 12px; }
.avatars { display: inline-flex; }
.avatars .avatar + .avatar { margin-left: -6px; }
.assignee { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }

/* ---------- leitura ---------- */
.d-head { padding: 14px 18px 10px; border-bottom: 1px solid var(--border); }
.d-head h2 { font-size: 18px; margin-bottom: 8px; word-break: break-word; }
.d-from { display: flex; gap: 10px; align-items: flex-start; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.seen { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.seen .who { display: inline-flex; gap: 5px; align-items: center; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px 2px 3px; }
.presence { color: var(--ok); font-weight: 600; font-size: 12.5px; }
.presence::before { content: "● "; }
.d-body { flex: 1; min-height: 240px; position: relative; }
.d-body iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.att { display: flex; flex-direction: column; gap: 6px; padding: 10px 18px; border-top: 1px solid var(--border); }
.att-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.att a { display: inline-flex; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; color: var(--text); background: var(--panel-2); }
.att-row .check { font-size: 13px; color: var(--muted); }
.tabs { display: flex; gap: 2px; border-top: 1px solid var(--border); padding: 0 12px; background: var(--panel-2); }
.tab { border: 0; background: transparent; padding: 9px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-body { padding: 12px 18px; max-height: 260px; overflow: auto; background: var(--panel-2); }
.note { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.note .meta { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.autocomplete-wrap { position: relative; }
.autocomplete { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin: 2px 0 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow: auto; }
.autocomplete li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.autocomplete li:hover, .autocomplete li.active { background: var(--sel); }
.editor { min-height: 220px; max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--panel); }
.editor:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.editor p { margin: 0 0 .5em; }
.editor blockquote { margin: .4em 0; padding-left: .8em; border-left: 3px solid var(--border); color: var(--muted); }
.note-body { white-space: pre-wrap; word-break: break-word; }
.big { font-size: 42px; line-height: 1; margin-bottom: 8px; }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { padding: 5px 0 5px 14px; border-left: 2px solid var(--border); margin-left: 6px; position: relative; font-size: 13px; }
.tl li::before { content: ""; position: absolute; left: -5px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.remote-note { padding: 6px 18px; font-size: 12.5px; background: var(--panel-2); border-top: 1px solid var(--border); }

/* ---------- admin ---------- */
.page { padding: 20px; max-width: 980px; margin: 0 auto; width: 100%; overflow: auto; }
.page-title { font-size: 22px; margin-bottom: 14px; }
.scroll-list { max-height: 260px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.color-picker { width: 60px; height: 36px; padding: 2px; }
.rule-inactive { opacity: .5; }
.mt { margin-top: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .num { font-size: 24px; font-weight: 700; line-height: 1.2; }
.kpi .lbl { font-size: 12px; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; min-width: 0; }
.bar-col .bar { width: 100%; max-width: 28px; min-height: 2px; background: var(--accent); border-radius: 3px 3px 0 0; }
.bar-col .bar-n { font-size: 10.5px; color: var(--muted); }
.bar-col .bar-day { font-size: 10px; color: var(--muted); writing-mode: vertical-rl; text-orientation: mixed; height: 34px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; }
.table td { padding: 8px; border-top: 1px solid var(--border); vertical-align: middle; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.pill-ok { color: var(--ok); } .pill-bad { color: var(--danger); }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal.wide { max-width: 760px; }
.modal h3 { margin-bottom: 14px; font-size: 17px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- responsivo ---------- */
.only-mobile { display: none; }
@media (max-width: 1100px) { .mail { grid-template-columns: 200px 320px minmax(0, 1fr); } }
@media (max-width: 860px) {
  .mail { grid-template-columns: 1fr; }
  .mail .side, .mail .list, .mail .detail { display: none; }
  .mail.view-side .side, .mail.view-list .list, .mail.view-detail .detail { display: flex; }
  .only-mobile { display: inline-flex; }
  .topbar .search { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .d-body { min-height: 320px; }
  .hide-mobile { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
