:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #171a23;
  --muted: #6b7183;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --error: #e5484d;
  --error-soft: #fdecec;
  --update: #2f7bf5;
  --update-soft: #e8f1fe;
  --addition: #12a26b;
  --addition-soft: #e4f6ee;
  --p-critical: #e5484d;
  --p-high: #f07b1a;
  --p-medium: #d6a100;
  --p-low: #8a90a2;
  --shadow: 0 1px 2px rgba(16, 20, 40, .06), 0 4px 16px rgba(16, 20, 40, .06);
  --shadow-lg: 0 20px 60px rgba(16, 20, 40, .22);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1e222d;
  --border: #2a2f3d;
  --text: #e8eaf1;
  --muted: #8e94a6;
  --primary: #6d66f2;
  --primary-hover: #7f79f5;
  --primary-soft: #252650;
  --error-soft: #3a1d20;
  --update-soft: #172a47;
  --addition-soft: #133326;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic, .logo svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-weight: 550; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-block { width: 100%; justify-content: center; height: 42px; }
.btn-danger-ghost { color: var(--error); border-color: transparent; background: transparent; }
.btn-danger-ghost:hover { background: var(--error-soft); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 9px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input:not([type=checkbox]):not([type=range]), select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); font-size: 14px; font-weight: 400; color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=range] { accent-color: var(--primary); }
.form-error { color: var(--error); font-size: 13px; min-height: 18px; }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent 60%), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px;
}
.login-card p { margin: 0 0 4px; }

/* ---------- brand / topbar ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6d66f2, #4f46e5); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}
.logo svg { stroke-width: 3; }
.brand-name { font-weight: 750; font-size: 15px; letter-spacing: -.01em; line-height: 1.1; }
.brand-sub { font-size: 11.5px; color: var(--muted); line-height: 1.1; }
.brand-lg .logo { width: 42px; height: 42px; }
.brand-lg .brand-name { font-size: 19px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px; padding: 10px 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tab {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer;
  font-weight: 600; color: var(--muted);
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.user-menu { position: relative; }
.avatar-btn { border: 0; background: transparent; padding: 0; cursor: pointer; border-radius: 50%; }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--primary); flex: none;
}
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.empty { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border); }
.dropdown {
  position: absolute; right: 0; top: 42px; min-width: 190px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 30;
}
.dropdown-head { padding: 8px 10px; font-weight: 650; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent; border-radius: 7px; cursor: pointer; }
.dropdown button:hover { background: var(--surface-2); }

/* ---------- filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 14px 24px 0; max-width: 1400px; margin: 0 auto;
}
.filters select { width: auto; min-width: 140px; height: 36px; padding: 0 10px; }
.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.search input { padding-left: 34px !important; height: 36px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 550; color: var(--muted);
}
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* item type colours: every type class sets --c, the rest is derived */
.ty-bug { --c: #e5484d; }
.ty-error { --c: #c2410c; }
.ty-task { --c: #2f7bf5; }
.ty-update { --c: #0891b2; }
.ty-addition { --c: #12a26b; }
.ty-idea { --c: #c79100; }
.ty-design { --c: #db2777; }
.ty-accounting { --c: #7c3aed; }
:root[data-theme="dark"] .ty-error { --c: #f97316; }
:root[data-theme="dark"] .ty-idea { --c: #eab308; }
:root[data-theme="dark"] .ty-accounting { --c: #a78bfa; }
.badge[class*="ty-"] { background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.dot[class*="ty-"] { background: var(--c); }
.emo { font-size: 13px; line-height: 1; }

/* ---------- layout ---------- */
.view { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card h3 { margin: 0 0 14px; font-size: 14px; font-weight: 700; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; cursor: pointer; transition: transform .15s; }
.stat:hover { transform: translateY(-2px); }
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; font-size: 12.5px; }
.stat-value { font-size: 30px; font-weight: 750; letter-spacing: -.03em; line-height: 1.1; }
.stat-foot { font-size: 12px; color: var(--muted); }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.stat.s-error .stat-icon { background: var(--error-soft); color: var(--error); }
.stat.s-update .stat-icon { background: var(--update-soft); color: var(--update); }
.stat.s-addition .stat-icon { background: var(--addition-soft); color: var(--addition); }
.stat.s-done .stat-icon { background: var(--primary-soft); color: var(--primary); }
.dash-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }
.dash-col { display: flex; flex-direction: column; gap: 14px; }

.roadmap-row { display: grid; grid-template-columns: 130px 1fr 90px; align-items: center; gap: 12px; padding: 9px 0; }
.roadmap-row + .roadmap-row { border-top: 1px solid var(--border); }
.roadmap-name { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.roadmap-num { text-align: right; color: var(--muted); font-size: 12.5px; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #6d66f2, #4f46e5); transition: width .6s ease; }
.bar.thin { height: 4px; }

.pipeline { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin-bottom: 12px; }
.pipeline span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend b { color: var(--text); }
.st-open { background: #8a90a2; }
.st-in_progress { background: var(--update); }
.st-testing { background: #a855f7; }
.st-done { background: var(--addition); }

.mini-list { display: flex; flex-direction: column; }
.mini-item { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-radius: 8px; cursor: pointer; }
.mini-item:hover { background: var(--surface-2); }
.mini-item + .mini-item { border-top: 1px solid var(--border); }
.mini-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }

.feed { display: flex; flex-direction: column; }
.feed-row { display: flex; gap: 10px; padding: 9px 0; font-size: 13px; }
.feed-row + .feed-row { border-top: 1px solid var(--border); }
.feed-text { flex: 1; min-width: 0; }
.feed-text a { color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer; }
.feed-text a:hover { color: var(--primary); }
.feed-time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.b-neutral { background: var(--surface-2); color: var(--muted); }
.prio { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650; text-transform: capitalize; }
.prio i { display: inline-block; width: 3px; height: 10px; border-radius: 2px; background: var(--border); }
.prio.p-critical { color: var(--p-critical); } .prio.p-critical i { background: var(--p-critical); }
.prio.p-high { color: var(--p-high); } .prio.p-high i:nth-child(-n+3) { background: var(--p-high); }
.prio.p-medium { color: var(--p-medium); } .prio.p-medium i:nth-child(-n+2) { background: var(--p-medium); }
.prio.p-low { color: var(--p-low); } .prio.p-low i:nth-child(1) { background: var(--p-low); }
.id { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(250px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 300px; display: flex; flex-direction: column; gap: 8px; transition: background .15s, outline-color .15s; outline: 2px dashed transparent; outline-offset: -2px; }
.column.drag-over { outline-color: var(--primary); background: var(--primary-soft); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 6px; font-weight: 700; }
.col-head .count { margin-left: auto; font-size: 12px; color: var(--muted); background: var(--surface); padding: 1px 8px; border-radius: 99px; }
.col-head .dot { width: 10px; height: 10px; }
.icard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  cursor: pointer; box-shadow: 0 1px 2px rgba(16, 20, 40, .05); transition: box-shadow .15s, transform .15s, border-color .15s;
  display: flex; flex-direction: column; gap: 8px; border-left: 3px solid var(--border);
}
.icard:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.icard.dragging { opacity: .45; }
.icard[class*="ty-"] { border-left-color: var(--c); }
.icard-top { display: flex; align-items: center; gap: 6px; }
.icard-title { font-weight: 600; line-height: 1.35; word-break: break-word; }
.icard-foot { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.icard-foot .avatar { margin-left: auto; }
.meta-ic { display: inline-flex; align-items: center; gap: 3px; }
.meta-ic svg { width: 13px; height: 13px; }

/* ---------- list ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; text-transform: uppercase; letter-spacing: .03em; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.title-cell { font-weight: 600; min-width: 240px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.status-pill .dot { width: 7px; height: 7px; }
.prog-cell { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.prog-cell .bar { flex: 1; }
.prog-cell small { color: var(--muted); width: 32px; text-align: right; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 20, .5); backdrop-filter: blur(3px); z-index: 50; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { width: 100%; max-width: 980px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop .18s ease; overflow: hidden; }
.modal-sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 700; font-size: 16px; }
.modal-body { display: grid; grid-template-columns: 1fr; overflow: auto; }
.modal-body.with-side { grid-template-columns: 1.25fr 1fr; }
.pad { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.item-form { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.attach { display: flex; flex-direction: column; gap: 8px; }
.attach-head { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.attach-head .muted { font-weight: 400; }
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 8px; height: 64px;
  border: 1.5px dashed color-mix(in srgb, var(--muted) 50%, transparent); border-radius: 10px; color: var(--muted); cursor: pointer; font-weight: 600;
  transition: border-color .15s, background .15s, color .15s; outline: none;
}
.dropzone:hover, .dropzone:focus, .dropzone.drag-over { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.dropzone.busy { opacity: .6; pointer-events: none; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 4 / 3; border-radius: 9px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: block; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.thumb:hover img { transform: scale(1.04); }
.thumb.pending::after { content: "not saved yet"; position: absolute; left: 0; right: 0; bottom: 0; font-size: 10.5px; text-align: center; color: #fff; background: rgba(0, 0, 0, .55); padding: 2px 0; }
.thumb-del {
  position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 15px; line-height: 1; display: grid; place-items: center; opacity: 0; transition: opacity .15s;
}
.thumb:hover .thumb-del, .thumb:focus-within .thumb-del { opacity: 1; }
@media (hover: none) { .thumb-del { opacity: 1; } }

.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(5, 6, 10, .88); display: grid; place-items: center; padding: 20px; cursor: zoom-out; animation: fade .15s; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: var(--shadow-lg); }
.form-actions { display: flex; align-items: center; gap: 8px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg-btn { display: flex; align-items: center; justify-content: center; gap: 6px; height: 38px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 650; color: var(--muted); }
.seg-btn:hover { border-color: var(--c); }
.seg-btn.active { background: color-mix(in srgb, var(--c) 14%, transparent); border-color: var(--c); color: var(--c); }

.type-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.type-cell { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; cursor: pointer; background: color-mix(in srgb, var(--c) 9%, transparent); border: 1px solid transparent; transition: border-color .15s; }
.type-cell:hover { border-color: var(--c); }
.type-cell b { font-size: 20px; letter-spacing: -.02em; color: var(--c); line-height: 1.2; }
.type-cell span { font-size: 12px; color: var(--muted); font-weight: 600; }
.side { border-left: 1px solid var(--border); background: var(--surface-2); padding: 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side h4 { margin: 8px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.side-meta { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.side-meta b { color: var(--text); font-weight: 600; }
.comments { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow: auto; }
.comment { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; }
.comment-head { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 4px; }
.comment-head b { font-size: 12.5px; }
.comment-head .del { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.comment-head .del:hover { color: var(--error); }
.comment-body { white-space: pre-wrap; word-break: break-word; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; }
.history { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); max-height: 200px; overflow: auto; }
.history b { color: var(--text); font-weight: 600; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 60; font-weight: 550; animation: pop .2s; }

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

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .modal-body.with-side { grid-template-columns: 1fr; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tab { flex: 1; padding: 6px 8px; }
  #new-item-btn span { display: none; }
  #new-item-btn { padding: 0 10px; }
  .filters { padding: 12px 16px 0; }
  .filters select { flex: 1 1 140px; }
  .search { max-width: none; flex-basis: 100%; }
  .view { padding: 16px 16px 60px; }
  .board { grid-template-columns: repeat(4, 82vw); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .grid-2 { grid-template-columns: 1fr; }
  .seg, .type-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .roadmap-row { grid-template-columns: 100px 1fr 70px; }
  .overlay { padding: 0; place-items: end stretch; }
  .modal { max-height: 94vh; border-radius: 16px 16px 0 0; }
  .stat-value { font-size: 24px; }
}
