/* ============================================================
   VERSE v2 design system — Stripe-style scientific dashboard.
   Light by default, dark via [data-theme="dark"] on <html>.
   Single accent (indigo), soft shadows, monospace for numerics.
   ============================================================ */

:root,
[data-theme="light"] {
  --bg:        #f7f8fa;
  --panel:     #ffffff;
  --panel-2:   #fbfbfd;
  --border:    #e6e8eb;
  --border-2:  #eef0f3;

  --text:      #1a1f36;
  --text-2:    #4f566b;
  --text-dim:  #8792a2;

  --primary:    #635bff;
  --primary-50: #f0f0ff;
  --primary-700:#4b46d4;

  --ok:        #1ea672;
  --ok-bg:     #e3f9ef;
  --warn:      #b86b00;
  --warn-bg:   #fff5d4;
  --error:     #cd3500;
  --error-bg:  #ffe9e3;

  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(20,30,60,.06);
  --shadow-lg: 0 8px 24px rgba(20,30,60,.10);
  --radius:    10px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --bg:        #0e1018;
  --panel:     #161922;
  --panel-2:   #1a1e29;
  --border:    #2a2f3d;
  --border-2:  #21253033;

  --text:      #e6e8eb;
  --text-2:    #a4a8b3;
  --text-dim:  #6e7280;

  --primary:    #7c75ff;
  --primary-50: #1e1b3a;
  --primary-700:#9c95ff;

  --ok:        #4ade80;
  --ok-bg:     #0f2e22;
  --warn:      #fbbf24;
  --warn-bg:   #2e2510;
  --error:     #f87171;
  --error-bg:  #3a1f1c;

  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font: 14px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.mono, code, pre, .num, .id { font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   App shell — sidebar + main column
   ============================================================ */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 22px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border-2);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  display: grid; place-items: center; color: #fff; font-weight: 700;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(99,91,255,.35);
  flex-shrink: 0;
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; color: var(--text); }
.brand-sub  { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

.nav-section {
  font-size: 11px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .06em; padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text-2);
  font-weight: 500; cursor: pointer; user-select: none;
  font-size: 13px; text-decoration: none;
  border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-50); color: var(--primary-700); }
.nav-item .nav-count { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.nav-item .proj-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.nav-icon { width: 16px; height: 16px; opacity: .9; flex-shrink: 0; }

.sidebar-foot {
  margin-top: auto; padding: 12px 10px;
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid var(--border-2);
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #ffd29c, #ff8c5b);
  display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}
.avatar-name { font-size: 13px; font-weight: 500; color: var(--text); }
.avatar-sub  { font-size: 11px; color: var(--text-dim); }

/* ============================================================
   Main column
   ============================================================ */
.main { padding: 28px 40px; max-width: 1280px; }

.pageheader {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 24px; gap: 20px; flex-wrap: wrap;
}
.h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--text); }
.h1-sub { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  cursor: pointer; box-shadow: var(--shadow);
  font-family: inherit; transition: background .12s, border-color .12s;
  text-decoration: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(99,91,255,.4);
}
.btn-primary:hover { background: var(--primary-700); border-color: var(--primary-700); color: #fff; }
.btn-ghost { box-shadow: none; border-color: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-icon { padding: 6px; width: 32px; height: 32px; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ============================================================
   Stat cards
   ============================================================ */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.stat-num { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -0.01em; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.stat-sub.up { color: var(--ok); }
.stat-sub.down { color: var(--error); }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .app   { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main  { padding: 18px 16px; }
}

/* ============================================================
   Two-column layout
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* ============================================================
   Panel / card
   ============================================================ */
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.panel-h {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border-2);
  gap: 8px;
}
.panel-title { font-size: 14px; font-weight: 600; color: var(--text); }
.panel-body { padding: 14px 18px; }

/* ============================================================
   Project cards
   ============================================================ */
.proj-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 18px; }
.proj-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 14px;
  background: var(--panel); cursor: pointer; transition: box-shadow .12s, transform .12s;
  text-decoration: none; color: inherit; display: block;
}
.proj-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); text-decoration: none; }
.proj-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.proj-name { font-weight: 600; font-size: 14px; color: var(--text); }
.proj-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.proj-card.empty {
  border-style: dashed; background: transparent; box-shadow: none;
  display: grid; place-items: center; color: var(--text-dim);
  text-align: center; min-height: 90px;
}
.proj-card.empty:hover { border-color: var(--primary); color: var(--primary-700); transform: none; }

/* ============================================================
   Job table
   ============================================================ */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 11px 18px; text-align: left; font-size: 13px; }
.tbl th {
  font-weight: 500; color: var(--text-dim); text-transform: uppercase;
  font-size: 11px; letter-spacing: .04em; border-bottom: 1px solid var(--border-2);
  background: var(--panel-2);
}
.tbl td { border-bottom: 1px solid var(--border-2); color: var(--text); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--bg); }
.tbl td.id, .tbl td.num { font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--text-2); }
.tbl-empty {
  padding: 28px; text-align: center; color: var(--text-dim); font-size: 13px;
}

/* ============================================================
   Pills
   ============================================================ */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .03em;
  border: 1px solid transparent;
}
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-done    { background: var(--ok-bg);   color: var(--ok); }
.pill-running { background: var(--primary-50); color: var(--primary-700); }
.pill-queued  { background: var(--warn-bg); color: var(--warn); }
.pill-failed,
.pill-timed_out { background: var(--error-bg); color: var(--error); }
.pill-muted   { background: var(--panel-2); color: var(--text-dim); border-color: var(--border); }

/* ============================================================
   Form
   ============================================================ */
.form-field { display: block; margin-bottom: 12px; }
.form-label {
  font-size: 12px; color: var(--text-2); font-weight: 500;
  margin-bottom: 5px; display: block;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--text); font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50);
}
.form-textarea { min-height: 110px; font-family: "JetBrains Mono", monospace;
  font-size: 12px; resize: vertical; }

/* The HTML `hidden` attribute is supposed to set display:none, but our
 * .btn rule sets display:inline-flex which has higher specificity than
 * the user-agent default for [hidden]. Force [hidden] to actually hide. */
[hidden] { display: none !important; }

/* File-drop zone. Contains a hidden <input type="file"> + label text only.
 * The "clear" button lives outside the label (see .file-drop-wrap) so we
 * don't get nested-interactive-element focus weirdness. */
.file-drop-wrap { display: flex; flex-direction: column; gap: 8px; }

.file-drop {
  border: 1.5px dashed var(--border); border-radius: 8px; padding: 18px;
  text-align: center; color: var(--text-dim); cursor: pointer;
  transition: border-color .12s, background .12s, color .12s, box-shadow .12s;
  display: block; margin: 0;
}
.file-drop:hover { border-color: var(--primary); background: var(--primary-50); color: var(--primary-700); }
.file-drop.has-file { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }

/* Kill ALL default keyboard-focus indicators on every child of the drop
 * zone. They were stacking dashed-line fragments around each text run.
 * Focus is shown once, on the wrapper itself, via :focus-within. */
.file-drop, .file-drop * { outline: none !important; -webkit-tap-highlight-color: transparent; }
.file-drop:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-50);
}

.file-drop-reset {
  font-size: 12px; padding: 4px 10px; height: auto;
  align-self: center;
}

/* Make the drop-zone prompt match the "browse" link color. The size hint
 * below it stays muted because it has class="small muted". */
.file-drop-label { color: var(--primary); font-weight: 500; }
.file-drop:hover .file-drop-label { color: var(--primary-700); }

.divider {
  text-align: center; color: var(--text-dim); font-size: 12px;
  position: relative; margin: 8px 0;
}
.divider::before, .divider::after {
  content: ""; position: absolute; top: 50%; width: 42%;
  border-top: 1px solid var(--border);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }
.divider span { background: var(--panel); padding: 0 8px; }

/* Inline error display */
.field-error {
  color: var(--error); font-size: 12px; margin-top: 4px; min-height: 1em;
}

/* ============================================================
   Topbar (used on pages without the sidebar layout, e.g. /share)
   Compatible with the current base.html as we transition.
   ============================================================ */
.topbar-v2 {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.theme-toggle {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); width: 30px; height: 30px;
  cursor: pointer; display: grid; place-items: center;
  transition: background .12s, border-color .12s;
}
.theme-toggle:hover { background: var(--bg); }

/* ============================================================
   Toast / inline notice
   ============================================================ */
.notice {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 14px;
  border: 1px solid transparent;
}
.notice-error { background: var(--error-bg); color: var(--error); border-color: var(--error); }
.notice-ok    { background: var(--ok-bg);    color: var(--ok);    border-color: var(--ok); }
.notice-warn  { background: var(--warn-bg);  color: var(--warn);  border-color: var(--warn); }

/* ============================================================
   Loading spinner (used by HTMX swaps)
   ============================================================ */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* HTMX request indicator: show .htmx-indicator only during requests */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

/* ============================================================
   Utility helpers
   ============================================================ */
.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.flex  { display: flex; align-items: center; gap: 8px; }
.flex-end { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.no-margin { margin: 0; }
