:root {
  --ink: #0e2233;
  --ground: #f3f7fa;
  --surface: #ffffff;
  --line: #d5e0e8;
  --line-soft: #e6edf2;
  --muted: #4a6072;
  --accent: #0b6e8f;
  --accent-dark: #084f68;
  --accent-soft: #e1f0f5;
  --note: #9a3d08;
  --note-soft: #fceee4;
  --note-line: #f0c9ad;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.47 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2 { font-family: "Space Grotesk", Inter, system-ui, sans-serif; font-weight: 600; margin: 0; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-size: 0.92em; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 18px; }
.strong { font-weight: 500; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.hint { font-size: 13px; line-height: 19px; color: var(--muted); }
.error, .notice { padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.error { background: var(--note-soft); color: var(--note); border: 1px solid var(--note-line); }
.notice { background: var(--accent-soft); color: var(--accent-dark); }
.empty { color: var(--muted); padding: 24px 4px; }
.dev-banner { background: var(--note-soft); color: var(--note); font-size: 12px; font-weight: 600; text-align: center; padding: 3px 8px; }

.button, button.primary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid #b9c9d4; background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.button.primary, button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover, button.primary:hover { background: var(--accent-dark); color: #fff; }
button.link { min-height: 44px; padding: 0 10px; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="email"], textarea {
  width: 100%; padding: 12px 14px; border: 1px solid #b9c9d4; border-radius: 12px;
  background: var(--ground); font-size: 16px;
}
textarea { resize: vertical; line-height: 1.4; }
.stack { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.stack label { font-size: 14px; font-weight: 600; }

/* Sign-in pages */
body.dark { background: var(--ink); }
.entry { min-height: 100%; max-width: 440px; margin: 0 auto; display: flex; flex-direction: column; }
.entry-top { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; padding: 32px 24px 28px; color: #fff; }
.entry-top .range { width: 100%; height: auto; }
.entry-top h1 { font-size: 34px; line-height: 38px; }
.kicker { margin: 8px 0 0; font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: #9fd3e4; }
.lede { margin: 0; color: #c9dbe5; }
.entry-card { background: var(--surface); border-radius: 20px 20px 0 0; padding: 24px 24px 32px; display: flex; flex-direction: column; gap: 12px; }
.entry-card h2 { font-size: 22px; }
.entry-card button.primary, .entry-card .button.primary { min-height: 52px; font-size: 16px; border-radius: 12px; }
.dev-pick { font-size: 13px; color: var(--muted); }
.dev-pick .button { min-height: 36px; margin: 6px 4px 0 0; }
@media (min-width: 520px) {
  .entry { justify-content: center; }
  .entry-top { flex: none; }
  .entry-card { border-radius: 20px; margin-bottom: 32px; }
}

/* Top bar */
.bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.bar .brand { color: var(--accent); display: flex; }
.bar .titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar h1 { font-size: 18px; line-height: 22px; }
.bar .titles span { font-size: 12px; line-height: 16px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar h1 .muted { font-weight: 500; font-size: inherit; }
.bar > a:not(.icon-button) { min-height: 44px; display: flex; align-items: center; font-size: 14px; font-weight: 600; text-decoration: none; }
.icon-button { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--ink); font-size: 22px; }
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; }

.menu { position: relative; }
.menu summary { list-style: none; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 10px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute; right: 0; top: 48px; z-index: 5; min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(14, 34, 51, 0.14);
  display: flex; flex-direction: column;
}
.menu-items form { margin: 0; }
.menu-name { padding: 8px 10px; font-size: 12px; font-weight: 600; color: var(--muted); }
.menu-items a, .menu-items button {
  display: flex; align-items: center; width: 100%; min-height: 44px; padding: 0 10px; border: 0; border-radius: 8px;
  background: none; color: var(--ink); font-size: 15px; text-decoration: none; text-align: left;
}
.menu-items a:hover, .menu-items button:hover { background: var(--ground); color: var(--ink); }

/* Chat */
body.chat { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; background: var(--ground); }
@media (min-width: 760px) { body.chat { border-inline: 1px solid var(--line); } html { background: #e9eff3; } }
.thread { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 16px; overscroll-behavior: contain; }
.msg { max-width: min(84%, 560px); overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--ink); color: #fff; border-radius: 16px 16px 4px 16px; padding: 10px 14px; }
.msg.bot { align-self: flex-start; display: flex; flex-direction: column; gap: 6px; }
.msg .who { margin: 0 0 -3px 4px; font-size: 12px; line-height: 16px; font-weight: 600; color: var(--accent); }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 12px 14px; }
.bubble p:last-child, .bubble ul:last-child { margin-bottom: 0; }
.bubble ul { margin: 0 0 10px; padding-left: 20px; }
.bubble strong { font-weight: 600; }
.bubble.thinking { color: var(--muted); animation: pulse 1.6s ease-in-out infinite; }
.bubble.problem { background: var(--note-soft); border-color: var(--note-line); color: var(--note); }
@keyframes pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .bubble.thinking { animation: none; } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 32px; padding: 4px 12px; border-radius: 16px;
  font-size: 12px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.chip span { overflow: hidden; text-overflow: ellipsis; max-width: 210px; }
.chip svg { flex: none; font-size: 13px; }
.chip.doc { background: var(--accent-soft); color: var(--accent-dark); }
.chip.note { background: var(--note-soft); color: var(--note); }

.saved { background: var(--note-soft); border: 1px solid var(--note-line); border-radius: 12px; padding: 12px 14px 4px; display: flex; flex-direction: column; gap: 6px; }
.saved.removed { flex-direction: row; align-items: center; padding-bottom: 12px; font-size: 13px; color: var(--note); }
.saved-head { display: flex; align-items: center; gap: 6px; font-size: 12px; line-height: 16px; font-weight: 600; color: var(--note); }
.saved-text { font-size: 14px; line-height: 20px; }
.saved-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: #5a4a40; }
.saved-actions { display: flex; align-items: center; }
.saved-actions form { margin: 0; }
.saved-actions a, .saved-actions button { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; border: 0; background: none; color: var(--note); font-size: 13px; font-weight: 600; text-decoration: none; }

.welcome { margin: auto 0; padding: 8px 4px; }
.welcome h2 { font-size: 26px; margin-bottom: 8px; }
.welcome p { color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.suggestion { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); font-size: 13px; font-weight: 500; }
.suggestion:hover { border-color: var(--accent); }

.composer { display: flex; align-items: flex-end; gap: 8px; margin: 0; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)) 16px; background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-height: 48px; max-height: 140px; padding: 12px 16px; border-radius: 24px; resize: none; font-size: 16px; line-height: 22px; }
.composer button { width: 48px; height: 48px; flex: none; border: 0; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.composer button:disabled { background: #8fb3c2; cursor: default; }

/* Notes and admin */
.page { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 12px; }
.page.wide, .bar.wide { max-width: none; }
.page.wide { padding: 24px max(16px, calc((100% - 1120px) / 2)) 48px; gap: 20px; }
.bar.wide { padding-inline: max(16px, calc((100% - 1120px) / 2)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.card h2 { font-size: 18px; line-height: 24px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 10px; }
.card-head > div { flex: 1; min-width: 220px; }
.card-head .hint { margin: 2px 0 0; }
.columns { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.columns > .card { flex: 1 1 420px; min-width: 0; }

.note { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 4px; scroll-margin-top: 16px; }
.note:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.note p { margin: 0; overflow-wrap: anywhere; }
.note-foot { display: flex; align-items: center; justify-content: space-between; min-height: 44px; font-size: 12px; color: var(--muted); }
.note-actions form { margin: 0; }
.note .edit { margin: -44px 0 0; padding-bottom: 8px; }
.note .edit summary { list-style: none; display: flex; align-items: center; width: fit-content; min-height: 44px; margin-left: auto; margin-right: 62px; padding: 0 10px; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }
.note .edit summary::-webkit-details-marker { display: none; }

.row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.row form { margin: 0; }
.row .avatar { width: 36px; height: 36px; font-size: 14px; }
.badge { margin-left: 6px; padding: 2px 8px; border-radius: 10px; background: var(--line-soft); font-size: 11px; font-weight: 600; }
.scroll-x { overflow-x: auto; }
table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 14px; line-height: 20px; }
th { text-align: left; padding: 8px 12px 8px 0; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
td { padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line-soft); }
td form { margin: 0; }
tr:last-child td { border-bottom: 0; }
td:first-child a { font-weight: 500; text-decoration: none; }
