/* Meros Project Tracker — dark-first. The full palette lives on bare :root so it
   holds regardless of any theme attribute; every colour below comes from a token. */
:root {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #141a2e;
  --surface-2: #1b2340;
  --border: #2a3354;
  --text: #e6e9f2;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --accent-strong: #2f5fe0;   /* button ground: white text = 5.6:1 */
  --accent-2: #a78bfa;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --danger: #ff6b6b;
  --overlay: rgba(4, 7, 16, 0.72);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
a { color: var(--accent); }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.state:empty { display: none; }
.state { padding: 18px 0; }
.state.error { color: var(--danger); }

.logo {
  font-weight: 800; letter-spacing: -.3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--accent);
}

/* ── Form controls ─────────────────────────────────────────── */
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px rgba(91,140,255,.25); }
textarea { resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
h3 label { display: inline; margin: 0; font-size: inherit; }
.field-error { color: var(--danger); font-size: 12px; margin: 4px 0 0; min-height: 0; }
.field-error:empty { display: none; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--text); background: var(--surface-2);
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-icon { padding: 4px 10px; }
.btn-block { width: 100%; margin-top: 18px; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.row-end { justify-content: flex-end; margin-top: 18px; }

/* ── Banner ────────────────────────────────────────────────── */
.banner {
  background: var(--danger); color: var(--bg); font-weight: 700;
  padding: 10px var(--gutter); text-align: center;
}
.banner a { color: var(--bg); text-decoration: underline; }

/* ── Top bar ───────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter); background: var(--surface);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
  position: sticky; top: 0; z-index: 5;
}
.brand { font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 12px; cursor: pointer;
}
.pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.pill[data-state="ok"] .pill-dot { background: var(--ok); }
.pill[data-state="partial"] .pill-dot, .pill[data-state="running"] .pill-dot { background: var(--warn); }
.pill[data-state="error"] .pill-dot { background: var(--danger); }
.user-menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px;
}
.menu-meta { color: var(--muted); font-size: 12px; padding: 6px 10px; overflow-wrap: anywhere; }
.menu-item { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); text-decoration: none; }

/* ── Sweep panel ───────────────────────────────────────────── */
.sweep-panel { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px var(--gutter) 18px; }
.sweep-panel h2 { margin: 10px 0 8px; }
.sweep-panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sweep-panel-head p { margin: 0; }
.status-text { font-weight: 600; }
.status-text.ok { color: var(--ok); }
.status-text.blocked, .status-text.partial, .status-text.running { color: var(--warn); }
.status-text.error { color: var(--danger); }
.reason { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; margin-top: 2px; }
.runs-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.runs-list li { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; overflow-wrap: anywhere; }

/* ── Layout ────────────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: calc(100vh - 60px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px var(--gutter); overflow-y: auto; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.project-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.project-list li { min-width: 0; }
.project-btn {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: transparent; border: 0; border-radius: 8px; padding: 8px 10px;
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.project-btn:hover { background: var(--surface-2); }
.project-btn[aria-current="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.project-name { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; }
.project-title { display: block; overflow: hidden; text-overflow: ellipsis; }
.project-client { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 11px; color: var(--muted); }
.badge {
  flex: none; min-width: 24px; text-align: center; font-size: 12px; font-weight: 700;
  padding: 1px 8px; border-radius: 999px; background: var(--border); color: var(--text);
}
.badge.has-open { background: var(--accent-strong); color: #fff; }

.main { padding: 18px var(--gutter) 40px; min-width: 0; }
.main-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.main-head p { margin: 4px 0 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filters input[type="search"] { flex: 1 1 220px; width: auto; }
.filters select { flex: 0 0 auto; width: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.issues-table tbody tr { cursor: pointer; }
.issues-table tbody tr:hover { background: var(--surface); }
.issue-title-btn { background: none; border: 0; padding: 0; color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.issue-title-btn:hover { color: var(--accent); }
.issue-sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.issues-table select { width: auto; padding: 5px 8px; font-size: 13px; }
.sev { display: inline-flex; align-items: center; gap: 6px; text-transform: capitalize; }
.sev-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.sev-low .sev-dot { background: var(--ok); }
.sev-medium .sev-dot { background: var(--warn); }
.sev-high .sev-dot { background: var(--danger); }

/* ── Drawer + modals (native <dialog>) ─────────────────────── */
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); padding: 20px; box-shadow: var(--shadow); }
dialog::backdrop { background: var(--overlay); }
.modal { width: min(520px, calc(100vw - 2 * var(--gutter))); border-radius: var(--radius); }
.modal h2 { font-size: 17px; margin-bottom: 4px; }
.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh;
  width: min(620px, 100vw); max-width: 100vw; border-radius: 0; border-width: 0 0 0 1px; overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.drawer-head h2 { font-size: 18px; overflow-wrap: anywhere; }
#drawer-meta { margin: 6px 0 0; font-size: 12px; }
.evidence-list, .comments { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.evidence-list li { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; overflow-wrap: anywhere; }
.ev-head { font-size: 12px; color: var(--muted); }
.comments li { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.comments li.system { background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 13px; }
.comment-head { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { margin-top: 10px; }

/* ── Login ─────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; padding: var(--gutter); }
.login-card {
  width: 100%; max-width: 380px; padding: 36px 32px; border-radius: 20px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.login-card .logo { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.login-err {
  color: var(--danger); font-size: 13px; margin: 0 0 8px; padding: 8px 12px;
  border: 1px solid var(--danger); border-radius: 8px; background: rgba(255,107,107,.08);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); max-height: 40vh; }
}
@media (max-width: 600px) {
  .topbar { position: static; }
  .topbar-actions { width: 100%; }
  .pill { flex: 1 1 100%; justify-content: flex-start; }
  .main-head { flex-direction: column; }
  /* Issues table collapses to cards — no horizontal scroll on phones. */
  .issues-table thead { display: none; }
  .issues-table, .issues-table tbody, .issues-table tr, .issues-table td { display: block; width: 100%; }
  .issues-table tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 4px; }
  .issues-table td { border: 0; padding: 4px 10px; }
  .issues-table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; }
  .login-card { padding: 28px 20px; }
}

/* ── Backlog schema: keys, priority/type chips, fields grid, members, activity ── */
.mono, .key-chip { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.key-chip {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); white-space: nowrap;
}
.key-chip:empty { display: none; }
.prio {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.prio-P0 { background: var(--danger); border-color: var(--danger); color: var(--bg); }
.prio-P1 { border-color: var(--warn); color: var(--warn); }
.prio-P2 { border-color: var(--accent); color: var(--accent); }
.prio-P3 { color: var(--muted); }
.type-tag {
  display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); border-left: 3px solid var(--border); padding-left: 6px; margin-right: 6px;
}
.type-bug { border-left-color: var(--danger); }
.type-risk { border-left-color: var(--warn); }
.type-decision, .type-question { border-left-color: var(--accent-2); }
.type-task, .type-request { border-left-color: var(--accent); }
.sev-critical .sev-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(255,107,107,.3); }
.fields-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0 12px; margin-top: 6px; }
.fields-grid label { margin-top: 10px; }
.resolve-prompt { margin-top: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.resolve-prompt label { margin-top: 0; }
.resolve-prompt select { width: auto; }
.member-chips { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.member-chips:empty { display: none; }
.member-chips li { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.member-chips li.role-owner { border-color: var(--accent); }
.project-key { margin-right: 6px; font-size: 11px; padding: 0 5px; }
.project-counts { display: block; font-size: 11px; color: var(--muted); }
.activity { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 2px solid var(--border); display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.activity li { overflow-wrap: anywhere; }
