:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2128;
  --border: rgba(48,54,61,0.8);
  --accent: #388bfd;
  --accent-dim: rgba(56,139,253,0.15);
  --text: #e6edf3;
  --muted: #8b949e;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --epic: #a371f7;
  --story: #388bfd;
  --task: #58a6ff;
  --radius: 6px;
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, "Segoe UI", sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topnav ──────────────────────────────────────────────────────────────── */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; height: 48px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px; z-index: 100;
}
.topnav-logo { font-weight: 700; font-size: 15px; color: var(--text); letter-spacing: 0.04em; }
.topnav-logo span { color: var(--accent); }
.topnav-spacer { flex: 1; }
.topnav-user { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.btn-logout { padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); font-size: 12px; cursor: pointer; background: transparent; transition: border-color .15s, color .15s; }
.btn-logout:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }

/* Search */
.topnav-search { flex: 1; max-width: 400px; position: relative; }
.topnav-search input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 5px 10px; font-size: 13px; outline: none; }
.topnav-search input:focus { border-color: var(--accent); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-shell { display: flex; padding-top: 48px; min-height: 100%; }
.sidebar {
  width: var(--sidebar-w); min-height: calc(100vh - 48px);
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px 0; flex-shrink: 0; position: sticky; top: 48px;
  height: calc(100vh - 48px); overflow-y: auto;
}
.sidebar-label { padding: 6px 14px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); opacity: .7; }
.sidebar a { display: flex; align-items: center; gap: 8px; padding: 6px 14px; color: var(--muted); font-size: 13px; border-left: 2px solid transparent; transition: background .1s, color .1s; }
.sidebar a:hover, .sidebar a.active { background: var(--accent-dim); color: var(--text); border-left-color: var(--accent); text-decoration: none; }
.main-content { flex: 1; padding: 24px 28px; min-width: 0; max-width: 1400px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: background .15s, border-color .15s; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #4d99ff; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }
.btn-danger { background: transparent; border-color: rgba(248,81,73,.4); color: var(--danger); }
.btn-danger:hover { background: rgba(248,81,73,.1); }
.btn-sm { padding: 3px 8px; font-size: 12px; }

/* ── Type icons + badges ─────────────────────────────────────────────────── */
.type-badge { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.type-epic   { background: rgba(163,113,247,.2); color: var(--epic); }
.type-story  { background: rgba(56,139,253,.2);  color: var(--story); }
.type-task   { background: rgba(88,166,255,.15); color: var(--task); }

.priority-critical { color: var(--danger); }
.priority-high     { color: var(--warning); }
.priority-medium   { color: var(--accent); }
.priority-low      { color: var(--muted); }

.status-badge { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.status-backlog     { background: rgba(139,148,158,.15); color: var(--muted); }
.status-todo        { background: rgba(139,148,158,.2);  color: #cdd5e0; }
.status-in_progress { background: rgba(56,139,253,.2);   color: var(--accent); }
.status-in_review   { background: rgba(210,153,34,.2);   color: var(--warning); }
.status-done        { background: rgba(63,185,80,.2);    color: var(--success); }
.status-cancelled   { background: rgba(248,81,73,.15);   color: var(--danger); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th { background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody tr { border-bottom: 1px solid rgba(48,54,61,.5); transition: background .1s; }
.data-table tbody tr:hover { background: rgba(56,139,253,.05); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table td { padding: 9px 14px; vertical-align: middle; }
.data-table td.muted { color: var(--muted); }
.data-table td.mono { font-family: monospace; font-size: 12px; }
.ticket-id { font-family: monospace; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 640px; }
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
input, select, textarea { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 7px 10px; font-size: 13px; font-family: inherit; outline: none; transition: border-color .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--surface); }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 20px; }
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header-actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Stat grid ───────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); }
.stat-value.accent { color: var(--accent); }

/* ── Kanban board ────────────────────────────────────────────────────────── */
.board { display: grid; grid-template-columns: repeat(5,minmax(200px,1fr)); gap: 12px; overflow-x: auto; }
.board-col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.board-col-header { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; }
.board-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; cursor: pointer; transition: border-color .15s; }
.board-card:hover { border-color: var(--accent); }
.board-card-id { font-size: 11px; color: var(--muted); font-family: monospace; }
.board-card-title { font-size: 13px; margin: 3px 0; }
.board-card-meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; }

/* ── Ticket detail ───────────────────────────────────────────────────────── */
.ticket-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; }
.ticket-main { min-width: 0; }
.ticket-sidebar { min-width: 0; }
.detail-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.detail-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.detail-value { font-size: 13px; color: var(--text); }
.markdown-body { font-size: 14px; line-height: 1.7; color: var(--text); }
.markdown-body p { margin-bottom: 10px; }
.markdown-body code { background: var(--surface-2); border-radius: 3px; padding: 2px 5px; font-size: 12px; }
.markdown-body pre { background: var(--surface-2); border-radius: var(--radius); padding: 12px; overflow-x: auto; margin-bottom: 10px; }

/* Comments */
.comment { border-bottom: 1px solid var(--border); padding: 12px 0; }
.comment:last-child { border-bottom: none; }
.comment-header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.comment-author { font-weight: 600; color: var(--text); }

/* Changelog */
.cl-entry { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); padding: 4px 0; border-bottom: 1px solid rgba(48,54,61,.4); }
.cl-field { font-weight: 600; color: var(--text); }

/* Flash */
.flash { padding: 8px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.flash-success { background: rgba(63,185,80,.12); border: 1px solid rgba(63,185,80,.3); color: var(--success); }
.flash-error   { background: rgba(248,81,73,.12);  border: 1px solid rgba(248,81,73,.3);  color: var(--danger); }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-wrap { display: grid; place-items: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px; width: 340px; }
.login-logo { font-size: 22px; font-weight: 800; letter-spacing: .04em; margin-bottom: 24px; text-align: center; }
.login-logo span { color: var(--accent); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .sidebar { display: none; }
  .ticket-layout { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(3, minmax(160px,1fr)); }
  .main-content { padding: 16px; }
}
