/* =====================================================================
   Lumi design system
   ---------------------------------------------------------------------
   Tokens → base → shell → components → workflows (builder, runs, Lumi).
   Theme is chosen by html[data-theme="light|dark"]; light is default.
   Legacy variable names (--ink, --muted, --accent …) are aliased at the
   bottom of the token block so older templates inherit the system.
   ===================================================================== */

:root,
html[data-theme="light"] {
  color-scheme: light;

  /* Surfaces */
  --canvas: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --sunken: #f1f1ee;
  --hover: rgba(25, 32, 44, .045);
  --pressed: rgba(25, 32, 44, .08);
  --overlay: rgba(19, 23, 31, .42);

  /* Text */
  --ink: #19202c;
  --ink-2: #3d4553;
  --muted: #69717f;
  --faint: #9aa0ab;
  --on-brand: #ffffff;

  /* Lines */
  --line: #e6e5e0;
  --line-strong: #d5d3cc;

  /* Brand + accent */
  --brand: #2859e8;
  --brand-hover: #1f4bd1;
  --brand-ink: #1d45bd;
  --brand-soft: #eaf0fe;
  --brand-line: #c6d5fb;
  --accent: #ff805a;
  --accent-ink: #c4471f;
  --accent-soft: #fff0ea;

  /* Status */
  --ok: #16815d;      --ok-soft: #e6f4ee;      --ok-line: #bfe3d3;
  --bad: #c8373b;     --bad-soft: #fcebeb;     --bad-line: #f2c4c5;
  --warn: #a8660c;    --warn-soft: #fbf1de;    --warn-line: #f0d9a8;
  --run: #2859e8;     --run-soft: #eaf0fe;
  --idle: #69717f;    --idle-soft: #efefec;

  /* Navigation (deep ink, independent of theme) */
  --nav-bg: #141922;
  --nav-line: rgba(255, 255, 255, .07);
  --nav-ink: #d3d7df;
  --nav-muted: #858d9b;
  --nav-hover: rgba(255, 255, 255, .06);
  --nav-active: rgba(255, 255, 255, .1);

  /* Elevation (popovers, drawers only) */
  --shadow-pop: 0 1px 2px rgba(19, 23, 31, .06), 0 8px 24px rgba(19, 23, 31, .1);
  --shadow-drawer: -12px 0 32px rgba(19, 23, 31, .12);
  --focus: 0 0 0 3px rgba(40, 89, 232, .28);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0f1217;
  --surface: #161a21;
  --surface-2: #1a1f27;
  --sunken: #12151b;
  --hover: rgba(255, 255, 255, .045);
  --pressed: rgba(255, 255, 255, .08);
  --overlay: rgba(0, 0, 0, .55);

  --ink: #e9ebef;
  --ink-2: #bcc1cb;
  --muted: #8b929f;
  --faint: #626a78;

  --line: #252a33;
  --line-strong: #323844;

  --brand: #5b85f6;
  --brand-hover: #7097f8;
  --brand-ink: #93b1fa;
  --brand-soft: rgba(91, 133, 246, .14);
  --brand-line: rgba(91, 133, 246, .38);
  --accent: #ff8f6b;
  --accent-ink: #ffab90;
  --accent-soft: rgba(255, 143, 107, .13);

  --ok: #43c093;   --ok-soft: rgba(67, 192, 147, .13);  --ok-line: rgba(67, 192, 147, .35);
  --bad: #f07171;  --bad-soft: rgba(240, 113, 113, .13); --bad-line: rgba(240, 113, 113, .38);
  --warn: #e3ac4f; --warn-soft: rgba(227, 172, 79, .13); --warn-line: rgba(227, 172, 79, .35);
  --run: #5b85f6;  --run-soft: rgba(91, 133, 246, .14);
  --idle: #8b929f; --idle-soft: rgba(139, 146, 159, .13);

  --nav-bg: #0b0d11;
  --nav-line: rgba(255, 255, 255, .06);

  --shadow-pop: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .45);
  --shadow-drawer: -12px 0 32px rgba(0, 0, 0, .45);
  --focus: 0 0 0 3px rgba(91, 133, 246, .35);
}

:root {
  /* Type */
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --t-xs: 11px; --t-sm: 12px; --t-base: 13px; --t-md: 14px; --t-lg: 16px; --t-xl: 20px; --t-2xl: 24px;

  /* Space (4px grid) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;

  /* Geometry */
  --r-sm: 4px; --r: 6px; --r-md: 8px; --r-lg: 12px;
  --h-sm: 28px; --h: 32px; --h-lg: 36px;
  --sidebar-w: 232px;
}

/* Legacy aliases — older templates use these names inline. */
:root, html[data-theme] {
  --bg-base: var(--canvas);
  --border: var(--line);
  --border-strong: var(--line-strong);
  --sky: var(--brand); --sky-600: var(--brand); --sky-700: var(--brand-ink);
  --emerald: var(--ok); --emerald-600: var(--ok); --emerald-soft: var(--ok-soft);
  --rose: var(--bad); --rose-soft: var(--bad-soft);
  --amber: var(--warn); --amber-soft: var(--warn-soft);
  --cyan-soft: var(--run-soft);
  --grad: var(--brand);
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--ink);
  font-family: var(--font); font-size: var(--t-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
}
::selection { background: var(--brand-soft); color: var(--ink); }
a { color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.tc-icon { flex-shrink: 0; display: inline-block; vertical-align: -0.18em; }
.mono, .tc-mono { font-family: var(--mono); font-size: .94em; letter-spacing: -.01em; }
.tabnum { font-variant-numeric: tabular-nums; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--faint); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Tailwind white-overlay hovers used by older templates → theme aware */
.hover\:bg-white\/5:hover { background: var(--hover) !important; }

/* ---------------------------------------------------------------- shell */
.tc-app { display: flex; height: 100%; }
.tc-main { flex: 1; min-width: 0; height: 100%; overflow-y: auto; position: relative; }

.tc-sidebar {
  width: var(--sidebar-w); flex-shrink: 0; height: 100%;
  background: var(--nav-bg); color: var(--nav-ink);
  display: flex; flex-direction: column; border-right: 1px solid var(--nav-line);
}
.tc-brand { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px; }
.tc-brand b { font-size: 14.5px; font-weight: 650; letter-spacing: -.015em; color: #fff; }
.mark { width: 24px; height: 24px; flex-shrink: 0; display: block; }
.tc-topbar .mark { width: 22px; height: 22px; }

.tc-ws { margin: 2px 10px 6px; position: relative; }
.tc-ws select {
  appearance: none; -webkit-appearance: none; width: 100%; height: 34px; cursor: pointer;
  background: rgba(255, 255, 255, .05) !important; border: 1px solid var(--nav-line) !important;
  color: var(--nav-ink) !important; border-radius: var(--r-md) !important;
  padding: 0 30px 0 10px !important; font-size: var(--t-sm) !important; font-weight: 500;
}
.tc-ws select:hover { background: rgba(255, 255, 255, .08) !important; }
.tc-ws select option { color: #19202c; background: #fff; }
.tc-ws .tc-icon { position: absolute; right: 9px; top: 9px; color: var(--nav-muted); pointer-events: none; }

.tc-navsection {
  font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--nav-muted); padding: 0 18px; margin: 16px 0 4px;
}
.tc-nav {
  display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; margin: 1px 8px;
  border-radius: var(--r); font-size: var(--t-base); font-weight: 450; color: var(--nav-ink);
  text-decoration: none; position: relative; transition: background .12s, color .12s;
}
.tc-nav .tc-icon { color: var(--nav-muted); transition: color .12s; }
.tc-nav:hover { background: var(--nav-hover); color: #fff; }
.tc-nav:hover .tc-icon { color: var(--nav-ink); }
.tc-nav.active { background: var(--nav-active); color: #fff; font-weight: 550; }
.tc-nav.active .tc-icon { color: var(--accent); }
.tc-nav.active::before {
  content: ""; position: absolute; left: -8px; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}
.tc-nav .count {
  margin-left: auto; font-size: 11px; font-weight: 600; min-width: 20px; height: 18px; padding: 0 6px;
  border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #2a1007;
}
.tc-sidebar nav { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.tc-account { border-top: 1px solid var(--nav-line); padding: 10px; display: flex; align-items: center; gap: 8px; }
.tc-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 650; background: var(--accent); color: #2a1007;
}
.tc-account .who { min-width: 0; flex: 1; line-height: 1.25; }
.tc-account .who b { display: block; font-size: var(--t-sm); font-weight: 550; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-account .who span { font-size: var(--t-xs); color: var(--nav-muted); }
.tc-navbtn {
  width: 28px; height: 28px; border-radius: var(--r); display: inline-flex; align-items: center; justify-content: center;
  color: var(--nav-muted); background: none; border: 0; cursor: pointer;
}
.tc-navbtn:hover { background: var(--nav-hover); color: #fff; }

/* Mobile: top bar + off-canvas sidebar */
.tc-topbar { display: none; }
@media (max-width: 1023px) {
  .tc-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 80; transform: translateX(-100%); transition: transform .18s ease; }
  .tc-app.nav-open .tc-sidebar { transform: none; box-shadow: 0 0 0 100vmax var(--overlay); }
  .tc-topbar {
    display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 12px; position: sticky; top: 0; z-index: 40;
    background: var(--nav-bg); color: #fff; border-bottom: 1px solid var(--nav-line);
  }
  .tc-topbar b { font-size: 14px; font-weight: 650; }
}

/* ---------------------------------------------------------------- page */
.tc-page { padding: 24px 32px 40px; max-width: 1440px; margin: 0 auto; }
.tc-page.wide { max-width: none; }
@media (max-width: 767px) { .tc-page { padding: 16px; } }
.tc-pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.tc-pagehead .crumbs { font-size: var(--t-sm); color: var(--muted); margin-bottom: 4px; display: flex; align-items: center; gap: 4px; }
.tc-pagehead .crumbs a { color: var(--muted); text-decoration: none; }
.tc-pagehead .crumbs a:hover { color: var(--ink); }
.tc-h1 { font-size: var(--t-xl); font-weight: 620; letter-spacing: -.02em; color: var(--ink); line-height: 1.25; margin: 0; }
.tc-h2 { font-size: var(--t-md); font-weight: 600; letter-spacing: -.01em; color: var(--ink); margin: 0; }
.tc-h3 { font-size: var(--t-base); font-weight: 600; color: var(--ink); margin: 0; }
.tc-sub { font-size: var(--t-base); color: var(--muted); }
.tc-eyebrow { font-size: var(--t-xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tc-label { display: block; font-size: var(--t-sm); font-weight: 520; color: var(--ink-2); margin-bottom: 5px; }
.tc-help { font-size: var(--t-xs); color: var(--muted); margin-top: 4px; }
.tc-error { font-size: var(--t-xs); color: var(--bad); margin-top: 4px; }

/* ---------------------------------------------------------------- surfaces */
.tc-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.tc-card-pad { padding: var(--s4); }
.tc-hair { border-color: var(--line) !important; }
.tc-section { border-top: 1px solid var(--line); padding-top: var(--s4); margin-top: var(--s4); }
.tc-divider { height: 1px; background: var(--line); border: 0; margin: var(--s3) 0; }

/* ---------------------------------------------------------------- buttons */
.tc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--h); padding: 0 12px;
  border-radius: var(--r); font: inherit; font-size: var(--t-base); font-weight: 520; line-height: 1; white-space: nowrap;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, color .12s;
}
.tc-btn:hover { background: var(--sunken); }
.tc-btn:active { background: var(--pressed); }
.tc-btn:disabled, .tc-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.tc-btn .tc-icon { color: var(--muted); }
.tc-btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.tc-btn-primary .tc-icon { color: inherit; opacity: .9; }
.tc-btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--on-brand); }
.tc-btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.tc-btn-ghost:hover { background: var(--hover); color: var(--ink); }
.tc-btn-danger { background: transparent; border-color: var(--line-strong); color: var(--bad); }
.tc-btn-danger .tc-icon { color: var(--bad); }
.tc-btn-danger:hover { background: var(--bad-soft); border-color: var(--bad-line); }
.tc-btn-sm { height: var(--h-sm); padding: 0 9px; font-size: var(--t-sm); gap: 5px; }
.tc-btn-icon { width: var(--h); padding: 0; }
.tc-btn-sm.tc-btn-icon { width: var(--h-sm); }
.tc-btn kbd, .tc-kbd {
  font-family: var(--mono); font-size: 10.5px; padding: 1px 5px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--muted); line-height: 1.3;
}
.tc-btn-primary kbd { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .25); color: #fff; }

/* ---------------------------------------------------------------- inputs (high specificity beats Tailwind preflight) */
body .tc-input,
body input[type=text], body input[type=url], body input[type=number], body input[type=password],
body input[type=email], body input[type=search], body input[type=time], body input:not([type]),
body select, body textarea {
  width: 100%; min-height: var(--h); border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: var(--r); padding: 6px 10px; font: inherit; font-size: var(--t-base); color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
body textarea { min-height: 72px; line-height: 1.5; resize: vertical; }
body select { cursor: pointer; }
body .tc-input:hover, body input:hover, body select:hover, body textarea:hover { border-color: var(--faint); }
body .tc-input:focus, body input:focus, body select:focus, body textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
body input::placeholder, body textarea::placeholder { color: var(--faint); }
body input:disabled, body select:disabled, body textarea:disabled { background: var(--sunken); color: var(--muted); cursor: not-allowed; }
body input[type=checkbox], body input[type=radio] { width: 15px; height: 15px; min-height: 0; accent-color: var(--brand); cursor: pointer; }
body input[type=range] { width: 100%; min-height: 0; padding: 0; border: 0; accent-color: var(--brand); }
body input[type=file] { padding: 4px; font-size: var(--t-sm); }
body input.mono, body textarea.mono { font-family: var(--mono); font-size: 12.5px; }
.tc-check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--t-base); color: var(--ink-2); cursor: pointer; }

/* ---------------------------------------------------------------- status + badges */
.tc-status {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: var(--t-sm); font-weight: 520; white-space: nowrap; background: var(--idle-soft); color: var(--idle);
}
.tc-status i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.tc-status.s-success, .tc-status.s-active { background: var(--ok-soft); color: var(--ok); }
.tc-status.s-failed { background: var(--bad-soft); color: var(--bad); }
.tc-status.s-running, .tc-status.s-queued { background: var(--run-soft); color: var(--run); }
.tc-status.s-running i { animation: tcPulse 1.2s ease-in-out infinite; }
.tc-status.s-draft { background: var(--warn-soft); color: var(--warn); }
.tc-status.s-archived, .tc-status.s-canceled { background: var(--idle-soft); color: var(--idle); }
@keyframes tcPulse { 50% { opacity: .35; } }

.tc-badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: var(--r-sm);
  font-size: var(--t-xs); font-weight: 520; white-space: nowrap; background: var(--idle-soft); color: var(--ink-2);
}
.b-success { background: var(--ok-soft); color: var(--ok); }
.b-failed { background: var(--bad-soft); color: var(--bad); }
.b-running { background: var(--run-soft); color: var(--run); }
.b-neutral { background: var(--idle-soft); color: var(--ink-2); }
.b-accent { background: var(--brand-soft); color: var(--brand-ink); }
.b-warm { background: var(--accent-soft); color: var(--accent-ink); }
.tc-tag {
  display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 6px; border-radius: var(--r-sm);
  font-family: var(--mono); font-size: 11px; color: var(--ink-2); border: 1px solid var(--line); background: var(--surface-2);
}
.tc-tag.safe { color: var(--ok); border-color: var(--ok-line); background: var(--ok-soft); }

/* ---------------------------------------------------------------- tables & lists */
.tc-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--t-base); }
.tc-table th {
  text-align: left; font-size: var(--t-xs); font-weight: 560; color: var(--muted); letter-spacing: .02em;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
.tc-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tc-table tr:last-child td { border-bottom: 0; }
.tc-table tbody tr { transition: background .1s; }
.tc-table tbody tr:hover { background: var(--surface-2); }
.tc-table tbody tr.is-link { cursor: pointer; }
.tc-table .primary { font-weight: 550; color: var(--ink); text-decoration: none; }
.tc-table .primary:hover { color: var(--brand-ink); }
.tc-table .meta { font-size: var(--t-sm); color: var(--muted); }
.tc-table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.tc-table-wrap .scroll { overflow-x: auto; }

.tc-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tc-search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.tc-search .tc-icon { position: absolute; left: 10px; top: 8px; color: var(--faint); pointer-events: none; }
body .tc-search input { padding-left: 32px; }
.tc-seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--r-md); background: var(--sunken); border: 1px solid var(--line); }
.tc-seg button, .tc-seg a {
  height: 26px; padding: 0 10px; border-radius: var(--r); border: 0; background: none; font: inherit;
  font-size: var(--t-sm); font-weight: 520; color: var(--muted); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.tc-seg button:hover, .tc-seg a:hover { color: var(--ink); }
.tc-seg .on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(19, 23, 31, .08); }

.tc-empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.tc-empty .ic { width: 40px; height: 40px; border-radius: var(--r-md); margin: 0 auto 12px; display: flex; align-items: center; justify-content: center; background: var(--sunken); color: var(--muted); }
.tc-empty h3 { font-size: var(--t-md); font-weight: 600; color: var(--ink); margin: 0 0 4px; }
.tc-empty p { max-width: 380px; margin: 0 auto 16px; }

/* ---------------------------------------------------------------- drawer */
.tc-drawer-bg { position: fixed; inset: 0; background: var(--overlay); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .16s; }
.tc-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 91; background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow-drawer); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .18s ease;
}
.tc-drawer.open { transform: none; }
.tc-drawer.open + .tc-drawer-bg, .tc-drawer-bg.open { opacity: 1; pointer-events: auto; }
.tc-drawer header { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 52px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tc-drawer .body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.tc-drawer footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.tc-fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; }
.tc-fieldset legend { font-size: var(--t-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.tc-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------------------------------------------------------------- toasts */
.tc-toasts { position: fixed; top: 14px; right: 16px; z-index: 120; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.tc-toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-pop); font-size: var(--t-base); color: var(--ink);
  animation: tcIn .18s ease-out;
}
.tc-toast.t-success .tc-icon { color: var(--ok); }
.tc-toast.t-error { border-color: var(--bad-line); }
.tc-toast.t-error .tc-icon { color: var(--bad); }
.tc-toast.t-info .tc-icon, .tc-toast.t-warning .tc-icon { color: var(--brand); }
@keyframes tcIn { from { opacity: 0; transform: translateY(-4px); } }

/* ---------------------------------------------------------------- brand mark */
.tc-mark-bg { fill: var(--accent); }

/* =====================================================================
   Scenario editor
   ===================================================================== */
.ed { display: flex; flex-direction: column; min-height: 100%; }
.ed-bar {
  display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; flex-wrap: wrap;
}
.ed-bar .back { color: var(--muted); }
body .ed-name {
  border-color: transparent; background: transparent; font-size: var(--t-lg); font-weight: 600; letter-spacing: -.015em;
  width: clamp(180px, 22vw, 380px); padding: 4px 8px; height: 34px; min-height: 0;
}
body .ed-name:hover { border-color: var(--line-strong); }
.ed-meta { display: flex; align-items: center; gap: 8px; min-width: 0; }
body .ed-meta select { max-width: 190px; }
@media (max-width: 1023px) { .ed-meta { flex-wrap: wrap; width: 100%; } body .ed-meta .ed-name { width: 100%; } }
.ed-bar .sep { width: 1px; height: 20px; background: var(--line); }
body .ed-bar select { width: auto; min-width: 150px; height: var(--h-sm); min-height: 0; padding: 0 28px 0 8px; font-size: var(--t-sm); }
.ed-save-state { font-size: var(--t-sm); color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.ed-save-state.dirty { color: var(--warn); }
.ed-grow { flex: 1; }

.ed-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 256px minmax(0, 1fr) 340px; }
.ed-lib, .ed-insp { background: var(--surface); overflow-y: auto; min-height: 0; }
.ed-lib { border-right: 1px solid var(--line); padding: 12px; }
.ed-insp { border-left: 1px solid var(--line); }
@media (max-width: 1279px) { .ed-body { grid-template-columns: 220px minmax(0, 1fr) 300px; } }
@media (max-width: 1023px) {
  .ed-body { grid-template-columns: 1fr; }
  .ed-lib { border-right: 0; border-bottom: 1px solid var(--line); max-height: 260px; }
  .ed-insp { border-left: 0; border-top: 1px solid var(--line); }
}

.lib-group { margin-top: 14px; }
.lib-group h4 { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 4px 4px; }
.lib-item {
  width: 100%; display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: var(--r); text-align: left;
  border: 1px solid transparent; background: none; font: inherit; color: var(--ink); cursor: grab;
}
.lib-item:hover { background: var(--hover); border-color: var(--line); }
.lib-item:active { cursor: grabbing; }
.lib-item .ic { width: 26px; height: 26px; border-radius: var(--r); flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: var(--sunken); color: var(--ink-2); }
.lib-item .t { font-size: var(--t-base); font-weight: 520; line-height: 1.2; }
.lib-item .d { font-size: var(--t-xs); color: var(--muted); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item > .min-w-0 { min-width: 0; flex: 1; }
.lib-item.comp .ic { background: var(--accent-soft); color: var(--accent-ink); }

/* Category hue — used only on the small icon tile + node rail */
[data-cat="nav"]    { --cat: #2859e8; --cat-soft: var(--brand-soft); }
[data-cat="act"]    { --cat: #7a5af5; --cat-soft: rgba(122, 90, 245, .12); }
[data-cat="assert"] { --cat: #16815d; --cat-soft: var(--ok-soft); }
[data-cat="api"]    { --cat: #c4471f; --cat-soft: var(--accent-soft); }
[data-cat="util"]   { --cat: #69717f; --cat-soft: var(--idle-soft); }
[data-cat="comp"]   { --cat: #ff805a; --cat-soft: var(--accent-soft); }
html[data-theme="dark"] [data-cat="act"] { --cat: #a28cff; }
html[data-theme="dark"] [data-cat="assert"] { --cat: #43c093; }
html[data-theme="dark"] [data-cat="api"] { --cat: #ff9f80; }
html[data-theme="dark"] [data-cat="nav"] { --cat: #7b9cf8; }
.lib-item[data-cat] .ic { background: var(--cat-soft); color: var(--cat); }

.ed-canvas { overflow-y: auto; min-height: 0; padding: 24px 24px 80px; background: var(--canvas); }
.flow { max-width: 680px; margin: 0 auto; position: relative; }
.flow-start {
  display: flex; align-items: center; gap: 8px; font-size: var(--t-sm); color: var(--muted); margin-bottom: 8px; padding-left: 4px;
}
.flow-start .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.step {
  position: relative; display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  min-height: 52px; padding: 8px 10px 8px 0; margin-left: 4px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; user-select: none;
  transition: border-color .12s, box-shadow .12s, opacity .12s;
}
.step::before { content: ""; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 3px; border-radius: var(--r-md) 0 0 var(--r-md); background: var(--cat, var(--line-strong)); }
.step:hover { border-color: var(--line-strong); }
.step.selected { border-color: var(--brand); box-shadow: var(--focus); }
.step.invalid { border-color: var(--warn-line); }
.step.dragging { opacity: .4; }
.step .num { font-family: var(--mono); font-size: 11px; color: var(--faint); text-align: right; }
.step .head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.step .head .tc-icon { color: var(--cat, var(--muted)); }
.step .kind { font-size: var(--t-base); font-weight: 560; color: var(--ink); white-space: nowrap; }
.step .detail { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.step .detail.el { font-family: var(--font); color: var(--brand-ink); }
.step .warn { color: var(--warn); display: inline-flex; }
.step .acts { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.step:hover .acts, .step.selected .acts { opacity: 1; }
.step .grip { color: var(--faint); cursor: grab; display: inline-flex; }
.step-sub { font-size: var(--t-xs); color: var(--muted); margin-top: 2px; }
/* Gap between steps doubles as connector + drop target */
.drop-line { height: 12px; margin-left: 4px; position: relative; }
.drop-line::before { content: ""; position: absolute; left: 22px; top: 0; bottom: 0; border-left: 1px solid var(--line-strong); }
.flow-start + .drop-line::before { display: none; }
.drop-line.on::after { content: ""; position: absolute; left: 0; right: 0; top: 4px; height: 3px; border-radius: 3px; background: var(--brand); }
.flow-end {
  margin: 10px 0 0 4px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); min-height: 52px;
  display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: var(--t-sm);
  transition: border-color .12s, background .12s, color .12s;
}
.flow-end.on, .flow-end:hover { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); }
.flow-empty { text-align: center; padding: 56px 24px; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); color: var(--muted); }
.flow-empty h3 { font-size: var(--t-md); color: var(--ink); margin: 8px 0 4px; font-weight: 600; }

.insp-head { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.insp-head .t { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insp-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.insp-empty { padding: 32px 18px; color: var(--muted); font-size: var(--t-base); }
.insp-empty h4 { color: var(--ink); font-weight: 600; margin: 0 0 6px; font-size: var(--t-base); }
.insp-empty ul { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.insp-note { font-size: var(--t-xs); color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; }
.insp-actions { display: flex; gap: 6px; padding: 12px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* Scenario list */
.src-claude { display: inline-flex; align-items: center; gap: 4px; font-size: var(--t-xs); color: var(--accent-ink); }

/* =====================================================================
   Lumi assistant
   ===================================================================== */
#lumi-orb {
  position: fixed; right: 18px; bottom: 18px; z-index: 70; height: 36px; padding: 0 12px 0 10px; border-radius: 18px;
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font: inherit; font-size: var(--t-base); font-weight: 550;
  background: var(--nav-bg); color: #fff; border: 1px solid rgba(255, 255, 255, .08); box-shadow: var(--shadow-pop);
  transition: transform .12s, background .12s;
}
#lumi-orb:hover { transform: translateY(-1px); }
#lumi-orb .tc-icon { color: var(--accent); }
#lumi-panel {
  position: fixed; right: 18px; bottom: 64px; z-index: 70; width: min(380px, calc(100vw - 36px)); height: min(560px, calc(100vh - 100px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  display: none; flex-direction: column; overflow: hidden;
}
#lumi-panel.open { display: flex; animation: tcIn .16s ease-out; }
.lumi-head { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 10px 0 14px; border-bottom: 1px solid var(--line); }
.lumi-head .mk { width: 26px; height: 26px; border-radius: var(--r); background: var(--accent-soft); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; }
.lumi-head b { font-size: var(--t-md); font-weight: 600; display: block; line-height: 1.15; }
.lumi-head span { font-size: var(--t-xs); color: var(--muted); }
.lumi-tabs { padding: 10px 12px 0; }
.lumi-body { flex: 1; overflow-y: auto; }
.lumi-guides { padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.lumi-intro { font-size: var(--t-base); color: var(--muted); margin: 2px 2px 6px; }
.guide-card {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--r-md); text-align: left; width: 100%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font: inherit;
}
.guide-card:hover { border-color: var(--line-strong); background: var(--surface-2); }
.guide-ic { width: 32px; height: 32px; border-radius: var(--r); display: flex; align-items: center; justify-content: center; background: var(--sunken); color: var(--ink-2); flex-shrink: 0; }
.guide-card h4 { font-size: var(--t-base); font-weight: 560; margin: 0; }
.guide-card p { font-size: var(--t-xs); color: var(--muted); margin: 1px 0 0; }
.guide-card .tc-icon.chev { margin-left: auto; color: var(--faint); }
.lumi-ctx { font-size: var(--t-xs); color: var(--muted); padding: 8px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 5px; }
.lumi-msgs { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.lumi-msg { max-width: 88%; padding: 8px 11px; border-radius: var(--r-md); font-size: var(--t-base); line-height: 1.5; white-space: pre-wrap; }
.lumi-msg.bot { background: var(--sunken); color: var(--ink); align-self: flex-start; }
.lumi-msg.me { background: var(--brand); color: #fff; align-self: flex-end; }
.lumi-input { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.lumi-suggest {
  font: inherit; font-size: var(--t-sm); color: var(--ink-2); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r); padding: 3px 9px; cursor: pointer;
}
.lumi-suggest:hover { border-color: var(--brand); color: var(--brand-ink); }

/* Guided tour */
#tc-tour-spot {
  position: fixed; z-index: 9998; border-radius: var(--r-md); pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(15, 18, 24, .55), 0 0 0 2px var(--accent); transition: all .2s ease;
}
#tc-tour-spot.pulse { animation: none; }
#tc-tour-tip {
  position: fixed; z-index: 9999; width: min(320px, calc(100vw - 32px)); background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 14px;
}
#tc-tour-tip .tt-step { font-size: var(--t-xs); font-weight: 600; color: var(--accent-ink); display: flex; align-items: center; gap: 6px; }
#tc-tour-tip h4 { font-size: var(--t-md); font-weight: 600; margin: 6px 0 4px; }
#tc-tour-tip p { font-size: var(--t-base); line-height: 1.5; color: var(--ink-2); white-space: pre-line; margin: 0; }
#tc-tour-tip .tt-actions { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
#tc-tour-tip .tt-spacer { flex: 1; }

/* Theme toggle icon */
html[data-theme="light"] .theme-dark, html:not([data-theme="dark"]) .theme-dark { display: none; }
html[data-theme="dark"] .theme-light { display: none; }

/* Lumi · Claude chat */
#lumi-panel.wide { width: min(480px, calc(100vw - 36px)); height: min(700px, calc(100vh - 100px)); }
.lumi-connect { padding: 24px 14px; display: flex; justify-content: center; }
.lumi-msg code { font-family: var(--mono); font-size: 12px; background: var(--hover); padding: 0 4px; border-radius: 3px; }
.lumi-msg pre { font-family: var(--mono); font-size: 11.5px; background: var(--hover); padding: 8px; border-radius: var(--r); white-space: pre-wrap; margin: 6px 0; }
.lumi-msg a { color: var(--brand-ink); text-decoration: underline; }
.lumi-msg.me a { color: #fff; }
.lumi-tool {
  display: grid; grid-template-columns: 14px auto 1fr; column-gap: 6px; align-items: baseline; font-size: var(--t-sm);
  color: var(--muted); padding: 2px 4px;
}
.lumi-tool .tc-icon { color: var(--ok); align-self: center; }
.lumi-tool.bad .tc-icon { color: var(--bad); }
.lumi-tool .nm { color: var(--ink-2); font-weight: 520; white-space: nowrap; }
.lumi-tool .ar { font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lumi-tool .pv { grid-column: 2 / -1; font-size: var(--t-xs); }
.lumi-tool .pv a { color: var(--brand-ink); }
.lumi-note { font-size: var(--t-sm); color: var(--muted); padding: 2px 4px; display: flex; align-items: center; gap: 6px; }
.lumi-note.bad { color: var(--bad); }
.lumi-note.working .tc-icon { animation: tcSpin 1s linear infinite; }
@keyframes tcSpin { to { transform: rotate(360deg); } }
body .lumi-input textarea { min-height: 36px; max-height: 140px; resize: none; line-height: 1.45; padding: 7px 10px; }
.lumi-input .tc-btn { height: 36px; width: 36px; align-self: flex-end; }
