@import url("https://fonts.googleapis.com/css2?family=Golos+Text:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Source+Serif+4:opsz,wght@8..60,400;8..60,600&display=swap");

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.app.light {
  --bg:#faf9f6; --surface:#ffffff; --sunken:#f3f1ec; --raised:#ffffff;
  --ink:#1a1917; --ink-2:#57544c; --ink-3:#8b877d;
  --rule:#e6e2d8; --rule-2:#d2cdc0;
  --accent:#c33527; --accent-hover:#a52a1e; --accent-soft:#fbe9e5; --accent-line:#eec9c2;
  --ok:#3d7a52; --ok-soft:#e7f0e9;
  --warn:#8f5e1a; --warn-soft:#f7eeda;
  --tg:#2aabee;
  --shadow:0 1px 2px rgba(26,25,23,.05);
  --shadow-lg:0 18px 44px -22px rgba(26,25,23,.38);
}
.app.dark {
  --bg:#191816; --surface:#23211e; --sunken:#141311; --raised:#2b2825;
  --ink:#f2efe8; --ink-2:#b5b0a5; --ink-3:#87827a;
  --rule:#35322d; --rule-2:#4a463f;
  --accent:#f0655a; --accent-hover:#f8887d; --accent-soft:#3a1f1c; --accent-line:#5b2f28;
  --ok:#6fbb87; --ok-soft:#1e2f24;
  --warn:#d9a05b; --warn-soft:#332616;
  --tg:#54a9eb;
  --shadow:0 1px 2px rgba(0,0,0,.28);
  --shadow-lg:0 18px 44px -18px rgba(0,0,0,.6);
}

.app {
  --sans:"Golos Text", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --serif:"Source Serif 4", Georgia, "Times New Roman", serif;
  --mono:"JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  display: grid; grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh; width: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.app.plain { display: block; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* ---------- sidebar ---------- */
.side {
  display: flex; flex-direction: column; gap: 28px;
  padding: 22px 16px; border-right: 1px solid var(--rule); background: var(--sunken);
}
.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px; }
.brand-mark { width: 22px; height: 22px; flex: none; color: var(--accent); }
.brand-name { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px; color: var(--ink-2);
  font-size: 13.5px; font-weight: 500; cursor: default;
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .8; }
.nav-item:hover { background: var(--rule); color: var(--ink); }
.nav-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.on svg { opacity: 1; }
.nav-count { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.tg-user {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--surface);
}
.avatar {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--rule); background: var(--bg);
}
.h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -.015em; }
.crumb { color: var(--ink-3); font-size: 13px; }
.spacer { flex: 1 1 auto; }
.body { display: flex; flex-direction: column; gap: 22px; padding: 24px 28px 40px; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.sec-title {
  margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
}
.muted { color: var(--ink-2); font-size: 13px; }
.dim { color: var(--ink-3); font-size: 12.5px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px; border-radius: 7px;
  border: 1px solid var(--rule-2); background: var(--surface); color: var(--ink);
  font-family: var(--sans); font-size: 13.5px; font-weight: 500; cursor: default;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--rule); color: var(--ink); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 6px; }
.input {
  height: 34px; padding: 0 11px; border-radius: 7px;
  border: 1px solid var(--rule-2); background: var(--surface); color: var(--ink);
  font-family: var(--sans); font-size: 13.5px; width: 100%;
}
.input::placeholder { color: var(--ink-3); }
.seg { display: flex; gap: 0; border: 1px solid var(--rule-2); border-radius: 7px; overflow: hidden; }
.seg-item {
  padding: 7px 14px; font-size: 13px; font-weight: 500; color: var(--ink-2);
  background: var(--surface); border-right: 1px solid var(--rule); cursor: default;
}
.seg-item:last-child { border-right: 0; }
.seg-item.on { background: var(--accent); color: #fff; font-weight: 600; }
.seg-item.off { color: var(--ink-3); background: var(--sunken); }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 20px; border-bottom: 1px solid var(--rule);
}

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px; border-radius: 20px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  border: 1px solid var(--rule-2); color: var(--ink-2); background: var(--surface);
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.chip.run { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.chip.done { color: var(--ok); border-color: transparent; background: var(--ok-soft); }
.chip.fail { color: #fff; background: var(--accent); border-color: var(--accent); }
.chip.wait { color: var(--ink-3); }
.chip.type { font-family: var(--mono); font-size: 11.5px; height: 20px; padding: 0 7px; border-radius: 5px; }

/* ---------- table ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 9px 14px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--sunken); }
.tbl td.r, .tbl th.r { text-align: right; }

/* ---------- progress ---------- */
.bar { height: 5px; border-radius: 3px; background: var(--rule); overflow: hidden; width: 100%; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.ok > i { background: var(--ok); }

/* phase ladder */
.ladder { display: flex; align-items: stretch; gap: 0; }
.step { flex: 1 1 0; display: flex; flex-direction: column; gap: 7px; padding-right: 14px; }
.step .rail { height: 3px; border-radius: 2px; background: var(--rule); }
.step.past .rail { background: var(--accent); }
.step.now .rail { background: linear-gradient(90deg, var(--accent) 55%, var(--rule) 55%); }
.step .lbl { font-size: 12.5px; color: var(--ink-3); }
.step.past .lbl { color: var(--ink-2); }
.step.now .lbl { color: var(--accent); font-weight: 600; }

/* counter strip */
.strip { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 9px; overflow: hidden; }
.cell { background: var(--surface); padding: 11px 14px; display: flex; flex-direction: column; gap: 3px; }
.cell .k { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.cell .v { font-family: var(--mono); font-size: 19px; font-weight: 500; letter-spacing: -.02em; }
.cell .v.accent { color: var(--accent); }

/* key-value */
.kv { display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 9px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

/* ---------- graph ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; }
.legend .li { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.gnode rect, .gnode circle { stroke-width: 1.4px; }
.gedge { fill: none; stroke: var(--rule-2); stroke-width: 1.2px; }
.glabel { font-family: var(--mono); font-size: 11px; fill: var(--ink-2); }
.gsub { font-family: var(--mono); font-size: 9.5px; fill: var(--ink-3); }

/* ---------- tabs inside one scan ---------- */
.tabs { display: flex; gap: 2px; padding: 0 28px; border-bottom: 1px solid var(--rule); background: var(--bg); }
.tab {
  padding: 9px 12px; margin-bottom: -1px; font-size: 13.5px; font-weight: 500;
  color: var(--ink-2); border-bottom: 2px solid transparent; cursor: default;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab.off { color: var(--ink-3); }
.tab.off:hover { color: var(--ink-3); }

/* ---------- search field with mode toggles ---------- */
.field {
  display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 6px 0 10px;
  border: 1px solid var(--rule-2); border-radius: 7px; background: var(--surface); min-width: 0;
}
.field.on { border-color: var(--accent-line); }
.field input {
  flex: 1 1 auto; min-width: 0; height: 100%; border: 0; outline: none;
  background: transparent; color: var(--ink); font-family: var(--sans); font-size: 13.5px;
}
.field input.re { font-family: var(--mono); font-size: 12.5px; }
.field input::placeholder { color: var(--ink-3); font-family: var(--sans); }
.tog {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 24px; padding: 0 6px; border-radius: 5px;
  border: 1px solid transparent; font-family: var(--mono); font-size: 11.5px; font-weight: 500;
  color: var(--ink-3); cursor: default;
}
.tog:hover { background: var(--rule); color: var(--ink-2); }
.tog.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.sel {
  display: flex; align-items: center; gap: 7px; height: 34px; padding: 0 10px;
  border: 1px solid var(--rule-2); border-radius: 7px; background: var(--surface);
  font-size: 13.5px; color: var(--ink); white-space: nowrap; cursor: default;
}
.sel:hover { border-color: var(--ink-3); }
.sel .cap { color: var(--ink-3); }
.filters { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--rule); }
mark.hit { background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 1px; }

/* ---------- console: the design is static, this makes it work ---------- */

.btn, .seg-item, .nav-item, .tab, .tog, .sel, .chip.pick { cursor: pointer; user-select: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.off { opacity: .45; pointer-events: none; }
.seg-item.off { cursor: default; pointer-events: none; }
.tbl tr.pick { cursor: pointer; }
.tbl tr.pick:hover td { background: var(--sunken); }
.side { position: sticky; top: 0; height: 100vh; }
.main { min-height: 100vh; }

.chip.pick.off { opacity: .4; }
.chip.pick.on { border-color: var(--ink-3); color: var(--ink); }
.chip.pick.on.accent { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.chip.solid { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.input:focus, .field:focus-within { outline: none; border-color: var(--accent-line); }
.input.bad { border-color: var(--accent); background: var(--accent-soft); }
.err { font-size: 12.5px; color: var(--accent); padding-left: 2px; }

.pop { position: relative; }
.pop-menu {
  position: absolute; z-index: 40; top: calc(100% + 5px); left: 0; min-width: 100%;
  max-height: 320px; overflow-y: auto; padding: 5px;
  background: var(--surface); border: 1px solid var(--rule-2); border-radius: 9px;
  box-shadow: var(--shadow-lg);
}
.pop-menu.right { left: auto; right: 0; }
.pop-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 6px;
  font-size: 13px; white-space: nowrap; cursor: pointer; color: var(--ink);
}
.pop-item:hover { background: var(--sunken); }
.pop-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 46px 20px; color: var(--ink-3); font-size: 13.5px; text-align: center;
}
.empty b { color: var(--ink-2); font-weight: 600; font-size: 14px; }

.spin {
  width: 14px; height: 14px; flex: none; border-radius: 50%;
  border: 2px solid var(--rule-2); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toasts {
  position: fixed; z-index: 90; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  display: flex; align-items: flex-start; gap: 9px; padding: 11px 14px;
  border: 1px solid var(--rule-2); border-radius: 9px;
  background: var(--surface); box-shadow: var(--shadow-lg);
  font-size: 13px; color: var(--ink); animation: rise .18s ease-out;
}
.toast.bad { border-color: var(--accent-line); color: var(--accent); }
.toast.ok { border-color: var(--ok); color: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.gnode { cursor: pointer; }
.gnode.dim { opacity: .28; }
.gnode.sel rect:first-child { stroke: var(--accent); stroke-width: 1.6px; }
.gwrap { background: var(--sunken); position: relative; display: flex; min-width: 0; overflow: hidden; }
.gwrap svg { width: 100%; height: 100%; }

.wrap { display: flex; flex-direction: column; gap: 22px; }
.link { color: var(--accent); }
.link:hover { text-decoration: underline; }
.main.fixed { height: 100vh; min-height: 0; overflow: hidden; }

/* ---------- compact: telegram mini app and narrow screens ---------- */

.app.compact { display: block; }
.app.compact .side { display: none; }
.app.compact .main { min-height: 100vh; }
.app.compact .main.fixed { height: 100vh; }

.topnav {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 11px;
  padding: 12px 14px; background: var(--bg); border-bottom: 1px solid var(--rule);
}
.topnav .who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.topnav .who .name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seg.wide { width: 100%; }
.seg.wide .seg-item { flex: 1 1 0; text-align: center; padding: 7px 4px; }

.rail-x { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.rail-x::-webkit-scrollbar { display: none; }
.rail-x > * { flex: none; }

.rail-wrap { display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.rail-wrap.shut { overflow: hidden; }

.mrow { display: flex; flex-direction: column; gap: 7px; padding: 11px 13px; border-bottom: 1px solid var(--rule); }
.mrow:last-child { border-bottom: 0; }
.mrow .head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mrow .val {
  flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: 13.5px; font-weight: 500;
  color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mrow .file { color: var(--ink); font-size: 12.5px; }
.mrow .meta { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--ink-3); }

.erow { display: flex; align-items: center; gap: 9px; padding: 9px 13px; border-bottom: 1px solid var(--rule); }
.erow:last-child { border-bottom: 0; }
.erow .v {
  flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.erow .w { font-family: var(--mono); font-size: 11px; color: var(--ink-3); flex: none; }

.app.compact .topbar { padding: 12px 14px; }
.app.compact .topbar .h1 { font-size: 17px; }
.app.compact .body { padding: 13px 14px 20px; gap: 13px; }
.app.compact .tabs { padding: 0 14px; }
.app.compact .card-pad { padding: 15px 16px; }
.app.compact .filters { padding: 11px 13px; }
.app.compact .kv { grid-template-columns: 84px minmax(0, 1fr) !important; font-size: 12.5px; }
.app.compact .strip { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.app.compact .strip .cell { padding: 9px 11px; }
.app.compact .strip .cell .v { font-size: 17px; }
.app.compact .strip .cell .k { font-size: 10px; }
.app.telegram .hide-tg { display: none !important; }

.ladder.bare .step { padding-right: 6px; }
.ladder.bare .step:last-child { padding-right: 0; }

.gcanvas { position: relative; flex: 1 1 auto; min-height: 0; background: var(--sunken); overflow: hidden; }
.gcanvas #svg-host > svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.gtools { position: absolute; left: 12px; top: 12px; display: flex; gap: 6px; z-index: 4; }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  max-height: 62%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 11px;
  padding: 9px 16px 16px;
  background: var(--surface); border-top: 1px solid var(--rule-2);
  border-radius: 15px 15px 0 0; box-shadow: var(--shadow-lg);
}
.sheet .grip { align-self: center; width: 36px; height: 4px; border-radius: 2px; background: var(--rule-2); flex: none; }
.rule { height: 1px; background: var(--rule); }

.app.telegram .topnav { padding-top: 8px; }
.app.telegram .no-tg { display: none !important; }

.app.compact #progress { grid-template-columns: minmax(0, 1fr) !important; gap: 14px !important; }
.app.compact #progress > div:last-child {
  padding-left: 0 !important; padding-top: 13px;
  border-left: 0 !important; border-top: 1px solid var(--rule);
}
.app.compact .field { max-width: none !important; }
.app.compact .filters .row { flex-wrap: wrap; }

.app.compact { display: flex; flex-direction: column; min-height: 100vh; }
.app.compact > .main { flex: 1 1 auto; min-height: 0; }
.app.compact > .main.fixed { height: auto; }
.app.compact:has(> .main.fixed) { height: 100vh; overflow: hidden; }
.app.compact:has(> .main.fixed) .topnav { position: static; }

.app.compact .topbar { flex-direction: column; align-items: flex-start; gap: 5px; }
.app.compact .topbar .spacer { display: none; }
.app.compact .topbar > .dim { font-size: 12px; }
.app.compact .strip .cell .k { white-space: normal; line-height: 1.25; }
.app.compact .sel { padding: 0 9px; }

.crumbs {
  flex: none; display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 9px 16px; border-bottom: 1px solid var(--rule);
  background: var(--bg); font-size: 12.5px; color: var(--ink-2);
}
.crumbs .sep { color: var(--ink-3); }
.ghub rect { transition: fill .12s; }
.ghub:hover rect { fill: var(--rule); }

.tbl th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.tbl th.sortable:hover { color: var(--ink-2); }
.tbl th.sortable.on { color: var(--accent); }
.tbl th .arrow { display: inline-block; margin-left: 4px; font-size: 8.5px; vertical-align: 1px; }
