:root {
  color-scheme: dark;
  --bg: #07080d;
  --bg-2: #0b0e17;
  --panel: #0f131f;
  --panel-2: #131829;
  --ink: #e7ecf5;
  --muted: #97a2bb;
  --faint: #5a6580;
  --line: rgba(255,255,255,.09);
  --line-2: rgba(255,255,255,.14);
  --a: #8fb4ff;
  --b: #c9a7ff;
  --c: #7ce0d3;
  --ok: #57d9a3;
  --warn: #f4c560;
  --err: #ff7a8a;
  --info: #6fb4ff;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1000px 500px at 80% -10%, #141d36 0%, transparent 60%),
    radial-gradient(900px 500px at 0% 0%, #1a1430 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 14.5px;
  line-height: 1.5;
}
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.grow { flex: 1; }
.row { display: flex; align-items: center; }
.gap { gap: 9px; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  padding: 13px 22px;
  background: rgba(8,10,17,.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand-mark { font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.grad {
  background: linear-gradient(115deg, var(--a), var(--b) 50%, var(--c));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { font-size: 11px; color: var(--faint); letter-spacing: .14em; text-transform: uppercase; }

.tabs { display: flex; gap: 4px; background: rgba(255,255,255,.03); padding: 4px; border-radius: 999px; border: 1px solid var(--line); }
.tab {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 14px; font-weight: 600; padding: 8px 18px; border-radius: 999px;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: #0b0e17; background: linear-gradient(115deg, var(--a), var(--c)); }

.status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); transition: background .2s; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(87,217,163,.16); }
.dot.bad { background: var(--err); box-shadow: 0 0 0 3px rgba(255,122,138,.16); }

/* -------------------------------------------------------------------- main */
main { max-width: 1240px; margin: 0 auto; padding: 22px; }
.panel { display: none; animation: fade .25s ease; }
.panel.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
/* min-width:0 stops a wide <pre> from blowing the column out past its 1fr track */
.grid > .card { min-width: 0; }
@media (max-width: 960px) { .grid { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------- cards */
.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.hint { font-size: 11.5px; color: var(--faint); font-family: var(--mono); }

/* ----------------------------------------------------------------- inputs */
textarea, input[type=text], select {
  width: 100%; color: var(--ink); background: rgba(255,255,255,.04);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  font-size: 13.5px; outline: none; transition: border-color .15s, background .15s;
}
textarea { min-height: 160px; resize: vertical; line-height: 1.45; }
textarea:focus, input:focus, select:focus { border-color: rgba(143,180,255,.6); background: rgba(255,255,255,.06); }
select { cursor: pointer; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px;
}
/* the native dropdown popup — keep it dark (was white-on-white) */
select option, select optgroup { background: #131829; color: var(--ink); }
::placeholder { color: var(--faint); }

/* ---------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--line-2); background: rgba(255,255,255,.05); color: var(--ink);
  font-size: 13.5px; font-weight: 600; padding: 9px 16px; border-radius: 10px; cursor: pointer;
  transition: transform .12s, filter .15s, background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.09); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { border: 0; color: #0b0e17; background: linear-gradient(115deg, var(--a), var(--c)); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: rgba(255,255,255,.035); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.danger { color: var(--err); }
.danger:hover { background: rgba(255,122,138,.12); border-color: rgba(255,122,138,.4); }
.row .spacer { flex: 1; }

/* --------------------------------------------------------------- json view */
.json-view {
  background: #060810; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; max-height: 62vh; overflow: auto; font-size: 12.8px; line-height: 1.55;
  white-space: pre; tab-size: 2;
}
.json-view .placeholder { color: var(--faint); }
.tok-key { color: #8fb4ff; }
.tok-str { color: #7ce0d3; }
.tok-num { color: #f4c560; }
.tok-bool { color: #c9a7ff; }
.tok-null { color: var(--faint); }
.tok-punc { color: var(--muted); }

/* ------------------------------------------------------------------ alerts */
.alert { border-radius: 10px; padding: 10px 13px; font-size: 13px; margin-bottom: 12px;
  background: rgba(255,122,138,.10); border: 1px solid rgba(255,122,138,.35); color: #ffd2d8; }
.alert-info { background: rgba(111,180,255,.10); border-color: rgba(111,180,255,.35); color: #d4e6ff; }

/* ------------------------------------------------------------------- rules */
.rules { display: flex; flex-direction: column; gap: 12px; }
.rule { background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px; padding: 12px; }
.rule.dirty { border-color: rgba(244,197,96,.45); }
.rule-top { display: flex; align-items: center; gap: 10px; }
.rule-param { flex: 1 1 230px; }
.rule-param.invalid { border-color: rgba(255,122,138,.7); background: rgba(255,122,138,.08); }
.rule-op { flex: 0 0 150px; width: 150px; }
.rule-body { display: flex; gap: 10px; margin-top: 11px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.field.grow { flex: 1 1 160px; }
.field label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.field input, .field select { padding: 8px 10px; font-size: 13px; }
.f-new input { min-width: 180px; }
.f-type select { width: 110px; }
.rule-summary { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); }
.rule-summary:empty { display: none; }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: 0 0 auto; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: rgba(255,255,255,.12); border-radius: 999px; transition: background .2s; }
.switch .track::before { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .track { background: linear-gradient(115deg, var(--a), var(--c)); }
.switch input:checked + .track::before { transform: translateX(16px); }

.empty { text-align: center; color: var(--muted); padding: 26px; border: 1px dashed var(--line); border-radius: 11px; }

/* ----------------------------------------------------------------- apply edits */
.card-sub { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
.apply-out-head { margin-top: 14px; margin-bottom: 8px; }
#apply-output { min-height: 84px; color: var(--c); white-space: pre-wrap; word-break: break-all; }
.apply-details { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.ad-line { font-family: var(--mono); font-size: 12.3px; padding: 6px 10px; border-radius: 7px; background: rgba(255,255,255,.03); border: 1px solid var(--line); word-break: break-all; }
.ad-line.ok { border-color: rgba(87,217,163,.3); }
.ad-line.skip { color: var(--muted); }
.ad-old { color: var(--err); }
.ad-new { color: var(--ok); }

/* ----------------------------------------------------------------- history */
.live { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ok); letter-spacing: .08em; text-transform: uppercase; }
.live.paused { color: var(--faint); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(87,217,163,.7); animation: pulse 2s infinite; }
.live.paused .live-dot { background: var(--faint); animation: none; box-shadow: none; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(87,217,163,.6);} 70%{box-shadow:0 0 0 9px rgba(87,217,163,0);} 100%{box-shadow:0 0 0 0 rgba(87,217,163,0);} }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table.history { width: 100%; border-collapse: collapse; font-size: 13px; }
table.history th, table.history td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.history th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); background: rgba(255,255,255,.02); position: sticky; top: 0; }
table.history tbody tr { transition: background .15s; }
table.history tbody tr:hover { background: rgba(255,255,255,.025); }
table.history tr.flash { animation: flashrow 1.4s ease; }
@keyframes flashrow { 0% { background: rgba(124,224,211,.18); } 100% { background: transparent; } }
.tok-cell { display: inline-flex; align-items: center; gap: 7px; }
.tok-chip { font-family: var(--mono); font-size: 11.5px; color: var(--muted); max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.copy-mini { border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--muted); border-radius: 6px; padding: 2px 7px; font-size: 11px; cursor: pointer; }
.copy-mini:hover { color: var(--ink); background: rgba(255,255,255,.1); }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.badge.success { background: rgba(87,217,163,.15); color: var(--ok); }
.badge.passthrough { background: rgba(151,162,187,.15); color: var(--muted); }
.badge.partial { background: rgba(244,197,96,.15); color: var(--warn); }
.badge.error { background: rgba(255,122,138,.15); color: var(--err); }
.rules-cell { white-space: normal; max-width: 220px; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: rgba(17,22,38,.96); border: 1px solid var(--line-2);
  color: var(--ink); padding: 11px 18px; border-radius: 10px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: rgba(87,217,163,.5); }
.toast.err { border-color: rgba(255,122,138,.5); }

/* scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); background-clip: padding-box; }
