/* ===== Tokens ===== */
:root {
  --canvas: #F3F4F5;
  --surface: #FFFFFF;
  --surface-2: #EBECEE;
  --sunken: #E2E4E6;
  --ink: #1F2328;
  --ink-2: #57606A;
  --ink-3: #8C959F;
  --line: #DCDFE2;
  --line-2: #C6CBD0;
  --accent: #1F7BA8;
  --accent-hover: #186A92;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(31, 123, 168, .13);
  --danger: #CF222E;
  --danger-soft: rgba(207, 34, 46, .1);
  --p-urgent: #CF222E;
  --p-high: #BC4C00;
  --p-medium: #0969DA;
  --p-low: #8C959F;
  --ok: #1A7F37;
  --grid-col: rgba(31, 123, 168, .06);
  --shadow-card: 0 1px 2px rgba(31, 35, 40, .06);
  --shadow-lift: 0 14px 34px rgba(31, 35, 40, .18);
  --backdrop: rgba(18, 19, 20, .4);
  --font-display: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif;
  --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --topbar-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #121314; --surface: #202122; --surface-2: #191A1B; --sunken: #0E0F10;
    --ink: #D4D7D8; --ink-2: #9A9EA0; --ink-3: #6B6F71; --line: #2A2B2D; --line-2: #3A3C3E;
    --accent: #3994BC; --accent-hover: #4BA6CE; --accent-ink: #FFFFFF; --accent-soft: rgba(57, 148, 188, .18);
    --danger: #FF7B72; --danger-soft: rgba(255, 123, 114, .14);
    --p-urgent: #FF7B72; --p-high: #FFA657; --p-medium: #79C0FF; --p-low: #6B6F71;
    --ok: #7EE787;
  --grid-col: rgba(57, 148, 188, .07);
    --grid-col: rgba(57, 148, 188, .07);
    --shadow-card: none; --shadow-lift: 0 16px 40px rgba(0, 0, 0, .55);
    --backdrop: rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: #121314; --surface: #202122; --surface-2: #191A1B; --sunken: #0E0F10;
  --ink: #D4D7D8; --ink-2: #9A9EA0; --ink-3: #6B6F71; --line: #2A2B2D; --line-2: #3A3C3E;
  --accent: #3994BC; --accent-hover: #4BA6CE; --accent-ink: #FFFFFF; --accent-soft: rgba(57, 148, 188, .18);
  --danger: #FF7B72; --danger-soft: rgba(255, 123, 114, .14);
  --p-urgent: #FF7B72; --p-high: #FFA657; --p-medium: #79C0FF; --p-low: #6B6F71;
  --ok: #7EE787;
  --grid-col: rgba(57, 148, 188, .07);
  --shadow-card: none; --shadow-lift: 0 16px 40px rgba(0, 0, 0, .55);
  --backdrop: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
:root { padding-top: env(safe-area-inset-top, 0px); --nav-h: 0px; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.btn, .icon-btn, .tab, .seg button, .prio-chip, .tag-chip, .menu-item, .hour-chips button, .check, .swatch {
  transition: transform .12s ease, background-color .15s, color .15s, border-color .15s, box-shadow .15s, opacity .15s;
}
.btn:active, .icon-btn:active, .tab:active, .seg button:active, .prio-chip:active, .tag-chip:active, .menu-item:active, .hour-chips button:active, .swatch:active { transform: scale(.96); }
.check:active { transform: scale(.9); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.spacer { flex: 1; }
.wordmark {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 740;
  letter-spacing: -.035em;
  font-variation-settings: "opsz" 48;
}
kbd {
  font: 600 11px/1 var(--font-body);
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 3px 6px;
}

/* ===== Controls ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; flex: none;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink-2);
  transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.input, .select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.select {
  appearance: none; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.select.small { width: auto; height: 34px; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span:first-child { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.fields { display: grid; gap: 14px; }
.fields.two { grid-template-columns: 1fr 1fr; }
.hint { margin: 0; font-size: 13px; color: var(--ink-3); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); font-size: 14px; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--sunken); border-radius: 10px;
}
.seg button {
  border: 0; background: transparent; color: var(--ink-2);
  height: 30px; padding: 0 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { width: 32px; height: 18px; border-radius: 99px; background: var(--line-2); position: relative; transition: background-color .15s; }
.switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== Login ===== */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 18px;
  padding: 32px 28px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--line);
}
.login-card .wordmark { font-size: 40px; line-height: 1; }
.login-sub { margin: -8px 0 4px; color: var(--ink-2); }
#login-fields { display: flex; flex-direction: column; gap: 14px; }

/* ===== App shell ===== */
.app { height: calc(100dvh - env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; background: var(--canvas); }
.topbar {
  position: relative; z-index: 20; flex: none;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.demo-chip { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 2px 9px; cursor: help; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface-2); }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; color: var(--ink-3);
  font: 600 15px/1 var(--font-body);
  height: 34px; padding: 0 12px; border-radius: 8px;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); background: var(--sunken); }
.tab .i { display: none; }
#space-seg.off { visibility: hidden; }
.view { flex: 1; min-height: 0; }
.view.entering { animation: view-in .2s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }
.board-view, .notes-view { overflow-y: auto; overflow-x: hidden; padding-bottom: env(safe-area-inset-bottom, 0px); }
.time-view { overflow-y: auto; }

/* ===== Board ===== */
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 14px 20px 10px; position: sticky; top: 0; z-index: 25; background: var(--canvas); }
.filter-btn.on { color: var(--accent); }
.tool-btn { position: relative; }
.sort-wrap { cursor: pointer; }
.sort-wrap select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 16px; border: 0; }
.sort-wrap:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar-note { margin: 0; font-size: 13px; color: var(--ink-3); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.select.bare { border-color: transparent; background-color: transparent; color: var(--ink-2); font-weight: 600; }
.select.bare:hover { background-color: var(--surface-2); color: var(--ink); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { height: 28px; padding: 0 10px; border-radius: 99px; border: 1px solid var(--line); background: transparent; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.tag-chip:hover { color: var(--ink); border-color: var(--line-2); }
.tag-chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.popover.wide { width: 300px; }
.menu-item .switch-ui { flex: none; }
.switch-ui.on { background: var(--accent); }
.switch-ui.on::after { transform: translateX(14px); }
.search {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 8px 0 10px; width: 260px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--ink-3);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 14px; }
.search input::-webkit-search-cancel-button { display: none; }
.prio-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 99px; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.prio-chip::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--c); }
.prio-chip:hover { border-color: var(--line-2); color: var(--ink); }
.prio-chip.on { background: var(--surface); border-color: var(--c); color: var(--ink); }

/* The canvas: lists are absolutely positioned on a 12-column grid by app.js */
.board { position: relative; margin: 4px 20px 32px; min-height: 120px; border-radius: 14px; }
.board.editing {
  background-image: repeating-linear-gradient(to right, var(--grid-col) 0 var(--colw), transparent var(--colw) calc(var(--colw) + var(--gap)));
}
.col {
  position: absolute; top: 0; left: 0; width: 300px;
  display: flex; flex-direction: column;
  background: var(--surface-2);
  border-radius: 14px;
}
.board.ready .col { transition: left .18s ease, top .18s ease; }
.board.editing .col { box-shadow: inset 0 0 0 1px var(--line-2); }
.col.lifting { z-index: 30; box-shadow: var(--shadow-lift), inset 0 0 0 1px var(--accent) !important; transition: none !important; cursor: grabbing; }
body.dragging { user-select: none; -webkit-user-select: none; }
.col.resizing, .card.resizing { transition: none !important; }
.drop-ghost { position: absolute; z-index: 1; border: 2px dashed var(--accent); border-radius: 14px; background: var(--accent-soft); pointer-events: none; transition: left .12s, top .12s; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 6px 6px 14px; }
.board:not(.stacked) .col-head { cursor: grab; user-select: none; -webkit-user-select: none; }
.board:not(.stacked) .col-head:focus-visible { outline-offset: -2px; border-radius: 14px 14px 0 0; }
.col-head .icon-btn { opacity: 0; transition: opacity .15s; }
.col:hover .col-head .icon-btn, .col-head .icon-btn:focus-visible, .board.editing .col-head .icon-btn { opacity: 1; }
@media (hover: none) { .col-head .icon-btn { opacity: 1; } }
.col-title {
  margin: 0; flex: 1; min-width: 0;
  font: 650 15px/1.2 var(--font-display); letter-spacing: -.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.col-title::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--list); flex: none; }
.col-title-input {
  flex: 1; min-width: 0; height: 30px; padding: 0 8px;
  font: 650 15px var(--font-display); border: 1px solid var(--accent); border-radius: 7px; background: var(--surface); outline: none;
}
.col-count { font-size: 12px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.col-body {
  display: grid; grid-template-columns: repeat(var(--sub, 1), minmax(0, 1fr)); align-items: start;
  gap: 6px; padding: 4px 8px 6px; min-height: 40px;
}
.board.stacked .col-body { grid-template-columns: minmax(0, 1fr); }
.board.stacked .card { grid-column: auto !important; }
.col-empty { grid-column: 1 / -1; margin: 4px 2px; font-size: 13px; color: var(--ink-3); }
.quick-add { padding: 0 8px 8px; }
.quick-add input {
  width: 100%; height: 36px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; font-size: 14px; color: var(--ink);
}
.quick-add input:hover { background: var(--surface); }
.quick-add input::placeholder { color: var(--ink-3); }
.quick-add input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.board-empty { padding: 60px 20px; text-align: center; color: var(--ink-2); }
.board-empty h2 { font: 700 26px/1.15 var(--font-display); letter-spacing: -.02em; color: var(--ink); margin: 0 0 6px; }

/* Resize handles, visible only while editing the layout */
.rs { display: none; position: absolute; right: 0; bottom: 0; width: 20px; height: 20px; cursor: nwse-resize; touch-action: none; z-index: 2; }
.rs::after { content: ""; position: absolute; right: 5px; bottom: 5px; width: 7px; height: 7px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); border-radius: 0 0 2px 0; }
.rs:hover::after { border-color: var(--accent); }
.board.editing:not(.stacked) .rs { display: block; }
.board.editing .card { box-shadow: inset 0 0 0 1px var(--line-2); }

/* Notes */
.note {
  position: absolute; top: 0; left: 0; width: 300px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-card);
}
.board.ready .note { transition: left .18s ease, top .18s ease, border-color .15s; }
.note:focus-within { border-color: var(--line-2); }
.note.lifting { z-index: 30; box-shadow: var(--shadow-lift); border-color: var(--accent); transition: none !important; cursor: grabbing; }
.note.resizing { transition: none !important; }
.note-head { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 4px 0 8px; border-bottom: 1px solid transparent; }
.board:not(.stacked) .note-head { cursor: grab; user-select: none; -webkit-user-select: none; }
.note-head:focus-visible { outline-offset: -2px; border-radius: 13px 13px 0 0; }
.note-grip { display: flex; color: var(--ink-3); opacity: .6; }
.note-grip .i { width: 14px; height: 14px; }
.note-meta { flex: 1; min-width: 0; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-bar { display: none; flex: 1; min-width: 0; gap: 1px; overflow-x: auto; scrollbar-width: none; }
.note-bar::-webkit-scrollbar { display: none; }
.note-bar button { flex: none; min-width: 28px; height: 28px; padding: 0 5px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); display: inline-grid; place-items: center; font-size: 13px; }
.note-bar button:hover { background: var(--surface-2); color: var(--ink); }
.note-bar .i { width: 15px; height: 15px; }
.note:focus-within .note-meta { display: none; }
.note:focus-within .note-bar { display: flex; animation: fade-in .15s ease-out; }
.note:focus-within .note-head { border-bottom-color: var(--line); }
.note-head .icon-btn { width: 30px; height: 30px; opacity: 0; }
.note:hover .note-head .icon-btn, .note:focus-within .note-head .icon-btn, .note-head .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .note-head .icon-btn { opacity: 1; } }
.note .note-body { min-height: 56px; padding: 8px 14px 16px; outline: none; flex: 1; cursor: text; }
.notes-board:not(.stacked) .note:hover .rs, .notes-board:not(.stacked) .note:focus-within .rs, .notes-board .note.resizing .rs { display: block; }

/* Cards */
.card {
  position: relative; flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s;
}
.card:hover { border-color: var(--line-2); }
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--pc, transparent);
}
.card.p-low { --pc: var(--p-low); }
.card.p-medium { --pc: var(--p-medium); }
.card.p-high { --pc: var(--p-high); }
.card.p-urgent { --pc: var(--p-urgent); }
.card-cover { display: block; width: 100%; height: 96px; object-fit: cover; background: var(--sunken); }
.card-inner { padding: 10px 12px 10px 13px; display: flex; flex-direction: column; gap: 6px; }
.card-row { display: flex; gap: 10px; align-items: flex-start; }
.card-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; line-height: 1.45; overflow-wrap: anywhere; }
.card.is-done .card-title { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line-2); }
.card.is-done { opacity: .78; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding-left: 28px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 18px; color: var(--ink-3);
  font-size: 12px; font-weight: 500; white-space: nowrap; max-width: 100%;
}
.chip.complete { color: var(--ok); }
.tags { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.chip .i { width: 13px; height: 13px; }
.chip.overdue { color: var(--danger); }
.chip.today { color: var(--accent); font-weight: 600; }
.chip.bamboo { max-width: 100%; overflow: hidden; }
.chip.bamboo span { overflow: hidden; text-overflow: ellipsis; }
.card-ghost { opacity: .3; }
.card-chosen { box-shadow: var(--shadow-lift); }
.card-drag { transform: rotate(1.5deg); }

.check {
  width: 18px; height: 18px; flex: none; margin-top: 1px;
  display: grid; place-items: center;
  border: 1.5px solid var(--line-2); border-radius: 5px; background: transparent; color: transparent;
  padding: 0; position: relative;
}
.check::after { content: ""; position: absolute; inset: -9px; }
.check .i { width: 13px; height: 13px; stroke-width: 2.6; }
.check:hover { border-color: var(--accent); color: var(--accent); }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check.big { width: 26px; height: 26px; border-radius: 8px; margin-top: 6px; }
.check.big .i { width: 17px; height: 17px; }

/* ===== Popover & menus ===== */
.pop-scrim { position: fixed; inset: 0; z-index: 59; background: var(--backdrop); animation: fade-in .2s ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.popover:not([hidden]) { animation: pop-in .14s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.popover.sheet {
  left: 8px; right: 8px; top: auto; bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  width: auto; min-width: 0; max-height: 75dvh; overflow-y: auto; padding: 10px; border-radius: 20px;
  animation: sheet-up .26s cubic-bezier(.2, .8, .2, 1);
}
.popover.sheet.wide { width: auto; }
.popover.sheet .menu-item { height: 46px; font-size: 15px; }
.popover.sheet .seg button, .popover.sheet .prio-chip, .popover.sheet .tag-chip { height: 38px; }
@keyframes sheet-up { from { transform: translateY(48px); opacity: 0; } }
.popover {
  position: fixed; z-index: 60; min-width: 220px;
  padding: 6px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lift);
}
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent;
  font-size: 14px; font-weight: 500; text-align: left;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-group { padding: 6px 10px; display: flex; flex-direction: column; gap: 8px; }
.menu-group > span { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 24px; height: 24px; border-radius: 7px; border: 2px solid transparent; background: var(--c); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }

/* ===== Dialogs ===== */
dialog { color: var(--ink); }
dialog::backdrop { background: var(--backdrop); }
.drawer {
  position: fixed; inset: 0 0 0 auto;
  width: min(580px, 100vw); height: 100dvh; max-height: none; max-width: none;
  margin: 0; padding: 0; border: 0;
  background: var(--surface); box-shadow: var(--shadow-lift);
}
.drawer[open] { animation: drawer-in .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes drawer-in { from { transform: translateX(32px); opacity: 0; } }
.drawer-inner { height: 100%; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.drawer-inner.dropping { outline: 3px dashed var(--accent); outline-offset: -10px; }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 16px 8px 24px; }
.title-input {
  flex: 1; min-width: 0; resize: none; overflow: hidden;
  border: 0; outline: 0; background: transparent; padding: 0;
  font: 700 25px/1.25 var(--font-display); letter-spacing: -.02em;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 10px 24px 24px; display: flex; flex-direction: column; gap: 20px; }
.drawer-foot { display: flex; align-items: center; gap: 10px; padding: 12px 16px 12px 24px; border-top: 1px solid var(--line); }
.save-state { font-size: 13px; color: var(--ink-3); }

.prio-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.prio-seg button {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.prio-seg button::before { content: ""; width: 9px; height: 9px; border-radius: 3px; background: var(--c); }
.prio-seg button[aria-checked="true"] { border-color: var(--c); color: var(--ink); background: color-mix(in srgb, var(--c) 12%, var(--surface)); }

.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: 40px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
}
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-input input { flex: 1; min-width: 120px; border: 0; outline: 0; background: transparent; height: 28px; font-size: 14px; }
.tag-pill { display: inline-flex; align-items: center; gap: 2px; height: 26px; padding: 0 4px 0 9px; border-radius: 99px; background: var(--accent-soft); font-size: 13px; font-weight: 600; }
.tag-pill button { border: 0; background: transparent; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); padding: 0; }
.tag-pill button:hover { background: var(--surface); }
.tag-pill .i { width: 12px; height: 12px; }

.rte { border: 1px solid var(--line); border-radius: 11px; background: var(--surface); overflow: hidden; }
.rte:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rte-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 5px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.rte-bar button {
  min-width: 30px; height: 30px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-2);
  display: inline-grid; place-items: center; font-size: 14px;
}
.rte-bar button:hover { background: var(--sunken); color: var(--ink); }
.rte-bar .i { width: 16px; height: 16px; }
.rte-bar .sep { width: 1px; background: var(--line); margin: 5px 3px; }
.rte-body {
  min-height: 160px; padding: 12px 14px; outline: none;
  font-size: 15px; line-height: 1.6; overflow-wrap: anywhere;
}
.rte-body:empty::before { content: attr(data-placeholder); color: var(--ink-3); pointer-events: none; }
.rte-body > :first-child { margin-top: 0; }
.rte-body > :last-child { margin-bottom: 0; }
.rte-body p { margin: 0 0 .6em; }
.rte-body h3 { font: 680 18px/1.3 var(--font-display); margin: .8em 0 .3em; letter-spacing: -.01em; }
.rte-body ul, .rte-body ol { margin: 0 0 .6em; padding-left: 1.4em; }
.rte-body blockquote { margin: 0 0 .6em; padding: 2px 0 2px 12px; border-left: 3px solid var(--line-2); color: var(--ink-2); }
.rte-body code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; padding: 1px 5px; border-radius: 5px; background: var(--surface-2); }
.rte-body a { color: var(--accent); }
.rte-body ul.checklist { list-style: none; padding-left: 0; }
.rte-body ul.checklist > li { position: relative; padding-left: 28px; }
.rte-body ul.checklist > li::before {
  content: ""; position: absolute; left: 2px; top: .32em;
  width: 16px; height: 16px; border-radius: 5px; border: 1.6px solid var(--ink-3); cursor: pointer;
}
.rte-body ul.checklist > li[data-checked="true"] { color: var(--ink-3); text-decoration: line-through; }
.rte-body ul.checklist > li[data-checked="true"]::before {
  background: var(--accent) center / 12px no-repeat; border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}

.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.img-tile { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--sunken); }
.img-tile > button.open { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; }
.img-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-tile .del {
  position: absolute; top: 5px; right: 5px; width: 26px; height: 26px;
  background: rgba(0, 0, 0, .55); color: #fff; border-radius: 7px; opacity: 0; transition: opacity .15s;
}
.img-tile:hover .del, .img-tile .del:focus-visible { opacity: 1; }
.img-tile.loading { display: grid; place-items: center; font-size: 12px; color: var(--ink-3); }
.img-add {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 1px dashed var(--line-2); border-radius: 10px; background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 600; text-align: center; padding: 6px;
}
.img-add:hover { border-color: var(--accent); color: var(--ink); }
.bamboo-row { display: flex; gap: 8px; }
.bamboo-row .select { flex: 1; min-width: 0; }

.modal {
  width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow-lift);
}
.modal.small { width: min(400px, calc(100vw - 24px)); }
.modal[open] { animation: modal-in .18s ease-out; }
@keyframes modal-in { from { transform: translateY(8px) scale(.985); opacity: 0; } }
.modal-inner { display: flex; flex-direction: column; max-height: inherit; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 20px 16px 4px 24px; }
.modal-head h2 { margin: 0; flex: 1; font: 700 24px/1.2 var(--font-display); letter-spacing: -.02em; }
.modal-body { padding: 14px 24px 8px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 16px 16px 24px; }
.confirm-text { margin: 8px 0 0; font-size: 16px; line-height: 1.5; }
.hour-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -6px; }
.hour-chips button { height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: transparent; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.hour-chips button:hover { border-color: var(--accent); color: var(--ink); }
.day-total { margin: 0; font-size: 14px; color: var(--ink-2); }
.day-total b { font-family: var(--font-display); font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ===== Timesheet ===== */
.time-view { padding: 22px 20px 40px; }
.ts { max-width: 1180px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.ts-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.ts-range { margin: 0; flex: 1; font: 760 38px/1.05 var(--font-display); letter-spacing: -.035em; font-variation-settings: "opsz" 72; }
.ts-nav { display: flex; align-items: center; gap: 2px; }
.days { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.day { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.day-chip { display: flex; flex-direction: column; line-height: 1.2; padding-top: 2px; }
.day-chip .dow { font: 700 17px var(--font-display); letter-spacing: -.01em; }
.day-chip .dom { font-size: 13px; color: var(--ink-3); }
.day.is-today .day-chip .dow { color: var(--accent); }
.day.is-today .day-chip .dom { color: var(--ink-2); font-weight: 600; }
.day.is-weekend .day-chip .dow { color: var(--ink-3); }
.day-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.day-top { display: flex; align-items: center; gap: 8px; min-height: 34px; }
.day-sum { font: 700 19px var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.day-sum.zero { font: 500 14px var(--font-body); color: var(--ink-3); }
.day-top .icon-btn { margin-left: auto; }
.entry {
  display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: baseline;
  width: 100%; padding: 10px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 11px; background: var(--surface);
  transition: border-color .15s;
}
.entry:hover { border-color: var(--line-2); }
.entry:disabled { cursor: default; }
.entry-h { font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-what { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.entry-proj { font-weight: 600; font-size: 14px; }
.entry-note { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-flag { font-size: 12px; color: var(--ink-3); }

.ts-side {
  position: sticky; top: 0;
  display: flex; flex-direction: column;
  border-radius: 18px; background: var(--surface); border: 1px solid var(--line);
}
.ts-side > section { padding: 20px 22px; }
.ts-side > section + section { border-top: 1px solid var(--line); }
.sum-week .sum-num { display: block; font: 780 60px/1 var(--font-display); letter-spacing: -.045em; font-variant-numeric: tabular-nums; font-variation-settings: "opsz" 96; }
.sum-week .sum-sub { display: block; margin-top: 8px; color: var(--ink-2); font-size: 14px; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-top: 22px; }
.bar { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar-track { width: 100%; max-width: 30px; height: 84px; border-radius: 7px; background: var(--surface-2); position: relative; overflow: hidden; }
.bar-fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); border-radius: 7px 7px 0 0; transition: height .3s ease; }
.bar-fill.over { background: var(--p-high); }
.bar-label { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.bar.is-today .bar-label { color: var(--accent); }
.bar.is-today .bar-track { box-shadow: inset 0 0 0 2px var(--accent); }
.sum-period { display: flex; flex-direction: column; gap: 2px; }
.sum-period b { font: 720 26px/1.1 var(--font-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.sum-period span { font-size: 14px; color: var(--ink-2); }
.by-proj h3 { margin: 0 0 10px; font-size: 14px; font-weight: 650; color: var(--ink-2); }
.by-proj ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.by-proj li { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; font-size: 14px; line-height: 1.4; }
.by-proj li b { font-variant-numeric: tabular-nums; }
.ts-empty { max-width: 560px; margin: 50px auto; padding: 28px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); }
.ts-empty h2 { margin: 0 0 8px; font: 720 28px/1.15 var(--font-display); letter-spacing: -.02em; }
.ts-empty p { margin: 0 0 12px; color: var(--ink-2); }
.ts-empty code { font-size: 13px; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); }
.ts-loading { opacity: .5; pointer-events: none; }

/* ===== Lightbox & toasts ===== */
.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border: 0; background: transparent; padding: 24px; }
.lightbox[open] { display: grid; place-items: center; }
.lightbox::backdrop { background: rgba(5, 8, 6, .88); }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; object-fit: contain; }
.lightbox .icon-btn { position: absolute; color: #fff; background: rgba(255, 255, 255, .1); width: 42px; height: 42px; }
.lightbox .icon-btn:hover { background: rgba(255, 255, 255, .2); }
.lb-close { top: calc(16px + env(safe-area-inset-top, 0px)); right: 16px; }
.lb-prev { left: 16px; top: 50%; }
.lb-next { right: 16px; top: 50%; }
.toasts { position: fixed; inset: auto auto calc(20px + var(--nav-h) + env(safe-area-inset-bottom, 0px)) 50%; margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px; border-radius: 11px;
  background: var(--ink); color: var(--canvas); font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lift); animation: toast-in .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transition: opacity .25s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ===== Responsive ===== */
@media (max-width: 960px) {
  .ts { grid-template-columns: 1fr; }
  .ts-side { position: static; order: -1; }
}
@media (max-width: 720px) {
  :root { --nav-h: 64px; }
  .topbar { gap: 8px; padding: 0 8px 0 14px; height: 52px; }
  .icon-btn { width: 40px; height: 40px; }

  /* Bottom tab bar */
  .tabs {
    position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--surface-2) 94%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .tab {
    height: 100%; padding: 0; border-radius: 12px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font: 600 11.5px/1 var(--font-body); color: var(--ink-3);
  }
  .tab .i { display: block; width: 22px; height: 22px; transition: transform .2s cubic-bezier(.2, .8, .2, 1); }
  .tab.on { background: transparent; color: var(--accent); }
  .tab.on .i { transform: translateY(-1px) scale(1.06); }
  .board-view, .notes-view, .time-view { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 12px); }

  /* Toolbars with fixed, even layouts */
  .toolbar { padding: 10px 12px; gap: 8px; }
  .board-view .toolbar { display: grid; grid-template-columns: minmax(0, 1fr) repeat(3, 44px); }
  .board-view .toolbar .space-seg { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); }
  .board-view .toolbar .space-seg button { height: 34px; }
  .board-view .toolbar .spacer, #f-edit { display: none; }
  .search { width: auto; height: 44px; }
  .search kbd { display: none; }
  .tool-btn { width: 44px; height: 44px; padding: 0; }
  .tool-btn .lbl { display: none; }
  .tool-btn .i { width: 20px; height: 20px; }
  .tool-btn .badge { position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; font-size: 10px; }
  .toolbar-note { font-size: 12px; }
  .notes-view .toolbar-note { display: none; }
  #n-new { width: auto; padding: 0 16px; }
  #n-new .lbl { display: inline; }
  .board { margin: 2px 12px 16px; }

  /* Bigger touch targets and no zoom on focus (iOS zooms inputs under 16px) */
  input, select, textarea, .rte-body, .quick-add input, .search input { font-size: 16px; }
  .quick-add input { height: 44px; }
  .card-inner { padding: 12px 12px 12px 13px; }
  .card-title { font-size: 15px; }
  .check { width: 22px; height: 22px; border-radius: 6px; }
  .col-head { padding: 12px 6px 6px 14px; }
  .note-head { height: 44px; }
  .note-bar button { min-width: 36px; height: 36px; }
  .note-head .icon-btn { width: 36px; height: 36px; }

  /* Dialogs become bottom sheets */
  .modal {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 22px 22px 0 0;
    max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .modal[open] { animation: sheet-up .28s cubic-bezier(.2, .8, .2, 1); }
  .modal-head { padding: 18px 12px 2px 20px; }
  .modal-body { padding: 12px 20px 8px; }
  .modal-foot { padding: 12px 16px 16px 20px; }
  .modal-foot .btn { height: 46px; }
  .modal-foot .btn.primary { flex: 1; max-width: 220px; }
  .hour-chips button { height: 38px; padding: 0 14px; }
  .drawer { width: 100vw; }
  .drawer[open] { animation: sheet-up .3s cubic-bezier(.2, .8, .2, 1); }
  .drawer-head { padding: 14px 8px 6px 16px; }
  .title-input { font-size: 22px; }
  .drawer-body { padding: 8px 16px 20px; gap: 18px; }
  .drawer-foot { padding: 10px 12px 10px 16px; }
  .fields.two { grid-template-columns: 1fr; }
  .input, .select { height: 46px; }
  .rte-bar button { min-width: 36px; height: 36px; }
  .prio-seg button { height: 40px; flex: 1 1 auto; justify-content: center; }
  .bamboo-row { flex-direction: column; }
  .bamboo-row .btn { height: 44px; }
  .img-grid { grid-template-columns: repeat(3, 1fr); }
  .img-tile .del { opacity: 1; }

  /* Timesheet */
  .time-view { padding-top: 14px; padding-left: 12px; padding-right: 12px; }
  .ts-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px 8px; }
  .ts-range { grid-column: 1 / -1; order: -1; font-size: 30px; }
  .ts-head .btn.primary { grid-column: 3; height: 42px; }
  .ts-head .btn.ghost { justify-self: start; }
  .ts-nav .icon-btn { width: 42px; height: 42px; background: var(--surface-2); }
  .ts-nav { gap: 6px; }
  .day { grid-template-columns: 64px minmax(0, 1fr); gap: 10px; }
  .day-top .icon-btn { width: 40px; height: 40px; }
  .entry { grid-template-columns: 1fr; gap: 2px; padding: 12px; }
  .sum-week .sum-num { font-size: 48px; }
  .ts-side > section { padding: 18px; }
  .lb-prev, .lb-next { top: auto !important; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
