:root {
  --bg: #f4f3f1;
  --surface: #ffffff;
  --surface-2: #efeeeb;
  --text: #161616;
  --muted: #6b6965;
  --line: #e2e0dc;
  --accent: #f07a1a;
  --accent-ink: #ffffff;
  --accent-soft: #fde9d8;
  --danger: #c2372d;
  --ok: #1f8a4c;
  --note-bg: #fff6df;
  --note-line: #f0d48a;
  --bubble-in: #ffffff;
  --bubble-out: #ffe8d4;
  --f-escritorio: #2c5ea8;
  --f-fuinha: #f07a1a;
  --f-audiovisual: #7b4fc4;
  --f-pessoal: #2e8b57;
  --f-outros: #8a8781;
  --f-indefinido: #8a8781;
  --alta-bg: #fde2df;
  --auto: #2f7d6d;
  --auto-soft: #dff1ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0f; --surface: #1a1a1a; --surface-2: #242424; --text: #f2f1ef; --muted: #a3a09b;
    --line: #2d2d2d; --accent-soft: #3a2614; --note-bg: #2a2412; --note-line: #5c4b1d;
    --bubble-in: #222; --bubble-out: #3a2614; --shadow: none; --alta-bg: #3b1916; --auto: #5cc2ab; --auto-soft: #143029; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f0f; --surface: #1a1a1a; --surface-2: #242424; --text: #f2f1ef; --muted: #a3a09b;
  --line: #2d2d2d; --accent-soft: #3a2614; --note-bg: #2a2412; --note-line: #5c4b1d;
  --bubble-in: #222; --bubble-out: #3a2614; --shadow: none; --alta-bg: #3b1916; --auto: #5cc2ab; --auto-soft: #143029; color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100dvh;
}
button, textarea, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); }

/* Barra superior */
.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  padding: 10px 16px 8px; border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 26px; letter-spacing: -.02em; margin: 0; flex: 1; }
.top h2 { font-size: 17px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-line { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); } .dot.off { background: var(--danger); }

/* Filtros */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .6; margin-left: 4px; }
.seg { display: flex; margin: 8px 16px 4px; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 7px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

/* Lista */
.list { padding: 8px 12px 120px; display: grid; gap: 8px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: grid; gap: 4px; text-align: left; width: 100%; border-left: 4px solid var(--f-indefinido); }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-time { font-size: 13px; color: var(--muted); flex: none; }
.card-sum { font-size: 14.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.front { color: #fff; }
.tag.alta { background: var(--alta-bg); color: var(--danger); font-weight: 600; }
.tag.auto { background: var(--auto-soft); color: var(--auto); font-weight: 600; }
.auto-band { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--auto-soft); color: var(--text); border: 1px solid var(--auto); border-radius: var(--radius); padding: 12px 14px; }
.auto-band div { display: grid; gap: 2px; min-width: 0; }
.auto-band span { font-size: 13px; color: var(--muted); }
.auto-band .btn { flex: none; padding: 9px 14px; }
.bubble.auto { background: var(--auto-soft); }
.tag.ready { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 60px 24px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* Conversa */
.detail { padding: 8px 12px 24px; display: grid; gap: 12px; }
.msgs { display: grid; gap: 6px; padding: 4px 2px; }
.bubble { max-width: 84%; padding: 8px 11px; border-radius: 14px; background: var(--bubble-in); box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; font-size: 15px; }
.bubble.me { justify-self: end; background: var(--bubble-out); }
.bubble time { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; text-align: right; }
.media-img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; object-fit: cover; }
.media-audio { display: block; width: 240px; max-width: 100%; height: 40px; margin-bottom: 4px; }
.media-doc { display: inline-block; font-weight: 600; margin-bottom: 4px; }
.media-note { font-size: 13.5px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 8px; margin-top: 4px; white-space: pre-wrap; }
.media-note b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }
.media-note.muted { font-style: italic; }
.more { justify-self: center; font-size: 13px; color: var(--muted); }
.box { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.box h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.note { background: var(--note-bg); border: 1px solid var(--note-line); border-radius: 12px; padding: 10px 12px; font-size: 14.5px; white-space: pre-wrap; }
.sources { display: grid; gap: 4px; font-size: 14px; }
.sources a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
textarea.draft { width: 100%; min-height: 120px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); resize: none; font-size: 16px; line-height: 1.45; }
textarea.draft:focus, textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn { padding: 13px 14px; border-radius: 12px; font-weight: 600; background: var(--surface-2); text-align: center; display: flex; gap: 6px; align-items: center; justify-content: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); grid-column: 1 / -1; font-size: 17px; }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 500; }
.btn:disabled { opacity: .5; }
.btn svg { width: 18px; height: 18px; }
select.front-select { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 8px; font-size: 14px; }
.btn.recording { background: var(--danger); color: #ffffff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .7; } }
@media (prefers-reduced-motion: reduce) { .btn.recording { animation: none; } }
.btn.spin svg { animation: spin 1s linear infinite; }
details.ctx summary { list-style: none; cursor: pointer; }
details.ctx summary::-webkit-details-marker { display: none; }
details.ctx summary h3::after { content: " ▸"; }
details.ctx[open] summary h3::after { content: " ▾"; }
.memo { font-size: 14.5px; color: var(--text); white-space: pre-wrap; margin: 0; }
.memo b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 2px; }
.note-input { width: 100%; min-height: 70px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); resize: vertical; font-size: 16px; }
.badge-wrap { position: relative; }
.badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #ffffff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.card.task { border-left-color: var(--accent); }
.card.task .card-name { white-space: normal; }
.task-res { white-space: pre-wrap; font-size: 14.5px; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; max-height: 60vh; overflow: auto; }
.card.task .actions { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.sources small { color: var(--muted); display: block; }
.contact-list { display: grid; gap: 6px; max-height: 55dvh; overflow: auto; }
.contact { text-align: left; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); display: grid; gap: 2px; }
.contact span { font-size: 13px; color: var(--muted); }
.revs { display: grid; gap: 10px; }
.rev { font-size: 14px; border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 4px; }
.rev q { font-weight: 600; quotes: "“" "”"; }

/* Folhas (bottom sheets) */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; animation: fade .15s ease; }
.sheet { background: var(--surface); width: 100%; max-height: 92dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 12px; animation: up .2s ease; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); justify-self: center; }
.sheet h3 { margin: 0; font-size: 19px; }
.sheet p { margin: 0; color: var(--muted); font-size: 15px; }
.sheet .preview { background: var(--surface-2); border-radius: 12px; padding: 12px; white-space: pre-wrap; max-height: 40dvh; overflow: auto; }
.sheet textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); resize: vertical; font-size: 16px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.row { display: flex; justify-content: space-between; gap: 12px; align-items: center; font-size: 15px; }
.qr { justify-self: center; background: #ffffff; padding: 10px; border-radius: 12px; width: min(280px, 80vw); }
@media (min-width: 700px) { .backdrop { align-items: center; justify-content: center; } .sheet { max-width: 520px; border-radius: 18px; } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }

/* Login */
.login { min-height: 90dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; justify-self: center; }
.login input { padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; }
.err { color: var(--danger); font-size: 14px; min-height: 1.2em; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; opacity: 0; transition: .2s; z-index: 40; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.loading::before { content: ""; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
