:root {
  --bg: #0b1020;
  --bg-soft: #111936;
  --panel: #151d3b;
  --panel-2: #1b2547;
  --border: #29335c;
  --text: #e8ecf8;
  --muted: #8e9ac2;
  --accent: #4f7cff;
  --accent-2: #7c5cff;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --cyan: #22d3ee;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(79,124,255,.28), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(124,92,255,.22), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 34px 30px 28px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }

.brand-mark {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px; letter-spacing: -.5px;
}

.brand-title { font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.field { margin-bottom: 15px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.field input, .inp, select, textarea {
  width: 100%;
  background: #0d1330;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus, .inp:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,124,255,.18);
}

textarea { resize: vertical; min-height: 70px; font-family: var(--mono); font-size: 12.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: 0; border-radius: 10px;
  padding: 11px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: filter .15s, transform .05s, opacity .15s;
}

.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn.block { width: 100%; margin-top: 6px; }

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.ghost:hover { background: var(--panel-2); }

.btn.danger { background: linear-gradient(135deg, #e25555, #b91c1c); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }

.alert {
  display: none;
  padding: 10px 13px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}

.alert.show { display: block; }
.alert.error { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.4); color: #fca5a5; }
.alert.warn  { background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.4); color: #fcd34d; }
.alert.ok    { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.4); color: #86efac; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.tiny { font-size: 11.5px; }

.login-foot {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.shell { min-height: 100vh; background: var(--bg); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 22px;
  background: rgba(11,16,32,.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar .brand { margin: 0; gap: 10px; }
.topbar .brand-mark { width: 34px; height: 34px; font-size: 14px; border-radius: 10px; }
.topbar .brand-title { font-size: 14px; }
.topbar .brand-sub { font-size: 11px; }

.nav { display: flex; gap: 4px; margin-left: 18px; flex-wrap: wrap; }

.nav button {
  background: transparent; border: 0; color: var(--muted);
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  transition: background .15s, color .15s;
}

.nav button:hover { background: var(--panel); color: var(--text); }
.nav button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

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

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
}

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }

/* ---------- layout ---------- */
.page { padding: 22px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 700; letter-spacing: -.3px; margin: 0; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}

.card + .card { margin-top: 16px; }
.card-title { font-size: 14px; font-weight: 700; margin: 0 0 3px; letter-spacing: -.1px; }
.card-sub { font-size: 12px; color: var(--muted); margin-bottom: 14px; }

.grid { display: grid; gap: 14px; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* ---------- KPI ---------- */
.kpi-card { position: relative; overflow: hidden; }
.kpi-card::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.kpi-card.green::after { background: linear-gradient(180deg, #34d399, #059669); }
.kpi-card.amber::after { background: linear-gradient(180deg, #fbbf24, #d97706); }
.kpi-card.cyan::after  { background: linear-gradient(180deg, #22d3ee, #0891b2); }

.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.7px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-value.sm { font-size: 21px; }
.kpi-foot { font-size: 11.5px; color: var(--muted); margin-top: 5px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left; padding: 9px 10px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td { padding: 10px; border-bottom: 1px solid rgba(41,51,92,.55); vertical-align: middle; }
tbody tr:hover { background: rgba(41,51,92,.28); }
tbody tr:last-child td { border-bottom: 0; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }

.table-wrap { overflow-x: auto; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}

.badge.ok { background: rgba(34,197,94,.14); color: #86efac; border-color: rgba(34,197,94,.35); }
.badge.warn { background: rgba(245,158,11,.14); color: #fcd34d; border-color: rgba(245,158,11,.35); }
.badge.err { background: rgba(239,68,68,.14); color: #fca5a5; border-color: rgba(239,68,68,.35); }
.badge.info { background: rgba(34,211,238,.14); color: #67e8f9; border-color: rgba(34,211,238,.35); }
.badge.purple { background: rgba(124,92,255,.16); color: #c4b5fd; border-color: rgba(124,92,255,.36); }

/* ---------- chart ---------- */
.chart-box { position: relative; height: 240px; width: 100%; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; }

.bars { display: flex; flex-direction: column; gap: 9px; }

.bar-row { display: grid; grid-template-columns: 132px 1fr 92px; gap: 12px; align-items: center; font-size: 12.5px; }
.bar-label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: rgba(41,51,92,.55); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .35s ease; }
.bar-val { text-align: right; font-family: var(--mono); font-size: 12px; }

/* ---------- forms ---------- */
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.help { font-size: 11.5px; color: var(--muted); margin-top: 5px; }

/* A switch is a <label class="switch">. The generic ".form-group label"
   rule sets display:block + margin-bottom, which wins on specificity (0,2,0
   vs 0,1,0) and breaks the switch into stacked block boxes - the track ends
   up on its own line and the caption is pushed below it. Re-assert the flex
   layout explicitly, scoped to .form-group so it outranks that rule. */
.form-group .switch,
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.form-group .switch { margin-bottom: 0; }
.switch input { display: none; }
.switch-track {
  width: 40px; height: 22px; border-radius: 999px;
  background: rgba(41,51,92,.9); border: 1px solid var(--border);
  position: relative; transition: background .18s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted); transition: transform .18s, background .18s;
}
.switch > span:last-child { color: var(--text); font-size: 13px; font-weight: 500; }
.switch input:checked + .switch-track { background: rgba(79,124,255,.55); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: #fff; }

.tag-input { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 8px; font-size: 11.5px; font-family: var(--mono);
}
.tag button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; padding: 0; }
.tag button:hover { color: var(--red); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 7, 18, .78);
  display: none; padding: 24px;
  overflow-y: auto;
}
.modal-backdrop.show { display: block; }

.modal {
  max-width: 760px; margin: 24px auto;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}

.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--border);
  position: sticky; bottom: 0; background: var(--bg-soft);
  border-radius: 0 0 16px 16px;
}

/* ---------- misc ---------- */
.empty { padding: 34px 18px; text-align: center; color: var(--muted); font-size: 13px; }

.toast-host {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 9px; align-items: flex-end;
}

.toast {
  padding: 11px 15px; border-radius: 10px; font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--border);
  box-shadow: var(--shadow); animation: toast-in .18s ease;
  max-width: 380px;
}
.toast.ok { border-color: rgba(34,197,94,.5); }
.toast.err { border-color: rgba(239,68,68,.5); }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.code-block {
  background: #070b1a; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-family: var(--mono); font-size: 12px;
  overflow-x: auto; color: #b9c6f0; white-space: pre;
}

.asset-preview {
  width: 100%; max-height: 190px; object-fit: contain;
  border-radius: 10px; border: 1px solid var(--border);
  background: #070b1a;
}

.stat-strip { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12.5px; }
.stat-strip div { display: flex; flex-direction: column; gap: 2px; }
.stat-strip b { font-size: 15px; font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .nav { margin-left: 0; order: 3; width: 100%; overflow-x: auto; }
  .page { padding: 14px; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .bar-row { grid-template-columns: 90px 1fr 78px; }
}

/* ===========================================================================
 * Data tab — prompt catalogue editor
 * =========================================================================== */

.data-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.data-sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 130px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.data-cat-list {
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.data-cat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
}
.data-cat:hover { background: var(--panel-2); }
.data-cat.active {
  background: var(--panel-2);
  border-color: var(--accent);
}

.data-cat-toggle {
  width: 18px; height: 18px; flex: 0 0 18px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: transparent;
  color: transparent;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}
.data-cat-toggle.on {
  background: var(--green);
  border-color: var(--green);
  color: #06210f;
}

.data-cat-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-cat-count {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.data-main {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
  overflow: hidden;
}

.data-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.data-main-title { font-size: 14px; font-weight: 700; }
.data-main-title .mono { color: var(--muted); font-weight: 400; margin-left: 6px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 8px 8px;
  border-bottom: 1px solid rgba(41, 51, 92, .5);
  vertical-align: top;
}
.data-table tr.row-off td { opacity: .45; }
.data-table .col-check { width: 34px; }
.data-table .col-actions { white-space: nowrap; text-align: right; }
.data-table .col-actions .btn + .btn { margin-left: 6px; }
.data-table .col-prompt { max-width: 520px; min-width: 220px; }

.data-prompt {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  color: #cdd7f5;
  max-height: 4.8em;
  overflow: hidden;
}

.data-thumb {
  width: 42px; height: 42px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #070b1a;
  display: block;
}
.data-thumb-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.badge.warn#data-dirty { font-weight: 600; }

@media (max-width: 900px) {
  .data-layout { grid-template-columns: 1fr; }
  .data-sidebar { position: static; max-height: 300px; }
}

/* --- Data tab: bulk selection controls --- */

.data-bulk {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}

.data-bulk-all {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.data-bulk-all input { cursor: pointer; }

.data-bulk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.data-bulk-actions .btn {
  padding: 5px 6px;
  font-size: 11.5px;
  text-align: center;
}

.data-bulk-count { color: var(--muted); }

/* Inline variant used in the right pane's toolbar */
.data-bulk.data-bulk-inline {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1 1 auto;
  padding: 8px 10px;
  background: transparent;
  border-color: transparent;
}
.data-bulk-inline .data-bulk-all { white-space: nowrap; }
.data-bulk-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

.data-toolbar-sub {
  padding-top: 0;
  border-top: 1px solid rgba(41, 51, 92, .55);
  margin-top: -4px;
  padding-top: 10px;
}

.data-sel-count {
  color: var(--muted);
  white-space: nowrap;
}

/* Category row: selection checkbox sits before the on/off switch */
.data-cat-check {
  flex: 0 0 auto;
  cursor: pointer;
  margin: 0;
}

.data-main-title .badge { margin-left: 6px; font-weight: 600; }

@media (max-width: 900px) {
  .data-bulk.data-bulk-inline { flex-direction: column; align-items: stretch; }
  .data-bulk-sep { display: none; }
  .data-bulk-inline .btn { width: 100%; }
}

/* --- Data tab: image / video split --- */

.media-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(41, 51, 92, .55);
}

.media-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.media-tab:hover { background: var(--panel-2); color: var(--text); }
.media-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.media-tab-count {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .13);
}
.media-tab:not(.active) .media-tab-count {
  background: var(--panel-2);
  color: var(--muted);
}

.media-group-state {
  font-size: 11.5px;
  color: var(--muted);
  margin-left: 4px;
}

/* Category row: per-media counters */
.data-cat-badges {
  display: inline-flex;
  gap: 5px;
  flex: 0 0 auto;
}
.cat-num {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(34, 211, 238, .12);
  color: #67e8f9;
  white-space: nowrap;
}
.cat-num.vid {
  background: rgba(124, 92, 255, .16);
  color: #c4b5fd;
}
.cat-num.zero { opacity: .4; }

.data-video-link {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--cyan);
  text-decoration: none;
  word-break: break-all;
}
.data-video-link:hover { text-decoration: underline; }

.data-table .col-actions { width: 1%; }

/* --- Data tab: sidebar Image / Video switch --- */

.sidebar-media-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.sidebar-media-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
}
.sidebar-media-tab:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.sidebar-media-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.smt-label { letter-spacing: .02em; }
.smt-count {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 400;
  opacity: .85;
}

.sidebar-media-note {
  color: var(--muted);
  line-height: 1.35;
  padding: 0 2px;
}

/* Media badge in the right pane's title bar */
.media-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  padding: 2px 7px;
  border-radius: 5px;
  margin-right: 8px;
  vertical-align: 1px;
  background: rgba(34, 211, 238, .16);
  color: #67e8f9;
  border: 1px solid rgba(34, 211, 238, .35);
}
.media-pill.vid {
  background: rgba(124, 92, 255, .18);
  color: #c4b5fd;
  border-color: rgba(124, 92, 255, .38);
}

/* ===========================================================================
 * Data tab: category row — checkbox (select) vs switch (enable)
 *
 * Both controls used to be small squares, which read as "two checkboxes".
 * Now: the select control is a plain checkbox on the left, and the enable
 * control is a labelled track switch on the right — different shape, different
 * position, different affordance.
 * =========================================================================== */

.data-cat {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 9px;
}

/* Select-for-bulk: a real checkbox, no extra chrome */
.data-cat-check-wrap {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 2px 0;
}
.data-cat-check {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.data-cat-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-cat-badges { justify-self: end; }

/* Enable switch: track + knob + text label.
 *
 * Class names are "data-sw-*", NOT "switch-track": the global .switch-track
 * rule draws its knob with ::after, which showed up as a second dot inside
 * this control. Keeping the names unique avoids inheriting any of that. */
.data-cat-switch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 2px 2px 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  flex: 0 0 auto;
}

.data-sw-track {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: #2b3559;
  border: 1px solid var(--border);
  transition: background .15s ease, border-color .15s ease;
  flex: 0 0 auto;
  display: block;
}
.data-sw-knob {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #8e9ac2;
  transition: transform .15s ease, background .15s ease;
  display: block;
}
.data-cat-switch.on .data-sw-track {
  background: var(--green);
  border-color: var(--green);
}
.data-cat-switch.on .data-sw-knob {
  transform: translateX(12px);
  background: #06210f;
}

.data-sw-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
  width: 22px;
  text-align: left;
}
.data-cat-switch.on .data-sw-label { color: var(--green); }

/* Hidden switch (old markup) — keep dormant in case of cached HTML */
.data-cat-toggle { display: none; }

/* --- Data modal: image / video picker --- */

.media-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 6px;
}

.media-pick-opt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
}
.media-pick-opt:hover { background: var(--panel-2); color: var(--text); }
.media-pick-opt.active {
  border-color: var(--accent);
  background: rgba(79, 124, 255, .14);
  color: var(--text);
}
.media-pick-opt input {
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.media-pick-label { line-height: 1; }

.label-hint {
  font-weight: 400;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

/* Hidden-by-media fields must not leave a gap */
.field[hidden] { display: none !important; }

/* A field heading that is not a <label> (e.g. the media radiogroup, whose
 * options are already labelled by their own <label> elements). */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ===========================================================================
 * Data modal: fix field-inheritance breakage
 *
 * `.field label` is display:block, so a <label> that wraps a single checkbox
 * ("Bật prompt này") stretched to the full column width. A checkbox inside a
 * label must stay inline with its text.
 * =========================================================================== */

.field > label.data-check-row,
.field label.data-check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  margin-bottom: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.field label.data-check-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Media picker options: keep a tight, single-line pill instead of inheriting
 * the form's large line-height. */
.media-pick-opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 10px;
  min-height: 38px;
  line-height: 1.15;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.media-pick-opt > input {
  width: 15px;
  height: 15px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}
.media-pick-label { line-height: 1; }

/* The picker itself must not inherit the form's block spacing */
.media-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 6px;
}

/* ---------------------------------------------------------------------------
 * Data modal: media picker — reset the form-input styling it inherits
 *
 * `.field input` sets width:100%, padding and a bordered box. A radio inside
 * that field inherits all of it, which squashed the gap to the label and made
 * the pill look cramped. Reset those properties on the radiogroup only.
 * ------------------------------------------------------------------------- */

.field .media-pick input[type="radio"] {
  /* undo `.field input` */
  width: 16px !important;
  height: 16px !important;
  min-width: 16px;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  background: none !important;
  box-shadow: none !important;
  border-radius: 50%;
  accent-color: var(--accent);
  cursor: pointer;
  flex: 0 0 16px;
  -webkit-appearance: radio;
  appearance: radio;
}
.field .media-pick input[type="radio"]:focus {
  box-shadow: 0 0 0 3px rgba(79, 124, 255, .28) !important;
}

.field .media-pick-opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* roomy, even spacing between the dot and the word */
  gap: 10px;
  padding: 9px 16px;
  min-height: 40px;
  line-height: 1.2;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s, color .15s;
}
.field .media-pick-opt:hover {
  background: var(--panel-2);
  color: var(--text);
}
.field .media-pick-opt.active {
  border-color: var(--accent);
  background: rgba(79, 124, 255, .14);
  color: var(--text);
}

.field .media-pick-opt .media-pick-label {
  line-height: 1;
  /* keep the word from touching the dot even if gap is collapsed */
  margin-left: 0;
}

/* ===========================================================================
 * Dashboard: daily chart — hover readout
 * =========================================================================== */

.chart-host {
  position: relative;
  width: 100%;
}

.chart-box { display: block; overflow: visible; }

.chart-bar { transition: opacity .12s ease; }

.chart-crosshair { pointer-events: none; }

.chart-hit { pointer-events: all; }

.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 148px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(13, 19, 48, .97);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .5);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.5;
}
.chart-tip[hidden] { display: none; }

.chart-tip .tip-date {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--text);
  margin-bottom: 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.chart-tip .tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.chart-tip .tip-row b {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.chart-tip .tip-sub {
  color: var(--muted);
  font-size: 11.5px;
  padding-left: 14px;
}
.chart-tip .swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex: 0 0 9px;
}

.chart-tip .tip-row + .tip-row { margin-top: 1px; }

/* ---------------------------------------------------------------
   JSON preview (Data URL tab)

   Colours reuse the palette already defined for .badge.ok / .badge.warn
   and the theme tokens, so the preview matches the console instead of
   introducing new hard-coded values.
   --------------------------------------------------------------- */
#preview-body .j-key { color: var(--accent); }
#preview-body .j-str { color: #86efac; }
#preview-body .j-num { color: #fcd34d; }
#preview-body .j-lit { color: var(--muted); font-style: italic; }

#preview-body::-webkit-scrollbar { width: 10px; height: 10px; }
#preview-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 6px;
}
#preview-body::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------
   In-place view refresh (see beginViewLoad in app.js)

   Re-rendering the current view used to blank #view-root and repaint it,
   which read to the operator as a browser reload. Instead the existing
   content stays put, dims slightly, and an aria-busy hint appears in the
   corner. Nothing reflows, so scroll position and the visual context
   survive the update.
   --------------------------------------------------------------- */
#view-root {
  position: relative;
  transition: opacity 120ms ease;
}

#view-root.view-refreshing {
  opacity: 0.55;
  pointer-events: none;
}

/* Small "đang cập nhật" chip, only while refreshing. */
#view-root.view-refreshing::after {
  content: "Đang cập nhật…";
  position: fixed;
  top: 74px;
  right: 24px;
  z-index: 40;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(10, 14, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

/* Respect an OS-level reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
  #view-root { transition: none; }
}
