/* ---------- tool UI tokens (same as Customize) ---------- */
:root {
  --bg: #f4f2f8;
  --surface: #ffffff;
  --surface-2: #f7f5fb;
  --text: #1e1b2b;
  --muted: #6b6780;
  --border: #e2deec;
  --accent: #8e00af;
  --accent-soft: rgba(142, 0, 175, .08);
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b25b00;
  --warn-bg: #fff3e0;
  --err: #c62828;
  --err-bg: #fdecec;
  --shadow: 0 1px 2px rgba(30, 20, 60, .06), 0 8px 24px rgba(30, 20, 60, .06);
  /* The admin around the AdvBox, light and dark (always both, whatever the tool theme). */
  --admin-light-bg: #f3f3f7; --admin-light-card: #ffffff; --admin-light-line: #e4e4ec; --admin-light-text: #2a2838;
  --admin-dark-bg: #16151c;  --admin-dark-card: #22212b;  --admin-dark-line: #34323f;  --admin-dark-text: #e7e5f0;
  --topbar-h: 57px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15131d; --surface: #1f1c2a; --surface-2: #26222f; --text: #eeebf6; --muted: #a39fb6; --border: #353046;
    --accent: #c46be0; --accent-soft: rgba(196, 107, 224, .14); --accent-text: #15131d;
    --ok: #5fd08d; --warn: #ffb866; --warn-bg: #3a2a14; --err: #ff8a80; --err-bg: #3b1c1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15131d; --surface: #1f1c2a; --surface-2: #26222f; --text: #eeebf6; --muted: #a39fb6; --border: #353046;
  --accent: #c46be0; --accent-soft: rgba(196, 107, 224, .14); --accent-text: #15131d;
  --ok: #5fd08d; --warn: #ffb866; --warn-bg: #3a2a14; --err: #ff8a80; --err-bg: #3b1c1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Montserrat, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--accent); }
code { font: 12.5px/1.4 ui-monospace, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand-name { white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, #8e00af, #c46be0); }
.beta { padding: 2px 7px; border-radius: 6px; background: #70d44b; color: #141121; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; cursor: help; }
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected=true] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; flex: none;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
}
.icon-btn.small { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.small svg { width: 16px; height: 16px; }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 260px; padding: 6px;
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-list button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu-list button:hover, .menu-list button:focus { background: var(--surface-2); outline: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); gap: 20px; padding: 20px; align-items: start; }
.panel {
  display: flex; flex-direction: column; gap: 14px; min-width: 0;
  position: sticky; top: calc(var(--topbar-h) + 20px); max-height: calc(100vh - var(--topbar-h) - 40px);
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-right: 4px;
}
.workspace { min-width: 0; }
.view { display: flex; flex-direction: column; gap: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.cols > div { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.sticky { position: sticky; top: calc(var(--topbar-h) + 20px); }
@media (max-width: 1250px) { .cols { grid-template-columns: minmax(0, 1fr); } .sticky { position: static; } }
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  .panel { position: static; max-height: none; overflow: visible; }
  .topbar { flex-wrap: wrap; height: auto; }
  :root { --topbar-h: 0px; }
  .tabs { order: 3; width: 100%; justify-content: center; }
}

/* ---------- cards and fields ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.hint:empty { display: none; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { align-items: flex-end; }
.grow { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.field { display: flex; flex-direction: column; gap: 5px; margin: 0 0 10px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=number], input[type=url], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); outline: none;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=color] { width: 36px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
.btn.danger:hover { border-color: var(--err); color: var(--err); }
.segmented { display: inline-flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed=true] { background: var(--accent); color: var(--accent-text); }
.segmented.small button { padding: 3px 9px; font-size: 12px; }

/* ---------- case list ---------- */
.case-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.case-item {
  display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); cursor: grab;
}
.case-item:hover { border-color: var(--accent); }
.case-item.selected { border-color: var(--accent); background: var(--accent-soft); }
.case-item.off { opacity: .55; }
.case-item.off .case-text b { text-decoration: line-through; }
.case-order { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 11.5px; font-weight: 700; }
.case-text { min-width: 0; display: flex; flex-direction: column; }
.case-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.case-text small { color: var(--muted); font-size: 11.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.case-count { font-size: 12px; font-weight: 700; color: var(--muted); text-align: right; white-space: nowrap; }
.handle { cursor: grab; color: var(--muted); letter-spacing: -2px; user-select: none; padding: 2px; font-size: 13px; line-height: 1; }
.handle:active { cursor: grabbing; }
.drop-line { height: 3px; border-radius: 2px; background: var(--accent); margin: -2px 0; pointer-events: none; }
.dragging { opacity: .4; }

/* ---------- palette ---------- */
.palette-group { margin-top: 12px; }
.palette-group h4 { margin: 0 0 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: grab; font-size: 12.5px; font-weight: 500; user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.preset { border-style: dashed; }
.chip .tbd, .badge-tbd { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 5px; background: var(--warn-bg); color: var(--warn); }

/* ---------- case editor ---------- */
.case-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.case-head .name { flex: 1 1 260px; font-size: 16px; font-weight: 700; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.stat { flex: 1 1 150px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
details.notes summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 10px; }
details.notes textarea { margin-top: 6px; }

.group { border: 1px dashed var(--border); border-radius: 14px; padding: 10px; background: var(--surface); }
.group.root { border-style: solid; }
.group.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.group .group { background: var(--surface-2); margin: 2px 0; }
.group-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.group-head .grow { color: var(--muted); font-size: 12px; }
.group-body { display: flex; flex-direction: column; gap: 6px; min-height: 40px; }
.group-body.over { background: var(--accent-soft); border-radius: 10px; }
.joiner { align-self: flex-start; font-size: 10.5px; font-weight: 800; letter-spacing: .08em; color: var(--accent); padding: 0 8px; }
.drop-empty { border: 2px dashed var(--border); border-radius: 10px; padding: 12px; text-align: center; color: var(--muted); font-size: 12.5px; }
.cond {
  display: grid; grid-template-columns: auto minmax(130px, 1fr) auto minmax(150px, 1.5fr) auto auto; align-items: center; gap: 8px;
  padding: 7px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.cond-label { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cond-label .info { cursor: help; color: var(--muted); font-weight: 400; }
.cond select { width: auto; padding: 6px 8px; }
.cond-value { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.cond-value input { padding: 6px 8px; }
.cond-value input[type=number] { width: 90px; }
.cond-hits { font-size: 11.5px; color: var(--muted); white-space: nowrap; text-align: right; min-width: 52px; }
@media (max-width: 700px) {
  .cond { grid-template-columns: auto minmax(0, 1fr) auto; }
  .cond select, .cond-value { grid-column: 2 / 4; }
  .cond-hits { grid-column: 2; text-align: left; }
}
.pill {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 3px 9px; font-size: 12px; cursor: pointer;
}
.pill[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ---------- content ---------- */
.lang-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.lang-bar button {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 5px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 12.5px;
}
.lang-bar button img { width: 20px; height: 20px; border-radius: 50%; display: block; }
.lang-bar button[aria-pressed=true] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.lang-bar button .miss { width: 7px; height: 7px; border-radius: 50%; background: var(--err); }
.uploads { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.slot {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 2px dashed var(--border); border-radius: 12px; cursor: pointer; min-height: 92px;
  justify-content: center; align-items: center; text-align: center; font-size: 12px; color: var(--muted);
}
.slot:hover, .slot.over { border-color: var(--accent); color: var(--accent); }
.slot img { width: 100%; aspect-ratio: 1 / .42257; object-fit: cover; border-radius: 8px; }
.slot b { color: var(--text); }
.slot .warnline { color: var(--warn); }

/* ---------- admin preview ---------- */
.previews { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.admin { border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.admin .bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 11.5px; font-weight: 700; }
.admin .bar i { width: 18px; height: 18px; border-radius: 6px; background: linear-gradient(135deg, #8e00af, #c46be0); }
.admin .bar span:last-child { margin-left: auto; font-weight: 600; opacity: .6; }
.admin .body { display: grid; grid-template-columns: 38px minmax(0, 1fr); }
.admin .side { display: flex; flex-direction: column; gap: 8px; padding: 10px 9px; }
.admin .side i { height: 18px; border-radius: 6px; opacity: .35; }
.admin .main { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 10px; }
.admin .tile { border-radius: 16px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.admin .tile i { height: 8px; border-radius: 4px; opacity: .25; }
.advbox { grid-column: 2; grid-row: 1 / 3; border-radius: 24px; overflow: hidden; cursor: pointer; position: relative; aspect-ratio: 1 / .42257; }
.advbox img { display: block; width: 100%; height: 100%; object-fit: cover; }
.advbox .missing {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-align: center; padding: 10px; font-size: 11.5px; border: 2px dashed currentColor; border-radius: 24px; opacity: .7; word-break: break-all;
}
.advbox:hover { outline: 3px solid var(--accent); outline-offset: 2px; }
.admin.light { background: var(--admin-light-bg); color: var(--admin-light-text); }
.admin.light .bar, .admin.light .tile { background: var(--admin-light-card); }
.admin.light .side { background: var(--admin-light-card); border-right: 1px solid var(--admin-light-line); }
.admin.light .side i, .admin.light .tile i { background: var(--admin-light-text); }
.admin.dark { background: var(--admin-dark-bg); color: var(--admin-dark-text); }
.admin.dark .bar, .admin.dark .tile { background: var(--admin-dark-card); }
.admin.dark .side { background: var(--admin-dark-card); border-right: 1px solid var(--admin-dark-line); }
.admin.dark .side i, .admin.dark .tile i { background: var(--admin-dark-text); }
.click-what { font-size: 12.5px; color: var(--muted); word-break: break-all; }

/* ---------- simulation ---------- */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 220px) minmax(0, 1fr) 110px; align-items: center; gap: 10px; cursor: pointer; padding: 4px; border-radius: 10px; }
.bar-row:hover, .bar-row.open { background: var(--surface-2); }
.bar-row .name { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.bar-row .name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 14px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 7px; min-width: 2px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.bar-row .num b { font-size: 14px; }
.bar-row.none .name { color: var(--warn); }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; display: inline-block; }
@media (max-width: 560px) { .bar-row { grid-template-columns: minmax(0, 1fr) 90px; } .bar-track { grid-column: 1 / 3; grid-row: 2; } }
table.grid { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child { text-align: left; white-space: normal; }
table.grid th { color: var(--muted); font-weight: 600; font-size: 11.5px; }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover td { background: var(--surface-2); }
.scroll-x { overflow-x: auto; }
.probe-result { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--accent-soft); font-size: 15px; font-weight: 700; margin: 12px 0; }
.probe-result.none { background: var(--warn-bg); color: var(--warn); }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.fact { font-size: 11.5px; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.trace { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.trace > li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.trace > li.win { border-color: var(--accent); background: var(--accent-soft); }
.trace > li.skip { opacity: .55; }
.trace .t-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.trace ul { list-style: none; margin: 6px 0 0; padding: 0 0 0 18px; font-size: 12.5px; }
.trace ul ul { padding-left: 14px; border-left: 2px solid var(--border); }
.yes { color: var(--ok); font-weight: 700; }
.no { color: var(--err); font-weight: 700; }

/* ---------- checks and export ---------- */
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checks li { padding: 8px 10px; border-radius: 10px; font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.checks li.error { background: var(--err-bg); color: var(--err); }
.checks li.warn { background: var(--warn-bg); color: var(--warn); }
.checks li.info { background: var(--surface-2); color: var(--muted); }
.checks li.ok { background: var(--accent-soft); color: var(--ok); }
.checks li button { margin-left: auto; }
.md { font-size: 13.5px; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.md blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.md h2 { font-size: 20px; } .md h3 { font-size: 16px; margin-top: 20px; } .md h4 { font-size: 14px; }
.summary-box { max-height: 640px; overflow: auto; padding: 4px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }

/* ---------- dialog and toast ---------- */
.dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 18px; padding: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 6, 20, .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-foot { display: flex; justify-content: flex-end; margin-top: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast .btn.link { color: var(--bg); text-decoration: underline; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
