:root {
  --bg:         #0a0a0f;
  --surface:    #12131a;
  --surface-2:  #1a1b25;
  --border:     #1e1f2e;
  --fg:         #e8e9f0;
  --muted:      #6b6e88;
  --accent:     #4ade80;
  --blue:       #60a5fa;
  --red:        #f87171;
  --orange:     #fb923c;
  --sidebar-w:  200px;
  font-size: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.03em;
}
.sidebar-logo .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.sidebar-logo .sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--muted);
  transition: background 0.1s, color 0.1s;
}
.nav-link:hover { color: var(--fg); background: var(--surface-2); }
.nav-link.active { color: var(--blue); background: rgba(96,165,250,0.08); }
.nav-link svg { width: 15px; height: 15px; flex-shrink: 0; }

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-footer a { color: var(--muted); transition: color 0.1s; }
.sidebar-footer a:hover { color: var(--red); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── Page header ── */
.page-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-header h1 { font-size: 14px; font-weight: 600; }

.page-body { padding: 24px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 16px;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid;
}
.badge-green  { background: rgba(74,222,128,0.1);  color: var(--accent);  border-color: rgba(74,222,128,0.25); }
.badge-blue   { background: rgba(96,165,250,0.1);  color: var(--blue);   border-color: rgba(96,165,250,0.25); }
.badge-red    { background: rgba(248,113,113,0.1); color: var(--red);    border-color: rgba(248,113,113,0.25); }
.badge-orange { background: rgba(251,146,60,0.1);  color: var(--orange); border-color: rgba(251,146,60,0.25); }
.badge-muted  { background: var(--surface-2);      color: var(--muted);  border-color: var(--border); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #000; border-color: var(--blue); }
.btn-primary:hover { background: #93c5fd; border-color: #93c5fd; }
.btn-approve { background: rgba(74,222,128,0.1); color: var(--accent); border-color: rgba(74,222,128,0.3); }
.btn-approve:hover { background: rgba(74,222,128,0.2); }
.btn-danger { background: rgba(248,113,113,0.1); color: var(--red); border-color: rgba(248,113,113,0.3); }
.btn-danger:hover { background: rgba(248,113,113,0.2); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

/* ── Forms ── */
.form-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; color: var(--muted); }

input[type="text"],
input[type="password"],
input[type="search"],
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.1s;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
input::placeholder, textarea::placeholder { color: var(--muted); }
select option { background: var(--surface-2); }
textarea { resize: vertical; }

/* ── Tabs ── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 7px 14px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.1s, border-color 0.1s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--blue); }

/* ── Table ── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* ── Dossier markdown ── */
.narrative { line-height: 1.65; font-size: 13px; }
.narrative h1 { font-size: 16px; margin: 20px 0 8px; color: var(--fg); }
.narrative h2 { font-size: 14px; margin: 16px 0 6px; color: var(--fg); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.narrative h3 { font-size: 13px; margin: 12px 0 4px; color: var(--blue); }
.narrative p  { margin: 6px 0; color: var(--fg); }
.narrative ul, .narrative ol { margin: 6px 0 6px 20px; }
.narrative li { margin: 3px 0; }
.narrative strong { color: #fff; }
.narrative code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; font-size: 11px; }
.narrative pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 12px; overflow-x: auto; margin: 8px 0; }
.narrative table { margin: 8px 0; }

/* ── Merge review ── */
.merge-cards { display: flex; gap: 16px; }
.merge-cards .card { flex: 1; }
.merge-sep {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-family: monospace;
  font-size: 12px;
  flex-shrink: 0;
}
.merge-sep .line { width: 1px; height: 28px; background: var(--border); }
.merge-actions { display: flex; gap: 10px; margin-top: 4px; }
.merge-actions .btn { flex: 1; justify-content: center; }
.source-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.source-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1px solid;
}
.source-tag.on  { background: rgba(96,165,250,0.1); color: var(--blue);  border-color: rgba(96,165,250,0.25); }
.source-tag.off { background: var(--surface-2);     color: var(--muted); border-color: var(--border); }

/* ── Progress bar ── */
.progress-bar { height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.progress-fill { height: 100%; background: var(--blue); transition: width 0.3s; }

/* ── Alerts ── */
.alert { padding: 10px 14px; border-radius: 5px; font-size: 13px; border: 1px solid; }
.alert-error { background: rgba(248,113,113,0.08); color: var(--red); border-color: rgba(248,113,113,0.25); }
.alert-info  { background: rgba(96,165,250,0.08); color: var(--blue); border-color: rgba(96,165,250,0.25); }

/* ── Spinner ── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator  { display: inline-flex; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.7s linear infinite; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 340px; }
.login-logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 28px; }
.login-logo .brand { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; }

/* ── Misc ── */
.mono { font-family: ui-monospace, monospace; font-size: 11px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.w-full { width: 100%; }

/* ── Mobile top bar (hidden on desktop) ── */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 110;
}
.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--fg);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.menu-btn:hover { background: var(--surface-2); }

/* Nav backdrop (mobile) */
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
}

/* ── Responsive breakpoint ── */
@media (max-width: 768px) {
  .topbar  { display: flex; }
  .menu-btn { display: flex; }

  /* Push layout below topbar */
  .layout { margin-top: 48px; }

  /* Sidebar becomes a slide-in overlay */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: 220px;
    height: 100dvh;
  }
  body.nav-open .sidebar     { transform: translateX(0); }
  body.nav-open .nav-backdrop { display: block; }

  /* Content fills full width */
  .content { width: 100%; }

  /* Tighter page padding */
  .page-body   { padding: 14px; }
  .page-header { padding: 10px 14px; }

  /* Tabs: scroll horizontally, no wrap */
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab  { white-space: nowrap; flex-shrink: 0; }

  /* Form rows: stack on narrow screens */
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row .field { width: 100%; }
  .form-row .field input[type="text"],
  .form-row .field select { width: 100%; }
  .form-row .btn { width: 100%; justify-content: center; }

  /* Merge cards: stack vertically */
  .merge-cards { flex-direction: column; }
  .merge-sep   { flex-direction: row; padding: 4px 0; }
  .merge-sep .line { width: 40px; height: 1px; }
  .merge-actions { flex-wrap: wrap; }

  /* Narrative readable on small screens */
  .narrative { font-size: 14px; }
}
