/* ---------------------------------------------------------
   AIGatewayX Console v4 design layer (loaded after main.css)
   - Part A: v4 tokens and components, ported from the approved prototype
     (aigatewayx-console-prototype-v4.html). Prototype-only parts (proto pill,
     sample toasts, review badges) are not ported.
   - Part B: v4 skin for the existing aigw-* classes, so screens that keep their
     current markup look the same as restructured ones. Scoped to body.v4.
   The console commits to one dark look, so tokens live on :root only.
---------------------------------------------------------- */

/* =========================================================
   Part A. Tokens
========================================================= */
:root {
  color-scheme: dark;
  --bg: #0a111d;
  --surface: #101a2b;
  --surface-2: #0d1625;
  --raise: #15223a;
  --line: #22314a;
  --line-soft: #19253a;
  --fg: #e8eef7;
  --muted: #a3b3ca;
  --faint: #7686a0;
  --accent: #4cb3ff;
  --accent-strong: #2f8ae0;
  --accent-soft: #15304f;
  --ok: #4fd69a;   --ok-bg: #0f2e21;   --ok-line: #1d5a3f;
  --warn: #f5c46a; --warn-bg: #2f240c; --warn-line: #5c4612;
  --bad: #ff9aa0;  --bad-bg: #351519;  --bad-line: #7a3b3f;
  --font: "IBM Plex Sans KR", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r: 10px;
  --r-sm: 8px;
  --nav-w: 248px;
}

body.v4 * { box-sizing: border-box; }
body.v4 [hidden] { display: none !important; }
html:has(body.v4), body.v4 { background: var(--bg); color: var(--fg); }
body.v4 { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
body.v4 a { color: var(--accent); text-underline-offset: 3px; }
body.v4 a:hover { color: #9fd3ff; }
body.v4 h1, body.v4 h2, body.v4 h3, body.v4 h4 { text-wrap: balance; margin: 0; }
body.v4 button, body.v4 input, body.v4 select, body.v4 textarea { font: inherit; color: inherit; }
body.v4 :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
body.v4 code, .mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { body.v4 * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }
.nav { position: sticky; top: 0; height: 100vh; width: var(--nav-w); flex: 0 0 var(--nav-w); background: var(--surface-2); border-right: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 18px; padding: 18px 12px; overflow-y: auto; transition: width .18s ease, flex-basis .18s ease; z-index: 30; }
.nav-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; padding: 0 6px; min-height: 44px; }
body.v4 a.brand, body.v4 a.brand:hover { color: var(--fg); }
.brand strong { font-size: 17px; letter-spacing: -0.01em; }
.brand svg, .brand img { flex: 0 0 auto; }
.acct { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); }
.acct small { color: var(--faint); font-size: 12px; }
.acct b { font-size: 14px; overflow-wrap: anywhere; }
.acct span { color: var(--accent); font-size: 12px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group > span { font-size: 12px; color: var(--faint); padding: 0 12px 6px; letter-spacing: 0.02em; }
body.v4 .nav-item { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: var(--r-sm); color: #c5d2e4; text-decoration: none; font-size: 14px; }
body.v4 .nav-item:hover { background: #142036; color: var(--fg); }
body.v4 .nav-item[aria-current="page"] { background: var(--accent-soft); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-item svg { flex: 0 0 20px; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px; border-top: 1px solid var(--line-soft); }
.nav-foot .who { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.nav-foot form { margin: 0; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: #c5d2e4; cursor: pointer; flex: 0 0 auto; }
.icon-btn:hover { border-color: #33476a; color: var(--fg); }
.menu-close { display: none; }

.app.collapsed .nav { width: 72px; flex-basis: 72px; }
.app.collapsed .nav .brand strong, .app.collapsed .nav .acct, .app.collapsed .nav-group > span, .app.collapsed .nav-item span, .app.collapsed .nav-foot { display: none; }
.app.collapsed .nav-head { flex-direction: column; }
body.v4 .app.collapsed .nav-item { justify-content: center; padding: 0; }
.app.collapsed .nav-group + .nav-group { border-top: 1px solid var(--line-soft); padding-top: 10px; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 12px; min-height: 60px; padding-block: 10px; padding-left: max(32px, env(safe-area-inset-left, 0px)); padding-right: max(32px, env(safe-area-inset-right, 0px)); background: rgba(10, 17, 29, 0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line-soft); }
.topbar .menu-btn { display: none; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; font-size: 13px; color: var(--faint); }
body.v4 .crumbs a { color: var(--muted); text-decoration: none; }
body.v4 .crumbs a:hover { color: var(--fg); text-decoration: underline; }
.crumbs b { color: var(--fg); font-weight: 500; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { width: 100%; max-width: 1440px; padding-block: 28px 64px; padding-left: max(32px, env(safe-area-inset-left, 0px)); padding-right: max(32px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 20px; }
.content > section { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.scrim { display: none; }

@media (max-width: 959px) {
  .nav { position: fixed; left: 0; top: 0; bottom: 0; height: 100%; width: 280px; flex-basis: 280px; transform: translateX(-100%); transition: transform .2s ease; padding-top: calc(18px + env(safe-area-inset-top, 0px)); padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); padding-left: calc(12px + env(safe-area-inset-left, 0px)); }
  .app.mnav .nav { transform: none; box-shadow: 16px 0 40px rgba(0,0,0,.5); }
  .app.mnav .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 25; }
  .nav .collapse-btn { display: none; }
  .app.mnav .menu-close { display: inline-flex; }
  .app.collapsed .nav { width: 280px; flex-basis: 280px; }
  .app.collapsed .nav .brand strong, .app.collapsed .nav .acct, .app.collapsed .nav-group > span, .app.collapsed .nav-item span { display: revert; }
  .app.collapsed .nav-foot { display: flex; }
  body.v4 .app.collapsed .nav-item { justify-content: flex-start; padding: 0 12px; }
  .app.collapsed .nav-head { flex-direction: row; }
  .topbar { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 20px 56px; }
  .crumbs > a, .crumbs > span { display: none; }
  .crumbs b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
}

/* ---------- page head ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head .t { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 320px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.25; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; max-width: 72ch; }
.page-head .acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.page-head .sub-h { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
body.v4 .back { font-size: 13px; text-decoration: none; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; min-height: 32px; }
body.v4 .back:hover { color: var(--fg); }

/* ---------- buttons ---------- */
body.v4 .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--r-sm); border: 1px solid var(--line); background: transparent; color: var(--fg); font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; }
body.v4 .btn:hover { border-color: #3a5179; background: #13203a; color: var(--fg); }
body.v4 .btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
body.v4 .btn.primary:hover { background: #3d97ec; }
body.v4 .btn.danger { border-color: var(--bad-line); color: var(--bad); }
body.v4 .btn.danger:hover { background: var(--bad-bg); color: #ffc2c6; }
body.v4 .btn.danger.solid { background: #b4323c; border-color: #b4323c; color: #fff; }
body.v4 .btn.ghost { border-color: transparent; color: var(--muted); }
body.v4 .btn.ghost:hover { color: var(--fg); background: #13203a; }
body.v4 .btn.sm { height: 34px; padding: 0 12px; font-size: 13px; }
body.v4 .btn.lg { height: 46px; padding: 0 20px; font-size: 15px; }
body.v4 .btn[disabled], body.v4 .btn.disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row form { margin: 0; display: inline-flex; }
body.v4 .link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }
body.v4 .link-btn.danger { color: var(--bad); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.card-head h2 { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.card-head .sub { font-size: 13px; color: var(--faint); }
.card p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-32 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 1180px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-21, .g-32 { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .g-4, .g-3, .g-2 { grid-template-columns: 1fr; } }

.kpi { display: flex; flex-direction: column; gap: 6px; padding: 18px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.kpi .lbl { display: flex; align-items: center; gap: 2px; font-size: 13px; color: var(--muted); }
.kpi .val { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; line-height: 1.2; overflow-wrap: anywhere; }
.kpi .sub { font-size: 13px; color: #c5d2e4; }
.kpi a { font-size: 13px; margin-top: 2px; }
.bar { position: relative; display: block; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.bar.warn > i { background: #f5a524; }
.bar.bad > i { background: #e5484d; }
.bar.lg { height: 14px; border-radius: 7px; overflow: visible; }
.bar.lg > i { border-radius: 7px; }

/* ---------- table ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { font-size: 12px; font-weight: 500; color: var(--muted); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: none; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; }
.tbl .c { text-align: center; }
.tbl .nw { white-space: nowrap; }
.tbl tfoot td { font-weight: 700; border-top: 1px solid var(--line); border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover td { background: #121e33; }
.tbl .sub { display: block; font-size: 12px; color: var(--faint); margin-top: 2px; }
body.v4 .tbl .name { font-weight: 600; color: var(--fg); text-decoration: none; white-space: nowrap; }
body.v4 .tbl a.name:hover { color: var(--accent); }
.tbl .acts { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; align-items: center; }
.tbl .acts form { margin: 0; display: inline-flex; }
.tbl .dim td { color: var(--faint); }
.share { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.share .bar { flex: 1 1 auto; }
.share span { font-size: 12px; color: var(--muted); width: 44px; text-align: right; }
@media (max-width: 720px) { .hide-sm { display: none; } }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--line); color: #c5d2e4; border: 1px solid transparent; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.chip.plain::before { display: none; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
.chip.info { background: var(--accent-soft); color: #9fd3ff; border-color: #24496f; }
.chip.off { background: transparent; color: var(--faint); border-color: var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lock { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--faint); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 18px; max-width: 720px; }
.form.wide { max-width: 960px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 2px; margin: 0; }
.field .hint { font-size: 12px; color: var(--faint); }
.field .err { font-size: 12px; color: var(--bad); }
body.v4 .inp, body.v4 select.inp, body.v4 textarea.inp { height: 42px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid #2b3d5c; background: var(--surface-2); color: var(--fg); font-size: 14px; width: 100%; min-width: 0; box-shadow: none; }
body.v4 textarea.inp { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
body.v4 .inp:hover { border-color: #39507a; }
body.v4 .inp:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(76, 179, 255, 0.18); }
body.v4 .inp[readonly] { color: var(--muted); background: #0b1320; }
body.v4 .inp.mono { font-family: var(--mono); font-size: 13px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 720px) { .row2, .row3 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 10px; min-height: 32px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent-strong); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; min-height: 32px; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; cursor: pointer; flex: 0 0 auto; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #c5d2e4; transition: transform .15s; }
.switch input:checked { background: var(--accent-strong); }
.switch input:checked::after { transform: translateX(16px); background: #fff; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 6px; }
.fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 16px; margin: 0; min-width: 0; }
.fieldset legend { padding: 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.slider-row { display: grid; grid-template-columns: 140px minmax(0, 1fr) 64px; gap: 12px; align-items: center; font-size: 14px; }
.slider-row input[type="range"] { width: 100%; accent-color: var(--accent-strong); }
.slider-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
@media (max-width: 520px) { .slider-row { grid-template-columns: 1fr 64px; } .slider-row input { grid-column: 1 / -1; grid-row: 2; } }

/* ---------- filter bar & tabs ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; padding: 16px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.filters .field { min-width: 160px; }
.filters .grow { margin-left: auto; }
.filters form { display: contents; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
body.v4 .tab { display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px; border: 0; border-bottom: 2px solid transparent; background: none; color: #c5d2e4; text-decoration: none; font-size: 14px; white-space: nowrap; cursor: pointer; }
body.v4 .tab:hover { color: var(--fg); }
body.v4 .tab[aria-selected="true"], body.v4 .tab[aria-current="page"] { color: #fff; font-weight: 600; border-bottom-color: var(--accent); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line-soft); }
body.v4 .seg a, body.v4 .seg button { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; border-radius: 7px; border: 0; background: none; color: #c5d2e4; text-decoration: none; font-size: 14px; cursor: pointer; }
body.v4 .seg [aria-selected="true"], body.v4 .seg [aria-current="page"] { background: var(--accent-soft); color: #fff; font-weight: 600; }

/* ---------- notices ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2); font-size: 14px; line-height: 1.55; }
.notice svg { flex: 0 0 18px; margin-top: 2px; }
.notice b { display: block; margin-bottom: 2px; }
.notice.warn { border-color: var(--warn-line); background: var(--warn-bg); color: #f0dcae; }
.notice.warn b { color: var(--warn); }
.notice.ok { border-color: var(--ok-line); background: var(--ok-bg); color: #c4ecd8; }
.notice.ok b { color: var(--ok); }
.notice.bad { border-color: var(--bad-line); background: var(--bad-bg); color: #f6cfd2; }
.notice.bad b { color: var(--bad); }
.notice .grow { flex: 1 1 auto; min-width: 0; }
.notice p { margin: 0; }

/* ---------- empty / states ---------- */
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 28px; border: 1px dashed #2b3d5c; border-radius: var(--r); background: var(--surface-2); }
.empty .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty.err .ico { background: var(--bad-bg); color: var(--bad); }
.empty.gate .ico { background: var(--warn-bg); color: var(--warn); }
.empty h3 { font-size: 16px; }
.empty p { margin: 0; color: var(--muted); max-width: 60ch; }
.skel { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, #15223a 0%, #1d2d49 50%, #15223a 100%); background-size: 200% 100%; animation: skel 1.4s ease-in-out infinite; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- steps / dl ---------- */
.steps { display: flex; flex-direction: column; }
.step { display: flex; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line-soft); }
.step:last-child { border-bottom: 0; }
.step .dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; flex: 0 0 auto; background: var(--line); color: var(--muted); }
.step.done .dot { background: var(--ok-bg); color: var(--ok); }
.step .lbl { flex: 1 1 auto; min-width: 0; }
.step .det { font-size: 13px; color: var(--faint); }
.dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 20px; margin: 0; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.dl.r dd { text-align: right; }

/* ---------- code ---------- */
.code { position: relative; border-radius: var(--r-sm); background: #070d17; border: 1px solid var(--line-soft); }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.65; color: #c9d6ea; }
.code .copy { position: absolute; top: 8px; right: 8px; }
.secret { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px; border-radius: var(--r-sm); background: #070d17; border: 1px solid var(--warn-line); }
.secret code { font-size: 14px; overflow-wrap: anywhere; flex: 1 1 260px; color: #ffe2a8; }

/* ---------- info popover ---------- */
.info { position: relative; display: inline-flex; vertical-align: middle; }
.info > button { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; margin: -6px -2px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--faint); cursor: pointer; }
.info > button:hover, .info.open > button { color: var(--accent); }
.info .pop { display: none; position: absolute; top: 26px; left: -8px; z-index: 15; width: 260px; max-width: calc(100vw - 48px); padding: 12px 14px; border-radius: var(--r-sm); background: var(--raise); border: 1px solid #2f4468; box-shadow: 0 12px 28px rgba(0,0,0,.45); font-size: 13px; font-weight: 400; line-height: 1.6; color: var(--fg); text-align: left; white-space: normal; letter-spacing: 0; }
.info.right .pop { left: auto; right: -8px; }
.info.open .pop { display: block; }

/* ---------- modal (confirm dialogs, console-v4.js) ---------- */
.overlay { position: fixed; inset: 0; z-index: 70; background: rgba(3, 7, 14, 0.66); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border: 1px solid #2b3d5c; border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.55); padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { font-size: 18px; }
.modal p { margin: 0; color: #c5d2e4; white-space: pre-line; }
.modal .form-actions { justify-content: flex-end; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding-block: 32px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); background: radial-gradient(900px 420px at 50% -10%, #12305a 0%, rgba(10,17,29,0) 70%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 22px; padding: 28px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 30px 70px rgba(0,0,0,.4); }
.auth-card .brand { justify-content: center; }
.auth-card h1 { font-size: 20px; text-align: center; }
.auth-card .center { text-align: center; color: var(--muted); font-size: 13px; }
.auth-card form { margin: 0; }
.otp { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.otp input { height: 52px; text-align: center; font-size: 20px; font-family: var(--mono); padding: 0; }

/* ---------- misc ---------- */
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart .val { fill: #c5d2e4; }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; align-items: end; height: 170px; }
.days > div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; font-size: 12px; color: var(--muted); }
.days i { display: block; width: 100%; max-width: 52px; border-radius: 4px 4px 0 0; background: var(--accent); }
.plan-tbl td:nth-child(4), .plan-tbl th:nth-child(4) { background: rgba(76,179,255,.06); }
.prompt-prev { font-size: 13px; color: #c5d2e4; max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
details.adv { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); padding: 0 20px; }
details.adv > summary { cursor: pointer; min-height: 52px; display: flex; align-items: center; font-weight: 600; list-style: none; gap: 8px; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: "\25B8"; color: var(--faint); transition: transform .15s; }
details.adv[open] > summary::before { transform: rotate(90deg); }
details.adv > div { padding-bottom: 20px; display: flex; flex-direction: column; gap: 14px; }
.danger-zone { border-color: var(--bad-line); }
.danger-zone h2 { color: var(--bad); }
.sec-title { font-size: 13px; font-weight: 600; color: var(--faint); letter-spacing: 0.04em; margin-top: 8px; }
.kbd { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.pager { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }

/* =========================================================
   Part B. v4 skin for existing aigw-* markup (body.v4 only)
========================================================= */
/* Boxes that a script reveals with an inline style (aigw-flatpickr-range.js period errors) start hidden even when
   they also carry a v4 display class such as .notice. */
body.v4 .aigw-js-hidden { display: none; }

body.v4.aigw-body { background: var(--bg); color: var(--fg); font-family: var(--font); }
body.v4 .aigw-shell { min-height: 100vh; overflow-x: visible; }
body.v4 .aigw-main { background: none; overflow-x: visible; }
body.v4 .aigw-content { padding: 0; overflow-x: visible; }
body.v4 .aigw-footer { padding: 16px 32px 24px; border-top: 1px solid var(--line-soft); color: var(--faint); font-size: 12px; background: none; }

/* scope strip and breadcrumb parts kept from the 2026-10-06 shell */
body.v4 .aigw-scope-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0; padding: 10px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; color: var(--muted); }
body.v4 .aigw-scope-badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: #9fd3ff; border: 1px solid #24496f; }
body.v4 .aigw-scope-badge-project { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
body.v4 .aigw-scope-value { color: var(--fg); font-weight: 600; }
body.v4 .aigw-scope-note { color: var(--faint); }
body.v4 .aigw-help-link { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: transparent; color: var(--fg); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; }
body.v4 .aigw-help-link:hover { border-color: #3a5179; background: #13203a; }
body.v4 .aigw-breadcrumb-sep { color: var(--faint); }

/* help drawer = v4 help panel */
body.v4 .aigw-help-drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: 420px; max-width: 100%; display: flex; flex-direction: column; background: var(--surface-2); border-left: 1px solid #2b3d5c; box-shadow: -16px 0 40px rgba(0,0,0,.45); padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) 0; color: var(--fg); }
body.v4 .aigw-help-drawer[hidden] { display: none !important; }
body.v4 .aigw-help-drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
body.v4 .aigw-help-drawer-title { font-size: 16px; font-weight: 600; margin: 0; }
body.v4 .aigw-help-drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 20px; }
body.v4 .aigw-help-article h3 { font-size: 18px; margin-bottom: 8px; }
body.v4 .aigw-help-ref { font-size: 13px; color: var(--faint); }

/* panels and cards */
body.v4 .aigw-panel, body.v4 .aigw-card, body.v4 .aigw-form-section-card, body.v4 .aigw-meta-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: none; padding: 20px; }
body.v4 .aigw-panel + .aigw-panel, body.v4 .aigw-card + .aigw-card { margin-top: 20px; }
body.v4 .aigw-form-section-card-muted { background: var(--surface-2); }
body.v4 .aigw-panel-title, body.v4 .aigw-card-title, body.v4 .aigw-form-section-title, body.v4 .aigw-section-title { font-size: 16px; font-weight: 600; color: var(--fg); }
body.v4 .aigw-panel-desc, body.v4 .aigw-panel-subtitle, body.v4 .aigw-form-section-desc, body.v4 .aigw-page-help, body.v4 .aigw-help-text { color: var(--muted); font-size: 13px; }
body.v4 .aigw-card-header, body.v4 .aigw-panel-header { border-bottom: 0; background: none; padding: 0 0 12px; }
body.v4 .aigw-card-body, body.v4 .aigw-panel-body { padding: 0; }
body.v4 .aigw-summary-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: none; }
body.v4 .aigw-summary-label { color: var(--muted); font-size: 13px; }
body.v4 .aigw-summary-value { color: var(--fg); font-variant-numeric: tabular-nums; }

/* tables */
body.v4 .aigw-table { font-size: 14px; font-variant-numeric: tabular-nums; margin-top: 0; }
body.v4 .aigw-table th { background: none; color: var(--muted); font-size: 12px; font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--line); }
body.v4 .aigw-table td { padding: 12px; border-bottom: 1px solid var(--line-soft); color: var(--fg); background: none; }
body.v4 .aigw-table th:not(:last-child), body.v4 .aigw-table td:not(:last-child) { border-right: 0; }
body.v4 .aigw-table tbody tr:hover td { background: #121e33; }
body.v4 .aigw-table-link { color: var(--fg); font-weight: 600; text-decoration: none; }
body.v4 .aigw-table-link:hover { color: var(--accent); }

/* buttons */
body.v4 .aigw-btn { min-height: 40px; height: auto; padding: 0 16px; border-radius: var(--r-sm); border: 1px solid var(--line); background: transparent; color: var(--fg); font-size: 14px; font-weight: 500; gap: 8px; }
body.v4 .aigw-btn:hover { border-color: #3a5179; background: #13203a; color: var(--fg); }
body.v4 .aigw-btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
body.v4 .aigw-btn-primary:hover { background: #3d97ec; border-color: #3d97ec; color: #fff; }
body.v4 .aigw-btn-secondary, body.v4 .aigw-btn-search, body.v4 .aigw-btn-info, body.v4 .aigw-btn-light { border-color: var(--line); color: var(--fg); background: transparent; }
body.v4 .aigw-btn-danger { border-color: var(--bad-line); color: var(--bad); background: transparent; }
body.v4 .aigw-btn-danger:hover { background: var(--bad-bg); color: #ffc2c6; border-color: var(--bad-line); }
body.v4 .aigw-btn-ghost { border-color: transparent; color: var(--muted); }
body.v4 .aigw-btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
body.v4 .aigw-btn-xs { min-height: 28px; padding: 0 10px; font-size: 12px; }
body.v4 .aigw-btn-lg { min-height: 46px; padding: 0 20px; font-size: 15px; }
body.v4 .aigw-btn-disabled, body.v4 .aigw-btn[disabled] { opacity: .45; cursor: not-allowed; }

/* forms */
body.v4 .aigw-input, body.v4 .aigw-select, body.v4 .aigw-textarea { min-height: 42px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid #2b3d5c; background: var(--surface-2); color: var(--fg); font-size: 14px; }
body.v4 .aigw-textarea, body.v4 textarea.aigw-input { padding: 10px 12px; line-height: 1.5; }
body.v4 .aigw-input:hover, body.v4 .aigw-select:hover, body.v4 .aigw-textarea:hover { border-color: #39507a; }
body.v4 .aigw-input:focus, body.v4 .aigw-select:focus, body.v4 .aigw-textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(76, 179, 255, 0.18); }
body.v4 .aigw-input-readonly, body.v4 .aigw-input[readonly] { color: var(--muted); background: #0b1320; }
body.v4 .aigw-form-group label, body.v4 .aigw-field-label, body.v4 .aigw-label { font-size: 13px; color: var(--muted); font-weight: 500; }
body.v4 .aigw-field-hint, body.v4 .aigw-hint { font-size: 12px; color: var(--faint); }
body.v4 .aigw-field-error, body.v4 .aigw-error { font-size: 12px; color: var(--bad); }
body.v4 .aigw-filter-bar { padding: 16px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); margin: 0 0 16px; }

/* alerts = v4 notices */
body.v4 .aigw-alert { border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); font-size: 14px; padding: 14px 16px; margin: 0 0 16px; }
body.v4 .aigw-alert-info { border-color: #24496f; background: var(--accent-soft); color: #cfe8ff; }
body.v4 .aigw-alert-success { border-color: var(--ok-line); background: var(--ok-bg); color: #c4ecd8; }
body.v4 .aigw-alert-warning, body.v4 .aigw-alert-warn { border-color: var(--warn-line); background: var(--warn-bg); color: #f0dcae; }
body.v4 .aigw-alert-danger, body.v4 .aigw-alert-error { border-color: var(--bad-line); background: var(--bad-bg); color: #f6cfd2; }

/* chips and badges = v4 chips */
body.v4 .aigw-status-chip, body.v4 .aigw-badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--line); color: #c5d2e4; border: 1px solid transparent; }
body.v4 .aigw-status-chip-success, body.v4 .aigw-badge-success { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
body.v4 .aigw-status-chip-warning, body.v4 .aigw-badge-warning { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
body.v4 .aigw-status-chip-danger { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
body.v4 .aigw-status-chip-info { background: var(--accent-soft); color: #9fd3ff; border-color: #24496f; }
body.v4 .aigw-status-chip-muted { background: transparent; color: var(--faint); border-color: var(--line); }

/* pagination */
body.v4 .aigw-pagination { gap: 4px; margin-top: 16px; }
body.v4 .aigw-page-link { min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--line); background: transparent; color: #c5d2e4; font-size: 13px; }
body.v4 .aigw-page-link:hover { border-color: #3a5179; background: #13203a; color: var(--fg); }
body.v4 .aigw-page-link-active { background: var(--accent-soft); border-color: #24496f; color: #fff; font-weight: 600; }

/* typed data states = v4 empty states */
body.v4 .aigw-data-state { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 24px; border: 1px dashed #2b3d5c; border-radius: var(--r); background: var(--surface-2); text-align: left; }
body.v4 .aigw-data-state-title { font-size: 16px; font-weight: 600; color: var(--fg); }
body.v4 .aigw-data-state-desc { color: var(--muted); max-width: 60ch; }
body.v4 .aigw-data-state-actions { display: flex; flex-wrap: wrap; gap: 8px; }
body.v4 .aigw-data-state-error, body.v4 .aigw-data-state-backend_unavailable { border-color: var(--bad-line); }
body.v4 .aigw-data-state-no_permission { border-color: var(--warn-line); }
body.v4 .aigw-data-state-row td { padding: 12px 0; border-bottom: 0; }
body.v4 .aigw-data-state-row:hover td { background: none; }

/* setup guide card (dashboard): main.css lays it out as a centred, wrapping row; as a v4 card it is a column */
body.v4 .card.aigw-setup-guide { flex-wrap: nowrap; align-items: stretch; justify-content: flex-start; margin: 0; padding: 20px; border: 1px solid #24496f; background: var(--surface); }
body.v4 .aigw-setup-guide-main { flex: 0 0 auto; }
body.v4 .aigw-setup-guide-title { margin: 0; font-size: 16px; font-weight: 600; }
body.v4 .aigw-setup-guide-desc { color: var(--muted); font-size: 14px; }
body.v4 .aigw-setup-guide-progress { margin: 0; color: var(--muted); align-items: flex-start; text-align: left; }
body.v4 .aigw-setup-guide-bar { width: min(320px, 100%); }
body.v4 .aigw-setup-guide-next { margin: 0; }

/* legacy layout classes kept next to v4 ones: main.css gives them row-layout sizing that breaks a v4 column */
body.v4 .field.aigw-form-group { display: flex; flex: 0 0 auto; margin: 0; padding: 0; }
body.v4 .form.aigw-org-invite-form { align-items: stretch; flex-wrap: nowrap; }
body.v4 .inp.aigw-filter-input-sm, body.v4 .inp.aigw-project-api-key-search-input { width: 240px; max-width: 100%; }

/* locale switcher in the nav foot */
body.v4 .nav-foot .aigw-locale-switcher { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
body.v4 .nav-foot .aigw-locale-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body.v4 .aigw-locale-select { height: 34px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid #2b3d5c; background: var(--surface-2); color: var(--fg); font-size: 13px; }

/* code blocks */
body.v4 .aigw-code-block, body.v4 .aigw-json-preview { border-radius: var(--r-sm); background: #070d17; border: 1px solid var(--line-soft); color: #c9d6ea; font-family: var(--mono); }
