:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --surface-2: #F1F0EC;
  --ink: #1D1C21;
  --ink-2: #4A4852;
  --muted: #8A8794;
  --line: #E9E7E1;
  --line-2: #DEDBD3;
  --accent: #5B57E0;
  --accent-ink: #FFFFFF;
  --accent-soft: #EEEDFD;
  --good: #2E9D6B;
  --good-soft: #E4F4EC;
  --warn: #C9821B;
  --warn-soft: #FBF1E0;
  --bad: #D5405A;
  --bad-soft: #FBE8EC;
  --claude: #D97757;
  --claude-soft: #FBEDE7;
  --shadow: 0 1px 2px rgba(20, 18, 30, .04), 0 4px 16px rgba(20, 18, 30, .05);
  --shadow-lg: 0 8px 40px rgba(20, 18, 30, .14);
  --r: 16px;
  --r-sm: 10px;
  --side: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113; --surface: #1A1A1E; --surface-2: #222227; --ink: #EDECF1; --ink-2: #C3C1CC; --muted: #8C8A97;
    --line: #2A2A30; --line-2: #34343B; --accent: #8783FF; --accent-ink: #111113; --accent-soft: #25243F;
    --good: #4CC38A; --good-soft: #17291F; --warn: #E5A445; --warn-soft: #2D2416; --bad: #F06A80; --bad-soft: #321A20;
    --claude: #E8906F; --claude-soft: #2F211B;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); --shadow-lg: 0 8px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111113; --surface: #1A1A1E; --surface-2: #222227; --ink: #EDECF1; --ink-2: #C3C1CC; --muted: #8C8A97;
  --line: #2A2A30; --line-2: #34343B; --accent: #8783FF; --accent-ink: #111113; --accent-soft: #25243F;
  --good: #4CC38A; --good-soft: #17291F; --warn: #E5A445; --warn-soft: #2D2416; --bad: #F06A80; --bad-soft: #321A20;
  --claude: #E8906F; --claude-soft: #2F211B;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); --shadow-lg: 0 8px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--line); background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand img { width: 30px; height: 30px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--r-sm); color: var(--ink-2);
  font-weight: 600; font-size: 14.5px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.nav-item.on svg { color: var(--accent); }
.nav-item .badge { margin-left: auto; }
.side .grow { flex: 1; }
.side-add { margin-bottom: 14px; }
.main { min-width: 0; padding: 32px 40px 80px; }
.page { max-width: 980px; margin: 0 auto; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tabbar { display: none; }

/* ---------- typography ---------- */
.h1 { font-size: 30px; line-height: 1.15; font-weight: 800; letter-spacing: -.03em; margin: 0; }
.sub { color: var(--muted); font-weight: 500; margin-top: 4px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.sec-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.sec-title .cnt { color: var(--ink-2); }
.sec-title .more { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 600; }

/* ---------- primitives ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line-2); background: var(--surface); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.icon { width: 36px; padding: 0; }
.btn.block { width: 100%; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--line-2);
  background: var(--surface); font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2); white-space: nowrap;
}
.chip:hover { border-color: var(--muted); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); padding: 1px 8px; border-radius: 99px; background: var(--surface-2); }
.tag.overdue { background: var(--bad-soft); color: var(--bad); }
.tag.today { background: var(--accent-soft); color: var(--accent); }
.tag.claude { background: var(--claude-soft); color: var(--claude); }
.tag.p1 { background: var(--warn-soft); color: var(--warn); }
.tag.p2 { background: var(--bad-soft); color: var(--bad); }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line-2); background: var(--surface); border-radius: 11px; padding: 9px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-weight: 500; }
.empty .big { font-size: 30px; display: block; margin-bottom: 6px; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 38px; }

/* ---------- today ---------- */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; margin-bottom: 22px; }
.ring { position: relative; width: 84px; height: 84px; }
.ring svg { width: 84px; height: 84px; transform: rotate(-90deg); }
.ring .v { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-weight: 800; font-size: 19px; line-height: 1; }
.ring .v small { display: block; font-size: 10.5px; color: var(--muted); font-weight: 600; margin-top: 3px; }
.capture { display: flex; gap: 8px; padding: 8px; margin-bottom: 26px; align-items: center; }
.capture .input { border: 0; box-shadow: none !important; font-size: 16px; padding: 10px 12px; background: transparent; }
.capture .kinds { display: flex; gap: 4px; }
.today-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.stack { display: grid; gap: 24px; }

/* ---------- lists ---------- */
.list { display: grid; }
.item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); cursor: pointer; transition: background .12s; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); }
.card > .list > .item:first-child { border-radius: var(--r) var(--r) 0 0; }
.card > .list > .item:last-child { border-radius: 0 0 var(--r) var(--r); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; align-items: center; }
.item.done .title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-2); }
.check {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line-2); background: none; flex: none; margin-top: 1px; cursor: pointer;
  display: grid; place-items: center; color: transparent; transition: all .15s;
}
.check:hover { border-color: var(--accent); }
.check.on { background: var(--good); border-color: var(--good); color: #fff; animation: pop .25s ease; }
.check svg { width: 14px; height: 14px; stroke-width: 3; }
@keyframes pop { 50% { transform: scale(1.2); } }
.prio-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 8px; }

.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 800; font-size: 14px; color: #fff;
}
.avatar.emoji { background: var(--surface-2) !important; font-size: 19px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.lg.emoji { font-size: 32px; }

.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.pcard { padding: 16px; cursor: pointer; transition: transform .15s, box-shadow .15s; display: grid; gap: 12px; }
.pcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.pcard .who { display: flex; gap: 12px; align-items: center; min-width: 0; }
.pcard .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 5px; background: var(--surface-2); border-radius: 9px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 9px; background: var(--good); }

/* habits */
.habit { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.habit:first-child { border-top: 0; }
.habit .hb { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; border: 2px solid var(--line-2); background: var(--surface); cursor: pointer; flex: none; transition: all .15s; }
.habit .hb.on { border-color: transparent; animation: pop .25s ease; }
.habit .nm { font-weight: 600; }
.dots { display: flex; gap: 3px; margin-top: 5px; }
.dots i { width: 10px; height: 10px; border-radius: 3px; background: var(--surface-2); }
.heat { display: grid; grid-template-columns: repeat(42, 1fr); gap: 3px; margin-top: 10px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); cursor: pointer; }

/* activity */
.act { display: flex; gap: 10px; padding: 9px 16px; font-size: 13.5px; border-top: 1px solid var(--line); align-items: flex-start; }
.act:first-child { border-top: 0; }
.act .who { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; flex: none; font-size: 12px; background: var(--surface-2); margin-top: 1px; }
.act .who.claude { background: var(--claude-soft); color: var(--claude); }
.act .t { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; }

/* notes */
.ngrid { columns: 2 280px; column-gap: 12px; }
.note { break-inside: avoid; margin-bottom: 12px; padding: 16px 18px; cursor: pointer; transition: box-shadow .15s; }
.note:hover { box-shadow: var(--shadow-lg); }
.note .nt { font-weight: 700; margin-bottom: 4px; }
.note .nb { color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.note .meta { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.moods { display: flex; gap: 6px; }
.moods button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); font-size: 21px; cursor: pointer; transition: transform .1s; }
.moods button.on { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.08); }

/* inbox */
.inbox-item { display: flex; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); align-items: flex-start; }
.inbox-item:first-child { border-top: 0; }
.inbox-item .txt { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.inbox-item .res { margin-top: 6px; font-size: 13px; color: var(--claude); }
.hint { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r); background: var(--claude-soft); color: var(--ink-2); font-size: 14px; margin-bottom: 18px; align-items: flex-start; }
.hint b { color: var(--ink); }

/* ---------- overlays ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 14, 20, .38); z-index: 50; animation: fadein .18s ease; backdrop-filter: blur(2px); }
@keyframes fadein { from { opacity: 0; } }
.modal {
  position: fixed; z-index: 51; left: 50%; top: 12vh; transform: translateX(-50%); width: min(560px, calc(100vw - 32px));
  max-height: 80vh; overflow: auto; padding: 22px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-lg); animation: rise .2s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.modal h2, .drawer h2 { margin: 0 0 16px; font-size: 20px; letter-spacing: -.02em; }
.modal .foot, .drawer .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; align-items: center; }
.modal .foot .spacer, .drawer .foot .spacer { flex: 1; }
.drawer {
  position: fixed; z-index: 51; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); box-shadow: var(--shadow-lg);
  overflow: auto; padding: 24px; animation: slide .22s ease;
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer .x { position: absolute; top: 16px; right: 16px; }
.form { display: grid; gap: 14px; }
.qa-kinds { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.qa-text { font-size: 17px; border: 0; padding: 4px 0; min-height: 70px; box-shadow: none !important; background: transparent; }
.qa-opts { display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.kbd { font-size: 11px; font-weight: 700; color: var(--muted); border: 1px solid var(--line-2); border-radius: 6px; padding: 1px 6px; }
.timeline { display: grid; gap: 0; margin-top: 8px; }
.tl { display: flex; gap: 12px; padding: 10px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.tl:first-child { border-top: 0; }
.tl .ic { width: 30px; height: 30px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.contact-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-wrap: anywhere; white-space: pre-wrap; }
.copyrow { display: flex; gap: 8px; align-items: stretch; }
.copyrow .code { flex: 1; margin: 0; }

#toasts { position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); animation: rise2 .2s ease; pointer-events: auto; display: flex; gap: 12px; align-items: center; }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 800; cursor: pointer; padding: 0; filter: brightness(1.4); }
.toast.err { background: var(--bad); color: #fff; }
@keyframes rise2 { from { opacity: 0; transform: translateY(8px); } }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 32px 28px; text-align: center; }
.login img { width: 56px; height: 56px; margin-bottom: 8px; }
.login h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.03em; }
.login form { display: grid; gap: 10px; margin-top: 22px; }

.fab { display: none; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
  .h1 { font-size: 25px; }
  .today-grid { grid-template-columns: 1fr; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(16px); border-top: 1px solid var(--line);
  }
  .tabbar button { display: grid; justify-items: center; gap: 2px; border: 0; background: none; padding: 6px 0; font-size: 11px; font-weight: 700; color: var(--muted); cursor: pointer; }
  .tabbar button.on { color: var(--accent); }
  .tabbar svg.i { width: 22px; height: 22px; }
  .tabbar .plus { width: 48px; height: 48px; margin: -18px auto 0; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: var(--shadow-lg); }
  .tabbar .plus svg.i { width: 24px; height: 24px; stroke-width: 2.4; }
  .capture .kinds { display: none; }
  .hero { grid-template-columns: 1fr auto; }
  .ring, .ring svg { width: 68px; height: 68px; }
  .modal { top: auto; bottom: 0; left: 0; transform: none; width: 100%; border-radius: 22px 22px 0 0; max-height: 88vh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); animation: up .22s ease; }
  @keyframes up { from { transform: translateY(40px); opacity: 0; } }
  .grid2 { grid-template-columns: 1fr; }
  .drawer { padding: 20px 16px; }
  .kv { grid-template-columns: 96px 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
[hidden] { display: none !important; }
.capture .kinds { flex-wrap: nowrap; }
.contact-btns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.contact-btns .btn { padding: 0 8px; min-width: 0; }

/* === context === */
.ctx-actions { flex-wrap: wrap; gap: 6px; }
.ctx-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; margin-top: 24px; }
.ctx-side { position: sticky; top: 24px; }
.ctx-side .item { color: inherit; align-items: center; }
.ctx-side .item .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ctx-side .item.on { background: var(--surface-2); }
.ctx-side .item.on .title { color: var(--accent); }
.ctx-side .item .badge { margin-left: auto; }
.ctx-q { font-size: 18px; font-weight: 700; letter-spacing: -.015em; line-height: 1.35; }
.ctx-md { line-height: 1.6; overflow-wrap: anywhere; }
.ctx-md > :first-child { margin-top: 0; }
.ctx-md > :last-child { margin-bottom: 0; }
.ctx-md h2, .ctx-md h3, .ctx-md h4 { margin: 16px 0 6px; letter-spacing: -.01em; line-height: 1.25; }
.ctx-md h2 { font-size: 20px; }
.ctx-md h3 { font-size: 16px; }
.ctx-md h4 { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.ctx-md p { margin: 0 0 10px; }
.ctx-md ul, .ctx-md ol { margin: 0 0 10px; padding-left: 22px; }
.ctx-md li { margin: 3px 0; }
.ctx-md code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.ctx-md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.ctx-md .md-table { overflow-x: auto; margin: 0 0 12px; }
.ctx-md table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.ctx-md th, .ctx-md td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.ctx-md th { background: var(--surface-2); font-weight: 700; }
.ctx-md .empty { padding: 20px 8px; }
.ctx-auto { color: var(--ink-2); font-size: 14px; }
.ctx-factform { display: flex; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); align-items: center; }
.ctx-factform .input { border: 0; box-shadow: none !important; background: transparent; padding: 8px 10px; }
.ctx-fact { display: flex; gap: 10px; padding: 11px 16px; border-top: 1px solid var(--line); align-items: flex-start; }
.ctx-fact:first-child { border-top: 0; }
.ctx-fact .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ctx-fact .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.ctx-fact .ctx-ans { color: var(--ink-2); margin-top: 4px; white-space: pre-wrap; }
.ctx-qadd { display: grid; grid-template-columns: 200px 1fr auto; gap: 8px; padding: 10px; align-items: center; }
.ctx-editor { width: min(820px, calc(100vw - 32px)); }
.ctx-ta { min-height: min(60vh, 420px); font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13.5px; line-height: 1.55; }
.ctx-rev { display: flex; gap: 12px; padding: 10px 0; border-top: 1px dashed var(--line); align-items: center; font-size: 14px; }
.ctx-rev:first-of-type { border-top: 0; }
.ctx-rev .prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 860px) {
  .ctx-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; margin-top: 18px; }
  .ctx-side, .ctx-main { min-width: 0; }
  .ctx-side { position: static; }
  .ctx-side .card { overflow: hidden; }
  .ctx-side .list { display: flex; overflow-x: auto; gap: 6px; padding: 8px; scrollbar-width: none; }
  .ctx-side .list::-webkit-scrollbar { display: none; }
  .ctx-side .item { flex: none; border: 1px solid var(--line-2); border-radius: 99px !important; padding: 5px 12px; gap: 6px; }
  .ctx-side .item .meta { display: none; }
  .ctx-side .item .title { font-size: 13px; }
  .ctx-side .item.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .ctx-side .item.on .title { color: inherit; }
  .ctx-qadd { grid-template-columns: 1fr; }
  .ctx-editor { width: 100%; }
  .ctx-ta { min-height: 50vh; }
}

/* === brief === */
.brief-card { padding: 16px 18px; margin-bottom: 26px; }
.brief-card .sec-title { margin-bottom: 8px; }
.brief-lines { display: grid; gap: 4px; font-size: 14px; color: var(--ink-2); }
.brief-lines .bh1 { font-size: 17px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); margin-bottom: 2px; }
.brief-lines .bh { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 8px; }
.brief-lines .bl { position: relative; padding-left: 14px; overflow-wrap: anywhere; }
.brief-lines .bl::before { content: ""; position: absolute; left: 2px; top: 9px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.brief-lines .bn { padding-left: 14px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.brief-lines .bp { color: var(--ink); overflow-wrap: anywhere; }
.brief-lines .bhr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 8px 0 2px; }
.brief-lines .bhr + .bp { font-size: 12.5px; color: var(--muted); }
.brief-lines .brief-more { justify-self: start; margin-left: -10px; margin-top: 2px; }
.brief-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.brief-full { margin-bottom: 8px; }
.brief-raw { margin: 0 0 8px; max-height: 60vh; overflow: auto; }
.brief-chats { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 860px) { .brief-actions .btn { flex: 1 1 auto; min-width: 0; padding: 0 8px; } }

/* === integrations === */
:root { --gpt: #10A37F; --gpt-soft: #E1F4EC; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --gpt: #3FC9A0; --gpt-soft: #16302A; } }
:root[data-theme="dark"] { --gpt: #3FC9A0; --gpt-soft: #16302A; }
.integr .form { gap: 14px; }
.integr-tabs .chip svg.i { width: 13px; height: 13px; }
.integr-body { display: grid; gap: 14px; min-width: 0; }
.integr-h { margin: 6px 0 -6px; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.integr-note { color: var(--ink-2); font-size: 14px; }
.integr-steps { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 14px; display: grid; gap: 4px; }
.integr-prompt { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; min-width: 0; }
.integr-prompt summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.integr-prompt .code { margin: 10px 0 8px; }
.integr-keys { display: grid; }
.integr-key { display: flex; gap: 8px 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; flex-wrap: wrap; }
.integr-key:first-child { border-top: 0; padding-top: 0; }
.integr-key .lbl { font-weight: 600; flex: 1; min-width: 120px; display: inline-flex; align-items: center; gap: 6px; }
.integr-key .lbl svg.i { color: var(--gpt); }
.integr-key .meta { color: var(--muted); font-size: 12.5px; }
.integr-token { background: var(--gpt-soft); border-radius: var(--r-sm); padding: 12px; display: grid; gap: 8px; font-size: 14px; margin-top: 8px; }
.integr-newkey { flex-wrap: wrap; margin-top: 8px; }
.integr-newkey .input { flex: 1; min-width: 160px; }
.act .who.chatgpt { background: var(--gpt-soft); color: var(--gpt); }
.tag.chatgpt { background: var(--gpt-soft); color: var(--gpt); }

/* === calendar === */
.cal-card { padding: 14px 14px 10px; margin-bottom: 24px; }
.cal-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.cal-nav .cal-title { flex: 1; text-align: center; font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.cal-nav .btn.icon { font-size: 22px; font-weight: 600; line-height: 1; }
.cal-wd { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: center; margin-bottom: 4px; }
.cal-wd span:nth-child(n+6) { color: var(--bad); opacity: .75; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-day { min-height: 84px; min-width: 0; padding: 6px 6px 4px; border: 1px solid transparent; border-radius: 10px; background: none; color: inherit; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: background .12s; }
.cal-day:hover { background: var(--surface-2); }
.cal-day.out { opacity: .5; }
.cal-day.sel { border-color: var(--accent); background: var(--accent-soft); opacity: 1; }
.cal-day .dn { font-weight: 700; font-size: 13px; width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.cal-day.today .dn { background: var(--accent); color: var(--accent-ink); }
.cal-chips { display: flex; flex-direction: column; gap: 2px; width: 100%; min-width: 0; }
.cal-chip { --c: var(--accent); display: block; font-style: normal; font-size: 11px; font-weight: 600; line-height: 1.35; padding: 1px 5px; border-radius: 5px; background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-day.sel .cal-chip { background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.cal-chip.task { --c: var(--good); background: none; color: var(--ink-2); padding-left: 0; }
.cal-chip.task.done { color: var(--muted); text-decoration: line-through; }
.cal-chip.more { background: none; color: var(--muted); padding-left: 2px; }
.cal-agenda { margin-bottom: 24px; }
.cal-time { width: 86px; flex: none; font-size: 13px; font-weight: 600; color: var(--muted); padding-top: 2px; }
.cal-bar { width: 4px; min-height: 22px; border-radius: 3px; flex: none; align-self: stretch; background: var(--accent); }
.cal-ev .title .muted { font-weight: 500; }
.cal-sub { display: flex; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: center; }
.cal-sub:first-child { border-top: 0; }
.cal-sub .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.cal-sub .body { flex: 1; min-width: 0; }
.cal-sub .title { font-weight: 600; overflow-wrap: anywhere; }
.cal-sub .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.cal-dt { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.cal-dt input[type=time] { width: 104px; }
.cal-tl { display: grid; }
.cal-tl-row { display: flex; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); cursor: pointer; align-items: flex-start; transition: background .12s; }
.cal-tl-row:first-child { border-top: 0; }
.cal-tl-row:hover { background: var(--surface-2); }
.cal-tl-row.past { opacity: .55; }
.cal-tl-row.now .cal-time { color: var(--accent); }
.cal-tl-row .body { flex: 1; min-width: 0; }
.cal-tl-row .title { font-weight: 600; overflow-wrap: anywhere; }
.cal-tl-row .meta { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
@media (max-width: 860px) {
  .cal-card { padding: 10px 8px 6px; }
  .cal-grid { gap: 2px; }
  .cal-day { min-height: 56px; padding: 4px 2px 4px; gap: 3px; align-items: center; border-radius: 8px; }
  .cal-day .dn { width: 26px; height: 26px; font-size: 13.5px; }
  .cal-chips { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 3px; width: auto; max-width: 100%; }
  .cal-chip { width: 6px; height: 6px; padding: 0; border-radius: 50%; background: var(--c); font-size: 0; }
  .cal-day.sel .cal-chip { background: var(--c); }
  .cal-chip.task { background: var(--good); }
  .cal-chip.task.done { background: var(--line-2); }
  .cal-chip.more { width: auto; height: 6px; font-size: 9px; line-height: 6px; background: none; color: var(--muted); border-radius: 0; }
  .cal-time { width: 68px; font-size: 12.5px; }
  .cal-dt input[type=time] { width: 96px; }
}

/* === mail === */
.mail-toolbar { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-bottom: 12px; }
.mail-toolbar .search { margin-left: auto; min-width: 180px; flex: 0 1 260px; }
.mail-accs { margin-bottom: 18px; }
.mail-accs .chip.on .mail-dot { outline: 2px solid var(--bg); }
.mail-cnt { margin-left: 2px; opacity: .75; font-size: 12px; }
.mail-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.mail-dot.lg { width: 12px; height: 12px; }
.mail-row { position: relative; padding-left: 22px; min-width: 0; max-width: 100%; } /* строки — grid-элементы .list; без min-width:0 nowrap-текст растянул бы их за край */
.mail-mini { min-width: 0; max-width: 100%; }
.mail-row::before { content: ""; position: absolute; left: 9px; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--acc, var(--line-2)); }
.mail-row .avatar { width: 34px; height: 34px; font-size: 13px; }
.mail-top { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.mail-from { flex: 1; min-width: 0; font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-date { color: var(--muted); font-size: 12.5px; white-space: nowrap; flex: none; }
.mail-subj, .mail-snip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-snip { color: var(--muted); font-size: 13.5px; }
.mail-row.unread .mail-from, .mail-row.unread .mail-subj { color: var(--ink); font-weight: 700; }
.mail-row.unread .mail-date { color: var(--accent); font-weight: 600; }
.mail-row .meta .tag { font-size: 11.5px; }
.tag.mail-star { color: var(--warn); background: var(--warn-soft); }
.mail-acts { display: none; position: absolute; right: 10px; top: 8px; gap: 2px; padding: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
@media (hover: hover) { .mail-row:hover .mail-acts { display: flex; } }
.mail-acts .btn.icon { width: 30px; height: 30px; }
.mail-acts .btn.on, .mail-actions .btn.on { color: var(--warn); }
.mail-acts .btn.on svg, .mail-actions .btn.on svg { fill: var(--warn); }
.mail-menu { position: absolute; right: 12px; top: 44px; z-index: 5; display: grid; min-width: 210px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); animation: rise2 .15s ease; }
.mail-mi { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--ink); }
.mail-mi:hover { background: var(--surface-2); }
.mail-mi.danger { color: var(--bad); }
.mail-more { padding: 10px; text-align: center; border-top: 1px solid var(--line); }
.mail-first b { color: var(--ink); font-size: 16px; }
.mail-first > span { display: inline-block; max-width: 460px; font-size: 13.5px; margin-top: 4px; }
/* письмо */
.mail-drawer { width: min(680px, 100vw); }
.mail-h2 { padding-right: 44px; overflow-wrap: anywhere; font-size: 19px; }
.mail-hdr { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.mail-hdr .body { flex: 1; min-width: 0; }
.mail-hdr .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; align-items: center; }
.mail-who { overflow-wrap: anywhere; }
.tag.mail-person, .tag.mail-link, .tag.mail-x { cursor: pointer; border: 0; font: inherit; font-size: 12px; font-weight: 600; }
.tag.mail-person:hover, .tag.mail-link:hover { background: var(--accent-soft); color: var(--accent); }
.tag.mail-link svg.i { width: 13px; height: 13px; }
.tag.mail-x { padding: 1px 7px; }
.tag.mail-x:hover { background: var(--bad-soft); color: var(--bad); }
.mail-to { font-size: 13.5px; color: var(--ink-2); margin-bottom: 10px; min-width: 0; }
.mail-to summary { cursor: pointer; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-to .kv { margin-top: 8px; }
.mail-att { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.mail-att .tag { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
.mail-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 0; margin-bottom: 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.mail-view { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.mail-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.55; }
.mail-frame { display: block; width: 100%; height: 60vh; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; }
.mail-body .empty { padding: 20px; }
/* ящики в настройках */
.mail-acc-row { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: center; }
.mail-acc-row:first-child { border-top: 0; }
.mail-acc-row .body { flex: 1; min-width: 0; }
.mail-acc-row .title { font-weight: 600; overflow-wrap: anywhere; }
.mail-acc-row .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; min-width: 0; }
.mail-acc-row .tag.err { background: var(--bad-soft); color: var(--bad); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
.mail-acc-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.mail-switch { position: relative; width: 38px; height: 22px; flex: none; cursor: pointer; }
.mail-switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.mail-switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line-2); transition: background .15s; }
.mail-switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.mail-switch input:checked + i { background: var(--good); }
.mail-switch input:checked + i::after { transform: translateX(16px); }
.mail-hint { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink-2); font-size: 13.5px; align-items: flex-start; }
.mail-adv summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.mail-preview { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.mail-test { border-radius: var(--r-sm); padding: 10px 12px; font-size: 13.5px; overflow-wrap: anywhere; }
.mail-test.ok { background: var(--good-soft); color: var(--good); }
.mail-test.bad { background: var(--bad-soft); color: var(--bad); }
.mail-test .btn.sm { height: 26px; padding: 0 9px; font-size: 12px; margin-left: 4px; }
.mail-folders { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.mail-folders .chip { height: 26px; font-size: 12px; padding: 0 9px; }
/* «Сегодня» и карточка человека */
.mail-today-sub { padding: 12px 16px 4px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.mail-mini { align-items: center; }
.mail-mini .avatar { width: 32px; height: 32px; font-size: 12.5px; }
.mail-mini .title { font-size: 14.5px; }
.mail-mini .mail-snip { font-size: 13px; }
@media (max-width: 860px) {
  .mail-toolbar .search { margin-left: 0; flex: 1 1 100%; min-width: 0; }
  .mail-toolbar .chips, .mail-accs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; padding-bottom: 2px; }
  .mail-toolbar .chips::-webkit-scrollbar, .mail-accs::-webkit-scrollbar { display: none; }
  .mail-row { padding-left: 18px; }
  .mail-row::before { left: 6px; }
  .mail-actions .btn { flex: 1 1 auto; min-width: 0; padding: 0 8px; }
  .mail-actions .btn.icon { flex: 0 0 36px; }
  .mail-acc-row { flex-wrap: wrap; }
  .mail-acc-row .body { flex-basis: 100%; }
  .mail-acc-row .mail-switch { margin-left: 22px; }
  .mail-frame { height: 50vh; }
}
/* сломанный ящик: полоса над списком, метка на чипсе, строка на «Сегодня» */
.mail-alert { display: block; margin-bottom: 12px; padding: 10px 14px; border-radius: var(--r-sm); background: var(--bad-soft); color: var(--bad); font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.mail-alert a { color: inherit; text-decoration: underline; white-space: nowrap; }
.mail-warn { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; margin-left: 4px; border-radius: 50%; background: var(--bad); color: #fff; font-style: normal; font-size: 10px; font-weight: 800; line-height: 1; }
.mail-warn.sync { background: var(--warn); }
.mail-today-err { padding: 4px 16px 6px; font-size: 13px; font-weight: 600; color: var(--bad); }
.mail-today-err a { color: inherit; }
