/* PipeTwin UI. Tokens and components from pipetwin.figcraft (02 · Дизайн-система, 04 · Продуктовые экраны) and tokens.css
   (NEDRA × MYOW / Semantic · Light/Dark). Arial, cards radius 20, pills radius 28. */
:root {
  --brand-primary: #291275; --brand-secondary: #6A48D9; --lime: #D3FF3B;
  --text-primary: #1D164F; --text-secondary: #677083; --surface-page: #F4F6FA; --surface-card: #FFFFFF;
  --surface-raised: #F0F1F7; --surface-soft: #EAEEF4; --border: #E1E6ED;
  --forecast: #147BA7; --band: #D7E8F5; --critical: #EA7855; --critical-soft: #FCEBE5;
  --heading: #291275; --chip-bg: #EEEAFB; --chip-fg: #6A48D9;
  --btn-bg: #291275; --btn-fg: #FFFFFF; --btn-2-bg: #EEEAFB; --btn-2-fg: #291275;
  --ok: #1E8A63; --ok-soft: #E8F4EC; --warn: #9A6A00; --warn-soft: #FFF4D6;
  --navy: #121A2C; --nav-active: #2B3A55; --nav-text: #D8DFEA; --nav-muted: #9AA8BC;
  --panel: #172337; --panel-2: #22324B; --panel-text: #E8EDF5; --panel-muted: #AABBCB;
  --rust: #BE5A39; --rust-soft: #FFF0E9; --steel: #8FB5CA; --missing: #8490A0;
  --chart-base: #6A48D9; --chart-grid: #E6EAF0;
  --syn-bg: #FFF4D6; --syn-fg: #8A6400;
  --shadow: 0 1px 2px rgba(29, 22, 79, .04);
  --radius: 20px; --radius-pill: 28px; --radius-small: 8px; --page-max: 1500px;
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif; color: var(--text-primary); font-size: 14px;
}
:root[data-theme="dark"] {
  --brand-primary: #BCA8FF; --brand-secondary: #9E83FF;
  --text-primary: #F7F8FD; --text-secondary: #ADBBD0; --surface-page: #121A2C; --surface-card: #1D2940;
  --surface-raised: #273650; --surface-soft: #22304A; --border: #2F4060;
  --forecast: #72D8FF; --band: #3B6581; --critical: #FF8C67; --critical-soft: #3D2825;
  --heading: #F7F8FD; --chip-bg: #2E2A57; --chip-fg: #C9BBFF;
  --btn-bg: #D3FF3B; --btn-fg: #121A2C; --btn-2-bg: #2E2A57; --btn-2-fg: #DCD2FF;
  --ok: #5BD3A0; --ok-soft: #173A33; --warn: #F2CD6B; --warn-soft: #3A3218;
  --navy: #0C1322; --nav-active: #24324C;
  --panel: #0F1829; --panel-2: #1D2940;
  --rust: #E2774F; --rust-soft: #3D2825; --chart-base: #9E83FF; --chart-grid: #2C3B57;
  --syn-bg: #3A3218; --syn-fg: #F2CD6B;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { background: var(--surface-page); }
body { margin: 0; display: flex; min-height: 100vh; color: var(--text-primary); }
a { color: var(--brand-secondary); }
[hidden] { display: none !important; }

/* ---------- shell: sidebar ---------- */
.sidebar { width: 224px; flex: 0 0 224px; background: var(--navy); color: #fff; display: flex; flex-direction: column;
  padding: 34px 14px 22px; border-top: 6px solid var(--lime); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding-left: 14px; text-decoration: none; color: #fff; display: block; }
.brand .logo { font-size: 26px; font-weight: 700; line-height: 1.08; }
.brand .product { color: var(--lime); font-size: 11px; font-weight: 700; margin: 22px 0 18px; letter-spacing: .02em; }
nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { color: var(--nav-muted); font-size: 10px; text-transform: uppercase; font-weight: 700; letter-spacing: .06em;
  margin: 16px 0 6px 14px; }
nav a { color: var(--nav-text); text-decoration: none; padding: 10px 14px; border-radius: 10px; font-size: 14px;
  border-left: 4px solid transparent; }
nav a:hover { background: rgba(255, 255, 255, .05); }
nav a.active { background: var(--nav-active); color: #fff; font-weight: 700; border-left-color: var(--lime); }
.sidebar .foot { margin-top: auto; padding: 18px 0 0 14px; color: var(--nav-muted); font-size: 10px; text-transform: uppercase;
  letter-spacing: .03em; }
:focus-visible { outline: 3px solid var(--brand-secondary); outline-offset: 2px; }

/* ---------- shell: top bar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { min-height: 78px; background: var(--surface-card); display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 max(36px, calc((100% - var(--page-max)) / 2 + 36px)); border-bottom: 1px solid var(--border); }
.crumbs { color: var(--brand-secondary); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
.crumbs span + span::before { content: "/"; margin: 0 8px; opacity: .8; }
.top-right { display: flex; align-items: center; gap: 14px; }
.pill { background: var(--chip-bg); color: var(--chip-fg); border-radius: var(--radius-pill); padding: 9px 18px; min-width: 150px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; white-space: nowrap; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-primary); color: #fff; font-weight: 700;
  display: grid; place-items: center; font-size: 15px; border: 0; padding: 0; cursor: pointer; }
:root[data-theme="dark"] .avatar { background: #3A2E7A; }

/* segmented control (theme switch, metric switch, tabs) */
.seg { display: inline-flex; background: var(--surface-raised); border-radius: var(--radius-pill); padding: 4px; gap: 2px; }
.seg button { background: transparent; color: var(--text-secondary); border-radius: var(--radius-pill); padding: 7px 14px;
  font-size: 12px; font-weight: 700; text-transform: none; letter-spacing: 0; }
.seg button[aria-pressed="true"] { background: var(--surface-card); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.solid button[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-fg); }

.tabs { display: flex; gap: 12px; flex-wrap: wrap; }
.tabs button { background: var(--btn-2-bg); color: var(--btn-2-fg); min-width: 210px; justify-content: flex-start; padding: 13px 22px; }
.tabs button[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-fg); }

/* ---------- page ---------- */
#page { padding: 34px 36px 56px; max-width: var(--page-max); width: 100%; margin: 0 auto; }
#page > :not(h1):not(.lead) + :not(.lead) { margin-top: 24px; }
#page > .lead + * { margin-top: 34px; }
h1 { color: var(--heading); font-size: 36px; line-height: 1.15; margin: 4px 0 10px; letter-spacing: -.01em; }
.lead { color: var(--text-secondary); margin: 0 0 6px; font-size: 15px; }
h2, .card-title { font-size: 15px; color: var(--heading); text-transform: uppercase; font-weight: 700; margin: 0 0 16px; letter-spacing: .01em; }
h3 { font-size: 20px; color: var(--heading); margin: 0 0 6px; }
.label { color: var(--brand-secondary); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--text-secondary); font-size: 12px; }
.small { font-size: 12px; }
.grid { display: grid; gap: 24px; }
.g2 { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.g2e { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gside { grid-template-columns: minmax(300px, 1fr) minmax(0, 1.75fr); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack:has(> .card), .stack:has(> .grid) { gap: 24px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.card { background: var(--surface-card); border-radius: var(--radius); padding: 26px 28px; min-width: 0; box-shadow: var(--shadow); }
.card.soft { background: var(--surface-soft); box-shadow: none; }
.card.dark { background: var(--panel); color: var(--panel-text); }
.card.dark h2, .card.dark .card-title { color: #fff; }
.card.dark .muted { color: var(--panel-muted); }
.card.accent-left { border-left: 6px solid var(--lime); }
.card.accent-violet { border-left: 6px solid var(--brand-secondary); }
.card.accent-critical { border-left: 6px solid var(--critical); }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; width: 100%; }

/* KPI tiles */
.kpi .value { font-size: 36px; font-weight: 700; color: var(--heading); line-height: 1.1; }
.kpi .value.critical { color: var(--critical); }
.kpi .name { margin-top: 14px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-primary); }
.kpi .sub { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.big { font-size: 30px; font-weight: 700; color: var(--heading); margin: 4px 0; line-height: 1.15; }
.big.critical, .big.rust { color: var(--critical); }
.huge { font-size: 44px; font-weight: 700; color: var(--heading); line-height: 1.05; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 16px; padding: 7px 13px; font-size: 11px; font-weight: 700;
  background: var(--chip-bg); color: var(--chip-fg); white-space: nowrap; }
.chip.up { text-transform: uppercase; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn, .chip.critical { background: var(--critical-soft); color: var(--critical); }
.chip.check { background: var(--warn-soft); color: var(--warn); }
.chip.syn { background: var(--syn-bg); color: var(--syn-fg); }
.chip.lime { background: var(--lime); color: #121A2C; }
.chip.neutral { background: var(--surface-raised); color: var(--text-secondary); }
.chip button.x { background: none; border: 0; padding: 0 0 0 4px; color: inherit; font-size: 13px; cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px; }

/* buttons */
button, .btn { font: inherit; border: 0; border-radius: var(--radius-pill); padding: 11px 20px; font-weight: 700; cursor: pointer;
  background: var(--btn-2-bg); color: var(--btn-2-fg); text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
button.primary, .btn.primary { background: var(--btn-bg); color: var(--btn-fg); }
button.accent, .btn.accent { background: var(--lime); color: #121A2C; }
button.ghost, .btn.ghost { background: transparent; color: var(--brand-secondary); padding-left: 0; padding-right: 0; }
button.plain { text-transform: none; letter-spacing: 0; font-size: 13px; }
button.block, .btn.block { width: 100%; }
button.square { border-radius: 14px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.card.dark button:not(.primary):not(.accent) { background: var(--panel-2); color: #fff; }

/* forms */
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 11px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .02em; }
input, select, textarea { font: inherit; font-size: 14px; border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  background: var(--surface-raised); color: var(--text-primary); text-transform: none; font-weight: 400; letter-spacing: 0; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-secondary); outline: none; box-shadow: 0 0 0 3px rgba(106, 72, 217, .18); }
select.pill-select { border: 0; border-radius: var(--radius-pill); background: var(--chip-bg); color: var(--btn-2-fg); font-weight: 700;
  font-size: 12px; padding: 9px 14px; text-transform: uppercase; }
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; min-height: 240px; width: 100%; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--brand-secondary); padding: 0; }
input[type=range] { width: 100%; accent-color: var(--brand-secondary); padding: 0; border: 0; background: transparent; }
input[type=range].rust { accent-color: var(--rust); }
input[type=file] { padding: 8px; }
.unit-input { display: flex; align-items: center; background: var(--surface-raised); border-radius: 10px; border: 1px solid var(--border); }
.unit-input input { border: 0; background: transparent; font-weight: 700; font-size: 16px; flex: 1; }
.unit-input span { color: var(--text-secondary); font-size: 12px; padding-right: 14px; }
.param-row { display: grid; grid-template-columns: 1fr 190px; align-items: center; gap: 16px; padding: 6px 0; }
.param-row > span { color: var(--text-secondary); }
.err { color: var(--critical); font-size: 12px; }

/* tables */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; padding: 14px 14px; font-weight: 700;
  background: var(--surface-raised); position: sticky; top: 0; z-index: 1; }
th:first-child { border-radius: 10px 0 0 10px; } th:last-child { border-radius: 0 10px 10px 0; }
td { padding: 16px 14px; border-bottom: 1px solid var(--border); }
tr.sel td { background: var(--chip-bg); }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-raised); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.critical { color: var(--critical); font-weight: 700; }
.scroll { max-height: 460px; overflow: auto; }
.pager { display: flex; gap: 6px; align-items: center; }
.pager button { padding: 6px 10px; background: transparent; color: var(--brand-secondary); }
.pager button[aria-current="page"] { background: var(--chip-bg); }

/* lists */
.list-row { display: grid; align-items: center; gap: 16px; padding: 18px 0; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: 0; }
.list-title { font-size: 26px; font-weight: 700; color: var(--heading); }
.step-no { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 16px;
  background: var(--chip-bg); color: var(--heading); }
.step-no.done { background: var(--lime); color: #121A2C; }
.icon-tile { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--chip-bg);
  color: var(--brand-secondary); font-weight: 700; font-size: 16px; flex: 0 0 46px; }
.icon-tile.white { background: var(--surface-card); }
.dropzone { border-radius: 16px; background: var(--surface-soft); padding: 34px; text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 10px; border: 2px dashed transparent; }
.dropzone.over { border-color: var(--brand-secondary); }

/* canvases & legends */
canvas { display: block; width: 100%; }
.legend { display: flex; gap: 22px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); align-items: center; }
.sw { display: inline-block; width: 18px; height: 6px; border-radius: 3px; vertical-align: middle; margin-right: 8px; }
.sw.sq { width: 18px; height: 18px; border-radius: 5px; }
.note { background: var(--surface-soft); border-radius: 14px; padding: 16px 18px; font-size: 12px; color: var(--text-secondary); line-height: 1.45; }
.alert { border-radius: 14px; padding: 16px 18px; background: var(--critical-soft); color: var(--critical); font-weight: 700; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--chip-bg); color: var(--chip-fg); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; font-size: 13px; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.log { font-family: ui-monospace, Menlo, monospace; font-size: 12px; max-height: 220px; overflow: auto; }
.strip { height: 26px; border-radius: 6px; }
.scene-tools { display: flex; gap: 22px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.scene-tools button { background: transparent !important; padding: 6px 0; color: inherit; }
.card.dark .scene-tools button { color: #fff; }
.scene-chip { position: absolute; z-index: 2; pointer-events: none; font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: #fff; background: rgba(34, 50, 75, .88); border-radius: 8px; padding: 8px 12px; }
.scene-chip.tl { left: 16px; top: 16px; } .scene-chip.tr { right: 16px; top: 16px; border-radius: 16px; }
.scene-chip.bl { left: 18px; bottom: 14px; background: none; padding: 0; font-weight: 400; text-transform: none; color: #A9BDD2; }
.scene-overlay-left { z-index: 3; }
details > summary { cursor: pointer; color: var(--brand-secondary); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.interp { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: start; }
.bars { display: flex; gap: 28px; align-items: flex-end; height: 260px; padding-top: 30px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 8px; max-width: 90px; }
.bar .b { width: 100%; border-radius: 10px 10px 4px 4px; }
.bar .v { font-weight: 700; font-size: 13px; }
.bar .x { font-size: 11px; color: var(--text-secondary); text-align: center; }

/* login */
body.auth .sidebar, body.auth .topbar { display: none; }
body.auth #page { max-width: none; padding: 0; }
.login { display: grid; grid-template-columns: minmax(0, 45%) minmax(0, 1fr); min-height: 100vh; }
.login-hero { background: var(--navy); color: #fff; border-top: 6px solid var(--lime); padding: 60px 76px; display: flex; flex-direction: column; }
.login-hero h1 { color: #fff; font-size: 48px; margin-top: 90px; }
.login-hero p { color: #C9D2E0; font-size: 18px; }
.login-side { padding: 60px clamp(24px, 6vw, 90px); display: flex; flex-direction: column; justify-content: center; }
.login-card { background: var(--surface-card); border: 1px solid var(--border); border-radius: 22px; padding: 42px; max-width: 620px; }
.or { display: flex; align-items: center; gap: 14px; color: var(--text-secondary); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

@media (max-width: 1180px) { .g2, .g3, .g4, .gside, .g2e { grid-template-columns: 1fr 1fr; } .g2 > :first-child { grid-column: 1 / -1; } }
@media (max-width: 860px) { .g2, .g3, .g4, .gside, .g2e, .interp { grid-template-columns: 1fr; }
  body { flex-direction: column; } .sidebar { width: 100%; height: auto; position: static; flex: none; }
  nav { flex-direction: row; flex-wrap: wrap; } .nav-group { width: 100%; }
  #page { padding: 22px 16px 40px; } .topbar { padding: 12px 16px; flex-wrap: wrap; } h1 { font-size: 28px; }
  .login { grid-template-columns: 1fr; } .login-hero { padding: 36px 24px; } .login-hero h1 { margin-top: 30px; font-size: 32px; }
  .param-row { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
