:root {
  --bg: #0f1013;
  --panel: #15171b;
  --raised: #1c1f25;
  --line: #262a31;
  --text: #e6e8ec;
  --muted: #8b919c;
  --faint: #5d636e;
  --accent: #7c8cff;
  --accent-soft: rgba(124, 140, 255, 0.14);
  --danger: #ff6b6b;
  --warn: #f5b84d;
  --ok: #46c98b;
  --radius: 8px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f7f8;
    --panel: #ffffff;
    --raised: #f0f1f4;
    --line: #e3e5ea;
    --text: #17191d;
    --muted: #5f6672;
    --faint: #9aa0aa;
    --accent: #4b5cf0;
    --accent-soft: rgba(75, 92, 240, 0.1);
    --danger: #c62828;
    --warn: #9a6700;
    --ok: #1a7f4b;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
kbd {
  font: 11px var(--mono);
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--muted);
  background: var(--raised);
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: 220px minmax(320px, 420px) 1fr;
  height: 100vh;
  height: 100dvh;
}
.app.with-agenda { grid-template-columns: 220px minmax(320px, 420px) 1fr 260px; }
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 10px;
  gap: 2px;
  overflow-y: auto;
}
.brand { font-weight: 600; padding: 4px 10px 14px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); }
.nav-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
}
.nav-link:hover { background: var(--raised); color: var(--text); }
.nav-link.current { background: var(--accent-soft); color: var(--text); }
.nav-count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav-section { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); }
.sidebar-footer { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); display: grid; gap: 6px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--danger); }

/* List */
.list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-width: 0; }
.list-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.list-header h1 { font-size: 15px; margin: 0; font-weight: 600; flex: 1; }
.list-filter {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 8px 14px;
  outline: none;
}
#list { overflow-y: auto; flex: 1; }
.row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 4px 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.row:hover { background: var(--raised); }
.row.selected { background: var(--accent-soft); border-left-color: var(--accent); }
.row.checked .check { background: var(--accent); border-color: var(--accent); }
.row .check { width: 14px; height: 14px; border: 1px solid var(--faint); border-radius: 4px; margin-top: 3px; }
.row .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.read .who { font-weight: 400; color: var(--muted); }
.row .when { font-size: 12px; color: var(--faint); white-space: nowrap; }
.row .title { grid-column: 2 / 4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .snippet { grid-column: 2 / 4; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { grid-column: 2 / 4; display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--raised);
  color: var(--muted);
  border: 1px solid var(--line);
}
.chip.accent { color: var(--accent); border-color: transparent; background: var(--accent-soft); }
.chip.warn { color: var(--warn); }
.chip.danger { color: var(--danger); }

/* Detail */
#detail { overflow-y: auto; min-width: 0; }
.detail-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--raised); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn kbd { background: transparent; }
.btn.primary kbd { color: rgba(255, 255, 255, 0.85); border-color: rgba(255, 255, 255, 0.35); }
.detail-body { max-width: 860px; margin: 0 auto; padding: 22px 28px 80px; }
.detail-title { font-size: 20px; font-weight: 600; margin: 0 0 6px; }
.detail-meta { color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.summary { color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px; }
.message { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 12px; }
.message-head { display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.message-head b { color: var(--text); }
.message-text { padding: 12px 14px; white-space: pre-wrap; word-break: break-word; }
.message iframe { width: 100%; border: 0; min-height: 120px; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }
.section-title { margin: 26px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); }
.factors { width: 100%; border-collapse: collapse; font-size: 13px; }
.factors td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.factors td.mult { color: var(--danger); text-align: right; font-family: var(--mono); width: 70px; }
.factors tr.total td { font-weight: 600; border-bottom: 0; }
.related { display: grid; gap: 6px; }
.related-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); }

/* Composer and panels */
.composer, .panel {
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
  margin: 16px 0;
}
.composer-head { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.composer textarea, .panel textarea {
  width: 100%;
  min-height: 140px;
  border: 0;
  background: transparent;
  padding: 12px;
  resize: vertical;
  outline: none;
}
.composer-foot { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.composer-foot .spacer { flex: 1; }
.field {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 6px;
  padding: 5px 8px;
  min-width: 0;
}
.field.grow { flex: 1; }
.panel-body { padding: 12px; display: grid; gap: 10px; }
.panel-body label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

/* Agenda rail */
.agenda { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 14px; }
.agenda h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin: 14px 0 6px; }
.agenda h2:first-child { margin-top: 0; }
.event { padding: 6px 8px; border-radius: 6px; border-left: 3px solid var(--accent); background: var(--raised); margin-bottom: 6px; font-size: 13px; }
.event .time { color: var(--muted); font-size: 12px; }
.task { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; font-size: 13px; }
.task button { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--muted); background: transparent; margin-top: 3px; cursor: pointer; padding: 0; }
.task .overdue { color: var(--danger); font-size: 12px; }

/* Toasts and overlays */
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 6px; }
.toast { background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 30px rgba(0, 0, 0, 0.35); }
.toast.error { border-color: var(--danger); }
.overlay[hidden] { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: start center; padding-top: 12vh; z-index: 40; }
.dialog { width: min(560px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); overflow: hidden; }
.dialog input.search { width: 100%; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; outline: none; font-size: 15px; }
.dialog .commands { max-height: 50vh; overflow-y: auto; }
.command { display: flex; justify-content: space-between; padding: 9px 16px; cursor: pointer; }
.command.active, .command:hover { background: var(--accent-soft); }
.shortcuts { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 12px; padding: 16px; font-size: 13px; }

/* Settings and simple pages */
.page { max-width: 880px; margin: 0 auto; padding: 28px 24px 80px; }
.page h1 { font-size: 22px; margin: 0 0 18px; }
.card { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.card p { color: var(--muted); margin: 0 0 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.form-grid label, .stack label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.stack { display: grid; gap: 10px; }
table.plain { width: 100%; border-collapse: collapse; font-size: 13px; }
table.plain td, table.plain th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.metric { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--panel); }
.metric .value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .label { color: var(--muted); font-size: 12px; }
.login { min-height: 100vh; display: grid; place-items: center; }
.login .card { width: min(380px, 92vw); text-align: center; }

/* Attachments, Drive, parcels, invites */
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.attachment { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); max-width: 100%; }
.attachment a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.parcel b { margin-right: 4px; }
.conflicts { margin-top: 8px; display: grid; gap: 2px; }
.ok-text { color: var(--ok); margin-top: 6px; font-size: 13px; }
.warn-text { color: var(--warn); }
.dialog-title { font-size: 16px; margin: 0; }
.mono { font-family: var(--mono); font-size: 12px; }

/* Today and weekly review */
.page-nav { display: flex; gap: 16px; margin-bottom: 14px; color: var(--muted); }
.page-nav a:hover, .item-links a:hover { color: var(--accent); }
.brief-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.brief-grid .card { margin-bottom: 0; }
.card h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); }
.item-links { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.item-links li { overflow-wrap: anywhere; }
.parcel-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.parcel-row:last-child { border-bottom: 0; }
.task-check { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--muted); background: transparent; cursor: pointer; padding: 0; flex: none; margin-top: 2px; }

/* Focus is always visible for keyboard users */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.list-filter:focus-visible, .composer textarea:focus-visible, .dialog input.search:focus-visible { outline-offset: -2px; }

/* Swipe on touch screens: left = done, right = snooze */
#list .row { touch-action: pan-y; position: relative; }
#list .row.swiping { transition: none; z-index: 1; }
#list .row[data-swipe="done"] { background: color-mix(in srgb, var(--ok) 18%, var(--panel)); }
#list .row[data-swipe="snooze"] { background: color-mix(in srgb, var(--warn) 18%, var(--panel)); }
#list .row.swipe-armed[data-swipe="done"] { background: color-mix(in srgb, var(--ok) 40%, var(--panel)); }
#list .row.swipe-armed[data-swipe="snooze"] { background: color-mix(in srgb, var(--warn) 40%, var(--panel)); }
@media (prefers-reduced-motion: no-preference) {
  #list .row { transition: transform 0.18s ease-out, background 0.18s; }
}

/* Phone */
.mobile-back { display: none; }
@media (max-width: 900px) {
  .app, .app.with-agenda { grid-template-columns: 1fr; }
  .sidebar, .agenda { display: none; }
  .app.show-detail .list-pane { display: none; }
  .app:not(.show-detail) #detail { display: none; }
  .mobile-back { display: inline-flex; }
  .detail-body { padding: 16px 16px calc(90px + env(safe-area-inset-bottom)); overflow-wrap: anywhere; }
  .detail-toolbar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0;
    border-top: 1px solid var(--line); border-bottom: 0;
    flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }
  .detail-toolbar .btn { min-height: 44px; }
  #detail:has(textarea:focus, input:focus) .detail-toolbar { display: none; }
  input, textarea, select { font-size: 16px; }
  #toast { bottom: calc(76px + env(safe-area-inset-bottom)); width: calc(100% - 24px); }
  .row { padding: 12px 14px; }
  .page { padding: 18px 16px 60px; }
  table.plain { display: block; overflow-x: auto; }
  .btn kbd { display: none; }
  .mobile-nav { display: flex !important; overflow-x: auto; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
  .mobile-nav .chip { white-space: nowrap; flex: none; padding: 6px 12px; }
}
.mobile-nav { display: none; }

/* Task rows in the "Calendar & tasks" split */
.task-row .check { cursor: pointer; border-radius: 50%; padding: 0; background: transparent; }
.task-row .overdue { color: var(--danger); }
.drive-account { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.drive-account.active { border-color: var(--accent); }
.drive-account-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.drive-account-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.drive-account-form label { flex: 1 1 260px; display: grid; gap: 4px; }
.drive-accounts { margin-bottom: 16px; }
@keyframes row-arrived { from { background: var(--accent-soft); } to { background: transparent; } }
.row.arrived { animation: row-arrived 2.5s ease-out; }
@media (prefers-reduced-motion: reduce) { .row.arrived { animation: none; outline: 2px solid var(--accent-soft); } }

.archive-record, .job { display: grid; gap: 6px; padding: 12px 0; border-top: 1px solid var(--line); }
.archive-record:first-of-type, .job:first-of-type { border-top: 0; }
.archive-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.archive-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.archive-form label { display: grid; gap: 4px; }
.archive-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.archive-actions form { margin: 0; }
.inline-form { display: inline; }
.ledger { display: grid; gap: 4px; }
.ledger-row { padding: 8px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.job-item { display: block; padding: 2px 0; }
.error-text { color: var(--danger); }
.steps { padding-left: 20px; display: grid; gap: 6px; }
code.token { user-select: all; overflow-wrap: anywhere; }
@media (max-width: 640px) { .archive-form { grid-template-columns: 1fr; } }
