:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d2125;
  --muted: #6b7076;
  --line: #dedbd3;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --accent: #b8731f;
  --ok: #2e7d4f;
  --warn: #a15c00;
  --danger: #b3261e;
  --chip: #e6ecf3;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --surface: #1e2227; --surface-2: #262b31; --text: #e8e9ea; --muted: #9aa0a6;
    --line: #333940; --brand: #7fa7d6; --brand-ink: #0f1720; --accent: #e0a458; --chip: #26313e;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c; --surface: #1e2227; --surface-2: #262b31; --text: #e8e9ea; --muted: #9aa0a6;
  --line: #333940; --brand: #7fa7d6; --brand-ink: #0f1720; --accent: #e0a458; --chip: #26313e;
  --shadow: 0 1px 2px rgba(0,0,0,.4); 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, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .center { text-align: center; } .small { font-size: .85rem; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 1.2rem; font-weight: 600; color: var(--text); text-decoration: none; }
nav { display: flex; gap: .3rem; flex-wrap: wrap; margin-left: auto; align-items: center; }
nav[hidden], [hidden] { display: none !important; }
nav a, .link { color: var(--muted); text-decoration: none; padding: .35rem .6rem; border-radius: 8px; font-size: .95rem; background: none; border: 0; cursor: pointer; font: inherit; }
nav a.on { color: var(--text); background: var(--surface-2); }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: .55rem .9rem; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: wait; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: .55rem .7rem; width: 100%;
}
textarea { resize: vertical; min-height: 4.5rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .2rem; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile {
  text-align: left; display: flex; flex-direction: column; gap: .35rem; min-height: 120px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); cursor: pointer; position: relative; color: var(--text); text-decoration: none;
}
.tile:hover { border-color: var(--brand); }
.tile .t { font-weight: 600; font-size: 1.02rem; }
.tile .meta { margin-top: auto; font-size: .8rem; color: var(--muted); }
.tile .next { font-size: .85rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { position: absolute; top: 10px; right: 10px; background: var(--accent); color: #fff; border-radius: 999px; font-size: .75rem; padding: 0 .5rem; font-weight: 600; }
.chip { display: inline-block; background: var(--chip); color: var(--text); border-radius: 999px; font-size: .75rem; padding: .05rem .55rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 10px; }

.layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.item { border-left: 3px solid var(--line); padding: 8px 0 8px 12px; }
.item.reuniao { border-color: #4a7ab8; } .item.email { border-color: #b8731f; } .item.mensagem { border-color: #2e7d4f; } .item.nota { border-color: #8a6bb5; } .item.documento { border-color: #6b7076; }
.item .h { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.item .h .t { font-weight: 600; }
.item .resumo { margin: .25rem 0; }
.item details summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.item .corpo { white-space: pre-wrap; font-size: .92rem; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin-top: .4rem; max-height: 420px; overflow: auto; }
.item .md { white-space: normal; }
.item .thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: .4rem; }
.item .thumbs img { height: 90px; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }
.auto { font-size: .8rem; color: var(--warn); }
.auto button, .mini { font-size: .8rem; padding: .15rem .5rem; border-radius: 7px; }

.chat { display: flex; flex-direction: column; height: min(72vh, 760px); }
.chat .msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 10px; }
.msg { padding: 9px 12px; border-radius: 12px; max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); }
.msg.assistant p { margin: .3rem 0; } .msg.assistant ul, .msg.assistant ol { margin: .3rem 0; padding-left: 1.2rem; }
.chat form { display: flex; gap: 8px; align-items: flex-end; }
.chat form textarea { min-height: 2.8rem; max-height: 10rem; }
.chat.full { height: calc(100vh - 170px); }

.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--brand); color: var(--text); }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 18px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal img.full { max-width: 100%; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); }
#toast.on { opacity: .95; }

.login { max-width: 360px; margin: 12vh auto; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
