:root {
  --radius: 14px;
  --radius-sm: 9px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", ui-monospace, monospace;

  --s-planning: #8b93a7;
  --s-active: #3b82f6;
  --s-paused: #f59e0b;
  --s-blocked: #ef4444;
  --s-done: #10b981;
  --p-low: #8b93a7;
  --p-medium: #3b82f6;
  --p-high: #f59e0b;
  --p-critical: #ef4444;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7fb;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #e6e3ff 0%, transparent 60%), radial-gradient(900px 500px at -10% 0%, #dff6fd 0%, transparent 55%);
  --surface: #ffffffcc;
  --surface-solid: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e3e6ef;
  --text: #141824;
  --muted: #646b80;
  --accent: #6656f5;
  --accent-contrast: #fff;
  --shadow: 0 1px 2px #1018280d, 0 8px 24px -8px #10182820;
  --overlay: #0d0f1766;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0f17;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #2a2360 0%, transparent 60%), radial-gradient(900px 500px at -10% 0%, #0f3242 0%, transparent 55%);
  --surface: #161a26cc;
  --surface-solid: #161a26;
  --surface-2: #1d2231;
  --border: #272d3f;
  --text: #e8eaf2;
  --muted: #8f97ad;
  --accent: #8b7dff;
  --accent-contrast: #0d0f17;
  --shadow: 0 1px 2px #0006, 0 12px 32px -12px #000a;
  --overlay: #000a;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  min-height: 100dvh;
  transition: background-color .25s var(--ease), color .25s var(--ease);
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px clamp(14px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.brand h1 span { color: var(--muted); font-weight: 500; }
.saved { font-size: 11.5px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface-solid);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: transform .12s var(--ease), background .15s, border-color .15s;
}
.btn { padding: 8px 14px; font-weight: 600; }
.icon-btn { width: 36px; height: 36px; }
.btn:hover, .icon-btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.btn:active, .icon-btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.danger { color: var(--s-blocked) !important; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; padding: 6px;
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); display: grid; animation: pop .14s var(--ease);
}
.menu button { text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }

a { color: var(--accent); }
main > * { min-width: 0; }
main { padding: 18px clamp(14px, 3vw, 32px) 60px; max-width: 1600px; margin: 0 auto; display: grid; gap: 16px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat {
  text-align: left; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  backdrop-filter: blur(8px); cursor: pointer; transition: border-color .15s, transform .15s var(--ease);
}
.stat:hover { transform: translateY(-1px); }
.stat.on { border-color: var(--accent); }
.stat b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.stat i { width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--muted)); }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search {
  flex: 1 1 260px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.search svg { color: var(--muted); }
.search input[type="search"] { border: 0; border-radius: 0; background: none; outline: none; padding: 9px 0; width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-solid); cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--dot); }
.chip[aria-pressed="true"] { background: color-mix(in srgb, var(--dot, var(--accent)) 18%, var(--surface-solid)); border-color: var(--dot, var(--accent)); }
.selects { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select, input:not([type]), input[type="text"], input[type="url"], input[type="date"], input[type="search"], textarea {
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
.toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; color: var(--muted); font-size: 13px; }
.toggle input { accent-color: var(--accent); }
.views { display: inline-flex; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); margin-left: auto; }
.views button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); }
.views button[aria-selected="true"] { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  position: relative; display: grid; gap: 10px; padding: 16px 16px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(8px); cursor: pointer; overflow: hidden;
  transition: transform .18s var(--ease), border-color .18s; animation: rise .25s var(--ease) both;
}
.card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--c, var(--accent)); }
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--c, var(--accent)) 45%, var(--border)); }
.card.archived { opacity: .6; }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.card h3 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; display: flex; gap: 6px; align-items: center; }
.card h3 small { font: 500 11px var(--mono); color: var(--muted); }
.card p.desc { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pin { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px; border-radius: 6px; opacity: .5; }
.pin:hover, .pin.on { opacity: 1; color: var(--p-high); }
.pin.on svg { fill: currentColor; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--b) 16%, transparent); color: color-mix(in srgb, var(--b) 85%, var(--text)); }
.badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--b); }
.row-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 11.5px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); cursor: pointer; }
.tag:hover { color: var(--text); }

.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: var(--w); background: var(--c, var(--accent)); border-radius: inherit; transition: width .4s var(--ease); }
.progress-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.dates { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); gap: 8px; }
.due.overdue { color: var(--s-blocked); font-weight: 600; }
.due.soon { color: var(--p-high); font-weight: 600; }

/* Board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.col { background: color-mix(in srgb, var(--surface-2) 60%, transparent); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 240px; scroll-snap-align: start; transition: background .15s, border-color .15s; }
.col.drop { border-color: var(--dot); background: color-mix(in srgb, var(--dot) 10%, transparent); }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 2px 4px; }
.col-head i { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.col-head span { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 500; }
.board .card { padding: 12px; gap: 8px; }
.card.dragging { opacity: .4; }
.col-add { border: 1px dashed var(--border); background: none; border-radius: var(--radius-sm); padding: 8px; color: var(--muted); cursor: pointer; }
.col-add:hover { color: var(--text); border-color: var(--muted); }

/* Timeline */
.timeline { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.tl-inner { min-width: 820px; position: relative; }
.tl-head, .tl-row { display: grid; grid-template-columns: 220px 1fr; }
.tl-head { position: sticky; top: 0; background: var(--surface-solid); border-bottom: 1px solid var(--border); font-size: 11.5px; color: var(--muted); }
.tl-months { position: relative; height: 32px; }
.tl-months span { position: absolute; top: 8px; padding-left: 6px; border-left: 1px solid var(--border); height: 24px; white-space: nowrap; }
.tl-row { border-bottom: 1px solid var(--border); min-height: 44px; }
.tl-row:last-child { border-bottom: 0; }
.tl-name { padding: 10px 14px; font-weight: 600; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-right: 1px solid var(--border); }
.tl-track { position: relative; }
.tl-bar { position: absolute; top: 11px; height: 22px; border-radius: 7px; cursor: pointer; overflow: hidden; min-width: 8px;
  background: color-mix(in srgb, var(--c) 28%, transparent); border: 1px solid color-mix(in srgb, var(--c) 60%, transparent); }
.tl-bar > span { display: block; height: 100%; width: var(--w); background: var(--c); opacity: .75; }
.tl-bar b { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tl-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--s-blocked); opacity: .7; pointer-events: none; z-index: 1; }
.tl-empty { padding: 14px; color: var(--muted); font-size: 13px; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-solid); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td .bar { width: 100px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 8px; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); display: grid; gap: 12px; justify-items: center; }
.empty h3 { color: var(--text); font-size: 16px; }

/* Dialogs */
dialog.sheet {
  width: min(680px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 18px; background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow);
}
dialog.sheet.small { width: min(420px, calc(100vw - 24px)); }
dialog[open] { animation: pop .18s var(--ease); }
dialog::backdrop { background: var(--overlay); backdrop-filter: blur(3px); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
dialog header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
dialog h2 { font-size: 16px; }
.form-body { padding: 16px 20px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-body label { min-width: 0; display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form-body label > :is(input, select, textarea) { color: var(--text); font-weight: 400; width: 100%; }
.form-body small { font-weight: 400; }
.form-body label.toggle { display: inline-flex; font-weight: 500; }
.form-body input[type="color"] { padding: 2px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-solid); }
.full { grid-column: 1 / -1; }
textarea { resize: vertical; }
.progress-field .row { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.progress-field input[type="range"] { width: 100%; accent-color: var(--accent); }
.progress-field input:disabled { opacity: .5; }
fieldset.tasks { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px 12px; margin: 0; }
fieldset.tasks legend { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 0 4px; }
#taskList { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 2px; }
#taskList li { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 6px; }
#taskList li:hover { background: var(--surface-2); }
#taskList li.done span { text-decoration: line-through; color: var(--muted); }
#taskList li span { flex: 1; cursor: text; }
#taskList li small { color: var(--muted); font-size: 11.5px; }
#taskList li small.overdue { color: var(--s-blocked); }
#taskList input[type="checkbox"] { accent-color: var(--s-done); width: 16px; height: 16px; }
#taskList button { border: 0; background: none; color: var(--muted); cursor: pointer; opacity: 0; padding: 2px; }
#taskList li:hover button, #taskList button:focus-visible { opacity: 1; }
.task-add { display: flex; gap: 8px; }
.task-add #taskInput { flex: 1; }
.meta { font-size: 12px; color: var(--muted); display: grid; gap: 2px; }
.meta details summary { cursor: pointer; }
.meta ul { margin: 4px 0 0; padding-left: 16px; max-height: 120px; overflow-y: auto; }
dialog footer { display: flex; justify-content: space-between; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
dialog footer > div { display: flex; gap: 6px; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; padding: 16px 20px 20px; margin: 0; }
.keys dd { margin: 0; color: var(--muted); }
kbd { font: 600 11.5px var(--mono); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--border); border-bottom-width: 2px; background: var(--surface-2); }

/* Toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; }
.toast { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); animation: rise .2s var(--ease); font-weight: 500; }
.toast button { border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer; filter: brightness(1.3); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }

@media (max-width: 720px) {
  .top-actions .btn span { display: none; }
  .top-actions .btn { padding: 8px 10px; }
  .stats { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; }
  .stat { flex: 0 0 120px; padding: 10px 12px; scroll-snap-align: start; }
  .stat b { font-size: 19px; }
  .views { margin-left: 0; width: 100%; }
  .views button { flex: 1; }
  .form-body { grid-template-columns: minmax(0, 1fr); }
  dialog.sheet { width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .tl-head, .tl-row { grid-template-columns: 140px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .topbar, .toolbar, .toasts, .pin { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
}
