:root {
  --plum: #2F181B;
  --plum-2: #44262B;
  --plum-3: #5A3238;
  --berry: #6E3B47;
  --mauve: #8E5663;
  --blush: #C9A9AA;
  --beige: #E7DED5;
  --cream: #F5F1EC;
  --gold: #D2B47C;
  --card: #FFFDFB;
  --ink: #2F181B;
  --muted: #7C6B67;
  --line: #E7DED5;
  --danger: #B3261E;
  --ok: #5E8C6A;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(47,24,27,.06), 0 6px 20px rgba(47,24,27,.07);
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--cream); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--berry); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 8px 16px; }
.loading { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 16px; font-weight: 500; }
.btn:hover { border-color: var(--blush); }
.btn.primary { background: var(--berry); border-color: var(--berry); color: #fff; }
.btn.primary:hover { background: var(--plum-3); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 12px; font-size: 13px; }
.icon-btn { border: 0; background: transparent; border-radius: 8px; width: 28px; height: 28px; display: inline-grid; place-items: center; font-size: 16px; line-height: 1; color: inherit; flex: none; }
.icon-btn:hover { background: rgba(0,0,0,.07); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--mauve); box-shadow: 0 0 0 3px rgba(142,86,99,.15); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
label > input, label > select, label > textarea { margin-top: 4px; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink); font-size: 14px; }
.tag { display: inline-block; background: var(--beige); color: var(--berry); border-radius: 999px; padding: 0 8px; font-size: 11px; font-weight: 600; }

/* ---------- auth ---------- */
body.auth-page { background: var(--plum); }
.auth-card { max-width: 380px; margin: 10vh auto; background: var(--cream); border-radius: 20px; padding: 36px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.35); text-align: center; }
.auth-card h1 { font-family: var(--serif); font-weight: 500; font-size: 34px; margin: 0; color: var(--berry); }
.auth-card form { text-align: left; display: grid; gap: 14px; margin-top: 20px; }
.auth-card .btn { width: 100%; padding: 11px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13px; }
.auth-msg { min-height: 1.5em; font-size: 13px; color: var(--berry); }
.brand-mark { font-family: var(--serif); font-size: 22px; color: var(--berry); letter-spacing: .02em; }
.brand-mark span { color: var(--gold); font-style: italic; margin: 0 1px; }
.brand-mark em { font-style: italic; color: var(--gold); font-size: .8em; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 268px 1fr; height: 100vh; height: 100dvh; }
#sidebar { background: var(--plum); color: #EADCD6; display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.side-head .brand-mark { color: var(--cream); }
.side-search { padding: 4px 12px 8px; }
.side-search input { background: var(--plum-2); border-color: transparent; color: var(--cream); }
.side-search input::placeholder { color: #A98F8B; }
.side-nav { padding: 4px 8px; display: grid; gap: 2px; }
.side-nav a { color: #EADCD6; text-decoration: none; padding: 7px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.side-nav a:hover, .tree-row:hover { background: var(--plum-2); }
.side-nav a.active, .tree-row.active { background: var(--plum-3); color: #fff; }
.side-section { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px 18px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--gold); font-weight: 600; }
#tree { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.tree-row { display: flex; align-items: center; gap: 2px; border-radius: 8px; padding: 1px 2px; min-height: 30px; }
.tree-row .more { opacity: 0; color: #EADCD6; }
.tree-row:hover .more, .tree-row.active .more { opacity: 1; }
@media (hover: none) { .tree-row .more { opacity: .7; } }
.tree-label { flex: 1; min-width: 0; color: inherit; text-decoration: none; display: flex; align-items: center; gap: 8px; padding: 4px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-label .txt { overflow: hidden; text-overflow: ellipsis; }
.space-row .tree-label { font-weight: 600; color: #fff; }
.caret { border: 0; background: none; color: #A98F8B; width: 18px; font-size: 11px; transition: transform .15s; padding: 0; flex: none; }
.caret.c { transform: rotate(-90deg); }
.tree-children { margin-left: 14px; }
.dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.list-ico { width: 6px; height: 6px; border-radius: 50%; background: var(--blush); flex: none; margin: 0 2px 0 4px; }
.tree-row .tag { background: var(--plum-3); color: var(--gold); }
.side-foot { padding: 10px 12px 16px; border-top: 1px solid var(--plum-2); display: flex; gap: 8px; align-items: center; }
.side-foot button { background: none; border: 0; color: #EADCD6; padding: 6px 8px; border-radius: 8px; }
.side-foot button:hover { background: var(--plum-2); }
.side-foot .who { flex: 1; font-size: 12px; color: #A98F8B; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px 10px; flex-wrap: wrap; }
#crumbs { flex: 1; min-width: 0; }
#crumbs .path { font-size: 12px; color: var(--muted); }
#crumbs h1 { font-family: var(--serif); font-weight: 500; font-size: 28px; margin: 0; line-height: 1.2; overflow-wrap: anywhere; }
.tabs { display: flex; background: var(--beige); border-radius: 999px; padding: 3px; }
.tabs button { border: 0; background: none; border-radius: 999px; padding: 6px 14px; font-weight: 500; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--berry); box-shadow: var(--shadow); }
#view { flex: 1; overflow-y: auto; padding: 8px 28px 80px; }
.only-mobile { display: none !important; }
.scrim { display: none; }

/* ---------- task list ---------- */
.group { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.group-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.group-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.group-head h3 a { color: inherit; text-decoration: none; }
.group-head .count { color: var(--muted); font-size: 12px; }
.group-head .spacer { flex: 1; }
.status-chip { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.task-row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; border-bottom: 1px solid var(--cream); cursor: pointer; }
.task-row:last-child { border-bottom: 0; }
.task-row:hover { background: #FBF7F3; }
.task-row.is-done .task-title { color: var(--muted); text-decoration: line-through; }
.check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--c, var(--blush)); background: transparent; flex: none; display: grid; place-items: center; font-size: 11px; color: #fff; padding: 0; }
.check:hover { background: color-mix(in srgb, var(--c, var(--blush)) 25%, transparent); }
.is-done .check, .check.on { background: var(--ok); border-color: var(--ok); }
.task-main { flex: 1; min-width: 0; }
.task-title { overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); }
.task-meta:empty { display: none; }
.task-meta .path { color: var(--mauve); }
.due { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 56px; text-align: right; }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.today { color: var(--berry); font-weight: 600; }
.flag { width: 14px; height: 14px; flex: none; }
.status-pill { font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 8px; background: color-mix(in srgb, var(--c) 22%, white); color: var(--plum); white-space: nowrap; }
.add-row { display: flex; gap: 8px; padding: 8px 16px; align-items: center; }
.add-row input { border: 0; background: transparent; padding: 6px 0; box-shadow: none !important; }
.add-row .plus { color: var(--mauve); font-size: 18px; width: 20px; text-align: center; }
.done-toggle { border: 0; background: none; color: var(--muted); padding: 10px 16px; font-size: 12px; width: 100%; text-align: left; border-top: 1px solid var(--cream); }
.done-toggle:hover { color: var(--berry); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty-big { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty-big h2 { font-family: var(--serif); font-weight: 500; color: var(--berry); }

/* ---------- home ---------- */
.hello { margin: 4px 0 18px; }
.hello p { margin: 2px 0 0; color: var(--muted); }
.quick-add { display: grid; grid-template-columns: 1fr minmax(140px, 240px) 150px auto; gap: 8px; background: var(--card); padding: 12px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 22px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border-top: 4px solid var(--c); }
.stat b { display: block; font-family: var(--serif); font-size: 28px; font-weight: 500; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- board ---------- */
.board { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; min-height: 60vh; }
.col { background: var(--beige); border-radius: var(--radius); width: 280px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.col-body { padding: 4px 10px 10px; overflow-y: auto; min-height: 40px; display: grid; gap: 8px; align-content: start; }
.col.drop .col-body { background: rgba(142,86,99,.1); border-radius: 10px; }
.card { background: var(--card); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); cursor: grab; display: grid; gap: 6px; }
.card .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }
.card.dragging { opacity: .4; }
.col .add-row { padding: 4px 12px 12px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cal-head h2 { font-family: var(--serif); font-weight: 500; margin: 0 8px 0 0; font-size: 22px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--line); gap: 1px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal .dow { background: var(--beige); padding: 6px 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.cal .day { background: var(--card); min-height: 108px; padding: 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal .day.other { background: #FAF7F4; color: #B9ABA7; }
.cal .day.today .num { background: var(--berry); color: #fff; border-radius: 999px; padding: 0 7px; }
.cal .num { font-size: 12px; font-weight: 600; align-self: flex-start; }
.cal .ev { font-size: 12px; border-radius: 6px; padding: 2px 6px; background: color-mix(in srgb, var(--c) 25%, white); border-left: 3px solid var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border-top: 0; border-right: 0; border-bottom: 0; text-align: left; }
.cal .ev.done { text-decoration: line-through; opacity: .6; }

/* ---------- drawer ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--card); box-shadow: -10px 0 40px rgba(47,24,27,.18); transform: translateX(105%); transition: transform .2s ease; z-index: 40; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.drawer-head .path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { overflow-y: auto; padding: 18px 22px 40px; display: grid; gap: 18px; align-content: start; }
.title-input { font-family: var(--serif); font-size: 24px; border: 0 !important; padding: 0 !important; resize: none; background: transparent !important; box-shadow: none !important; line-height: 1.25; overflow: hidden; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.desc { min-height: 120px; resize: vertical; line-height: 1.55; }
.mini-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--cream); }
.mini-row .t { flex: 1; min-width: 0; overflow-wrap: anywhere; cursor: pointer; }
.mini-row.done .t { text-decoration: line-through; color: var(--muted); }
.mini-row input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--ok); flex: none; }
.mini-add { display: flex; gap: 8px; margin-top: 6px; }
.comment { background: var(--cream); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; }
.comment .by { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.comment .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.drawer-foot { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.progress { height: 6px; border-radius: 999px; background: var(--beige); overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }

/* ---------- menus, modals, toasts ---------- */
.menu { position: fixed; z-index: 60; background: var(--card); border-radius: 10px; box-shadow: 0 10px 40px rgba(47,24,27,.25); padding: 6px; min-width: 200px; display: grid; }
.menu button { border: 0; background: none; text-align: left; padding: 8px 12px; border-radius: 6px; color: var(--ink); }
.menu button:hover { background: var(--cream); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.modal-wrap { position: fixed; inset: 0; background: rgba(47,24,27,.45); display: grid; place-items: center; z-index: 70; padding: 16px; }
.modal { background: var(--cream); border-radius: 16px; width: min(480px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.3); display: grid; gap: 14px; }
.modal.wide { width: min(640px, 100%); }
.modal h2 { font-family: var(--serif); font-weight: 500; margin: 0; color: var(--berry); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal .row { display: flex; gap: 8px; align-items: center; }
.modal .row > * { min-width: 0; }
.modal hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
.status-edit .row input[type=text] { flex: 1; }
.status-edit input[type=color] { width: 38px; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; flex: none; }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 90; }
.toast { background: var(--plum); color: var(--cream); padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); font-size: 13px; }
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 290px; max-width: 85vw; z-index: 50; transform: translateX(-105%); transition: transform .2s ease; }
  .side-open #sidebar { transform: none; }
  .side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(47,24,27,.45); z-index: 45; }
  .only-mobile { display: inline-grid !important; }
  .topbar { padding: 14px 16px 8px; }
  #crumbs h1 { font-size: 22px; }
  #view { padding: 6px 16px 80px; }
  .quick-add { grid-template-columns: 1fr 1fr; }
  .quick-add input[name=title] { grid-column: 1 / -1; }
  .quick-add button { grid-column: 1 / -1; }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 22px; }
  .fields { grid-template-columns: 1fr; }
  .cal .day { min-height: 74px; padding: 4px; }
  .cal .ev { font-size: 10px; padding: 1px 4px; }
  .col { width: 82vw; }
  .task-row { padding: 10px 12px; gap: 10px; }
  .drawer-body { padding: 16px 16px 40px; }
}

/* ---------- accessibility ---------- */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--berry); outline-offset: 2px; }
#sidebar :focus-visible, .auth-page :focus-visible { outline-color: var(--gold); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
h1[tabindex="-1"]:focus, #view:focus { outline: none; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; background: var(--gold); color: var(--plum); border: 0; border-radius: 999px; padding: 8px 16px; font-weight: 600; transform: translateY(-200%); }
.skip-link:focus { transform: none; }
.tree-row:focus-within .more { opacity: 1; }
.task-title { border: 0; background: none; padding: 0; margin: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; display: block; width: 100%; }
.card .task-title { font-weight: 500; }
.mini-row .t { border: 0; background: none; padding: 0; text-align: left; font: inherit; color: inherit; text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 400; }
.mini-row.done .t { color: var(--muted); }
.group-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.group-head h2 a { color: inherit; text-decoration: none; }
.group-head h2 a:hover { text-decoration: underline; }
h2.col-head { margin: 0; }
.drawer { visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; }
.drawer.open { visibility: visible; transition: transform .2s ease; }
@media (max-width: 900px) {
  #sidebar { visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; }
  .side-open #sidebar { visibility: visible; transition: transform .2s ease; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; transition-delay: 0s !important; animation: none !important; }
}
