:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface2: #f1f3f6; --border: #dde1e7;
  --text: #1f2328; --muted: #6b7280; --primary: #2563eb; --primary-press: #1d4ed8;
  --danger: #dc2626; --radius: 12px;
  --shadow: 0 4px 18px rgba(15, 23, 42, .12);
  --tb-h: 52px; --tool-w: 68px; --panel-w: 310px;
  font-family: Inter, 'Segoe UI', Roboto, system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
svg { display: block; }
[hidden] { display: none !important; }

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
#topbar {
  height: var(--tb-h); flex: none; display: flex; align-items: center; gap: 4px; padding: 0 8px;
  padding-top: env(safe-area-inset-top, 0); background: var(--surface); border-bottom: 1px solid var(--border); z-index: 20;
}
.tb-btn { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.tb-btn:hover { background: var(--surface2); }
.tb-btn:disabled { opacity: .35; }
.tb-btn svg, .tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool svg .fill { fill: currentColor; }
#mapName {
  min-width: 60px; max-width: 340px; flex: 0 1 auto; height: 38px; border: 1px solid transparent; border-radius: 9px; padding: 0 10px;
  font-weight: 700; font-size: 16px; background: transparent;
}
#mapName:hover { border-color: var(--border); }
/* "by …" for a map opened from someone's link */
#mapAuthor { flex: 0 1 auto; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: -4px; }
#mapName:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.tb-spacer { flex: 1; }

/* ---------- layout ---------- */
#main { flex: 1; min-height: 0; display: flex; position: relative; }
#toolbar {
  width: var(--tool-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px; padding: 8px 6px; z-index: 15; overflow-y: auto;
}
.tool {
  border-radius: 12px; padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.tool:hover { background: var(--surface2); color: var(--text); }
.tool.active { background: #e8efff; color: var(--primary); }

#stage { flex: 1; min-width: 0; position: relative; overflow: hidden; background: #fff; }
#bgmap { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
#bgmap .leaflet-control-attribution { font-size: 9px; opacity: .7; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 1; user-select: none; -webkit-user-select: none; }
#canvas.panning { cursor: grabbing; }
#stage.tool-select #canvas { cursor: default; }
#stage.tool-station #canvas, #stage.tool-line #canvas, #stage.tool-landmark #canvas,
#stage.tool-bridge #canvas, #stage.tool-zone #canvas { cursor: crosshair; }
#stage.bg-edit #canvas { cursor: move; }

#panel {
  width: var(--panel-w); flex: none; background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 15;
}
#panelHead {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 12px 14px; min-height: 48px; box-sizing: border-box;
  font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--border); text-align: left; user-select: none;
}
#panelTitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* the panel's «‹ Все …» link lives in the header instead of the title, so it stays put while the panel scrolls */
#panelBack { flex: 1; min-width: 0; text-align: left; color: var(--primary); font-weight: 700; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 0; margin: -4px 0; }
#panelBack[hidden] { display: none; }
/* small red trash next to the title: deletes what the panel shows */
#panelDelete { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--danger);
  background: #fff5f5; border: 1px solid #f6caca; margin: -4px 0; }
#panelDelete:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
#panelDelete svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* copy button beside it (objects) */
#panelCopy { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border); margin: -4px 0; }
#panelCopy:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
#panelCopy svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#panelChevron { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; display: none; transition: transform .2s; }
#panelBody { flex: 1; overflow-y: auto; padding: 12px 14px 24px; }

/* ---------- canvas overlays ---------- */
#legend {
  position: absolute; top: 12px; right: 12px; z-index: 5; background: rgba(255,255,255,.95);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px; max-width: min(300px, 46vw); max-height: calc(100% - 24px); overflow-y: auto; font-size: 13px;
}
#legend:empty { display: none; }
#legend h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; cursor: pointer; }
.lg-row { display: flex; align-items: flex-start; gap: 8px; padding: 3px 0; }
.lg-sw { flex: none; min-width: 30px; height: 18px; border-radius: 9px; color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; padding: 0 5px; margin-top: 1px; }
.lg-name { font-weight: 600; line-height: 1.25; }
.lg-term { color: var(--muted); font-size: 12px; }
#legend.collapsed .lg-row { display: none; }

#zoomCtl { position: absolute; right: 12px; bottom: 14px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
.zbtn { width: 42px; height: 42px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); font-size: 22px; font-weight: 600; border: 1px solid var(--border); }

#bgEditBar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; gap: 10px; align-items: center;
  background: #111827; color: #fff; border-radius: 22px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow); font-size: 14px;
  width: max-content; max-width: calc(100% - 24px); box-sizing: border-box;
}
/* the hint wraps onto a second line on narrow screens; the button never shrinks */
#bgEditText { line-height: 1.25; min-width: 0; }
#bgEditBar .btn { flex: none; }
#toast {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 7; background: #111827; color: #fff;
  padding: 9px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); max-width: 90%; text-align: center;
}

/* ---------- panel controls ---------- */
.sec { margin-bottom: 16px; }
.sec-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 6px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 0 0 12px; }
.field { margin-bottom: 12px; }
.field > label, .lbl { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.lbl-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.lbl-row .lbl { margin: 0; }
.lbl-row .btn.small { height: 26px; padding: 0 10px; }
.inp, select.inp, textarea.inp {
  width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; background: var(--surface);
}
textarea.inp { height: 72px; padding: 8px 10px; resize: vertical; }
.inp:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.btn {
  height: 40px; padding: 0 14px; border-radius: 10px; background: var(--surface2); font-weight: 600; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
}
.btn:hover { background: #e7eaef; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-press); }
.btn.danger { color: var(--danger); border-color: #f2c4c4; background: #fff5f5; }
.btn.block { width: 100%; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.seg { display: flex; background: var(--surface2); border-radius: 10px; padding: 3px; gap: 3px; border: 1px solid var(--border); }
.seg button { flex: 1; height: 34px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid rgba(0,0,0,.08); flex: none; }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.palette button { aspect-ratio: 1; border-radius: 8px; border: 2px solid transparent; }
.palette button.on { border-color: var(--text); box-shadow: inset 0 0 0 2px #fff; }
input[type=color].inp { padding: 3px; height: 40px; }
.dir-grid { display: grid; grid-template-columns: repeat(3, 40px); gap: 4px; }
/* label placement: direction grid with a vertical distance slider beside it */
.label-ctl { display: flex; align-items: stretch; gap: 14px; }
.angle-ctl { margin-top: 10px; }
.angle-ctl input[type=range] { width: 100%; }
.angle-ctl.off { opacity: .45; }
.angle-ctl .check { margin-top: 4px; }
.gap-ctl { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.gap-ctl .lbl { margin: 0; font-size: 11px; }
.gap-val { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
/* vertical: bottom = close to the station, top = far */
.vrange { writing-mode: vertical-lr; direction: rtl; width: 28px; flex: 1; min-height: 80px; margin: 0; }
.vrange:disabled { opacity: .35; }
.dir-grid button { height: 40px; border-radius: 9px; background: var(--surface2); border: 1px solid var(--border); font-size: 18px; }
.dir-grid button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.widths { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.widths button { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; height: 36px; border-radius: 9px; background: var(--surface2); border: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; font-size: 9.5px; color: var(--muted); padding: 0 2px; }
.widths button i { display: block; width: 70%; background: #555; border-radius: 4px; }
.widths button.on { border-color: var(--primary); background: #e8efff; color: var(--primary); }
.widths button.on i { background: var(--primary); }
.check { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; }
.chip.on { border-color: var(--primary); background: #e8efff; color: var(--primary); }
.chip .dot { width: 12px; height: 12px; border-radius: 50%; }
.stnum { font-weight: 800; font-size: 16px; letter-spacing: .02em; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

/* icon picker */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; max-height: 55vh; overflow-y: auto; overflow-x: hidden; padding: 2px; }
.icon-cell { position: relative; min-width: 0; border: 1px solid var(--border); border-radius: 10px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10.5px; text-align: center; line-height: 1.15; background: var(--surface); }
.icon-cell > span:not(.del) { width: 100%; min-height: 2.3em; overflow-wrap: anywhere; hyphens: auto; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.icon-cell:hover { border-color: var(--primary); }
.icon-cell.on { border-color: var(--primary); background: #e8efff; }
.icon-cell .del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 6px; background: #fff5f5; color: var(--danger); font-size: 12px; line-height: 20px; }
.icon-current { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--border); border-radius: 10px; width: 100%; text-align: left; background: var(--surface); }
.icon-current b { display: block; }
.icon-current small { color: var(--muted); }

/* ---------- drawer (main menu) ---------- */
#drawerBackdrop, #modalBackdrop { position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 40; }
#drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(360px, 92vw); background: var(--surface); z-index: 41;
  box-shadow: var(--shadow); overflow-y: auto; padding: calc(14px + env(safe-area-inset-top, 0)) 8px 24px 16px;
  /* room for the scrollbar is always kept on the right, so opening a section never narrows the cards */
  scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: #c3c9d2 transparent;
}
#drawer::-webkit-scrollbar { width: 8px; }
#drawer::-webkit-scrollbar-thumb { background: #c3c9d2; border-radius: 4px; }
#drawer::-webkit-scrollbar-track { background: transparent; }
#drawer h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#drawer h2 { margin: 0 0 6px; font-size: 18px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 10px; border-radius: 10px; text-align: left; font-weight: 500; }
.menu-item .mi { font-size: 18px; width: 24px; text-align: center; flex: none; }
.menu-item small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
/* settings: collapsible sections */
.dsec { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin-bottom: 8px; }
.dsec > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px; cursor: pointer; font-weight: 700; font-size: 15px; user-select: none; }
.dsec > summary::-webkit-details-marker { display: none; }
.dsec > summary .ic { font-size: 18px; width: 24px; text-align: center; }
.dsec > summary .tt { flex: 1; min-width: 0; }
.dsec > summary .note { color: var(--muted); font-weight: 500; font-size: 12px; }
.dsec > summary .chev { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; transition: transform .15s; }
.dsec[open] > summary .chev { transform: rotate(180deg); }
.dsec[open] > summary { border-bottom: 1px solid var(--border); }
.dbody { padding: 10px 12px 12px; }
.dsub { margin: 12px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.dbody > .dsub:first-child { margin-top: 2px; }
.dtiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.dtiles.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dtile { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface2); text-align: center; min-width: 0; }
.dtile:hover { border-color: var(--primary); }
.dtile .mi { font-size: 20px; }
.dtile b { font-size: 13px; }
.dtile small { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.menu-item:hover { background: var(--surface2); }
.map-item { display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 6px; }
.map-item.cur { border-color: var(--primary); background: #f3f7ff; }
.map-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; cursor: pointer; padding: 6px 0; }
.map-item small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.img-item { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 6px; margin-bottom: 6px; }
.img-item img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.img-item.cur { border-color: var(--primary); background: #f3f7ff; }

/* ---------- modal ---------- */
#modalBackdrop { display: grid; place-items: center; padding: 16px; z-index: 50; }
#modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); width: min(460px, 100%); max-height: 90dvh; overflow-y: auto; padding: 18px; }
#modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  :root { --tb-h: 50px; }
  #main { flex-direction: column; }
  #toolbar {
    order: 3; width: 100%; height: 62px; flex-direction: row; border-right: none; border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0)); height: calc(62px + env(safe-area-inset-bottom, 0)); overflow-x: auto; gap: 2px;
  }
  .tool { flex: 1; min-width: 54px; padding: 6px 2px 4px; }
  #stage { order: 1; flex: 1; }
  #panel {
    order: 2; width: 100%; border-left: none; border-top: 1px solid var(--border); max-height: 46dvh;
    box-shadow: 0 -6px 20px rgba(0,0,0,.08);
  }
  #panel.collapsed #panelBody { display: none; }
  #panel.collapsed { max-height: none; }
  #panelHead { padding: 10px 14px; }
  #panelChevron { display: block; }
  #panel.collapsed #panelChevron { transform: rotate(180deg); }
  #legend { top: 8px; right: 8px; font-size: 12px; padding: 8px 10px; }
  #zoomCtl { display: none; }
  #mapName { font-size: 15px; }
  .tb-btn { width: 38px; }
  #simBtn span { display: none; }
}

/* element lists in the panel */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.list-head .sec-title { margin: 0; }
.ilist { display: flex; flex-direction: column; gap: 4px; }
.irow { display: flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.irow.on { border-color: var(--primary); background: #f3f7ff; }
.irow-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 8px 4px 8px 10px; text-align: left; }
.irow-main .tx { min-width: 0; flex: 1; }
.irow-main b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.irow-main small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.irow-btn { width: 38px; height: 38px; flex: none; border-radius: 9px; color: var(--muted); display: grid; place-items: center; }
.irow-btn:hover { background: var(--surface2); color: var(--text); }
.irow-btn.del:hover { color: var(--danger); background: #fff5f5; }
.irow-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* line hidden with the eye button */
.irow.off { background: var(--surface2); }
.irow.off .irow-main { opacity: .45; }
.irow.off .irow-btn.eye { color: var(--text); }
.lg-row.off > :not(.lg-eye) { opacity: .35; }
.lg-eye { flex: none; width: 26px; height: 22px; margin: -1px -4px 0 -6px; border-radius: 6px; color: var(--muted); display: grid; place-items: center; }
.lg-eye:hover { background: var(--surface2); color: var(--text); }
.lg-eye svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lg-row.off .lg-eye { color: var(--text); }
.btn[data-act="showAllLines"] svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.dots { display: flex; flex: none; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; margin-left: -5px; }
.dots i:first-child { margin-left: 0; }
.zsw { width: 22px; height: 22px; border-radius: 6px; flex: none; }
.empty-list { color: var(--muted); font-size: 13px; padding: 10px; border: 1px dashed var(--border); border-radius: 10px; text-align: center; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); font-weight: 600; font-size: 14px; margin: -2px 0 12px; padding: 4px 0; }
.btn.ok { background: #16a34a; border-color: #16a34a; color: #fff; }

/* ---------- 3D view ---------- */
#view3d { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 8; touch-action: none; cursor: grab; }
#view3d:active { cursor: grabbing; }
#view3dBtn { font-weight: 800; letter-spacing: .02em; margin-right: 4px; }
#view3dBtn.on { background: var(--primary); color: #fff; border-color: var(--primary); }
#stage.is3d #legend, #stage.is3d #zoomCtl { display: none; }
#app.is3d #toolbar .tool, #app.is-sim #toolbar .tool { opacity: .35; pointer-events: none; }
/* ---------- traffic simulation ---------- */
#simBtn { display: inline-flex; align-items: center; gap: 6px; margin-right: 4px; }
#simBtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#simBtn svg .fill { fill: currentColor; stroke: none; }
#simBtn.on { background: var(--primary); color: #fff; border-color: var(--primary); }
#L-units { pointer-events: auto; }
.sim-clock { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.sim-clock .btn { min-width: 44px; font-size: 16px; }
.sim-clock .sim-log { margin-left: auto; min-width: 0; font-size: 13px; }
.sim-clock .sim-log.bad { color: var(--danger); border-color: #f2c4c4; background: #fff5f5; }
.sim-clock .sim-log:disabled { opacity: .45; }
.clash-log { max-height: 50vh; overflow: auto; }
#simClock { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.sim-now { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 0 6px; }
.sim-now .btn { white-space: nowrap; flex: none; }
.sim-follow { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 8px 10px; margin: 8px 0;
  border: 1px solid var(--primary); border-radius: 10px; background: #f3f7ff; }
.sim-follow b { font-size: 14px; }
.tt { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; table-layout: fixed; }
.tt th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 4px 2px; }
.tt td { padding: 3px 2px; border-top: 1px solid var(--border); vertical-align: middle; }
.tt td:first-child { overflow: hidden; }
.tt td:first-child .nm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tt td:first-child small { display: block; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tt .inp { padding: 5px 4px; font-size: 13px; min-width: 0; width: 100%; box-sizing: border-box; font-variant-numeric: tabular-nums; }
.irow-btn.follow svg { stroke-width: 2.2; }
.pick-box { width: 22px; height: 22px; flex: none; margin-right: 8px; border: 2px solid var(--border); border-radius: 6px; display: grid; place-items: center; font-size: 14px; font-weight: 700; color: #fff; }
.irow.on .pick-box { background: var(--primary); border-color: var(--primary); }
/* unit card: follow (icon), copy, delete in one row */
.unit-actions { margin-top: 10px; gap: 6px; }
.unit-actions .btn { white-space: nowrap; padding-left: 10px; padding-right: 10px; }
.unit-actions .icon-btn { flex: none; width: 42px; padding: 0; display: grid; place-items: center; }
.unit-actions .icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.unit-actions .icon-btn.on { background: var(--primary); color: #fff; border-color: var(--primary); }
/* station style picker */
.st-styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 4px; }
.st-styles button { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; border: 1px solid transparent; border-radius: 9px; font-size: 9.5px; line-height: 1.15; color: var(--muted); text-align: center; hyphens: auto; }
.st-styles button svg { width: 34px; height: 34px; }
.st-styles button:hover { background: var(--surface2); }
.st-styles button.on { border-color: var(--primary); background: #f3f7ff; color: var(--text); }
/* icon picker categories */
.icon-cats { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; scrollbar-width: thin; }
.icon-cats .chip { white-space: nowrap; flex: none; }
.icon-cat-h { margin: 12px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#icGrid > .icon-cat-h:first-child { margin-top: 2px; }
#icGrid { max-height: 55vh; overflow-y: auto; overflow-x: hidden; }
#icGrid .icon-grid { max-height: none; overflow: visible; }
.unit-icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 4px; }
.unit-icons button { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; border: 1px solid transparent; border-radius: 9px; font-size: 9.5px; line-height: 1.15; color: var(--muted); text-align: center; hyphens: auto; }
.unit-icons button svg { width: 30px; height: 30px; }
.unit-icons button:hover { background: var(--surface2); }
.unit-icons button.on { border-color: var(--primary); background: #f3f7ff; color: var(--text); }
.depth-row { display: flex; align-items: center; gap: 6px; }
.depth-row .inp { width: 74px; text-align: center; flex: none; }
.depth-row .btn { flex: none; padding: 0 10px; }
.irow.depth-item { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 10px; }
.irow.depth-item .depth-row { min-width: 0; }
.irow.depth-item .depth-row .inp { flex: 1 1 0; width: 0; min-width: 0; }
.irow.depth-item .depth-row .btn { min-width: 52px; }
