:root {
    --bg: #0d1017; --panel: #151a24; --panel2: #1c2230; --line: #2a3243;
    --text: #e8ebf2; --dim: #8b95aa; --accent: #e0283a; --ok: #5adc78;
    --warn: #ff9a2e; --bad: #ff5a50; --blue: #4fa8ff;
    --r1: #aaaaaa; --r2: #78c8ff; --r3: #64dc78; --r4: #f0c83c; --r5: #ff8c28; --r6: #e64646;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  header { display: flex; align-items: center; gap: 16px; padding: 10px 16px;
    background: var(--panel); border-bottom: 3px solid var(--accent); flex-wrap: wrap; }
  .logo { font-weight: 800; letter-spacing: .5px; display: flex; align-items: center; gap: 10px;
    color: inherit; text-decoration: none; }
  .logo img { width: 42px; height: 42px; border-radius: 9px; background: #fff; padding: 2px; object-fit: contain; flex: none; }
  .logo .brand { display: flex; flex-direction: column; line-height: 1; font-size: 17px; letter-spacing: .6px; }
  .logo .brand em { font-style: normal; color: var(--accent); }
  .logo .brand small { font-size: 9.5px; letter-spacing: 4.2px; color: var(--dim); font-weight: 600; margin-top: 4px; }
  .logo .sub { border-left: 1px solid var(--line); padding-left: 10px; color: var(--dim); font-size: 12px;
    text-transform: uppercase; letter-spacing: 1px; }
  .srvPick select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
    padding: 6px 10px; font: inherit; font-weight: 600; cursor: pointer; max-width: 240px; }
  @media (max-width: 800px) { .logo .sub { display: none; } }
  nav { display: flex; gap: 4px; }
  nav button { background: none; border: 0; color: var(--dim); padding: 8px 14px; border-radius: 6px;
    font: inherit; font-weight: 600; cursor: pointer; }
  nav button.on { background: var(--panel2); color: var(--text); }
  .status { margin-left: auto; display: flex; gap: 14px; color: var(--dim); font-size: 13px; flex-wrap: wrap; }
  .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 6px; }
  .dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
  body { display: flex; flex-direction: column; }
  main { flex: 1; min-height: 0; }
  .view { display: none; height: 100%; }
  .view.on { display: flex; }

  /* карта */
  #mapWrap { flex: 1; position: relative; min-width: 0; }
  #map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
  #map.drag { cursor: grabbing; }
  .mapHint { position: absolute; left: 12px; bottom: 10px; color: var(--dim); font-size: 12px; pointer-events: none; }
  .mapBtns { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 6px; }
  .mapBtns button { width: 34px; height: 34px; border-radius: 6px; border: 1px solid var(--line);
    background: var(--panel); color: var(--text); font-size: 18px; cursor: pointer; }
  #empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); pointer-events: none; }
  aside { width: 340px; background: var(--panel); border-left: 1px solid var(--line);
    display: flex; flex-direction: column; min-height: 0; }
  aside h3 { margin: 0; padding: 12px 14px 6px; font-size: 12px; text-transform: uppercase;
    letter-spacing: 1px; color: var(--dim); }
  #trainList, #feed { overflow: auto; padding: 0 8px 8px; }
  #trainList { flex: 1.3; }
  #feed { flex: 1; border-top: 1px solid var(--line); }
  .tr { display: grid; grid-template-columns: 46px 1fr auto; gap: 8px; align-items: center;
    padding: 8px; border-radius: 6px; cursor: pointer; }
  .tr:hover, .tr.sel { background: var(--panel2); }
  .route { background: var(--accent); color: #fff; font-weight: 800; border-radius: 5px; text-align: center; padding: 3px 0; font-size: 13px; }
  .route.none { background: var(--line); color: var(--dim); }
  .tr small { color: var(--dim); display: block; }
  .spd { font-variant-numeric: tabular-nums; font-weight: 700; }
  .ev { padding: 6px 8px; font-size: 13px; border-bottom: 1px solid #1d2331; }
  .ev .p { font-weight: 800; margin-right: 6px; }
  .ev .p.pos { color: var(--ok); } .ev .p.neg { color: var(--bad); }
  .ev small { color: var(--dim); }
.achs { padding: 4px 14px 8px; }
.achs:empty { display: none; }
.achHead { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; margin: 6px 0; }
.achHead b { color: var(--text); }
.achList { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ach { display: flex; align-items: center; gap: 6px; padding: 5px 7px; border-radius: 8px; background: #151a25;
  border: 1px solid #222a3a; font-size: 12px; opacity: .55; position: relative; overflow: hidden; }
.ach.got { opacity: 1; border-color: #3a4a2a; background: #18221a; }
.ach .ai { font-size: 16px; filter: grayscale(1); } .ach.got .ai { filter: none; }
.ach .at { flex: 1; line-height: 1.2; }
.ach .ap { position: absolute; left: 0; bottom: 0; right: 0; height: 2px; background: #222a3a; }
.ach .ap i { display: block; height: 100%; background: var(--accent); }
  #tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line);
    padding: 8px 10px; border-radius: 6px; font-size: 13px; display: none; max-width: 260px; }

  /* рейтинг */
  #rating { flex-direction: column; overflow: auto; padding: 16px; gap: 12px; align-items: center; }
  .rbar { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; max-width: 1100px; }
  .rbar input { flex: 1; min-width: 180px; background: var(--panel); border: 1px solid var(--line);
    color: var(--text); padding: 9px 12px; border-radius: 6px; font: inherit; }
  .rbar button { background: var(--panel); border: 1px solid var(--line); color: var(--dim);
    padding: 8px 12px; border-radius: 6px; font: inherit; cursor: pointer; }
  .rbar button.on { color: var(--text); border-color: var(--accent); }
  table { width: 100%; max-width: 1100px; border-collapse: collapse; background: var(--panel); border-radius: 8px; overflow: hidden; }
  th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
  th { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; background: var(--panel2); }
  td.num { text-align: right; font-variant-numeric: tabular-nums; }
  tbody tr { cursor: pointer; } tbody tr:hover { background: var(--panel2); }
  .pos1 td:first-child { color: #ffd34d; font-weight: 800; }
  .pos2 td:first-child { color: #d0d6e2; font-weight: 800; }
  .pos3 td:first-child { color: #d9935a; font-weight: 800; }
  .rank { font-weight: 700; }
  .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; width: 80px; display: inline-block; vertical-align: middle; margin-left: 6px; }
  .bar i { display: block; height: 100%; background: var(--ok); }

  dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
    width: min(560px, 94vw); padding: 0; }
  dialog::backdrop { background: rgba(0, 0, 0, .6); }
  .dlgHead { padding: 16px 18px; border-bottom: 3px solid var(--accent); display: flex; justify-content: space-between; align-items: start; }
  .dlgHead h2 { margin: 0 0 4px; font-size: 20px; }
  .dlgHead button { background: none; border: 0; color: var(--dim); font-size: 22px; cursor: pointer; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); }
  .stats div { background: var(--panel); padding: 12px; }
  .stats b { display: block; font-size: 20px; }
  .stats span { color: var(--dim); font-size: 12px; }
  .dlgEvents { max-height: 260px; overflow: auto; padding: 8px 10px; }

  @media (max-width: 800px) {
    #map-view { flex-direction: column; }
    aside { width: auto; height: 40%; border-left: 0; border-top: 1px solid var(--line); }
    .hideM { display: none; }
    th, td { padding: 8px; }
  }

/* ---------- общее: кнопки, пользователь, уведомления ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px;
  padding: 0 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #3a4560; background: #232a3a; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, nav button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn.red { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.red:hover:not(:disabled) { background: #f0384a; }
.btn.ghost { background: none; }
.btn.steam { background: #171a21; border-color: #2a475e; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.user { display: flex; align-items: center; gap: 10px; }
.user img { width: 32px; height: 32px; border-radius: 50%; background: var(--line); }
.user .who { display: flex; flex-direction: column; line-height: 1.15; }
.user .who small { color: var(--dim); font-size: 11px; }
.userLinks { display: flex; gap: 6px; }
input.field, select.field { background: var(--bg); border: 1px solid var(--line); color: var(--text);
  min-height: 38px; padding: 0 12px; border-radius: 6px; font: inherit; font-size: 15px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--blue);
  padding: 10px 14px; border-radius: 6px; max-width: 360px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--line); color: var(--text); }
.pill.dispatcher { background: #173a5a; color: #8fd0ff; }
.pill.admin { background: #4a2a10; color: #ffb36b; }
.pill.owner { background: #4a1219; color: #ff8d98; }
.muted { color: var(--dim); }
.ctx { position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px; min-width: 220px; box-shadow: 0 8px 28px rgba(0,0,0,.5); }
.ctx div { padding: 8px 12px; border-radius: 5px; cursor: pointer; }
.ctx div:hover { background: var(--panel2); }
.ctx .h { color: var(--dim); font-size: 12px; cursor: default; }
.ctx .h:hover { background: none; }
dialog.ask { padding: 18px; }
dialog.ask h3 { margin: 0 0 10px; }
dialog.ask .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
dialog.ask input { width: 100%; }
[hidden] { display: none !important; }

/* ---------- окно светофора ---------- */
.sigPanel { position: absolute; left: 12px; top: 12px; width: 340px; z-index: 6; max-height: calc(100% - 24px); overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.55); overflow: hidden; }
.sigHead { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 14px 10px;
  border-bottom: 3px solid var(--accent); }
.sigHead b { font-size: 17px; display: block; }
.sigHead small { color: var(--dim); font-size: 12px; }
.sigHead .x { background: none; border: 0; color: var(--dim); font-size: 24px; line-height: 1; cursor: pointer; padding: 0 2px; }
.sigBody { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 14px; padding: 14px; align-items: start; }
.sigLamp { background: #07090d; border: 2px solid #2a3243; border-radius: 30px; padding: 10px 0; display: flex;
  flex-direction: column; align-items: center; gap: 10px; }
.sigLamp.depot { border-radius: 10px; }
.sigLamp .sec { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.sigLamp .sec + .sec { border-top: 2px solid #2a3243; padding-top: 10px; }
.ln { --c: #888; width: 26px; height: 26px; border-radius: 50%; background: var(--c); opacity: .16; display: block;
  border: 1px solid rgba(255,255,255,.12); }
.ln.R { --c: #ff3b3b; } .ln.Y { --c: #ffc933; } .ln.G { --c: #3ddc6a; } .ln.B { --c: #4f8dff; } .ln.W { --c: #f2f4f8; }
.ln.on { opacity: 1; box-shadow: 0 0 14px var(--c), 0 0 4px var(--c); }
.ln.blink { animation: lnBlink 1s steps(1) infinite; }
@keyframes lnBlink { 50% { opacity: .16; box-shadow: none; } }
.ln.m { border-radius: 4px; width: 26px; height: 20px; background: #222; opacity: 1; color: #555; font-size: 11px;
  font-style: normal; font-weight: 800; display: grid; place-items: center; }
.ln.m.on { color: #fff; box-shadow: none; }
.sigBody dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; font-size: 13px; }
.sigBody dt { color: var(--dim); }
.sigBody dd { margin: 0; font-weight: 600; }
.sigBody .busy { color: var(--bad); } .sigBody .free { color: var(--ok); }
.sigBtns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 14px 14px; }
.sigBtns .btn { min-height: 46px; font-weight: 700; font-size: 14px; white-space: normal; line-height: 1.15;
  padding: 6px 10px; text-align: center; overflow: visible; }
.sigBtns .btn.open { background: #1f7a3c; border-color: #2a9d4f; color: #fff; }
.sigBtns .btn.close { background: #9b1c26; border-color: #c4283a; color: #fff; }
.sigBtns .btn.pass { background: #e8ebf2; border-color: #fff; color: #111; }
.sigPanel p.small { margin: -6px 14px 12px; font-size: 12px; }
.muted.small { font-size: 12px; }
@media (max-width: 800px) {
  .mapHint { display: none; }
  .sigPanel { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; }
}

/* окно участка (напряжение) */
.secBody { padding: 14px; display: grid; gap: 12px; }
.secBody dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; font-size: 13px; }
.secBody dt { color: var(--dim); } .secBody dd { margin: 0; font-weight: 600; }
.volt { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px; padding: 10px 12px; border-radius: 8px; }
.volt i { width: 12px; height: 12px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.volt.on { color: var(--ok); background: rgba(90, 220, 120, .1); }
.volt.off { color: #ff6b6b; background: rgba(255, 60, 60, .12); }
.sigBtns.one { grid-template-columns: 1fr; }
/* блок «Напряжение» в пульте */
.pwList { display: grid; gap: 6px; margin-bottom: 8px; }
.pwList .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 8px;
  background: rgba(255, 60, 60, .1); border: 1px solid rgba(255, 60, 60, .3); border-radius: 6px; font-size: 13px; }
.pwList .row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pwActs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }

/* окно стрелки */
.swList { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 13px; }
.swList .busy, .secBody .busy { color: var(--bad); } .swList .free { color: var(--ok); }
.secBody b.small { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .5px; }
.sigBody code { font-size: 12px; background: #0a0d13; padding: 1px 5px; border-radius: 4px; }

/* маршруты в окне светофора */
.routes { padding: 0 14px 14px; display: grid; gap: 6px; }
.routes b.small { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .5px; }
.rt { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; align-items: center; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.rt.cur { border-color: var(--ok); }
.rt .rtName { font-weight: 700; font-size: 13px; }
.rt .rtSw { grid-column: 1; font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px; }
.rt .rtSw span { padding: 0 5px; border-radius: 4px; background: #0a0d13; font-variant-numeric: tabular-nums; }
.rt .rtSw .okk { color: var(--ok); } .rt .rtSw .chg { color: #ffd970; } .rt .rtSw .bad { color: var(--bad); }
.rt .btn { grid-column: 2; grid-row: 1 / span 2; }
.rt .rtWhy { grid-column: 1 / -1; font-size: 11px; color: var(--bad); }

/* маршрут в окне светофора: наведение — показ на схеме, нажатие — задать */
.rt.pick { cursor: pointer; }
.rt.pick:hover { background: rgba(60,200,255,.10); outline: 1px solid rgba(60,200,255,.45); }
.rtChg { font-size: 11px; color: #9fe6ff; margin-top: 2px; }

/* пульт депо карты */
.pult { padding: 0 14px 14px; }
.pultBtns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pultBtns .pb { font-size: 12px; padding: 5px 9px; border-radius: 6px; border: 1px solid #3a4560; background: #1b2131; color: #c9cfdc; }
.pultBtns .pb.on { background: #6b5a12; border-color: #d1b02a; color: #fff3b0; }
