:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --bubble-user: #2563eb;
  --bubble-user-text: #ffffff;
  --bubble-bot: #ffffff;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #1b2640;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #243049;
    --accent: #60a5fa;
    --accent-text: #0b1220;
    --danger: #f87171;
    --warn-bg: #3b2f0b;
    --warn-text: #fde68a;
    --bubble-user: #2563eb;
    --bubble-user-text: #ffffff;
    --bubble-bot: #1b2640;
  }
}

* { box-sizing: border-box; }
:root { --app-height: 100vh; } /* set from the visual viewport by common.js while the keyboard is up */
/* No position:fixed anywhere in the shell: iOS 26 Home Screen web apps render a permanent
   black band under viewport-sized fixed containers (Apple bug 158055568). */
html { height: 100%; background: var(--bg); }
body {
  margin: 0;
  height: 100%;
  overflow: hidden; /* the shell scrolls its <main>, never the page */
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---- App shell -------------------------------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  /* 100vh, deliberately not 100dvh: iOS 26.x has a regression where 100dvh leaves a gap at the
     bottom of the screen (Apple forum thread 803987). In Home Screen mode 100vh is exactly the
     screen. In a browser tab, common.js sets --app-height from window.innerHeight instead, so the
     shell tracks Safari's toolbar. */
  height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}
/* Only while the on-screen keyboard is up does the shell shrink to the visual viewport, so the
   composer sits right above the keyboard. */
.app.keyboard-open { height: var(--app-height); }
@media (display-mode: browser) {
  .app { height: var(--app-height); }
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 650; }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a, .topbar nav button {
  padding: 6px 10px; border-radius: 10px; font-size: 14px;
  background: var(--surface-2); border: 0; color: var(--text);
}
.topbar nav a.active { background: var(--accent); color: var(--accent-text); }
.back { font-size: 15px; padding: 6px 4px; }

main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px; }
main.centered { display: grid; place-items: center; }

/* ---- Components -------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.card + .card { margin-top: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="datetime-local"], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); outline: none;
  font-size: 16px; /* prevents iOS zoom-on-focus */
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 44px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-weight: 600; min-height: 44px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 14px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; }
.status { font-size: 14px; color: var(--muted); }
.hidden { display: none !important; }

/* ---- Due banner -------------------------------------------------------- */
.banner {
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
}
.banner .row { justify-content: space-between; }
.banner strong { font-weight: 650; }
.banner button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 8px; padding: 4px 8px; font-size: 13px; }

/* ---- Chat -------------------------------------------------------------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 86%; padding: 10px 13px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; font-size: 15.5px; }
.msg.user { align-self: flex-end; background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--bubble-bot); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.assistant.command, .msg.assistant.help { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; }
.msg .src { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.msg.pending { opacity: .6; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }
.chips button { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 13px; }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px 8px;
  background: var(--surface); border-top: 1px solid var(--border);
}
.composer textarea { flex: 1; max-height: 140px; }
.composer button { min-width: 64px; }

/* ---- Tasks ------------------------------------------------------------- */
.tabs { display: flex; gap: 6px; margin: 4px 0 12px; }
.tabs button { flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 14px; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.group-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 14px 4px 6px; }
.task { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; }
.task + .task { margin-top: 8px; }
.task input[type="checkbox"] { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; word-break: break-word; }
.task .desc { color: var(--muted); font-size: 14px; white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.task .due { font-size: 13px; color: var(--muted); margin-top: 4px; }
.task.overdue .due { color: var(--danger); font-weight: 600; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .del { background: transparent; border: 0; color: var(--muted); font-size: 20px; line-height: 1; padding: 2px 6px; }
.task .del:hover { color: var(--danger); }
details.new-task summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details.new-task summary::-webkit-details-marker { display: none; }
details.new-task summary::after { content: "+"; font-size: 22px; color: var(--accent); }
details.new-task[open] summary::after { content: "–"; }
details.new-task form { margin-top: 12px; }

/* ---- Version footer ---------------------------------------------------- */
/* The footer is the bottom-most element on every page, so it alone carries the home-indicator
   safe-area padding and paints down to the screen edge. */
.footer {
  flex: none;
  text-align: center; font-size: 11px; color: var(--muted); letter-spacing: .03em;
  padding: 8px 16px calc(8px + var(--safe-bottom));
  background: var(--bg);
}
.composer + .footer { padding-top: 0; background: var(--surface); }

/* ---- Login ------------------------------------------------------------- */
.login { width: min(420px, 100%); }
.login .logo { font-size: 28px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.login .tag { text-align: center; margin-bottom: 20px; }
