:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d1c1a;
  --muted: #6b675f;
  --border: #e2ddd2;
  --accent: #c2562f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3da;
  --ok: #2f7d4f;
  --ok-soft: #dcefe2;
  --warn: #a86a00;
  --warn-soft: #f7ead0;
  --danger: #b3261e;
  --danger-soft: #f8dcda;
  --info-soft: #e1e8f5;
  --info: #2e5aa8;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16161a; --surface: #1f1f24; --surface-2: #2a2a30; --text: #eeece8; --muted: #a29e96;
    --border: #34343b; --accent: #e57a51; --accent-ink: #1a0f0a; --accent-soft: #3a2620;
    --ok: #6cc28c; --ok-soft: #1d3326; --warn: #e3b052; --warn-soft: #3a2f17;
    --danger: #ef7d75; --danger-soft: #3d1f1d; --info-soft: #1f2a3d; --info: #8fb0ea;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16161a; --surface: #1f1f24; --surface-2: #2a2a30; --text: #eeece8; --muted: #a29e96;
  --border: #34343b; --accent: #e57a51; --accent-ink: #1a0f0a; --accent-soft: #3a2620;
  --ok: #6cc28c; --ok-soft: #1d3326; --warn: #e3b052; --warn-soft: #3a2f17;
  --danger: #ef7d75; --danger-soft: #3d1f1d; --info-soft: #1f2a3d; --info: #8fb0ea;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}
#app.no-tabs { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---------- Cabeçalho ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  margin: 0 -16px; padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.35rem; letter-spacing: -.01em; line-height: 1.2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar h1.big { font-size: 1.75rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
h3 { font-size: .95rem; margin: 16px 0 6px; }
p { margin: 0 0 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .875rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }

.field { display: grid; gap: 6px; }
.field label { font-size: .875rem; font-weight: 600; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 140px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .5; margin-bottom: 8px; }

.search { position: relative; margin: 4px 0 14px; }
.search svg { position: absolute; left: 14px; top: 13px; color: var(--muted); }
.search .input { padding-left: 44px; }

/* ---------- Lista de notas ---------- */
.note-item { display: block; text-decoration: none; color: inherit; }
.note-item .card { display: grid; gap: 6px; }
.note-item:active .card { transform: scale(.99); }
.note-item .title { font-weight: 650; line-height: 1.3; }
.note-item .excerpt { color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kind-ico { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); flex: none; }
.kind-ico svg { width: 18px; height: 18px; }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Botão flutuante e folha de ações ---------- */
.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 20px; border: 0; z-index: 6;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px rgb(0 0 0 / .2);
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.2; }
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 20; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 720px; margin: 0 auto;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto; animation: up .2s ease-out;
}
.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 12px; }
.sheet h2 { margin-top: 4px; }
.sheet-option { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 4px; border: 0; background: none; text-align: left; cursor: pointer; border-radius: 12px; }
.sheet-option:active { background: var(--surface-2); }
.sheet-option .kind-ico { width: 44px; height: 44px; border-radius: 14px; }
.sheet-option strong { display: block; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Barra de abas ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar[hidden] { display: none; }
.tabbar a { flex: 1; max-width: 140px; display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600; }
.tabbar a.active { color: var(--accent); }

/* ---------- Segmentos (abas internas) ---------- */
.segmented { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin: 4px 0 16px; overflow-x: auto; scrollbar-width: none; }
.segmented button { flex: 1; min-height: 38px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Detalhe da nota ---------- */
.status-banner { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-weight: 500; }
.status-banner.processing { background: var(--info-soft); color: var(--info); }
.status-banner.error { background: var(--danger-soft); color: var(--danger); }
.prose ul { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin: 4px 0; }
.segment { display: grid; grid-template-columns: 58px 1fr; gap: 8px; padding: 8px 6px; border-radius: 10px; scroll-margin-top: 80px; }
.segment .ts { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .82rem; padding-top: 2px; }
.segment.hl, .page-block.hl { background: var(--accent-soft); transition: background .3s; }
.page-block { padding: 10px; border-radius: 10px; scroll-margin-top: 80px; white-space: pre-wrap; }
.page-block .ts { display: block; color: var(--muted); font-size: .8rem; font-weight: 600; margin-bottom: 4px; }

/* ---------- Tarefas ---------- */
.action { display: flex; gap: 12px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--border); }
.action:last-child { border-bottom: 0; }
.check {
  appearance: none; -webkit-appearance: none; width: 26px; height: 26px; border-radius: 8px; flex: none; margin: 1px 0 0;
  border: 2px solid var(--border); background: var(--surface); cursor: pointer; display: grid; place-items: center;
}
.check:checked { background: var(--ok); border-color: var(--ok); }
.check:checked::after { content: ""; width: 7px; height: 12px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: translate(0, -1px) rotate(45deg); }
.action.done .text { text-decoration: line-through; color: var(--muted); }
.action .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.action .tools { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- Chat ---------- */
.chat-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - 140px); }
.messages { flex: 1; display: grid; gap: 14px; align-content: start; padding-bottom: 16px; }
.msg { max-width: 92%; padding: 12px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.user { justify-self: end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.assistant { justify-self: start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg .prose p:last-child { margin-bottom: 0; }
.cite { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; margin: 0 1px; border-radius: 6px; border: 0; background: var(--accent-soft); color: var(--accent); font-size: .72rem; font-weight: 700; vertical-align: 2px; cursor: pointer; }
.sources { margin-top: 10px; display: grid; gap: 6px; }
.source { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: .85rem; }
.source b { color: var(--accent); }
.source .q { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.composer {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  display: flex; gap: 8px; align-items: flex-end; padding: 8px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.composer textarea { flex: 1; border: 0; outline: none; background: transparent; resize: none; min-height: 40px; max-height: 140px; padding: 8px 6px; }
.composer .btn { min-height: 40px; width: 44px; padding: 0; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.suggestions button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: .88rem; cursor: pointer; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Gravador ---------- */
.recorder { display: grid; place-items: center; gap: 24px; padding: 32px 0; text-align: center; }
.rec-time { font-size: 3.2rem; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.rec-canvas { width: 100%; height: 96px; }
.rec-btn { width: 84px; height: 84px; border-radius: 50%; border: 6px solid var(--accent-soft); background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; }
.rec-btn svg { width: 34px; height: 34px; }
.rec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s steps(2) infinite; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- Login ---------- */
.auth { min-height: 100dvh; display: grid; align-content: center; gap: 24px; padding: 24px 0; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 52px; height: 52px; border-radius: 14px; }
.brand h1 { margin: 0; font-size: 2rem; letter-spacing: -.02em; }
.features { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.features li { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.features svg { color: var(--accent); }
.error-text { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 500; box-shadow: var(--shadow);
  animation: up .2s ease-out;
}
.select-note { display: flex; gap: 12px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.select-note:last-child { border-bottom: 0; }

@media (min-width: 760px) {
  .topbar h1.big { font-size: 2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
