:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #efeee9; --line: #e2e0d9;
  --text: #1d1f23; --muted: #6b6e76; --faint: #9a9ca3;
  --accent: #3b5bdb; --accent-soft: #e6ebfb; --on-accent: #fff;
  --good: #2f8a4f; --good-soft: #e3f3e8; --warn: #c2410c; --warn-soft: #fdece2; --info-soft: #e8eefb;
  --business: #3b5bdb; --health: #2f8a4f; --life: #b7791f; --other: #868e96;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --tabs-h: 62px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c; --surface: #1f2227; --surface-2: #272b31; --line: #31353c;
    --text: #e9eaec; --muted: #a0a4ab; --faint: #6f747c;
    --accent: #7c94f2; --accent-soft: #263055; --on-accent: #10131a;
    --good: #5cc283; --good-soft: #1e3427; --warn: #f0895a; --warn-soft: #3a261d; --info-soft: #232c45;
    --business: #7c94f2; --health: #5cc283; --life: #e0a948; --other: #9aa0a8;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 0 0 8px; font-size: 24px; }
.logo { font-size: 40px; color: var(--accent); line-height: 1; }
.login-card input { padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; }
.err { color: var(--warn); min-height: 1.4em; margin: 0; font-size: 14px; }

/* ---------- каркас ---------- */
.app { height: 100%; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 8px; }
.top h1 { margin: 0; font-size: 26px; letter-spacing: -.01em; }
#top-extra { color: var(--muted); font-size: 14px; }
main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; padding: 4px 16px 24px; display: none; -webkit-overflow-scrolling: touch; }
.view.on { display: block; }
.tabs { display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b); border-top: 1px solid var(--line); background: var(--surface); }
.tabs button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--faint); cursor: pointer; }
.tabs button.on { color: var(--accent); }

/* ---------- общие элементы ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 10px 14px; border-radius: 12px; cursor: pointer; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.small { padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px; }
.section-h { margin: 22px 0 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.section-h .count { font-weight: 500; color: var(--faint); }
.empty { color: var(--faint); padding: 10px 0; font-size: 15px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- карточка задачи ---------- */
.task { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 12px 10px 14px; margin-bottom: 8px; border-left: 4px solid var(--other); }
.task.business { border-left-color: var(--business); } .task.health { border-left-color: var(--health); } .task.life { border-left-color: var(--life); }
.task.done-anim { opacity: .4; transform: scale(.98); transition: .25s; }
.task-title { font-weight: 550; cursor: pointer; }
.task.is-done .task-title { text-decoration: line-through; color: var(--faint); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.tag { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); }
.tag.overdue, .tag.alert { background: var(--warn-soft); color: var(--warn); }
.tag.stuck { background: var(--warn-soft); color: var(--warn); }
.acts { display: flex; gap: 6px; margin-top: 10px; }
.acts button { flex: 1; border: 1px solid var(--line); background: none; border-radius: 10px; padding: 7px 4px; font-size: 13.5px; cursor: pointer; color: var(--muted); }
.acts .do { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, var(--line)); font-weight: 600; }

/* ---------- привычки ---------- */
.habit { display: flex; align-items: center; gap: 10px; background: var(--surface); box-shadow: var(--shadow); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.habit .name { flex: 1; font-weight: 500; }
.days { display: flex; gap: 4px; }
.days i { width: 14px; height: 14px; border-radius: 4px; background: var(--surface-2); display: block; }
.days i.on { background: var(--good); }
.check { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); background: none; display: grid; place-items: center; cursor: pointer; flex: none; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.check svg { width: 18px; height: 18px; }

/* ---------- чат ---------- */
.chat { padding-bottom: 12px; }
.msgs { display: flex; flex-direction: column; gap: 12px; padding-top: 4px; }
.msg { max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--on-accent); padding: 9px 13px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; }
.msg.assistant { align-self: stretch; max-width: 100%; }
.msg .time { font-size: 11px; color: var(--faint); margin-top: 2px; }
.msg.user .time { color: color-mix(in srgb, var(--on-accent) 70%, transparent); text-align: right; }
.bubble { background: var(--surface); padding: 10px 14px; border-radius: 4px 18px 18px 18px; box-shadow: var(--shadow); margin-bottom: 8px; }
.bubble > :first-child { margin-top: 0; } .bubble > :last-child { margin-bottom: 0; }
.status { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; padding: 4px 2px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .25 } to { opacity: 1 } }
.composer { padding: 8px 12px; border-top: 1px solid var(--line); background: var(--bg); }
.composer .row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); line-height: 1.35; }
.icon-btn { width: 42px; height: 42px; flex: none; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: var(--surface-2); color: var(--text); }
.icon-btn.send { background: var(--accent); color: var(--on-accent); }
.icon-btn.mic.recording { background: var(--warn); color: #fff; }
.rec { display: flex; align-items: center; gap: 10px; padding: 0 4px 8px; font-size: 14px; color: var(--muted); }
.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); animation: pulse .7s infinite alternate; }
.rec-hint { flex: 1; }

/* ---------- markdown ---------- */
.md h1, .md h2, .md h3 { margin: 16px 0 6px; line-height: 1.25; } .md h1 { font-size: 21px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md p { margin: 0 0 8px; } .md ul, .md ol { margin: 0 0 8px; padding-left: 22px; } .md li { margin: 2px 0; }
.md li.cb { list-style: none; margin-left: -20px; } .md li.cb::before { content: "☐ "; color: var(--muted); } .md li.cb.x::before { content: "☑ "; color: var(--good); }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.md a { color: var(--accent); }
.md .fm { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; white-space: pre-wrap; }

/* ---------- блоки ---------- */
.block { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 8px; }
.block.tasks-block { background: none; box-shadow: none; padding: 0; }
.block h4 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
.choice { display: flex; flex-wrap: wrap; gap: 8px; }
.choice .q { width: 100%; font-weight: 550; margin-bottom: 2px; }
.choice button { border: 1px solid var(--accent); color: var(--accent); background: var(--accent-soft); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 500; }
.choice.used button { opacity: .45; pointer-events: none; } .choice.used button.picked { opacity: 1; background: var(--accent); color: var(--on-accent); }
.bar { margin: 8px 0; } .bar .l { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; } .bar .l span:last-child { color: var(--muted); }
.bar .track { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; } .bar .fill { height: 100%; border-radius: 6px; background: var(--accent); }
.bar .note { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; gap: 12px; font-size: 12.5px; color: var(--muted); margin-top: 6px; } .chart .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.tbl { overflow-x: auto; } .tbl table { border-collapse: collapse; width: 100%; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; } .tbl th { color: var(--muted); font-weight: 600; font-size: 13px; }
.tl { position: relative; padding-left: 18px; } .tl::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl .it { position: relative; margin-bottom: 12px; } .tl .it::before { content: ""; position: absolute; left: -17px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tl .d { font-size: 12.5px; color: var(--muted); } .tl .t { font-weight: 550; } .tl .x { font-size: 14px; color: var(--muted); }
.callout { border-left: 4px solid var(--accent); background: var(--info-soft); } .callout.warn { border-left-color: var(--warn); background: var(--warn-soft); } .callout.good { border-left-color: var(--good); background: var(--good-soft); }
.callout .t { font-weight: 600; margin-bottom: 2px; }
.cl div { padding: 4px 0; } .cl .x { color: var(--faint); text-decoration: line-through; }
.hgrid { display: grid; grid-template-columns: minmax(80px, 1fr) auto; gap: 8px 12px; align-items: center; font-size: 14px; }
.hgrid .days i { width: 16px; height: 16px; }

/* ---------- проекты, файлы ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 8px; cursor: pointer; display: block; width: 100%; text-align: left; border: 0; }
.card .n { font-weight: 600; } .card .s { font-size: 13px; color: var(--muted); margin-top: 3px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.file-row svg { color: var(--faint); width: 20px; height: 20px; }
.crumbs { font-size: 14px; color: var(--muted); margin: 4px 0 10px; } .crumbs a { color: var(--accent); cursor: pointer; }
.editor { width: 100%; min-height: 60vh; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- шторка ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-width: 760px; margin: 0 auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); max-height: 88vh; overflow-y: auto; }
.sheet h3 { margin: 0 0 12px; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.sheet input, .sheet select, .sheet textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.sheet .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.sheet .bar-btns { display: flex; gap: 8px; margin-top: 16px; } .sheet .bar-btns .btn { flex: 1; }
.opts { display: grid; gap: 8px; } .opts .btn { text-align: left; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-b) + 80px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 20; font-size: 14px; max-width: 90%; }
