:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e5e7f0;
  --primary: #5b4cf0;
  --primary-2: #8b5cf6;
  --primary-ink: #ffffff;
  --primary-soft: #efedff;
  --side: #0f1023;
  --side-2: #17183a;
  --side-text: #b8bce0;
  --good: #059669; --good-soft: #e7f8f1;
  --warn: #c2410c; --warn-soft: #fff4e8;
  --bad: #dc2626; --bad-soft: #fdecec;
  --info: #0284c7; --info-soft: #e6f4fb;
  --shadow: 0 1px 2px rgba(17, 24, 64, .05), 0 6px 20px rgba(17, 24, 64, .06);
  --shadow-lg: 0 18px 50px rgba(30, 27, 90, .18);
  --radius: 16px;
  --c-LOG: #2563eb; --c-ECM: #7c3aed; --c-FNB: #ea580c; --c-FAC: #0d9488; --c-MFG: #db2777; --c-ADM: #16a34a;
  --c-COS: #ca8a04; --c-HRM: #e11d48; --c-ACC: #0891b2; --c-REC: #9333ea; --c-POL: #4f46e5; --c-OTH: #64748b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0b17; --surface: #13152a; --surface-2: #181b33; --text: #e8eaf6; --muted: #98a0c0; --border: #262a48;
    --primary: #8b7dff; --primary-2: #a78bfa; --primary-ink: #0a0b17; --primary-soft: #221f4a; --side: #07081a; --side-2: #10122b;
    --good: #34d399; --good-soft: #0f2a22; --warn: #fb923c; --warn-soft: #2b1d10; --bad: #f87171; --bad-soft: #2d1414; --info: #38bdf8; --info-soft: #0f2533;
    --shadow: 0 1px 2px rgba(0,0,0,.35); --shadow-lg: 0 18px 50px rgba(0,0,0,.5);
    --c-LOG: #60a5fa; --c-ECM: #a78bfa; --c-FNB: #fb923c; --c-FAC: #2dd4bf; --c-MFG: #f472b6; --c-ADM: #4ade80;
    --c-COS: #facc15; --c-HRM: #fb7185; --c-ACC: #22d3ee; --c-REC: #c084fc; --c-POL: #818cf8; --c-OTH: #94a3b8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0b17; --surface: #13152a; --surface-2: #181b33; --text: #e8eaf6; --muted: #98a0c0; --border: #262a48;
  --primary: #8b7dff; --primary-2: #a78bfa; --primary-ink: #0a0b17; --primary-soft: #221f4a; --side: #07081a; --side-2: #10122b;
  --good: #34d399; --good-soft: #0f2a22; --warn: #fb923c; --warn-soft: #2b1d10; --bad: #f87171; --bad-soft: #2d1414; --info: #38bdf8; --info-soft: #0f2533;
  --shadow: 0 1px 2px rgba(0,0,0,.35); --shadow-lg: 0 18px 50px rgba(0,0,0,.5);
  --c-LOG: #60a5fa; --c-ECM: #a78bfa; --c-FNB: #fb923c; --c-FAC: #2dd4bf; --c-MFG: #f472b6; --c-ADM: #4ade80;
  --c-COS: #facc15; --c-HRM: #fb7185; --c-ACC: #22d3ee; --c-REC: #c084fc; --c-POL: #818cf8; --c-OTH: #94a3b8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
b, strong { font-weight: 600; }
[hidden] { display: none !important; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(30px, -20px) scale(1.08); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: -400px 0; } 100% { background-position: 400px 0; } }
.rise > * { animation: rise .45s cubic-bezier(.2, .7, .2, 1) both; }
.rise > *:nth-child(2) { animation-delay: .04s; } .rise > *:nth-child(3) { animation-delay: .08s; } .rise > *:nth-child(4) { animation-delay: .12s; }
.rise > *:nth-child(5) { animation-delay: .16s; } .rise > *:nth-child(6) { animation-delay: .2s; } .rise > *:nth-child(n+7) { animation-delay: .24s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot .logo { animation: spin 1.2s linear infinite; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #a78bfa, #5b4cf0 60%, #3b82f6); box-shadow: 0 8px 20px rgba(91, 76, 240, .45);
}

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { position: relative; overflow: hidden; color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(140deg, #110f2e 0%, #2b1f78 50%, #4f46e5 100%); }
.blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55; animation: float 14s ease-in-out infinite; }
.blob.b1 { width: 380px; height: 380px; background: #8b5cf6; top: -80px; right: -60px; }
.blob.b2 { width: 300px; height: 300px; background: #06b6d4; bottom: -60px; left: -40px; animation-delay: -5s; }
.blob.b3 { width: 220px; height: 220px; background: #ec4899; top: 45%; left: 45%; animation-delay: -9s; opacity: .35; }
.auth-art > *:not(.blob) { position: relative; z-index: 1; }
.auth-brand { display: flex; align-items: center; gap: 14px; font-weight: 700; font-size: 17px; }
.auth-art h1 { font-size: 42px; line-height: 1.15; letter-spacing: -.025em; margin: 0 0 16px; max-width: 520px; }
.auth-art p { color: #d6d3ff; font-size: 17px; max-width: 480px; margin: 0; }
.auth-feats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 520px; }
.auth-feat { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); border-radius: 14px; padding: 14px 16px; backdrop-filter: blur(6px); font-size: 14px; }
.auth-feat b { display: block; font-size: 20px; }
.auth-form { display: grid; place-items: center; padding: 32px 24px; }
.auth-card { width: 100%; max-width: 400px; animation: rise .5s both; }
.auth-card h2 { font-size: 26px; margin: 0 0 6px; }
.auth-card .lead { margin-bottom: 26px; }
.auth-card .field input { padding: 12px 14px; font-size: 15px; }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 6px; }
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 64px !important; }
.pw-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; padding: 4px 8px; }
.form-error { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.auth-note { margin-top: 22px; font-size: 13px; color: var(--muted); display: flex; gap: 8px; }

/* ---------- Shell ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 268px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: radial-gradient(400px 260px at 0% 0%, rgba(139,92,246,.25), transparent 70%), linear-gradient(180deg, var(--side), var(--side-2));
  color: var(--side-text); display: flex; flex-direction: column; padding: 20px 14px 14px;
}
.side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; color: #fff; text-decoration: none !important; }
.side-brand b { display: block; font-size: 15px; line-height: 1.25; color: #fff; }
.side-brand small { display: block; font-size: 12.5px; color: var(--side-text); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #6f7399; padding: 14px 12px 6px; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 11px; color: var(--side-text); font-size: 14px; font-weight: 500; text-decoration: none; transition: background .15s, color .15s, transform .15s; }
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; transform: translateX(2px); }
.sidebar nav a.active { background: linear-gradient(90deg, rgba(139,92,246,.35), rgba(91,76,240,.12)); color: #fff; box-shadow: inset 3px 0 0 #a78bfa; }
.sidebar nav a .badge { margin-left: auto; background: rgba(255,255,255,.12); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 999px; }
.user-card { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 14px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); }
.user-card .who { min-width: 0; flex: 1; }
.user-card .who b { display: block; color: #fff; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .who span { font-size: 12px; }
.user-card button { background: none; border: 0; color: var(--side-text); cursor: pointer; padding: 6px; border-radius: 8px; display: grid; }
.user-card button:hover { background: rgba(255,255,255,.1); color: #fff; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0;
  background: linear-gradient(135deg, var(--a1, #8b5cf6), var(--a2, #3b82f6)); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 32px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.topbar .crumb { font-weight: 600; font-size: 15px; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; background: none; border: 0; color: var(--text); cursor: pointer; padding: 4px; }
.idle-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 5px 11px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.idle-chip.soon { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); background: var(--warn-soft); }
.role-pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.content { padding: 30px 32px 72px; }
.page { max-width: 1200px; margin: 0 auto; }
.scrim { position: fixed; inset: 0; background: rgba(5, 6, 20, .5); z-index: 30; display: none; }
.scrim.open { display: block; }

/* ---------- Typography ---------- */
h1 { font-size: 30px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; margin: 0 0 8px; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 36px 0 14px; }
h3 { font-size: 16px; font-weight: 600; margin: 22px 0 10px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--primary); margin-bottom: 8px; }
.eyebrow::before { content: ""; width: 18px; height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--primary-2), var(--primary)); }
.lead { color: var(--muted); font-size: 15.5px; margin: 0 0 22px; max-width: 780px; }
.page-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; }
.page-head .lead { margin-bottom: 0; }
.note { display: flex; gap: 12px; align-items: flex-start; background: var(--primary-soft); padding: 14px 16px; border-radius: 12px; margin: 16px 0; font-size: 14px; }
.note::before { content: "i"; flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); font: 700 12px/20px Georgia, serif; text-align: center; margin-top: 1px; }
.mono, .code-tag { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; white-space: nowrap; }
.code-tag { font-weight: 600; }
.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- Dashboard ---------- */
.hero { position: relative; overflow: hidden; border-radius: 22px; padding: 36px 40px; color: #fff; margin-bottom: 20px;
  background: linear-gradient(125deg, #1b1650 0%, #3b2fb8 45%, #6d4cf5 75%, #3b82f6 100%); box-shadow: var(--shadow-lg); }
.hero .blob { opacity: .45; }
.hero > *:not(.blob) { position: relative; z-index: 1; }
.hero .hello { font-size: 14.5px; color: #d9d5ff; margin-bottom: 4px; }
.hero h1 { font-size: 34px; color: #fff; max-width: 660px; }
.hero p { color: #e4e1ff; font-size: 16px; max-width: 620px; margin: 0 0 22px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero .btn { border-color: rgba(255,255,255,.3); background: rgba(255,255,255,.12); color: #fff; backdrop-filter: blur(6px); }
.hero .btn:hover { background: rgba(255,255,255,.22); }
.hero .btn.primary { background: #fff; color: #2b1f78; border-color: #fff; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.tile { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.tile::after { content: ""; position: absolute; right: -24px; top: -24px; width: 90px; height: 90px; border-radius: 50%; background: color-mix(in srgb, var(--tone) 14%, transparent); }
.tile .ti { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #fff; background: var(--tone); margin-bottom: 12px; box-shadow: 0 6px 14px color-mix(in srgb, var(--tone) 40%, transparent); }
.tile .ti svg { width: 19px; height: 19px; }
.tile b { display: block; font-size: 30px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13.5px; }
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.card-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); min-width: 0; }
.card-box h3 { margin: 0 0 4px; }
.card-box .sub { font-size: 13px; color: var(--muted); margin-bottom: 16px; }

.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pipe { position: relative; padding: 14px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); text-align: center; }
.pipe b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.pipe span { font-size: 12.5px; color: var(--muted); }
.pipe.on { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }
.pipe.on b { color: var(--primary); }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 34px; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 12px; border-radius: 0 6px 6px 0; background: var(--surface-2); position: relative; }
.bar-fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--primary); transition: width .7s cubic-bezier(.2, .7, .2, 1); min-width: 2px; }
.bar-row:hover .bar-fill { background: var(--primary-2); }
.bar-row .val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .grow span { font-size: 12.5px; color: var(--muted); }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); font-size: 14px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; }

/* ---------- Domain tiles ---------- */
.dom-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.dom-tile { cursor: pointer; text-align: left; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow);
  position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s, border-color .15s; }
.dom-tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--tone); }
.dom-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.dom-tile.on { border-color: var(--tone); background: color-mix(in srgb, var(--tone) 9%, var(--surface)); }
.dom-tile .code { font-size: 11.5px; font-weight: 700; color: var(--tone); letter-spacing: .06em; }
.dom-tile b { display: block; font-size: 14px; line-height: 1.3; margin: 2px 0 4px; }
.dom-tile span { font-size: 12.5px; color: var(--muted); }

/* ---------- Badges ---------- */
.dom { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--tone); background: color-mix(in srgb, var(--tone) 12%, transparent); white-space: nowrap; }
.dom::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--tone); }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-draft { background: var(--surface-2); color: var(--muted); }
.st-pilot { background: var(--info-soft); color: var(--info); }
.st-review { background: var(--warn-soft); color: var(--warn); }
.st-active { background: var(--good-soft); color: var(--good); }
.st-retired { background: var(--bad-soft); color: var(--bad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 12px 0 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: color-mix(in srgb, var(--primary) 4%, transparent); }
tr:last-child td { border-bottom: 0; }
td.center, th.center { text-align: center; }
td.actions { white-space: nowrap; text-align: right; }

/* ---------- Controls ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 14px 0; }
input[type=search], input[type=text], input[type=password], input[type=date], input[type=number], textarea, select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent); }
input:disabled, textarea:disabled, select:disabled { opacity: .7; cursor: not-allowed; }
.search { position: relative; flex: 1; min-width: 200px; }
.search input { width: 100%; padding-left: 38px; }
.search::before { content: ""; position: absolute; left: 13px; top: 50%; width: 15px; height: 15px; transform: translateY(-50%); background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E") center/contain no-repeat; }
.btn { display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none !important; white-space: nowrap;
  padding: 8px 15px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: background .15s, border-color .15s, transform .1s, box-shadow .15s; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--primary-2), var(--primary)); border-color: transparent; color: #fff; font-weight: 600; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.lg { padding: 11px 20px; font-size: 15px; border-radius: 12px; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 5px 8px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.chip-btn { font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: all .15s; }
.chip-btn:hover { border-color: var(--tone, var(--primary)); }
.chip-btn.on { background: var(--tone, var(--primary)); border-color: var(--tone, var(--primary)); color: #fff; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; width: fit-content; max-width: 100%; overflow-x: auto; margin-bottom: 16px; }
.tab { font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; padding: 7px 14px; border-radius: 9px; border: 0; background: none; color: var(--muted); white-space: nowrap; }
.tab.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; }
.field textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.strength { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 4px; }
.strength > div { height: 100%; transition: width .2s, background .2s; }

.switch { position: relative; width: 38px; height: 22px; border-radius: 999px; background: var(--border); border: 0; cursor: pointer; transition: background .15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch.on { background: var(--good); }
.switch.on::after { transform: translateX(16px); }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(5, 6, 20, .55); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; animation: rise .2s both; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 24px; animation: rise .25s both; }
.modal.wide { max-width: 760px; }
.modal h3 { margin: 0 0 6px; font-size: 19px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.secret { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px dashed var(--primary); border-radius: 12px; padding: 12px 14px; font: 600 16px ui-monospace, Menlo, monospace; letter-spacing: .04em; }
.secret span { flex: 1; }
.countdown { font-size: 46px; font-weight: 800; text-align: center; color: var(--warn); font-variant-numeric: tabular-nums; margin: 6px 0; }
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 380px; padding: 12px 16px; border-radius: 12px; background: #15173a; color: #fff; box-shadow: var(--shadow-lg); font-size: 14px; animation: rise .25s both; }
.toast.ok::before { content: "✓"; color: #4ade80; font-weight: 700; }
.toast.bad::before { content: "!"; width: 20px; height: 20px; border-radius: 50%; background: #ef4444; display: grid; place-items: center; font-weight: 700; font-size: 12px; }

/* ---------- Lifecycle ---------- */
.lifecycle { display: grid; grid-template-columns: repeat(5, 1fr); margin: 18px 0 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 12px 20px; box-shadow: var(--shadow); }
.stage { position: relative; text-align: center; padding: 0 8px; }
.stage::before { content: ""; position: absolute; top: 18px; left: -50%; width: 100%; height: 3px; background: linear-gradient(90deg, var(--border), color-mix(in srgb, var(--primary) 40%, var(--border))); }
.stage:first-child::before { display: none; }
.stage .dot { position: relative; z-index: 1; width: 38px; height: 38px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--border); font-weight: 700; color: var(--muted); }
.stage b { display: block; font-size: 14.5px; }
.stage span { display: block; font-size: 12.5px; color: var(--muted); }
.stage.on .dot { background: linear-gradient(135deg, var(--primary-2), var(--primary)); border-color: transparent; color: #fff; box-shadow: 0 0 0 6px var(--primary-soft); }
.stage.on b { color: var(--primary); }
.rules { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.rule { display: flex; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); font-size: 14px; }
.rule .ok { flex-shrink: 0; width: 28px; height: 28px; border-radius: 9px; background: var(--good-soft); color: var(--good); display: grid; place-items: center; font-weight: 700; }
.rule b { display: block; font-size: 14.5px; }
.rule span { color: var(--muted); }

/* ---------- Builder ---------- */
.builder { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 22px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.editor { overflow: hidden; }
.part { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.part:last-child { border-bottom: 0; }
.part-title { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 15px; margin: 0 0 14px; cursor: pointer; list-style: none; }
.part-title::-webkit-details-marker { display: none; }
.part-title::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .15s; }
details:not([open]) > .part-title { margin-bottom: 0; }
details:not([open]) > .part-title::after { transform: rotate(-90deg); }
.num { min-width: 28px; height: 28px; padding: 0 6px; border-radius: 9px; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; flex-shrink: 0; }
.editor-table { font-size: 13px; }
.editor-table th, .editor-table td { padding: 6px; }
.editor-table th { text-transform: none; letter-spacing: 0; font-size: 12px; }
.editor-table input, .editor-table select, .editor-table textarea { width: 100%; padding: 6px 8px; font-size: 13px; border-radius: 8px; min-width: 90px; }
.editor-table textarea { min-height: 36px; resize: vertical; min-width: 180px; }
.panel .table-wrap { box-shadow: none; margin: 0 0 10px; }
.preview { position: sticky; top: 84px; max-height: calc(100vh - 104px); overflow: auto; }
.preview-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 12px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--muted); }
.preview-bar i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.preview-bar i:nth-child(1) { background: #f87171; } .preview-bar i:nth-child(2) { background: #fbbf24; } .preview-bar i:nth-child(3) { background: #34d399; }
.paper { padding: 26px 28px; }
.paper h1 { font-size: 22px; }
.paper h2 { font-size: 16.5px; margin-top: 26px; padding-bottom: 6px; border-bottom: 2px solid var(--primary-soft); }
.paper h3 { font-size: 14.5px; }
.paper .table-wrap { box-shadow: none; border-radius: 10px; }
.paper th, .paper td { padding: 8px 10px; font-size: 13px; }
.issues { margin: 14px 18px 0; padding: 12px 14px; border-radius: 12px; font-size: 13.5px; }
.issues.ok { background: var(--good-soft); color: var(--good); }
.issues.warn { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent); }
.issues.warn b { color: var(--warn); }
.issues ul { margin: 6px 0 0; padding-left: 18px; }
.progress { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--primary-2), var(--primary)); border-radius: 999px; transition: width .3s; }
.meta-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px 22px; background: var(--surface-2); border-bottom: 1px solid var(--border); }

/* ---------- Forms (records) ---------- */
.form-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.form-card { cursor: pointer; text-align: left; font: inherit; color: var(--text); display: flex; gap: 12px; align-items: flex-start; padding: 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); transition: all .15s; }
.form-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.form-card.on { border-color: var(--tone); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 18%, transparent); }
.form-card .fi { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--tone) 14%, transparent); color: var(--tone); flex-shrink: 0; }
.form-card .fi svg { width: 20px; height: 20px; }
.form-card b { display: block; font-size: 14.5px; }
.form-card span { font-size: 12.5px; color: var(--muted); }
.form-body { padding: 22px; }
.box { display: inline-block; width: 14px; height: 14px; border: 1.5px solid var(--text); border-radius: 3px; vertical-align: -2px; }
.sign { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 20px; font-size: 13.5px; color: var(--muted); }
.sign div { flex: 1 1 200px; border-top: 1px dashed var(--border); padding-top: 8px; text-align: center; min-height: 70px; }
.print-only { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .builder, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; max-height: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .form-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 28px 22px; min-height: 0; gap: 24px; }
  .auth-art h1 { font-size: 28px; }
  .auth-feats { display: none; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform .22s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: grid; }
  .topbar { padding: 0 16px; }
  .topbar .crumb { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .role-pill { display: none; }
  .content { padding: 20px 16px 56px; }
  .hero { padding: 26px 20px; border-radius: 18px; }
  .hero h1 { font-size: 26px; }
  h1 { font-size: 24px; }
  .rules, .grid2, .grid3, .form-cards, .meta-bar { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(3, 1fr); }
  .lifecycle { grid-template-columns: 1fr; padding: 16px; gap: 14px; }
  .stage { display: grid; grid-template-columns: 38px 1fr; column-gap: 12px; text-align: left; padding: 0; }
  .stage::before { display: none; }
  .stage .dot { margin: 0; grid-row: span 2; }
  .paper { padding: 18px 16px; }
  .part { padding: 16px; }
  .bar-row { grid-template-columns: 96px 1fr 30px; }
  .table-wrap.stack { border: 0; background: none; box-shadow: none; overflow: visible; }
  .stack table, .stack tbody, .stack tr, .stack td { display: block; }
  .stack thead { display: none; }
  .stack tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
  .stack td { padding: 3px 0; border: 0; }
  .stack td.actions { text-align: left; padding-top: 8px; }
  .stack tbody tr:hover td { background: none; }
  .stack td:empty { display: none; }
  .stack td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
  .stack td:first-child::before, .stack td:nth-child(2)::before { display: none !important; }
  .stack td:first-child, .stack td:nth-child(2) { display: inline-block; margin-right: 8px; }
  #toasts { left: 16px; right: 16px; }
  .toast { max-width: none; }
  .idle-chip .lbl { display: none; }
}
@media (max-width: 480px) { .tiles { grid-template-columns: 1fr 1fr; } .tile b { font-size: 24px; } }

@media print {
  .sidebar, .topbar, .scrim, .toolbar, .no-print, .builder > .editor, .preview-bar, #toasts, .tabs, .form-cards { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  .content { padding: 0; }
  .builder { display: block; }
  .panel, .table-wrap, .card-box { border-color: #999; box-shadow: none; }
  .preview { position: static; max-height: none; overflow: visible; border: 0; }
  .print-only { display: block; }
  th { background: #eee !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  input, textarea, select { border: 0; border-bottom: 1px dotted #999; border-radius: 0; padding: 2px; }
  body.print-modal .layout { display: none !important; }
  body.print-modal .modal-back { position: static; background: none; backdrop-filter: none; padding: 0; display: block; }
  body.print-modal .modal { max-width: none; max-height: none; box-shadow: none; padding: 0; }
}
