:root {
  --bg: #f5f6fa;
  --bg-glow: radial-gradient(1200px 600px at 8% -10%, rgba(230, 0, 35, 0.07), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --sidebar: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --border: #e5e9f0;
  --border-strong: #cbd5e1;
  --accent: #e60023;
  --accent-strong: #c3001e;
  --accent-soft: #fee2e6;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #ffedd5;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 258px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --bg-glow: radial-gradient(1100px 600px at 10% -10%, rgba(230, 0, 35, 0.18), transparent 65%);
  --surface: #111827;
  --surface-2: #0f172a;
  --sidebar: #0d1424;
  --text: #e8edf6;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --border: #1f2a3d;
  --border-strong: #334155;
  --accent: #ff3b57;
  --accent-strong: #ff5771;
  --accent-soft: rgba(255, 59, 87, 0.14);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    var(--bg-glow),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

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

button, input { font: inherit; color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 16px 16px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 14px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  box-shadow: 0 8px 18px rgba(230, 0, 35, 0.28);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14.5px; letter-spacing: -0.2px; }
.brand-text small { color: var(--muted); font-size: 11.5px; margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 18px; overflow-y: auto; padding-bottom: 8px; }
.nav-group { display: flex; flex-direction: column; gap: 3px; }

.nav-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 0 10px 6px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 12px 10px 2px;
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  font-size: 11.5px;
}

.sidebar-foot .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--border-strong); }
.version { font-variant-numeric: tabular-nums; }

/* ---------------- Main / topbar ---------------- */

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 64px;
  padding: 0 26px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.menu-btn { display: none; }

.search {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  max-width: 460px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted-2);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.search input::placeholder { color: var(--muted-2); }

.search kbd {
  font-family: inherit;
  font-size: 10.5px;
  color: var(--muted-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  font-size: 12.5px;
  font-weight: 700;
}

[data-theme="dark"] .avatar { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); }

.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* ---------------- Content ---------------- */

.content {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 28px 26px 34px;
  flex: 1;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 10.5px;
  font-weight: 750;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--accent);
}

.page-head h1 {
  margin: 0 0 5px;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: -0.8px;
}

.page-sub { margin: 0; color: var(--muted); max-width: 620px; }

.page-actions { display: flex; gap: 9px; flex: none; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 8px 18px rgba(230, 0, 35, 0.24);
}

.btn-primary:hover { box-shadow: 0 10px 24px rgba(230, 0, 35, 0.32); }

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover { border-color: var(--border-strong); }

.btn-sm { height: 34px; padding: 0 12px; font-size: 12px; }

.btn-ok-ghost {
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 28%, transparent);
  color: var(--ok);
}

.btn-ok-ghost:hover {
  background: color-mix(in srgb, var(--ok) 18%, var(--surface));
  border-color: var(--ok);
}

.action-btn svg {
  width: 15px;
  height: 15px;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

/* ---------------- Cards / stats ---------------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.35fr);
  gap: 14px;
  margin-bottom: 14px;
}

.stat-card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stat-card {
  padding: 16px 17px 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.stat-value {
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.8px;
  font-variant-numeric: tabular-nums;
}

.stat-meta { color: var(--muted-2); font-size: 11.5px; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

.progress {
  height: 7px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  margin: 6px 0 2px;
}

.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: inherit;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel { padding: 17px 18px; min-width: 0; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head h2 { margin: 0 0 2px; font-size: 15px; letter-spacing: -0.2px; }
.panel-head p { margin: 0; color: var(--muted); font-size: 12px; }

.link { color: var(--accent); font-size: 12px; font-weight: 650; }
.link:hover { text-decoration: underline; }

/* ---------------- Empty states ---------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 7px;
  min-height: 210px;
  padding: 24px 18px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: var(--surface-2);
}

.empty.small { min-height: 150px; }

.empty-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 2px;
}

.empty h3 { margin: 0; font-size: 14px; }
.empty p { margin: 0 0 4px; max-width: 340px; color: var(--muted); font-size: 12.5px; }

/* ---------------- Metrics ---------------- */

.metric-list { display: flex; flex-direction: column; gap: 11px; margin-bottom: 14px; }

.metric {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.metric b { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

.meter { height: 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: inherit; opacity: 0.8; }

.hint {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
}

.hint strong { color: var(--text); font-size: 12px; }

/* ---------------- Footer ---------------- */

.footer {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 14px 26px 20px;
  color: var(--muted-2);
  font-size: 11.5px;
  border-top: 1px solid var(--border);
}

.footer strong { color: var(--muted); font-weight: 650; }
.footer-sep { opacity: 0.6; }

/* ---------------- Responsive ---------------- */

@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: translateX(0); }
  .menu-btn { display: grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 22px 16px 30px; }
  .status-pill { display: none; }
  .search kbd { display: none; }
}

@media (max-width: 640px) {
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .page-head h1 { font-size: 25px; }
  .stats-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar { gap: 8px; }
  .search { max-width: none; }
  .footer { flex-wrap: wrap; padding: 14px 16px 22px; }
  .empty { min-height: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------------- Forms ---------------- */

.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.limit-field { display: flex; flex-direction: column; gap: 7px; }
.limit-field input[disabled] { opacity: 0.6; }
.field > span { font-size: 12px; font-weight: 650; color: var(--text); }
.field small { color: var(--muted-2); font-size: 11.5px; }

.field input,
.field select,
.field textarea {
  width: 100%;
  height: 39px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input::placeholder { color: var(--muted-2); }

.checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--muted);
}

.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.form-note {
  margin: -6px 0 0;
  color: var(--muted-2);
  font-size: 11.5px;
  line-height: 1.45;
}

.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; }
.btn-block { width: 100%; }
.btn-danger-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
}
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }

/* ---------------- Alerts ---------------- */

.alert {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 13px;
  border-radius: 10px;
  font-size: 12.5px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}

.alert strong { font-size: 12.5px; }
.alert code { background: transparent; border: 0; padding: 0; font-size: 11.5px; }

.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 22%, transparent); }
.alert-warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 22%, transparent); }

/* ---------------- Tables ---------------- */

.table-wrap { overflow-x: auto; margin: -4px -4px 0; padding: 4px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.data-table th {
  text-align: left;
  padding: 9px 10px;
  color: var(--muted-2);
  font-size: 10.5px;
  font-weight: 750;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--surface-2); }

.cell-title { font-weight: 650; }
.cell-sub { color: var(--muted-2); font-size: 11.5px; }
.cell-error { color: var(--danger); font-size: 11.5px; margin-top: 3px; max-width: 260px; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 11.8px; }
.actions-col { width: auto; min-width: 320px; }
.row-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; min-width: 300px; }
.row-actions form { margin: 0; }
.row-actions .btn { white-space: nowrap; }

.chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: capitalize;
  white-space: nowrap;
}

.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------------- Job table actions ---------------- */

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-icon svg { width: 16px; height: 16px; }

.btn-icon:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.btn-icon:active:not(:disabled) { transform: translateY(1px); }
.btn-icon:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-icon-ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 28%, transparent);
}

.btn-icon-ok:hover:not(:disabled) {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 16%, var(--surface));
  border-color: var(--ok);
}

.btn-icon-danger { color: var(--danger); }

.btn-icon-danger:hover:not(:disabled) {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}

.row-actions-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
  flex: none;
}

.jobs-table .row-actions { gap: 5px; min-width: 0; }
.jobs-table .row-actions form { display: inline-flex; }
.jobs-table .actions-col { min-width: 0; }
.jobs-table tbody tr:nth-child(even) td { background: var(--surface-2); }
.jobs-table tbody tr:hover td { background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }

.narrow-panel { max-width: 760px; }
.hint-wide {
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 11px 14px;
  font-size: 12px;
}
.hint-wide strong { font-size: 12px; }

.logout-form { margin: 0; padding-top: 4px; }
.nav-button {
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--muted);
}
.nav-button:hover { background: var(--surface-2); color: var(--text); }

/* ---------------- Auth ---------------- */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.auth-shell { width: 100%; max-width: 420px; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px 26px 24px;
}

.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-brand strong { display: block; font-size: 14px; line-height: 1.2; }
.auth-brand small { color: var(--muted); font-size: 11.5px; }

.auth-card h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.6px; }
.auth-sub { margin: 0 0 18px; color: var(--muted); font-size: 12.5px; }
.auth-note { margin: 16px 0 0; color: var(--muted-2); font-size: 11.5px; text-align: center; }
.auth-foot { margin: 16px 0 0; text-align: center; color: var(--muted-2); font-size: 11px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
  .auth-card { padding: 22px 18px; }
}

/* ---------------- Jobs / submit / media ---------------- */

.segmented {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  width: fit-content;
}

.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.segmented label:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented input { accent-color: var(--accent); }

/* ---------------- Quality pickers ---------------- */

.quality-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.quality-panel {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.quality-panel legend {
  padding: 0 6px;
  margin-left: -4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.quality-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 8px;
}

.quality-option {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  min-height: 44px;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.quality-option:hover { border-color: var(--border-strong); }

.quality-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.quality-option::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  transform: translateY(-50%);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.quality-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.quality-option:has(input:checked)::before {
  border-color: var(--accent);
  background: var(--accent);
}

.quality-option:has(input:checked)::after {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translateY(-62%) rotate(45deg);
}

.quality-option strong {
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
  line-height: 1.25;
}

.quality-option small {
  font-size: 10.5px;
  color: var(--muted-2);
  line-height: 1.25;
}

.quality-wide { grid-column: 1 / -1; }

.quality-note {
  margin: 9px 0 0;
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1.45;
}

.quality-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--muted-2);
}

.quality-summary > span:first-child { font-weight: 700; }

@media (max-width: 760px) {
  .quality-panels { grid-template-columns: minmax(0, 1fr); }
}

.field textarea {
  height: auto;
  min-height: 140px;
  padding: 10px 12px;
  resize: vertical;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.source-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.job-count { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-thin { height: 5px; margin-top: 5px; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 13px;
}

.media-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.media-thumb {
  display: block;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
}

.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.media-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--muted-2);
}

.media-fallback svg { width: 30px; height: 30px; }

.media-body { padding: 10px 11px 11px; display: flex; flex-direction: column; gap: 3px; }
.media-id { font-family: Consolas, monospace; font-size: 10.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.media-meta { color: var(--muted-2); font-size: 11px; }
.media-select-wrap { display: flex; align-items: center; gap: 6px; color: var(--muted-2); font-size: 11px; }
.media-body form { margin-top: 4px; }
.media-status { width: fit-content; margin-top: 3px; }

.library-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.library-filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; flex: 1 1 460px; }
.library-filters .field { min-width: 170px; flex: 1 1 170px; }
.library-summary { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.library-bulkbar {
  position: sticky;
  top: 10px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.library-selected { color: var(--muted); font-size: 12px; margin-right: auto; }
.library-bulkbar .checkbox { margin: 0; }

.media-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.media-card {
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.media-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.media-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.media-check {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 4px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
}
.media-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.media-thumb { aspect-ratio: 4 / 5; position: relative; }
.media-count-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
}
.media-body { padding: 12px; gap: 7px; }
.media-head { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.media-title {
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.media-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.media-tag {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10.5px;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
a.media-tag:hover { border-color: var(--border-strong); color: var(--text); }
.media-desc {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.media-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted-2);
  font-size: 10.5px;
}
.media-footer form { margin: 0 0 0 auto; }
.media-meta.mono { font-size: 9.5px; overflow: hidden; text-overflow: ellipsis; }
.media-status { flex: 0 0 auto; margin-top: 0; }

@media (max-width: 640px) {
  .segmented { width: 100%; }
  .segmented label { flex: 1; justify-content: center; }
  .library-bar { padding: 12px; }
  .library-filters { flex: 1 1 100%; }
  .library-filters .field { min-width: 0; }
  .library-summary { justify-content: flex-start; }
  .library-bulkbar { top: 6px; gap: 8px; }
  .library-selected { margin-right: 0; }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .media-body { padding: 10px; }
}

/* Phase 2/3 additions */
.stats-grid.compact { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stats-grid.compact .stat-value { font-size: 22px; }
.panel-actions { justify-content: flex-start; margin-top: 12px; }
.status-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.status-list li { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.status-list strong { display: block; font-size: 12.5px; }
.status-list small { display: block; color: var(--muted); font-size: 11.5px; }
.status-dot { width: 9px; height: 9px; border-radius: 999px; background: var(--muted-2); box-shadow: 0 0 0 3px var(--border); flex: none; }
.status-dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.status-dot-danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { min-width: 160px; flex: 1 1 160px; }
.log-head { margin-top: 4px; }
.cell-context { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.detail-row td { padding-top: 0; }
.detail-row details { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 8px 11px; background: var(--surface-2); }
.detail-row summary { cursor: pointer; font-size: 11.5px; color: var(--muted); font-weight: 650; }
.detail-body { padding-top: 10px; }
.assistant-state { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.code-block { white-space: pre-wrap; word-break: break-word; line-height: 1.55; font-size: 11.5px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
form.search { margin: 0; }
