:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f5; --surface-3: #e9ecef;
  --border: #dee2e6; --border-strong: #ced4da;
  --text: #1d2125; --text-2: #495057; --muted: #6c757d;
  --primary: #3b5bdb; --primary-hover: #364fc7; --primary-soft: #edf2ff; --primary-text: #fff;
  --todo: #868e96; --todo-bg: #f1f3f5; --prog: #1c7ed6; --prog-bg: #e7f5ff; --done: #2b8a3e; --done-bg: #ebfbee;
  --danger: #e03131; --danger-bg: #fff5f5; --warn: #e67700; --warn-bg: #fff9db;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.18);
  --radius: 8px; --radius-sm: 6px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1a1e23; --surface-2: #22272e; --surface-3: #2d333b;
    --border: #30363d; --border-strong: #444c56;
    --text: #e6edf3; --text-2: #c9d1d9; --muted: #8b949e;
    --primary: #5c7cfa; --primary-hover: #748ffc; --primary-soft: #1e2a4a; --primary-text: #fff;
    --todo: #9aa4ae; --todo-bg: #2d333b; --prog: #4dabf7; --prog-bg: #102a43; --done: #51cf66; --done-bg: #12301b;
    --danger: #ff6b6b; --danger-bg: #3a1618; --warn: #fcc419; --warn-bg: #3a2e08;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; } h2 { font-size: 18px; font-weight: 600; } h3 { font-size: 15px; font-weight: 600; } h4 { font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
code, .mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; } .row.wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 4px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); margin-right: 12px; }
.brand img { width: 26px; height: 26px; }
.brand:hover { text-decoration: none; }
.nav a { color: var(--text-2); padding: 6px 10px; border-radius: var(--radius-sm); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.main { overflow: auto; }
.page { padding: 24px; max-width: 1280px; margin: 0 auto; }
.page.wide { max-width: none; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.project-layout { display: grid; grid-template-columns: 220px 1fr; height: 100%; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; overflow: auto; }
.side .proj { display: flex; gap: 10px; align-items: center; padding: 6px 8px 16px; }
.side a.item { display: flex; gap: 10px; align-items: center; color: var(--text-2); padding: 7px 10px; border-radius: var(--radius-sm); font-weight: 500; }
.side a.item:hover { background: var(--surface-2); text-decoration: none; }
.side a.item.active { background: var(--primary-soft); color: var(--primary); }
.side .sep { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 14px 10px 6px; }
.avatar-proj { width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 12px; flex: none; }
.proj-content { overflow: auto; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 13.5px var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12.5px; }
.btn.icon { width: 32px; padding: 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], input[type=search], select, textarea {
  width: 100%; height: 34px; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: 14px var(--font);
}
textarea { height: auto; min-height: 90px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
select[multiple] { height: auto; min-height: 90px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
label.field > span .req { color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- cards & tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-head h3 { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.tbl-wrap { overflow: auto; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; } .kpi .l { color: var(--muted); font-size: 12.5px; }
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

/* ---------- badges ---------- */
.lozenge { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.lozenge.todo { background: var(--todo-bg); color: var(--todo); }
.lozenge.in_progress { background: var(--prog-bg); color: var(--prog); }
.lozenge.done { background: var(--done-bg); color: var(--done); }
.type-dot { display: inline-block; width: 14px; height: 14px; border-radius: 3px; flex: none; vertical-align: -2px; }
.pri { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; white-space: nowrap; }
.pri i { font-style: normal; font-weight: 700; }
.pri.Highest i, .pri.High i { color: var(--danger); } .pri.Medium i { color: var(--warn); } .pri.Low i, .pri.Lowest i { color: var(--prog); }
.label { display: inline-block; padding: 0 6px; border-radius: 3px; background: var(--surface-3); color: var(--text-2); font-size: 11.5px; margin: 1px 2px 1px 0; }
.av { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; flex: none; }
.av.lg { width: 30px; height: 30px; font-size: 12px; }
.av.none { background: var(--surface-3) !important; color: var(--muted); }
.who { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.key { font-weight: 600; color: var(--muted); white-space: nowrap; font-size: 12.5px; }
.sla { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.sla.running { background: var(--prog-bg); color: var(--prog); }
.sla.paused { background: var(--todo-bg); color: var(--todo); }
.sla.met { background: var(--done-bg); color: var(--done); }
.sla.breached { background: var(--danger-bg); color: var(--danger); }
.sla.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- board ---------- */
.board-wrap { padding: 20px 24px; }
.board-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.board-tools input[type=search] { width: 220px; }
.chip { height: 30px; padding: 0 12px; border-radius: 15px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; font: 500 13px var(--font); }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; min-height: 60vh; }
.col { flex: 0 0 280px; background: var(--surface-2); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.col-head { padding: 10px 12px; display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.col-head .count { background: var(--surface-3); padding: 0 6px; border-radius: 8px; }
.col-head.over .count { background: var(--danger-bg); color: var(--danger); }
.col-body { padding: 0 8px 8px; overflow-y: auto; flex: 1; min-height: 60px; border-radius: var(--radius); transition: background .15s; }
.col-body.drop { background: var(--primary-soft); outline: 2px dashed var(--primary); outline-offset: -4px; }
.bcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: grab; }
.bcard:hover { border-color: var(--border-strong); }
.bcard.dragging { opacity: .4; }
.bcard .t { margin-bottom: 8px; word-wrap: break-word; }
.bcard .meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bcard.breach { border-left: 3px solid var(--danger); }
.drop-marker { height: 3px; background: var(--primary); border-radius: 2px; margin: -5px 0 5px; }

/* ---------- issue view ---------- */
.issue { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; }
.issue-title { font-size: 22px; font-weight: 600; padding: 4px 6px; margin: 0 -6px 8px; border-radius: 4px; border: 1px solid transparent; width: calc(100% + 12px); background: transparent; color: var(--text); font-family: var(--font); }
.issue-title:hover { background: var(--surface-2); }
.issue-title:focus { background: var(--surface); border-color: var(--primary); outline: none; }
.desc { white-space: pre-wrap; word-wrap: break-word; padding: 8px; margin: 0 -8px; border-radius: 4px; cursor: text; min-height: 40px; }
.desc:hover { background: var(--surface-2); }
.desc.empty-desc { color: var(--muted); }
.side-panel .fld { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; padding: 6px 0; min-height: 36px; }
.side-panel .fld > .l { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.side-panel select, .side-panel input { height: 30px; font-size: 13px; }
.trans { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 20px 0 12px; }
.tabs button { background: none; border: 0; padding: 8px 12px; font: 500 13.5px var(--font); color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.comment { display: flex; gap: 10px; margin-bottom: 16px; }
.comment .body { white-space: pre-wrap; word-wrap: break-word; margin-top: 2px; }
.hist { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.hist:last-child { border-bottom: 0; }
.hist del { color: var(--muted); }
.sub-list .si { color: inherit; display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 4px; background: var(--surface); }
.sub-list .si:hover { background: var(--surface-2); text-decoration: none; }
.section { margin-top: 20px; }
.section > .row:first-child { margin-bottom: 8px; }

/* ---------- drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(9,12,16,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow: auto; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; animation: pop .14s; }
.modal.lg { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.drawer-overlay { position: fixed; inset: 0; background: rgba(9,12,16,.3); z-index: 40; animation: fade .12s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(980px, 100vw); background: var(--bg); box-shadow: var(--shadow-lg); z-index: 41; overflow: auto; animation: slide .16s; }
.drawer .drawer-bar { position: sticky; top: 0; display: flex; gap: 8px; align-items: center; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 2; }
.drawer .page { padding: 20px 24px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }

/* ---------- menus, toasts ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 220px; z-index: 30; padding: 6px; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 4px; color: var(--text); background: none; border: 0; font: 14px var(--font); cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--surface-2); text-decoration: none; }
.notif { width: 360px; max-height: 460px; overflow: auto; }
.notif .n { padding: 8px 10px; border-radius: 4px; font-size: 13px; cursor: pointer; }
.notif .n:hover { background: var(--surface-2); }
.notif .n.unread { background: var(--primary-soft); }
.bell-dot { position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1d2125; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 520px; animation: pop .15s; font-size: 13.5px; }
.toast.err { background: var(--danger); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { justify-content: center; margin: 0 0 18px; font-size: 20px; }

/* ---------- search ---------- */
.jql-bar { display: flex; gap: 8px; }
.jql-bar input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; height: 38px; }
.jql-help { font-size: 12px; color: var(--muted); margin: 8px 0 14px; }
.jql-help code { background: var(--surface-3); padding: 1px 5px; border-radius: 3px; cursor: pointer; }
.search-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.filter-list a { display: flex; align-items: center; padding: 6px 8px; border-radius: 4px; color: var(--text-2); }
.filter-list a:hover { background: var(--surface-2); text-decoration: none; }

/* ---------- workflow editor ---------- */
.wf-status { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; background: var(--surface); }
.wf-flow { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.wf-node { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--surface); }
.wf-node .out { font-size: 12.5px; color: var(--text-2); margin-top: 6px; }
.wf-node .out div { padding: 2px 0; }
.rule-row { display: flex; gap: 6px; align-items: flex-start; padding: 8px; background: var(--surface-2); border-radius: var(--radius-sm); margin-bottom: 6px; flex-wrap: wrap; }
.rule-row > select { width: 220px; }
.rule-row input, .rule-row select { height: 30px; font-size: 13px; }
.rule-row .cfg { display: flex; gap: 6px; flex: 1; min-width: 200px; flex-wrap: wrap; }
.rule-row .cfg > * { flex: 1; min-width: 120px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- charts ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.bar-row { display: grid; grid-template-columns: 130px 1fr 40px; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.bar-row .track { height: 10px; background: var(--surface-3); border-radius: 5px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 5px; background: var(--primary); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .issue { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .search-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .project-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; display: flex; gap: 4px; overflow-x: auto; white-space: nowrap; }
  .side .proj, .side .sep { display: none; }
  .page { padding: 16px; }
  .board-wrap { padding: 16px; }
  .hide-sm { display: none !important; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .topbar { padding: 0 8px; }
  .brand span { display: none; }
  .notif { width: min(360px, calc(100vw - 24px)); }
  .col { flex-basis: 250px; }
}
