:root {
  --navy: #14233c; --navy-2: #1d3150; --navy-3: #2a4468; --accent: #1f6feb; --accent-2: #1558c0;
  --bg: #f4f6fa; --card: #ffffff; --line: #dfe4ec; --line-2: #eef1f6; --text: #18212f; --muted: #66728a;
  --ok: #157f3b; --ok-bg: #e5f5ea; --warn: #9a6200; --warn-bg: #fff4d6; --err: #b42318; --err-bg: #fde8e6;
  --input: #fffbea; --input-line: #e6dcae; --ro: #f3f5f8; --radius: 8px;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; font-size: 13px; color: var(--text);
}
* { box-sizing: border-box; }
html, body, #root { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); cursor: pointer; text-decoration: none; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { flex: 1; }

/* ------------------------------------------------ buttons & inputs */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f1f4f9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--err); border-color: #f1c4bf; }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .k { opacity: .7; font-size: 11px; }
input.f, select.f, textarea.f { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; width: 100%; outline: none; }
input.f:focus, select.f:focus, textarea.f:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,235,.15); }
input.f.y, select.f.y { background: var(--input); border-color: var(--input-line); }
label.l { display: block; font-size: 11px; color: var(--muted); margin: 0 0 3px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.fg { display: grid; gap: 10px 14px; }
.fg.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fg.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fg.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }

/* ------------------------------------------------ auth screens */
.auth { height: 100%; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% 0%, #24406a 0%, var(--navy) 55%, #0b1424 100%); }
.auth-card { width: 420px; background: #fff; border-radius: 14px; padding: 32px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.auth-card.wide { width: 560px; }
.brand-mark { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.logo { width: 42px; height: 42px; border-radius: 10px; background: linear-gradient(135deg, #2f80ed, #1d3150); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 16px; letter-spacing: -.02em; }
.brand-mark .t1 { font-weight: 700; font-size: 18px; }
.brand-mark .t2 { color: var(--muted); font-size: 12px; }
.auth-card .fg { margin: 16px 0; }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 9px; }
.machine { font-family: var(--mono); font-size: 16px; letter-spacing: .06em; background: var(--line-2); padding: 8px 12px; border-radius: 6px; display: inline-block; user-select: all; }
.msg { padding: 8px 10px; border-radius: 6px; margin: 10px 0; font-size: 12.5px; }
.msg.err { background: var(--err-bg); color: var(--err); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }

/* ------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100%; }
.side { background: var(--navy); color: #c9d4e6; display: flex; flex-direction: column; }
.side .brand-mark { padding: 18px 16px 6px; margin: 0; }
.side .brand-mark .t1 { color: #fff; font-size: 15px; }
.side .brand-mark .t2 { color: #8ea0bd; font-size: 11px; }
.side .logo { width: 34px; height: 34px; font-size: 13px; }
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.nav .sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6f82a3; padding: 14px 10px 6px; }
.nav a { color: #c9d4e6; padding: 8px 10px; border-radius: 6px; display: flex; align-items: center; gap: 10px; }
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a.on { background: var(--navy-3); color: #fff; }
.nav a .ic { width: 18px; text-align: center; opacity: .9; }
.side .foot { margin-top: auto; padding: 12px 16px; font-size: 11px; color: #7d8fae; border-top: 1px solid #22385a; }
.main { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.top { height: 52px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 20px; gap: 12px; flex: none; }
.top .title { font-size: 16px; font-weight: 600; }
.chip { border-radius: 999px; padding: 3px 10px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.err { background: var(--err-bg); color: var(--err); }
.chip.gray { background: var(--line-2); color: var(--muted); }
.chip.blue { background: #e7efff; color: var(--accent-2); }
.user-btn { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.user-btn:hover { background: var(--line-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--navy-3); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.content { flex: 1; overflow: auto; padding: 20px; }
.content.flush { padding: 0; overflow: hidden; display: flex; flex-direction: column; }

/* ------------------------------------------------ cards / kpis / tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; gap: 14px; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi .s { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .search { width: 280px; }
table.t { width: 100%; border-collapse: collapse; background: #fff; }
table.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfd; position: sticky; top: 0; z-index: 1; }
table.t td.nw, table.t th { white-space: nowrap; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f6f9ff; }
.tablewrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: #fff; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.bars .b { flex: 1; max-width: 46px; background: linear-gradient(180deg, #4a8cf0, #1f6feb); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .b span { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--muted); }
.bars-l { display: flex; gap: 6px; font-size: 10px; color: var(--muted); }
.bars-l div { flex: 1; max-width: 46px; text-align: center; }

/* ------------------------------------------------ editor */
.ed-head { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 20px; display: flex; align-items: center; gap: 8px; flex: none; }
.ed-head h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.banner { padding: 8px 20px; font-weight: 600; font-size: 13px; flex: none; display: flex; align-items: center; gap: 10px; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.err { background: var(--err-bg); color: var(--err); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.ed-body { flex: 1; overflow: auto; padding: 16px 20px; }
.hdr-card { margin-bottom: 14px; }
.hdr-card .totals { display: flex; gap: 28px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line-2); }
.hdr-card .totals div b { display: block; font-size: 16px; }
.hdr-card .totals div span { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a .n { background: var(--line-2); color: var(--muted); border-radius: 999px; padding: 0 7px; font-size: 11px; margin-left: 4px; }
.tabs a .n.e { background: var(--err-bg); color: var(--err); }

.grid-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: #fff; max-height: calc(100vh - 360px); min-height: 220px; }
table.g { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
table.g th { position: sticky; top: 0; z-index: 2; background: var(--navy); color: #fff; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; padding: 7px 6px; text-align: left; white-space: nowrap; border-right: 1px solid #2a3f60; }
table.g td { border-bottom: 1px solid var(--line-2); border-right: 1px solid var(--line-2); padding: 0; height: 28px; white-space: nowrap; }
table.g td.n { color: var(--muted); text-align: right; padding: 0 6px; background: #fafbfd; font-size: 11px; min-width: 34px; }
table.g td.ro { background: var(--ro); padding: 0 6px; color: #44506a; }
table.g td.st { padding: 0 8px; font-size: 11.5px; font-weight: 600; min-width: 150px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
table.g td.st.ok { color: var(--ok); background: var(--ok-bg); }
table.g td.st.warn { color: var(--warn); background: var(--warn-bg); }
table.g td.st.err { color: var(--err); background: var(--err-bg); }
table.g tr.err td.n { background: var(--err-bg); color: var(--err); }
table.g input, table.g select { border: 0; background: var(--input); height: 27px; padding: 0 6px; width: 100%; outline: none; font-size: 12.5px; border-radius: 0; }
table.g input:focus, table.g select:focus { background: #fff; box-shadow: inset 0 0 0 2px var(--accent); }
table.g td.chk { text-align: center; background: #fafbfd; padding: 0 4px; }
table.g td.chk input { width: auto; height: auto; }
.pager { display: flex; align-items: center; gap: 8px; padding: 8px 0; color: var(--muted); }
pre.out { font-family: var(--mono); font-size: 12px; background: #0f1a2c; color: #d6e2f5; padding: 14px; border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 380px); margin: 0; white-space: pre; }
pre.out .ih { color: #ffd479; } pre.out .id { color: #7ee2b8; } pre.out .vd { color: #a9c7ff; }

/* ------------------------------------------------ modal / toast / menu */
.modal-bg { position: fixed; inset: 0; background: rgba(13, 22, 38, .45); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 560px; max-width: calc(100vw - 40px); max-height: calc(100vh - 60px); display: flex; flex-direction: column; box-shadow: 0 24px 70px rgba(0,0,0,.3); }
.modal.wide { width: 860px; }
.modal .mh { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 15px; display: flex; }
.modal .mb { padding: 18px 20px; overflow: auto; }
.modal .mf { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 460px; font-size: 13px; }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }
.menu { position: fixed; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 30px rgba(0,0,0,.15); padding: 4px; z-index: 40; min-width: 180px; }
.menu a { display: block; padding: 7px 12px; color: var(--text); border-radius: 5px; }
.menu a:hover { background: var(--line-2); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.badge-s { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-s.Draft { background: var(--line-2); color: var(--muted); }
.badge-s.Ready { background: #e7efff; color: var(--accent-2); }
.badge-s.Exported { background: var(--ok-bg); color: var(--ok); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c8d0dc; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
.toast a { color: #fff; text-decoration: underline; }
