:root {
  /* Brand */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(99, 102, 241, .35);

  /* Surfaces */
  --bg: #f6f7fb;
  --bg-grad-1: #eef1fb;
  --bg-grad-2: #f6f7fb;
  --card: #ffffff;
  --border: #e6e8ef;
  --border-strong: #d3d7e2;

  /* Text */
  --text: #181c2a;
  --muted: #6b7280;
  --muted-soft: #9aa1ad;

  /* Status */
  --danger: #e23b3b;
  --danger-dark: #c42c2c;
  --green: #16a34a;
  --amber: #d97706;

  /* Sidebar/topbar dark */
  --top-bg: #161a2b;
  --top-text: #e7e9f3;
  --top-muted: #9aa0bd;
  --top-active: #2a3050;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 42, .06), 0 1px 3px rgba(20, 24, 42, .05);
  --shadow-md: 0 4px 14px rgba(20, 24, 42, .08);
  --shadow-lg: 0 18px 50px rgba(20, 24, 42, .22);
  --ease: cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(1200px 600px at 100% -10%, var(--bg-grad-1), transparent 60%),
                    radial-gradient(900px 500px at -10% 0%, #f0ecfb, transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

::selection { background: var(--primary-ring); }

/* ---- Top bar ---- */
#topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  background: var(--top-bg);
  color: var(--top-text);
  padding: 0 24px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-md);
}
.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand::before {
  content: "";
  width: 22px; height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, #818cf8, #6366f1 55%, #a855f7);
  box-shadow: 0 2px 8px rgba(99, 102, 241, .5);
}
#nav { display: flex; gap: 4px; flex: 1; }
#nav button {
  background: none; border: none; padding: 8px 14px; cursor: pointer;
  color: var(--top-muted); font-size: 14px; font-weight: 500; border-radius: var(--radius);
  transition: background .15s var(--ease), color .15s var(--ease);
}
#nav button:hover { background: rgba(255, 255, 255, .07); color: var(--top-text); }
#nav button.active { background: var(--top-active); color: #fff; font-weight: 600; }
.user-box { display: flex; align-items: center; gap: 14px; color: var(--top-muted); font-size: 13px; }
#who { color: var(--top-text); }

/* ---- Layout ---- */
main { max-width: 1120px; margin: 0 auto; padding: 32px 24px 60px; }
/* List/table pages use most of the screen width; forms stay narrow. */
main.wide { max-width: 1800px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.subtle { color: var(--muted); }

/* ---- Cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

/* ---- Buttons ---- */
.btn {
  background: var(--primary); color: #fff; border: none;
  padding: 9px 16px; border-radius: var(--radius); cursor: pointer;
  font-size: 14px; font-weight: 600; letter-spacing: .01em;
  transition: background .15s var(--ease), transform .05s var(--ease), box-shadow .15s var(--ease);
  box-shadow: 0 1px 2px rgba(79, 70, 229, .25);
}
.btn:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(79, 70, 229, .3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost {
  background: #fff; color: var(--text); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn.ghost:hover { background: #f7f8fb; border-color: var(--muted-soft); }
.btn.danger { background: var(--danger); box-shadow: 0 1px 2px rgba(226, 59, 59, .25); }
.btn.danger:hover { background: var(--danger-dark); box-shadow: 0 4px 12px rgba(226, 59, 59, .3); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ---- Tables ---- */
.card.table-card { padding: 4px 4px; overflow-x: auto; overflow-y: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-soft);
  font-weight: 700; background: #fafbfd;
}
tbody tr { transition: background .12s var(--ease); }
tbody tr:hover { background: #fafbff; }
tr:last-child td { border-bottom: none; }
td .row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
td.actions-cell { text-align: right; }
.check-cell { width: 28px; text-align: center; }
.check-cell input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }

/* ---- Task Detail dialog ---- */
.detail-table { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.detail-table th, .detail-table td { padding: 8px 12px; font-size: 13px; }
.detail-table > tbody > tr > th, .detail-table > tr > th { width: 150px; white-space: nowrap; vertical-align: top; }
.detail-table tbody tr:hover, .detail-table tr:hover { background: transparent; }
.detail-heading { margin: 18px 0 8px; font-size: 14px; }
.detail-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.detail-table.matched { border-color: #86b7fe; background: #f5f9ff; margin-bottom: 10px; }
.detail-table.matched > tbody > tr > th, .detail-table.matched > tr > th { color: #1d4ed8; }
.detail-table tbody tr.is-match, .detail-table tr.is-match { background: #eff6ff; }
/* A match found on an account the task is NOT assigned to — the case worth a second
   look, so it reads amber rather than blue. */
.detail-table.matched.foreign { border-color: #f0c36d; background: #fffaf0; }
.detail-table.matched.foreign > tbody > tr > th, .detail-table.matched.foreign > tr > th { color: #92400e; }
.warn-text { color: #92400e; background: #fffaf0; border: 1px solid #f0c36d; border-radius: 8px;
  padding: 8px 12px; margin: 0 0 10px; font-size: 13px; font-weight: 600; }
/* Snorkel task UIDs are long uuids: let them wrap instead of stretching the dialog,
   and stay selectable so an admin can copy one into Snorkel. */
.selectable { user-select: text; overflow-wrap: anywhere; }
.table-scroll { overflow-x: auto; }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ready { background: #eef1f6; color: #525a6b; }
.badge.submitted { background: #e0ecff; color: #1d4ed8; }
/* user-side split of 'submitted': first hand-off vs. back from a revision */
.badge.new { background: #e0ecff; color: #1d4ed8; }
.badge.resubmit { background: #f1e9ff; color: #7c3aed; }
.badge.revising { background: #fef1d7; color: #b45309; }
.badge.completed { background: #dcfce7; color: #15803d; }
.badge.accepted { background: #d1fae5; color: #047857; }
.badge.discard { background: #ede9e4; color: #6b5b4d; }
/* review-task statuses */
.badge.rv-requested { background: #fef1d7; color: #b45309; }
.badge.rv-ready { background: #dcfce7; color: #15803d; }
.badge.rv-error { background: #fde2e2; color: #c42c2c; }
.badge.role { background: #f1e9ff; color: #7c3aed; }
.badge.role::before { display: none; }
.badge.muted { background: #eef1f6; color: #6b7280; }
.badge.danger { background: #fde2e2; color: #c42c2c; }
.badge.warn { background: #fef1d7; color: #92400e; }

/* Submissions: totals chips + per-account status table. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .badge::before { display: none; }
tfoot td { border-top: 2px solid #e5e7eb; background: #fafbff; }
tr.row-muted { opacity: .55; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; margin: 14px 0 5px; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); font-size: 14px; font-family: inherit; background: #fff;
  color: var(--text);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
textarea { min-height: 90px; resize: vertical; }
.field-hint { color: var(--muted); font-size: 12px; margin-top: 5px; }

/* Inline assignee select inside tables */
td select { padding: 7px 10px; font-size: 13px; min-width: 150px; }

/* ---- Filter bar ---- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.seg {
  display: inline-flex; background: #fff; border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 3px; gap: 2px; box-shadow: var(--shadow-sm);
}
.seg button {
  border: none; background: none; padding: 6px 13px; border-radius: 7px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--muted);
  transition: background .12s var(--ease), color .12s var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--primary-soft); color: var(--primary-dark); }
.count-pill {
  display: inline-block; min-width: 20px; padding: 1px 7px; margin-left: 6px;
  border-radius: 999px; background: rgba(255,255,255,.25); font-size: 11px; font-weight: 700;
}
.seg button:not(.active) .count-pill { background: #eef1f6; color: var(--muted); }

/* ---- Pagination ---- */
.pager {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 4px 0 16px;
}
.pager-info { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---- Auth screens ---- */
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { width: 380px; box-shadow: var(--shadow-lg); border: none; padding: 30px 28px; }
.auth-card .brand-lg {
  display: flex; align-items: center; gap: 11px; font-size: 20px; font-weight: 700;
  letter-spacing: -.02em; margin-bottom: 18px;
}
.auth-card .brand-lg::before {
  content: ""; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #818cf8, #6366f1 55%, #a855f7);
  box-shadow: 0 4px 12px rgba(99, 102, 241, .45);
}
.auth-card h1 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.01em; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17, 20, 35, .5);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
  animation: fade .12s var(--ease);
}
.modal {
  background: #fff; border-radius: var(--radius-lg); width: 500px; max-width: 100%;
  max-height: 90vh; overflow: auto; padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: pop .16s var(--ease);
}
.modal h2 { margin-top: 0; font-size: 18px; letter-spacing: -.01em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1b1f30; color: #fff; padding: 12px 20px; border-radius: var(--radius);
  z-index: 100; box-shadow: var(--shadow-lg); font-weight: 500;
  animation: toastIn .2s var(--ease);
}
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

.empty { text-align: center; color: var(--muted); padding: 44px 30px; }
.empty-icon { font-size: 30px; opacity: .4; margin-bottom: 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: #4b5160; }
.err-text { color: var(--danger); margin-top: 10px; font-size: 13px; min-height: 18px; }

.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--primary); text-decoration: underline dotted;
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: inline-block; vertical-align: bottom;
}
.link-btn:hover { color: var(--primary-strong, var(--primary)); }

/* ---- Submit dialog: scratch-folder file picker ---- */
.file-picker {
  max-height: 320px; overflow-y: auto; margin-top: 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff;
}
.file-pick {
  display: flex; align-items: center; gap: 10px; margin: 0;
  padding: 9px 12px; font-weight: 400; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.file-pick:last-child { border-bottom: none; }
.file-pick:hover { background: var(--primary-ring); }
.file-pick input[type="checkbox"] { width: auto; margin: 0; flex: none; }
.file-pick .mono { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.file-pick .subtle { font-size: 12px; white-space: nowrap; }

/* ---- Clickable table rows (e.g. project list) ---- */
tr.clickable-row { cursor: pointer; transition: background .12s var(--ease); }
tr.clickable-row:hover { background: var(--primary-soft); }

/* ---- Multi-select filter dropdown ---- */
.task-search {
  width: 220px; padding: 8px 12px; font-size: 13px;
  background: #fff; border: 1px solid var(--border-strong); border-radius: var(--radius);
  color: var(--text);
}
.task-search:focus { outline: none; border-color: var(--primary); }

.ms { position: relative; display: inline-block; }
.ms-btn {
  width: auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; font-size: 13px; font-weight: 500; cursor: pointer;
  background: #fff; border: 1px solid var(--border-strong); border-radius: var(--radius);
  color: var(--text);
}
.ms-btn:hover { border-color: var(--primary); }
.ms-btn strong { font-weight: 600; }
.ms-caret { color: var(--muted); font-size: 11px; }
.ms-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  min-width: 220px; max-height: 300px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px;
}
.ms-opt {
  display: flex; align-items: center; gap: 9px; margin: 0;
  padding: 8px 9px; font-weight: 400; font-size: 13px; cursor: pointer; border-radius: 7px;
}
.ms-opt:hover { background: var(--primary-soft); }
.ms-opt input[type="checkbox"] { width: auto; margin: 0; flex: none; }
.ms-opt-label { flex: 1; }
.ms-opt .count-pill { background: #eef1f6; color: var(--muted); margin-left: 0; }

/* --- Claude run modal: live activity feed + result ----------------------- */
.run-meta { color: var(--muted); font-size: 12px; line-height: 1.5; margin-bottom: 10px; }
.run-meta .run-running { color: var(--amber); }
.run-meta .run-done    { color: var(--green); }
.run-meta .run-error,
.run-meta .run-stopped { color: var(--danger); }

.run-final {
  background: var(--primary-soft); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
  font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.run-final-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.run-final-err { background: #fdecec; color: var(--danger-dark); }

.run-log-head { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.run-log {
  max-height: 320px; overflow-y: auto;
  background: #11141f; color: #d7dbe8; border-radius: var(--radius);
  padding: 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.55;
}
.log-line { padding: 1px 0; white-space: pre-wrap; word-break: break-word; }
.log-kind {
  display: inline-block; min-width: 64px; margin-right: 8px;
  color: #6b7280; text-transform: uppercase; font-size: 10px;
}
.log-assistant { color: #e7e9f3; }
.log-tool      { color: #7dd3fc; }
.log-system    { color: #9aa0bd; }
.log-stderr    { color: #fca5a5; }

/* run-status badges on the Sessions list */
.badge.run-running { background: #fef1d7; color: #b45309; }
.badge.run-done    { background: #dcfce7; color: #15803d; }
.badge.run-error   { background: #fde2e2; color: #c42c2c; }
.badge.run-stopped { background: #eef1f6; color: #525a6b; }
.small-mono { font-size: 11px; color: var(--muted); word-break: break-all; }

/* A running session with a long idle stretch — likely stuck. Draw the eye. */
.idle-stuck { color: #c42c2c; font-weight: 600; }

/* queued = waiting for the host runner to claim it */
.badge.run-queued { background: #e0ecff; color: #1d4ed8; }
.run-meta .run-queued { color: #1d4ed8; }

/* which session-pool cap a run counts against (Sessions page) */
.badge.pool-create   { background: #e0ecff; color: #1d4ed8; }
.badge.pool-revision { background: #f1e9ff; color: #7c3aed; }

/* Create/revision pool occupancy strip atop the Sessions list */
.pool-strip { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
.pool-stat { display: flex; flex-direction: column; gap: 2px; }
.pool-stat .pool-stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.pool-stat .pool-stat-value { font-size: 15px; font-weight: 600; }
.pool-stat .pool-stat-value.at-cap { color: #b45309; }

/* Wide variant for the session-log modal (run popup) — more room for activity */
.modal.modal-wide { width: min(1100px, 96vw); }
.modal.modal-wide .run-log { max-height: 56vh; }
.modal.modal-wide .run-final { max-height: 22vh; overflow: auto; }

/* short run id shown next to the session label */
.run-id { color: var(--muted-soft); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

/* ---- Step-by-step progress modal (Download & Copy) ---- */
.step-list { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 6px; }
.step-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 13.5px;
  color: var(--muted);
}
.step-row .step-icon { width: 18px; text-align: center; flex: none; }
.step-row .step-note { margin-left: auto; font-size: 12px; }
.step-row.step-active { border-color: var(--amber); color: var(--text); }
.step-row.step-active .step-icon { color: var(--amber); animation: stepPulse 1s ease-in-out infinite; }
.step-row.step-done { border-color: var(--green); color: var(--text); }
.step-row.step-done .step-icon { color: var(--green); }
.step-row.step-done .step-note { color: var(--muted); }
.step-row.step-error { border-color: var(--danger); color: var(--danger-dark); background: #fdecec; }
.step-row.step-error .step-icon { color: var(--danger); }
.step-row.step-error .step-note { color: var(--danger-dark); font-weight: 500; }
@keyframes stepPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---- Progress bar (upload/download) ---- */
.progress-wrap { margin: 14px 0 4px; }
.progress-label {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.progress-label [data-progress-pct] { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.progress-track {
  height: 8px; border-radius: 999px; background: var(--border); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; border-radius: inherit;
  background: var(--primary); transition: width .15s var(--ease);
}
.progress-fill.indeterminate {
  width: 30%; animation: progressSlide 1.1s ease-in-out infinite;
}
@keyframes progressSlide {
  0% { margin-left: -30%; }
  100% { margin-left: 100%; }
}
