:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --surface-3: #e6e8f0;
  --border: #e2e4ec;
  --text: #1c1d29;
  --text-2: #5b5e72;
  --text-3: #8a8da0;
  --accent: #6d4aff;
  --accent-hover: #5a38eb;
  --accent-soft: #efebff;
  --accent-text: #ffffff;
  --success: #18a058;
  --success-soft: #e3f6ec;
  --warning: #d98e04;
  --warning-soft: #fff4dc;
  --danger: #e03e52;
  --danger-soft: #fde8eb;
  --info: #2f7de1;
  --info-soft: #e5f0fd;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 2px 8px rgba(20, 20, 40, .05);
  --shadow-lg: 0 12px 40px rgba(20, 20, 40, .18);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar: 232px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111218;
    --surface: #1a1b24;
    --surface-2: #22232e;
    --surface-3: #2c2d3a;
    --border: #2e3040;
    --text: #ecedf3;
    --text-2: #a7a9bb;
    --text-3: #777a8e;
    --accent: #8b70ff;
    --accent-hover: #9d86ff;
    --accent-soft: #2a2450;
    --success-soft: #16301f;
    --warning-soft: #33280f;
    --danger-soft: #3a1a20;
    --info-soft: #172a45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111218;
  --surface: #1a1b24;
  --surface-2: #22232e;
  --surface-3: #2c2d3a;
  --border: #2e3040;
  --text: #ecedf3;
  --text-2: #a7a9bb;
  --text-3: #777a8e;
  --accent: #8b70ff;
  --accent-hover: #9d86ff;
  --accent-soft: #2a2450;
  --success-soft: #16301f;
  --warning-soft: #33280f;
  --danger-soft: #3a1a20;
  --info-soft: #172a45;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.between { justify-content: space-between; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 15px; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--text-3); }
.project-switch { margin: 0 12px 10px; }
.project-switch select { width: 100%; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 10px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 4px; font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; align-items: center; gap: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar .search { flex: 1; max-width: 420px; position: relative; }
.topbar .search input { width: 100%; padding-left: 34px; }
.topbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); }
.btn.menu-btn { display: none; }
.content { padding: 24px; flex: 1; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); margin-top: 2px; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 550;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 6px; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], input[type=search], select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 10px;
  outline: none; min-width: 0; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 80px; width: 100%; line-height: 1.5; }
input[type=color] { width: 44px; height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; background: var(--surface); }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
label.field > span { color: var(--text-2); }
label.field input, label.field select, label.field textarea { font-weight: 400; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--text-3); font-weight: 400; }
.chip-select { display: flex; gap: 6px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select, .filters input { padding: 6px 10px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); gap: 10px; }
.card-body { padding: 14px 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; }

.stat { padding: 16px 18px; }
.stat .label { color: var(--text-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .foot { color: var(--text-3); font-size: 12px; }

.empty { text-align: center; padding: 36px 16px; color: var(--text-3); }
.empty svg { width: 36px; height: 36px; opacity: .6; margin-bottom: 6px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; line-height: 1.7;
}
.badge.todo { background: var(--surface-3); color: var(--text-2); }
.badge.in_progress { background: var(--info-soft); color: var(--info); }
.badge.review { background: var(--warning-soft); color: var(--warning); }
.badge.done { background: var(--success-soft); color: var(--success); }
.badge.label { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.badge.active { background: var(--success-soft); color: var(--success); }
.badge.planned { background: var(--info-soft); color: var(--info); }
.badge.closed { background: var(--surface-3); color: var(--text-3); }
.type-icon { width: 16px; height: 16px; border-radius: 4px; display: inline-grid; place-items: center; flex-shrink: 0; color: #fff; }
.type-icon svg { width: 11px; height: 11px; }
.type-task { background: #4a90e2; }
.type-improvement { background: #18a058; }
.type-bug { background: #e03e52; }
.type-story { background: #8e5cf7; }
.prio { display: inline-flex; align-items: center; }
.prio svg { width: 15px; height: 15px; }
.prio-critical { color: #e03e52; }
.prio-high { color: #f07b16; }
.prio-medium { color: #d9a404; }
.prio-low { color: #4a90e2; }
.key { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700;
  color: #fff; flex-shrink: 0; text-transform: uppercase;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.unassigned { background: var(--surface-3); color: var(--text-3); }

.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--success); border-radius: 99px; }

/* ---------- Board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.column { background: var(--surface-2); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 200px; }
.column-head { padding: 12px 14px 8px; display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.column-head .count { background: var(--surface-3); border-radius: 99px; padding: 0 8px; font-size: 11px; }
.column-body { padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 120px; border-radius: var(--radius); transition: background .12s; }
.column-body.drag-over { background: var(--accent-soft); }
.issue-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; transition: border-color .12s, transform .12s;
}
.issue-card:hover { border-color: var(--accent); }
.issue-card.dragging { opacity: .45; transform: rotate(1deg); }
.issue-card .title { font-weight: 500; word-break: break-word; }
.issue-card .meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.issue-card .meta .spacer { flex: 1; }
.issue-card .stripe { height: 3px; border-radius: 3px; margin: -4px 0 0; width: 32px; }
.due { font-size: 11.5px; color: var(--text-2); display: inline-flex; align-items: center; gap: 3px; }
.due.overdue { color: var(--danger); font-weight: 600; }
.due svg { width: 12px; height: 12px; }
.quick-add { border: 1px dashed var(--border); background: transparent; border-radius: 8px; padding: 8px; color: var(--text-3); cursor: pointer; text-align: left; }
.quick-add:hover { background: var(--surface); color: var(--text); }

/* ---------- Tables / lists ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.issue-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.issue-row:last-child { border-bottom: none; }
.issue-row:hover { background: var(--surface-2); }
.issue-row .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.issue-row select { padding: 3px 6px; font-size: 12px; }

.sprint-block { margin-bottom: 16px; }
.sprint-block .card-head { flex-wrap: wrap; }

.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.feed-item:last-child { border-bottom: none; }
.feed-item .text { flex: 1; min-width: 0; font-size: 13px; }
.feed-item .time { color: var(--text-3); font-size: 11.5px; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 10px 0 0; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .bar > div { width: 100%; max-width: 28px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar > div.zero { background: var(--surface-3); }
.bars .bar span { font-size: 10px; color: var(--text-3); }
.bars .bar b { font-size: 10.5px; color: var(--text-2); font-weight: 600; }

/* ---------- Modal / drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 10, 25, .45); z-index: 100; display: flex; align-items: flex-start;
  justify-content: center; padding: 5vh 16px; overflow-y: auto; animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; border: 1px solid var(--border); }
.modal.wide { max-width: 1040px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

.issue-detail { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
.issue-main { padding: 20px 24px; border-right: 1px solid var(--border); min-width: 0; }
.issue-side { padding: 20px; display: flex; flex-direction: column; gap: 12px; background: var(--surface-2); border-bottom-right-radius: 12px; }
.issue-side label.field select, .issue-side label.field input { width: 100%; }
.issue-title-input { font-size: 20px; font-weight: 650; border: 1px solid transparent !important; width: 100%; padding: 4px 6px !important; margin-left: -7px; background: transparent !important; }
.issue-title-input:hover { border-color: var(--border) !important; }
.issue-title-input:focus { border-color: var(--accent) !important; background: var(--surface) !important; }
.section-title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin: 22px 0 10px; display: flex; align-items: center; justify-content: space-between; }
.description { white-space: normal; word-break: break-word; padding: 8px 10px; border-radius: var(--radius-sm); cursor: text; min-height: 40px; margin-left: -10px; }
.description:hover { background: var(--surface-2); }
.description p { margin: 0 0 8px; }
.description ul { margin: 0 0 8px; padding-left: 20px; }
.description code, .comment-body code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 22px 0 14px; }
.tabs button { background: none; border: none; padding: 8px 12px; cursor: pointer; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.comment { display: flex; gap: 10px; margin-bottom: 14px; }
.comment-body { flex: 1; min-width: 0; }
.comment-body .text { margin-top: 2px; word-break: break-word; }
.comment-body .text p { margin: 0 0 6px; }
.comment .del { visibility: hidden; }
.comment:hover .del { visibility: visible; }
.attachments { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.attachment { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); position: relative; display: flex; flex-direction: column; }
.attachment .thumb { height: 86px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.attachment .thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment .thumb svg { width: 30px; height: 30px; color: var(--text-3); }
.attachment .info { padding: 6px 8px; font-size: 11.5px; }
.attachment .x { position: absolute; top: 4px; right: 4px; background: var(--surface); border-radius: 6px; border: 1px solid var(--border); padding: 2px; cursor: pointer; display: none; line-height: 0; }
.attachment:hover .x { display: block; }
.attachment .x svg { width: 14px; height: 14px; }
.dropzone { border: 1.5px dashed var(--border); border-radius: 8px; padding: 14px; text-align: center; color: var(--text-3); cursor: pointer; font-size: 13px; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.history-item { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.history-item:last-child { border-bottom: none; }
.time-summary { display: flex; gap: 16px; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; margin-bottom: 12px; }
.time-summary b { display: block; font-size: 18px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); font-weight: 500; animation: slide .18s ease-out; max-width: 360px; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at top, var(--accent-soft), var(--bg) 60%); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; padding: 0 0 20px; font-size: 18px; }

/* ---------- Project cards ---------- */
.project-card { padding: 18px; display: flex; flex-direction: column; gap: 12px; border-top: 4px solid var(--accent); }
.project-card h3 { font-size: 16px; }

.changelog h3 { margin: 16px 0 8px; font-size: 13px; }
.changelog ul { margin: 0; padding-left: 20px; }
.changelog li { margin-bottom: 4px; }

.report-print-head { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 90; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .issue-detail { grid-template-columns: 1fr; }
  .issue-main { border-right: none; border-bottom: 1px solid var(--border); padding: 16px; }
  .issue-side { border-radius: 0 0 12px 12px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(4, 82vw); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .topbar .hide-sm { display: none; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 22px; }
}

/* ---------- Print (reports → PDF) ---------- */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f5f5f7; --border: #ddd; --text: #111; --text-2: #444; --text-3: #777; }
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  .report-print-head { display: block; margin-bottom: 16px; }
  body { font-size: 12px; }
}
