:root {
  --accent: #B48BCF;
  --accent-soft: #E3D3F4;
  --accent-strong: #7b4fa0;
  --on-accent: #1e1033;
  --bg: #faf8fc;
  --surface: #ffffff;
  --surface-2: #f3eef8;
  --text: #241a31;
  --muted: #6b5f78;
  --border: #e4dcec;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1f7a4d;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(36 26 49 / 0.06), 0 4px 16px rgb(36 26 49 / 0.06);
  --sidebar-w: 248px;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --accent: #b48bcf;
  --accent-soft: #3a2a4d;
  --accent-strong: #d3b4ea;
  --on-accent: #1e1033;
  --bg: #15101c;
  --surface: #1e1729;
  --surface-2: #281f36;
  --text: #f1eaf8;
  --muted: #a89bb8;
  --border: #38294a;
  --danger: #ff8a80;
  --danger-soft: #3d1f1d;
  --ok: #6fd6a0;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent-strong); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 100; }
.skip-link:focus { left: 0.5rem; top: 0.5rem; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 44px; padding: 0 1.1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 0.8rem; font-size: 0.9rem; }
.btn.block { width: 100%; }
.field { display: grid; gap: 0.35rem; margin-bottom: 1rem; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field .hint { font-size: 0.82rem; color: var(--muted); }
input, select {
  min-height: 44px; padding: 0 0.8rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
input:focus-visible, select:focus-visible { border-color: var(--accent); }
.alert { padding: 0.7rem 0.9rem; border-radius: 10px; margin-bottom: 1rem; background: var(--danger-soft); color: var(--danger); font-size: 0.92rem; }
.alert.ok { background: var(--accent-soft); color: var(--text); }

/* Cards & states */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); animation: rise 0.2s ease both; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .glyph { font-size: 2rem; margin-bottom: 0.5rem; }
.badge { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: 0.78rem; font-weight: 600; }
.badge.pending { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
.boot { min-height: 100vh; display: grid; place-items: center; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.7rem 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; letter-spacing: 0.08em; background: var(--surface-2); padding: 0.5rem 0.8rem; border-radius: 8px; user-select: all; }

/* Auth layout */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: min(100%, 420px); padding: 1.75rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 800; font-size: 1.25rem; margin-bottom: 1.25rem; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: var(--on-accent); font-weight: 900; }
.choice { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.choice label { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.8rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { width: auto; min-height: 0; margin-top: 0.2rem; accent-color: var(--accent); }

/* App shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 1.25rem 0.9rem; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 0.25rem; }
.nav { display: grid; gap: 0.2rem; margin-top: 0.5rem; }
.nav a { display: flex; align-items: center; gap: 0.7rem; min-height: 44px; padding: 0 0.8rem; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current='page'] { background: var(--accent-soft); }
.nav .ico { width: 1.4rem; text-align: center; }
.nav .soon { margin-left: auto; font-size: 0.7rem; color: var(--muted); font-weight: 500; }
.sidebar .spacer { flex: 1; }
.main { padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 5.5rem; max-width: 1100px; width: 100%; }
.page-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.25rem; }
.tabbar { display: none; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { display: grid; place-items: center; gap: 0; min-height: 56px; font-size: 0.7rem; color: var(--muted); text-decoration: none; font-weight: 600; }
  .tabbar a .ico { font-size: 1.25rem; line-height: 1.2; }
  .tabbar a[aria-current='page'] { color: var(--accent-strong); }
}

/* Toasts */
.toasts { position: fixed; right: 1rem; bottom: 4.5rem; display: grid; gap: 0.5rem; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 0.7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); animation: rise 0.2s ease both; max-width: 320px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Utilities (CSP forbids inline style attributes) */
.mt { margin-top: 1rem; }
.center { margin: 0 auto; }
.side-user { font-size: 0.85rem; padding: 0 0.8rem; }
.auth .card.wide { width: min(100%, 520px); }
[hidden] { display: none !important; }

/* ---------- Phase 2 ---------- */
.mb { margin-bottom: 1rem; }
.small { font-size: 0.82rem; }
.pad { padding: 0.75rem 0; }
.strike { text-decoration: line-through; }
.row.space { justify-content: space-between; }
.h1-sm { font-size: 1.3rem; margin: 0; }
.overdue { color: var(--danger); font-weight: 600; font-size: 0.9rem; }
.show-mobile { display: none; }
progress { accent-color: var(--accent); height: 10px; }
progress.wide { width: 100%; }
textarea { font: inherit; }
input[type='checkbox'], input[type='radio'] { width: auto; min-height: 0; accent-color: var(--accent); }
input[type='search'] { min-height: 40px; }
summary { cursor: pointer; font-weight: 600; }

.topbar { display: flex; justify-content: flex-end; margin-bottom: 0.5rem; min-height: 36px; }
.bell-wrap { position: relative; }
.bell { position: relative; }
.bell-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 700; display: grid; place-items: center; }
.notif-panel { position: absolute; right: 0; top: calc(100% + 6px); width: min(360px, calc(100vw - 2rem)); max-height: 70vh; overflow: auto; z-index: 30; padding: 0.9rem; }
.notif-list li { display: block; padding: 0; }
.notif-list a { display: grid; gap: 0.1rem; padding: 0.6rem 0.4rem; color: var(--text); text-decoration: none; border-radius: 8px; }
.notif-list a:hover { background: var(--surface-2); }
.notif-list .unread a strong::before { content: '● '; color: var(--accent-strong); }
.notif-list .read { opacity: 0.7; }

.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab { min-height: 40px; padding: 0 1rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.tab[aria-selected='true'] { background: var(--accent-soft); border-color: var(--accent); }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 1rem; }
.task { padding: 0.8rem 0; border-top: 1px solid var(--border); display: block; }
.task:first-child { border-top: 0; }
.task-main { display: flex; gap: 0.75rem; align-items: flex-start; flex-wrap: wrap; }
.task-main > input[type='checkbox'] { width: 22px; height: 22px; margin-top: 0.15rem; }
.task-body { flex: 1 1 220px; min-width: 0; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.25rem; font-size: 0.88rem; }
.task-notes { margin: 0.3rem 0 0; font-size: 0.9rem; overflow-wrap: anywhere; }
.subtasks { margin: 0.6rem 0 0 2rem; }
.prio-high { background: var(--danger-soft); color: var(--danger); }
.prio-low { background: var(--surface-2); color: var(--muted); }
.cat-bar { margin-top: 0.75rem; }
.chip-x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 0.3rem; font-size: 0.8rem; }
ul.tasks { padding: 0.5rem 1.25rem; }

.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.5rem; width: min(94vw, 560px); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(20 10 30 / 0.55); }
.lightbox { width: auto; max-width: 96vw; text-align: center; }
.lightbox img { max-width: 100%; max-height: 80vh; display: block; margin: 0 auto 1rem; }

.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--surface-2); text-align: center; font-size: 0.78rem; font-weight: 700; padding: 0.4rem 0; color: var(--muted); }
.cal-cell { background: var(--surface); min-height: 104px; padding: 0.25rem; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-cell.other { background: var(--bg); }
.cal-cell.other .cal-date { color: var(--muted); }
.cal-cell.today .cal-date { background: var(--accent); color: var(--on-accent); }
.cal-date { align-self: flex-start; min-width: 28px; height: 28px; border-radius: 14px; border: 0; background: none; color: var(--text); font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.cal-date:hover { background: var(--accent-soft); }
.chip { display: block; width: 100%; text-align: left; border: 0; border-radius: 6px; padding: 2px 6px; font: inherit; font-size: 0.76rem; background: var(--accent-soft); color: var(--text); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { filter: brightness(0.96); }
.chip.recurs { border-left: 3px solid var(--accent-strong); }
.chip-time { color: var(--muted); }
.more { border: 0; background: none; color: var(--accent-strong); font: inherit; font-size: 0.76rem; cursor: pointer; text-align: left; padding: 0 6px; }
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.5rem; }
.cal-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-col h3 { font-size: 0.85rem; margin: 0 0 0.25rem; }
.cal-col.today { border-color: var(--accent); }

.notes-layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 1rem; align-items: start; }
.notes-list { display: grid; gap: 0.6rem; position: sticky; top: 1rem; max-height: calc(100vh - 3rem); overflow: auto; }
.note-items li { display: block; padding: 0; border-radius: 10px; }
.note-items li.active { background: var(--accent-soft); }
.note-items a { display: grid; gap: 0.1rem; padding: 0.6rem; color: var(--text); text-decoration: none; }
.snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; }
.small-label { font-size: 0.88rem; }
.notes-editor { display: grid; gap: 0.75rem; min-width: 0; }
.note-title { font-size: 1.4rem; font-weight: 700; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent; padding: 0.25rem 0; }
.toolbar { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.editor { min-height: 320px; padding: 0.75rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow-wrap: anywhere; }
.editor:focus-visible { border-color: var(--accent); }
.editor img { max-width: 100%; height: auto; border-radius: 8px; cursor: zoom-in; }
.editor blockquote { margin: 0.5rem 0; padding-left: 0.8rem; border-left: 3px solid var(--accent); color: var(--muted); }
.editor h2 { font-size: 1.2rem; }

@media (max-width: 800px) {
  .main { padding-bottom: 6rem; }
  .cal-cell { min-height: 64px; }
  .cal-cell .chip { font-size: 0; padding: 0; height: 6px; border-radius: 3px; }
  .cal-cell .chip .chip-time { display: none; }
  .cal-week { grid-template-columns: 1fr; }
  .notes-layout { grid-template-columns: 1fr; }
  .notes-layout.has-note .notes-list { display: none; }
  .notes-layout:not(.has-note) .notes-editor { display: none; }
  .show-mobile { display: inline-flex; }
  .hide-mobile { display: none; }
  .notes-list { position: static; max-height: none; }
  .subtasks { margin-left: 0.5rem; }
}
