:root {
  color-scheme: dark;
  --bg: #0e1014;
  --surface: #171a21;
  --surface-2: #1f232c;
  --surface-3: #2a2f3a;
  --line: #2c313c;
  --text: #e9ebf0;
  --muted: #9aa2b1;
  --accent: #7a1e22;
  --accent-hover: #93282d;
  --accent-text: #f0a3a6;
  --focus: #f0a3a6;
  --task: #7db0f5;
  --bug: #f08a7b;
  --ok: #6fcf97;
  --warn: #e7b45c;
  --series-1: #4a82d8;
  --series-2: #b97a2c;
  --radius: 10px;
  --display: "Barlow Condensed", "Bahnschrift Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --body: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--body); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: .01em; }
h1 { font-size: 32px; }
h2 { font-size: 20px; margin-bottom: 12px; }
h3 { font-size: 15px; font-family: var(--body); color: var(--muted); margin: 14px 0 4px; }
p { margin: 0 0 10px; }
code { background: var(--surface-3); border-radius: 4px; padding: 1px 5px; font: 13px/1.4 Consolas, Menlo, monospace; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.hint { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.plain { list-style: none; margin: 0; padding: 0; }

.topbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 24px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font: 600 22px/1 var(--display); }
.brand:hover { text-decoration: none; }
.brand-large { font-size: 34px; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 7px; }
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.on { color: var(--text); background: var(--surface-3); }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: wrap; }
.who { color: var(--text); }
.page { max-width: 1320px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; font: 600 14px/1.2 var(--body); color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-bug { background: transparent; border-color: var(--bug); color: var(--bug); }
.btn-bug:hover { background: rgba(240, 138, 123, .14); }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-wide { width: 100%; padding: 10px; }
.btn-link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font: inherit; }
.btn-link:hover { color: var(--text); text-decoration: underline; }
.btn-link.danger { color: var(--bug); }

input, select, textarea { width: 100%; padding: 8px 10px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; font: inherit; }
input[type="file"] { padding: 5px; width: auto; max-width: 100%; flex: 1 1 200px; }
input[type="checkbox"] { width: auto; }
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; font-size: 15px; color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel.narrow { max-width: 520px; }
.panel.archived { opacity: .65; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--surface-2); border: 1px solid var(--line); }
.flash p { margin: 0 0 6px; }
.flash-ok { border-color: var(--ok); }
.flash-error { border-color: var(--bug); }
.flash-info { border-color: var(--warn); }
.key-reveal { display: block; padding: 8px; user-select: all; }
.empty { text-align: center; padding: 44px 20px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.empty h1, .empty h2 { margin-bottom: 8px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); }
.type-task { color: var(--task); }
.type-bug { color: var(--bug); }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-in_progress i { background: var(--task); }
.status-blocked i { background: var(--warn); }
.status-done i, .status-squished i { background: var(--ok); }
.priority { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.priority-urgent { color: var(--bug); }
.priority-high { color: var(--warn); }
.agent-badge { display: inline-block; padding: 0 5px; font-size: 10px; font-weight: 700; letter-spacing: .04em; border-radius: 4px; background: var(--accent); color: #fff; vertical-align: 1px; }
.count { color: var(--muted); font: 600 13px var(--body); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 16px 0; }
.tile { display: flex; flex-direction: column; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); }
.tile:hover { border-color: var(--surface-3); background: var(--surface-2); text-decoration: none; }
.tile-value { font: 600 38px/1.1 var(--display); }
.tile-label { color: var(--muted); font-size: 13px; }
.columns-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }
.columns-2.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.project-line { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--line); }
.project-line:last-child { border-bottom: 0; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 18px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend b { color: var(--text); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.swatch.series-opened { background: var(--series-1); }
.swatch.series-closed { background: var(--series-2); }
path.series-opened { fill: var(--series-1); }
path.series-closed { fill: var(--series-2); }
.grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.grid.baseline { stroke-dasharray: none; stroke: var(--surface-3); }
.axis { fill: var(--muted); font-size: 11px; }
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: rgba(255, 255, 255, .05); }
.chart-tip { position: absolute; padding: 4px 8px; background: var(--surface-3); border: 1px solid var(--line); border-radius: 6px; font-size: 12px; pointer-events: none; white-space: nowrap; }
.chart-table { margin-top: 8px; font-size: 13px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; }
th, td { padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; margin-bottom: 14px; }

.rows.panel { padding: 4px 8px; }
.row { display: grid; grid-template-columns: 90px 44px minmax(0, 1fr) 54px 110px 120px; align-items: center; gap: 12px; padding: 9px 8px; color: var(--text); border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); text-decoration: none; border-radius: 6px; }
.row-ref { font: 600 12px Consolas, Menlo, monospace; color: var(--muted); white-space: nowrap; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-person { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows-compact .row { grid-template-columns: 76px 44px minmax(0, 1fr) 54px; }
.rows-compact .status, .rows-compact .row-person { display: none; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters input, .filters select { width: auto; flex: 0 1 170px; min-width: 120px; font-size: 14px; padding: 6px 8px; background: var(--surface); }
.filters input[type="search"] { flex: 1 1 200px; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.segmented a { padding: 4px 12px; color: var(--muted); border-radius: 6px; font-size: 13px; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.on { background: var(--surface-3); color: var(--text); }

.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: start; }
.board-col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: 240px; transition: border-color .12s; }
.board-col.drop-on { border-color: var(--accent-text); }
.board-col h2 { font-size: 17px; }
.board-cards { display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.card { background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--task); border-radius: 8px; padding: 10px; cursor: grab; }
.card-bug { border-left-color: var(--bug); }
.card.dragging { opacity: .4; }
.card-top { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin-bottom: 6px; }
.card-top .priority { margin-left: auto; }
.card-title { display: block; color: var(--text); font-weight: 600; overflow-wrap: anywhere; margin-bottom: 8px; }
.card-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.card-move select { padding: 2px 4px; font-size: 12px; width: auto; background: var(--surface-3); border-color: transparent; color: var(--muted); max-width: 120px; }

.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.item-head h1 { overflow-wrap: anywhere; }
.item-pills { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.item-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.item-main, .item-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 14px 0 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.comment { padding: 10px 12px; margin-bottom: 10px; background: var(--surface-2); border-radius: 8px; }
.comment-agent { border-left: 3px solid var(--accent); }
.comment header { font-size: 13px; margin-bottom: 4px; }
.attachments { list-style: none; margin: 0 0 14px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.attachments li { display: flex; flex-direction: column; gap: 2px; padding: 8px; background: var(--surface-2); border-radius: 8px; min-width: 0; font-size: 13px; }
.attachments img { display: block; width: 100%; height: 100px; object-fit: cover; border-radius: 5px; background: var(--bg); margin-bottom: 4px; }
.file-icon { display: flex; align-items: center; justify-content: center; height: 100px; border-radius: 5px; background: var(--bg); color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.file-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; }
[data-dropzone].drop-on { border-color: var(--accent-text); }
.upload { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.delete-form { text-align: center; font-size: 13px; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity.panel { padding: 8px 18px; }
.activity-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) auto; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.activity-row:last-child { border-bottom: 0; }
.activity-what { overflow-wrap: anywhere; }
.activity-when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.activity-compact .activity-row { grid-template-columns: 1fr; gap: 0; font-size: 13px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 820px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 8px; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-bottom: 14px; }
.project-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details form { margin: 10px 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 220px; width: auto; }

.bare { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }

@media (max-width: 1000px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .columns-2, .columns-2.even, .item-layout { grid-template-columns: minmax(0, 1fr); }
  .row { grid-template-columns: 76px 44px minmax(0, 1fr) 54px; }
  .row .status, .row-person { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; position: static; }
  .page { padding: 16px; }
  .board { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 32px; }
  .card { cursor: default; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .row, .rows-compact .row { grid-template-columns: 44px minmax(0, 1fr) 54px; }
  .row .row-ref { display: none; }
  .activity-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .filters input, .filters select { flex: 1 1 140px; }
  h1 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
