:root {
  --bg: #07080b;
  --bg-soft: #0c0e13;
  --panel: #12151b;
  --panel-2: #171b23;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --text: #f4f7fa;
  --muted: #98a2b3;
  --faint: #616b79;
  --line: rgba(255, 255, 255, 0.075);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #3ecf8e;
  --accent-2: #5eead4;
  --accent-dim: rgba(62, 207, 142, 0.14);
  --green: #3ecf8e;
  --yellow: #f0d84a;
  --orange: #ff9a3c;
  --blue: #4db8ff;
  --gen: rgb(255, 255, 220);
  --dead: #3d4552;
  --warn: #ff5c5c;
  --loss: #ff7aad;
  --ui: #171b23;
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius: 11px;
  --radius-sm: 8px;
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 28px 68px rgba(0, 0, 0, 0.5);
  --font: "Outfit", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

*::selection {
  background: rgba(62, 207, 142, 0.28);
  color: #fff;
}

html {
  height: 100%;
  height: 100dvh;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-feature-settings: "ss01" 1;
  -webkit-font-smoothing: antialiased;
}

body {
  height: 100%;
  height: 100dvh;
  min-height: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 42% at 10% -8%, rgba(62, 207, 142, 0.1), transparent 55%),
    radial-gradient(ellipse 55% 40% at 95% -4%, rgba(94, 234, 212, 0.07), transparent 55%),
    radial-gradient(ellipse 70% 55% at 50% 115%, rgba(77, 184, 255, 0.05), transparent 60%),
    linear-gradient(180deg, #0a0d12 0%, var(--bg) 45%);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
  background-clip: padding-box;
}

/* ——— Top bar ——— */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: calc(0.7rem + env(safe-area-inset-top, 0px)) 1.25rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 11, 15, 0.78);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  animation: bar-in 0.5s var(--ease) both;
}

@keyframes bar-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.station-picker {
  grid-column: 1;
  justify-self: start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  min-width: 0;
}

.app-title {
  grid-column: 2;
  margin: 0;
  text-align: center;
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text);
}

.topbar-end {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem 0.75rem;
  min-width: 0;
}

.station-picker-label {
  font-size: 0.62rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.station-select {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  max-width: min(100%, 15.5rem);
  padding: 0.4rem 2rem 0.4rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%) calc(100% - 14px) / 5px 5px no-repeat,
    linear-gradient(135deg, var(--accent) 50%, transparent 50%) calc(100% - 9px) / 5px 5px no-repeat,
    var(--ui);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.station-select:hover {
  border-color: rgba(62, 207, 142, 0.5);
  color: var(--accent);
  background-color: rgba(62, 207, 142, 0.08);
}

.station-select:focus-visible {
  outline: 2px solid rgba(62, 207, 142, 0.5);
  outline-offset: 2px;
}

.btn {
  appearance: none;
  background: var(--ui);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.44rem 0.9rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 550;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.18s ease, transform 0.15s var(--ease), box-shadow 0.18s ease;
}

.btn:hover:not(:disabled) {
  border-color: rgba(62, 207, 142, 0.5);
  color: var(--accent);
  background: rgba(62, 207, 142, 0.08);
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid rgba(62, 207, 142, 0.5);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.btn-accent {
  background: linear-gradient(180deg, rgba(62, 207, 142, 0.24) 0%, rgba(62, 207, 142, 0.14) 100%);
  border-color: rgba(62, 207, 142, 0.45);
  color: var(--accent);
  font-weight: 650;
}

.btn-accent:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(62, 207, 142, 0.34) 0%, rgba(62, 207, 142, 0.2) 100%);
  border-color: var(--accent);
  color: #eafff5;
  box-shadow: 0 4px 16px rgba(62, 207, 142, 0.2);
}

.btn-warn {
  background: linear-gradient(180deg, rgba(240, 216, 74, 0.18) 0%, rgba(240, 216, 74, 0.08) 100%);
  border: 2px solid var(--yellow);
  color: #ffe98a;
  font-weight: 650;
  box-shadow: 0 0 0 1px rgba(240, 216, 74, 0.22), 0 0 18px rgba(240, 216, 74, 0.12);
}

.btn-warn:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(240, 216, 74, 0.28) 0%, rgba(240, 216, 74, 0.14) 100%);
  border-color: #ffe566;
  color: #fff6c2;
  box-shadow: 0 0 0 1px rgba(240, 216, 74, 0.35), 0 4px 20px rgba(240, 216, 74, 0.22);
}

.retesz-toggle {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  padding: 0.32rem 0.55rem 0.32rem 0.6rem;
  border-radius: 4px;
  background: var(--ui);
  border: 1px solid var(--line-strong);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s ease, background 0.18s ease;
}

.retesz-toggle:hover {
  border-color: rgba(62, 207, 142, 0.5);
  background: rgba(62, 207, 142, 0.08);
}

.retesz-toggle-name {
  font-size: 0.62rem;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
}

.eng-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}

.retesz-track {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: #262c36;
  border: 1px solid var(--line-strong);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.retesz-knob {
  position: absolute;
  top: 1.5px;
  left: 1.5px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #98a2b3;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s var(--ease), background 0.2s ease;
}

.eng-switch[aria-checked="true"] .retesz-track {
  background: rgba(62, 207, 142, 0.22);
  border-color: rgba(62, 207, 142, 0.5);
}

.eng-switch[aria-checked="true"] .retesz-knob {
  transform: translateX(14px);
  background: var(--accent);
}

.eng-switch[aria-checked="false"] .retesz-track {
  background: rgba(255, 92, 92, 0.16);
  border-color: rgba(255, 92, 92, 0.45);
}

.eng-switch[aria-checked="false"] .retesz-knob {
  background: var(--warn);
}

.retesz-state {
  min-width: 1.2em;
  font-size: 0.65rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  font-family: var(--mono);
}

.eng-switch[aria-checked="true"] .retesz-state {
  color: var(--accent);
}

.eng-switch[aria-checked="false"] .retesz-state {
  color: var(--warn);
}

.engineer-btn {
  padding: 0.38rem 0.85rem;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  align-self: center;
}

.engineer-toggles {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.85rem 0 1rem;
}

.engineer-toggle {
  width: 100%;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0.55rem 0.7rem;
}

.engineer-set-default {
  width: 100%;
  white-space: normal;
  line-height: 1.35;
  text-align: center;
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
}

.status-msg {
  align-self: center;
  min-height: 1.2em;
  max-width: 18rem;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--warn);
  transition: color 0.15s ease;
}

.status-msg.ok {
  color: var(--accent);
}

/* ——— Workspace ——— */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 310px);
  gap: 0;
  min-height: 0;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  animation: workspace-in 0.55s var(--ease) 0.08s both;
}

@keyframes workspace-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.main-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.stage {
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.75rem;
  min-height: 0;
  flex: 1;
  border-radius: var(--radius-xl);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.stage::-webkit-scrollbar {
  display: none;
}

.schema-shell {
  position: relative;
  width: 100%;
  max-width: 1240px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  background:
    radial-gradient(ellipse at 22% 10%, rgba(240, 216, 74, 0.05), transparent 42%),
    radial-gradient(ellipse at 80% 22%, rgba(77, 184, 255, 0.06), transparent 42%),
    linear-gradient(165deg, rgba(23, 27, 35, 0.95) 0%, rgba(9, 11, 15, 0.98) 100%);
  padding: 0.85rem;
  box-shadow: var(--shadow-md);
}

#schema {
  display: block;
  width: 100%;
  max-width: 1240px;
  height: auto;
  min-height: 400px;
  aspect-ratio: 1240 / 720;
  user-select: none;
  -webkit-user-select: none;
  border-radius: var(--radius);
}

/* Állomás áttekintő — séma jobb alsó sarkában */
.overview-fab {
  position: absolute;
  right: 1.1rem;
  bottom: 0.85rem;
  border-radius: 4px;
}

/* Alapállapot — séma jobb felső sarkában */
.reset-fab {
  position: absolute;
  right: 1.1rem;
  top: 0.85rem;
  border-radius: 4px;
  z-index: 2;
}

/* Nézetváltó — séma bal alsó sarkában, ugyanaz a szögletes stílus */
.viewmode-fab {
  position: absolute;
  left: 1.1rem;
  bottom: 0.85rem;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  z-index: 2;
}

.viewmode-fab-icon {
  flex-shrink: 0;
}

/* ——— Overview ———
   (kompozit szelektor, hogy a specifikációja felülírja a generikus .modal-card-ot) */
.overview-modal .overview-modal-card {
  width: calc(100vw - 1.5rem);
  height: calc(100dvh - 1.5rem);
  max-width: none;
  max-height: none;
  display: flex;
  flex-direction: column;
  padding: 1.1rem 1.25rem 1.2rem;
}

.overview-modal-card .overview-stations {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.15rem 0.1rem 0.3rem;
  margin: 0 -0.1rem;
  justify-content: center;
  align-content: center;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.overview-modal-card .overview-stations::-webkit-scrollbar {
  display: none;
}

.overview-stations {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.55rem;
}

.station-card {
  border: 1.5px solid rgba(77, 184, 255, 0.28);
  background: #05070a;
  border-radius: var(--radius-sm);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
  cursor: pointer;
}

.station-card:hover {
  border-color: rgba(94, 234, 212, 0.7);
  transform: translateY(-3px);
  box-shadow: var(--shadow-sm);
}

.station-card.no-schema {
  cursor: default;
  min-width: 230px;
  padding-bottom: 0.4rem;
}

.station-card.no-schema:hover {
  transform: none;
  border-color: rgba(77, 184, 255, 0.28);
  box-shadow: none;
}

.station-card-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.22rem 0.45rem;
  border-bottom: 1px solid rgba(77, 184, 255, 0.22);
  background: linear-gradient(180deg, rgba(77, 184, 255, 0.07) 0%, transparent 100%);
}

.station-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.08rem 0.45rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #0c0f14;
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-family: var(--font);
  white-space: nowrap;
}

.station-mini-schema-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: #05070a;
}

.station-mini-schema-row .station-mini-schema {
  flex: 1 1 0;
  min-width: 0;
}

.station-mini-schema-row .station-mini-schema + .station-mini-schema {
  border-left: 1px dashed rgba(255, 255, 255, 0.12);
}

.station-mini-schema {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.4rem 0.1rem;
  background: #05070a;
}

.station-mini-schema svg.station-schema-svg {
  width: auto;
  height: min(170px, 24vh);
  min-height: 0;
  display: block;
}

.station-mini-schema-row .station-mini-schema svg.station-schema-svg {
  height: min(150px, 22vh);
  max-width: 100%;
}

.station-mini-schema .st-title {
  display: none;
}

/* ——— Log ——— */
.log-panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 100%);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: calc(0.85rem + env(safe-area-inset-top, 0px)) 1.05rem 0.75rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.log-header-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text);
}

.log-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.log-persist {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  padding: 0.75rem 1.05rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  flex-shrink: 0;
}

.log-persist-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.log-persist .btn {
  flex: 1;
  padding: 0.38rem 0.65rem;
  font-size: 0.78rem;
}

.log-undo-btn {
  padding: 0.28rem 0.65rem;
  font-size: 0.74rem;
  border-radius: 4px;
}

.event-log {
  flex: 1;
  overflow: auto;
  padding: 0.7rem 0.9rem 1rem;
  font-size: 0.75rem;
  line-height: 1.45;
  color: #b8c0cc;
  font-family: var(--mono);
}

.event-log .log-empty {
  color: var(--faint);
  font-style: normal;
  padding: 0.75rem 0.25rem;
}

.event-log .log-entry {
  padding: 0.42rem 0.4rem;
  border-radius: var(--radius-sm);
  border-bottom: none;
  margin-bottom: 0.18rem;
  transition: background 0.15s ease;
}

.event-log .log-entry:hover {
  background: var(--surface-hover);
}

.event-log .log-entry .time {
  color: var(--faint);
  margin-right: 0.45rem;
}

.event-log .log-entry .action-close {
  color: var(--accent);
}

.event-log .log-entry .action-open {
  color: var(--orange);
}

.event-log .log-entry .action-meta {
  color: var(--muted);
}

@media (max-width: 960px) {
  .topbar {
    grid-template-columns: 1fr auto;
    position: static;
  }

  .app-title {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
    font-size: 1.2rem;
  }

  .station-picker {
    grid-column: 1;
    grid-row: 2;
  }

  .topbar-end {
    grid-column: 2;
    grid-row: 2;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(150px, 28dvh);
  }

  .log-panel {
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .log-header {
    padding-top: 0.75rem;
  }

  .stage {
    padding: 0.5rem;
  }
}

/* Rövid magasság / fekvő: ne stackelje a topbart a ≤960px szabály */
@media (max-width: 960px) and (orientation: landscape) and (max-height: 500px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 0.45rem;
    padding: 0.4rem 0.75rem;
    position: sticky;
  }

  .app-title {
    font-size: 1.05rem;
  }

  .workspace {
    grid-template-columns: 1fr minmax(200px, 28vw);
    grid-template-rows: 1fr;
  }

  .log-panel {
    border-left: 1px solid var(--line);
    border-top: none;
  }

  .log-header {
    padding-top: calc(0.4rem + env(safe-area-inset-top, 0px));
  }

  .stage {
    min-height: 0;
    padding: 0.35rem;
  }

  #schema {
    min-height: 0;
  }
}

/* ——— Schema SVG ——— */
.wires path,
.wires line {
  fill: none;
  stroke: var(--dead);
  stroke-width: 2.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
  pointer-events: none;
}

.wires .bus {
  stroke-width: 4;
}

.wires .live-y { stroke: var(--yellow); }
.wires .live-o { stroke: var(--orange); }
.wires .live-b { stroke: var(--blue); }
.wires .live-g { stroke: #cfd5de; }
.wires .live-r { stroke: var(--warn); }
.wires .live-gen { stroke: var(--gen); }

/* Feszültségvesztés előnézet: alatta ne látszódjon a sín színe */
.wires path.loss-preview {
  stroke: transparent !important;
}

.loss-highlights {
  pointer-events: none;
}

/* Feszültségvesztés: rózsaszín szaggatott, villogó jelzés */
.loss-highlights path.loss-preview-core {
  fill: none;
  stroke: var(--loss) !important;
  stroke-width: 5.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 6 18;
  animation: loss-dash-blink 0.85s ease-in-out infinite;
}

.loss-highlights path.loss-preview-core.loss-preview-bus {
  stroke-width: 7.5;
  stroke-dasharray: 8 20;
}

@keyframes loss-dash-blink {
  0%,
  100% {
    opacity: 1;
    stroke-dashoffset: 0;
  }
  50% {
    opacity: 0.28;
    stroke-dashoffset: 24;
  }
}

.fixed text {
  fill: #d5dbe4;
  font-family: var(--font);
  font-size: 12px;
}

.fixed .title {
  font-size: 13px;
  font-weight: 650;
}

.fixed .title-y { fill: var(--yellow); }
.fixed .title-o { fill: var(--orange); }
.fixed .title-b { fill: var(--blue); }
.fixed .title-g { fill: var(--accent); }

.generator {
  fill: #07080b;
  stroke: var(--dead);
  stroke-width: 2.5;
}

.generator.live-y { stroke: var(--yellow); }
.generator.live-o { stroke: var(--orange); }
.generator.live-b { stroke: var(--blue); }
.generator.live-g { stroke: #cfd5de; }
.generator.live-r { stroke: var(--warn); }
.generator.live-gen { stroke: var(--gen); }

.generator-mark {
  fill: var(--muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.generator.live-y ~ .generator-mark { fill: var(--yellow); }
.generator.live-o ~ .generator-mark { fill: var(--orange); }
.generator.live-b ~ .generator-mark { fill: var(--blue); }
.generator.live-g ~ .generator-mark { fill: #cfd5de; }
.generator.live-r ~ .generator-mark { fill: var(--warn); }
.generator.live-gen ~ .generator-mark { fill: var(--gen); }

.transformer {
  fill: #07080b;
  stroke: var(--dead);
  stroke-width: 2.5;
}

.transformer.live-y { stroke: var(--yellow); }
.transformer.live-o { stroke: var(--orange); }
.transformer.live-b { stroke: var(--blue); }
.transformer.live-r { stroke: var(--warn); }

.transformer.hazi-tr {
  stroke-width: 2.2;
}

.parallel-frame {
  fill: none;
  stroke: var(--warn);
  stroke-width: 2.5;
  opacity: 0;
  pointer-events: none;
}

.parallel-frame.active {
  animation: parallel-blink 0.9s ease-in-out infinite;
}

@keyframes parallel-blink {
  0%,
  100% { opacity: 1; }
  50% { opacity: 0.15; }
}

.ossze-fogas-banner {
  opacity: 0;
  pointer-events: none;
}

.ossze-fogas-frame {
  fill: rgba(255, 92, 92, 0.12);
  stroke: rgba(255, 92, 92, 0.55);
  stroke-width: 1.75;
}

.ossze-fogas-text {
  fill: var(--warn);
  font-family: var(--font);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ossze-fogas-banner.active {
  opacity: 1;
  animation: parallel-blink 0.9s ease-in-out infinite;
}

.switch {
  cursor: pointer;
}

.switch.locked {
  cursor: default;
  pointer-events: none;
}

.switch:focus {
  outline: none;
}

.switch:focus-visible .hit {
  fill: rgba(62, 207, 142, 0.12);
  stroke: rgba(62, 207, 142, 0.5);
  stroke-width: 1;
}

.switch .body {
  stroke-width: 2;
  transition: fill 0.15s ease, stroke 0.15s ease;
}

.switch.breaker .body {
  stroke: #9aa3b0;
  fill: transparent;
}

.switch .breaker-divider {
  stroke: #1a212b;
  stroke-width: 1.5;
  pointer-events: none;
}

.switch.open .breaker-divider {
  stroke: #8b95a3;
}

.switch.disc .body {
  stroke: #9aa3b0;
  fill: transparent;
}

.switch.closed .body {
  fill: #5c6674;
  stroke: #5c6674;
}

.switch.closed.live-y .body { fill: var(--yellow); stroke: var(--yellow); }
.switch.closed.live-o .body { fill: var(--orange); stroke: var(--orange); }
.switch.closed.live-b .body { fill: var(--blue); stroke: var(--blue); }
.switch.closed.live-g .body { fill: #cfd5de; stroke: #cfd5de; }
.switch.closed.live-gen .body { fill: var(--gen); stroke: var(--gen); }
.switch.open.disc.live-gen .body { stroke: var(--gen); }
.switch.closed.live-r .body,
.switch.closed.parallel .body { fill: var(--warn); stroke: var(--warn); }

/* Összefogás-előnézet: nyitott kapcsolóra is (pl. háziüzem QS, amit épp zárni készülünk) */
.switch.parallel-preview .body {
  fill: var(--warn) !important;
  stroke: var(--warn) !important;
}

.switch.open.breaker .body,
.switch.open.disc .body {
  fill: #07080b;
}

.switch.blocked {
  opacity: 0.5;
}

.switch .hit {
  fill: transparent;
  stroke: none;
}

.switch:hover .hit {
  fill: rgba(255, 255, 255, 0.08);
}

.switch-label {
  fill: #ff7a7a;
  font-family: var(--font);
  font-size: 8px;
  font-weight: 600;
  pointer-events: none;
}

.bus-label {
  fill: #ccd3dd;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 650;
}

.cell-label {
  fill: #d5dbe4;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 650;
  pointer-events: none;
}

.cell-label-hot {
  fill: #ffe0e0;
  font-weight: 700;
}

.cell-label-frame {
  fill: rgba(255, 92, 92, 0.12);
  stroke: var(--warn);
  stroke-width: 1.6;
  pointer-events: none;
}

.fixed .bay-label {
  font-weight: 600;
  pointer-events: none;
}

/* Csak a 2 sínáthidaló — ugyanaz a gyengébb rózsaszín, mint a sínbontó felirat */
.fixed .bay-label-hot {
  fill: #ff7a7a;
}

/* ——— Modal ——— */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: modal-fade 0.2s ease both;
}

/* Az állomás-séma modal az áttekintő modal fölé kerüljön, ha onnan nyitják meg. */
#station-dialog {
  z-index: 110;
}

/* Feszültségvesztés / összefogás előnézet: séma látszik, panel oldalt.
   Fent az Alapállapot gomb magasságában; jobbról behúzva a séma közepe felé. */
.modal.schema-side {
  align-items: flex-start;
  justify-content: flex-end;
  padding:
    calc(6.1rem + env(safe-area-inset-top, 0px))
    clamp(5.5rem, 12vw, 9rem)
    1.15rem
    1.15rem;
  pointer-events: none;
}

.modal.schema-side .modal-backdrop {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
}

.modal.schema-side .modal-card {
  pointer-events: auto;
  width: min(360px, calc(100vw - 2rem));
  box-shadow: var(--shadow-lg);
}

.modal.schema-side.loss-danger .modal-card {
  border-color: rgba(255, 122, 173, 0.45);
}

.modal.schema-side.parallel-danger .modal-card {
  border-color: rgba(255, 92, 92, 0.5);
}

.modal.schema-side.loss-danger.parallel-danger .modal-card {
  border-color: rgba(255, 140, 100, 0.55);
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 2rem));
  background: linear-gradient(180deg, #191f29 0%, #10151c 100%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  padding: 1.35rem 1.4rem 1.3rem;
  box-shadow: var(--shadow-lg);
  animation: modal-rise 0.3s var(--ease) both;
}

#switch-dialog.bus-mode .modal-card {
  width: min(460px, calc(100vw - 2rem));
}

.modal-card.password-modal-card {
  width: min(320px, calc(100vw - 2rem));
  border-color: rgba(240, 216, 74, 0.45);
  box-shadow: var(--shadow-lg), 0 0 28px rgba(240, 216, 74, 0.12);
}

.modal-card.engineer-modal-card {
  width: min(260px, calc(100vw - 2rem));
  padding: 1.1rem 1rem 1.05rem;
  border-color: rgba(240, 216, 74, 0.4);
  box-shadow: var(--shadow-lg), 0 0 28px rgba(240, 216, 74, 0.1);
}

.password-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.85rem 0 0.55rem;
}

.password-field-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.password-input {
  appearance: none;
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
  font-family: var(--mono);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
}

.password-input:focus {
  outline: none;
  border-color: rgba(240, 216, 74, 0.7);
  box-shadow: 0 0 0 2px rgba(240, 216, 74, 0.18);
}

.password-error {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  color: var(--warn);
}

@keyframes modal-rise {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-title {
  margin: 0 0 0.4rem;
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.modal-name {
  margin: 0 0 0.3rem;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

.modal-current {
  margin: 0 0 1.15rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.modal-warn {
  margin: 0 0 0.75rem;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.35;
  animation: loss-preview-blink 0.75s ease-in-out infinite;
}

.modal-warn-loss {
  border: 1px solid rgba(255, 122, 173, 0.55);
  background: rgba(255, 122, 173, 0.12);
  color: #ffb3d0;
}

.modal-warn-interlock {
  border: 1px solid rgba(255, 196, 86, 0.55);
  background: rgba(255, 196, 86, 0.12);
  color: #ffd78a;
  animation: none;
}

.modal-warn-parallel {
  border: 1px solid rgba(255, 92, 92, 0.55);
  background: rgba(255, 92, 92, 0.12);
  color: #ffb0b0;
}

.modal-warn[hidden] {
  display: none !important;
}

.wires path.parallel-preview {
  stroke: var(--warn) !important;
  animation: loss-preview-blink 0.75s ease-in-out infinite;
}

.parallel-frame.preview {
  animation: parallel-blink 0.9s ease-in-out infinite;
}

.ossze-fogas-banner.preview {
  opacity: 1;
  animation: parallel-blink 0.9s ease-in-out infinite;
}

.transformer.parallel-preview {
  stroke: var(--warn);
}

.switch-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-bottom: 1.2rem;
}

.switch-choice.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.95rem 0.4rem 0.85rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s var(--ease);
}

.choice-btn:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.04);
  transform: translateY(-1px);
}

.choice-btn:disabled,
.choice-btn.blocked {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.choice-btn:disabled:hover,
.choice-btn.blocked:hover {
  border-color: var(--line-strong);
  background: rgba(0, 0, 0, 0.25);
  transform: none;
}

.choice-btn.selected.tone-be {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.choice-btn.selected.tone-ki {
  border-color: var(--warn);
  background: rgba(255, 92, 92, 0.12);
}

.choice-symbol {
  width: 34px;
  height: 34px;
  border: 2.5px solid #8b95a3;
  box-sizing: border-box;
  border-radius: 5px;
}

.choice-symbol.circle {
  border-radius: 50%;
}

.choice-symbol.be {
  background: var(--accent);
  border-color: var(--accent);
}

.choice-symbol.ki {
  background: transparent;
  border-color: var(--warn);
}

.choice-label {
  font-size: 0.88rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.2;
}

.choice-btn.selected.tone-be .choice-label {
  color: var(--accent);
}

.choice-btn.selected.tone-ki .choice-label {
  color: var(--warn);
}

.choice-hint {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
}

/* Sín K/B szakaszoló dialógus */
.switch-choice.bus-layout {
  display: block;
  margin-bottom: 1.2rem;
}

.bus-panel {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-strong);
  background:
    radial-gradient(ellipse 70% 90% at 12% 40%, rgba(62, 207, 142, 0.07), transparent 55%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 45%),
    rgba(0, 0, 0, 0.28);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.bus-target-block {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.65rem 0.7rem;
}

.bus-preview {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.55rem 0.55rem 0.45rem;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.08));
}

.bus-preview-svg {
  display: block;
  width: 132px;
  max-width: 100%;
  height: auto;
}

.bus-preview-rail {
  stroke: #6d7786;
  stroke-width: 3.2;
  stroke-linecap: round;
}

.bus-preview-feeder {
  stroke: #6d7786;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.bus-preview-rail.live-y,
.bus-preview-feeder.live-y { stroke: var(--yellow); }
.bus-preview-rail.live-o,
.bus-preview-feeder.live-o { stroke: var(--orange); }
.bus-preview-rail.live-b,
.bus-preview-feeder.live-b { stroke: var(--blue); }
.bus-preview-rail.live-g,
.bus-preview-feeder.live-g { stroke: #cfd5de; }
.bus-preview-rail.live-r,
.bus-preview-feeder.live-r { stroke: var(--warn); }

.bus-preview-disc {
  stroke-width: 2.4;
}

.bus-preview-disc.open {
  fill: #12151b;
  stroke: #8b95a3;
}

.bus-preview-disc.closed {
  fill: var(--accent);
  stroke: var(--accent);
}

.bus-preview-disc.closed.live-y { fill: var(--yellow); stroke: var(--yellow); }
.bus-preview-disc.closed.live-o { fill: var(--orange); stroke: var(--orange); }
.bus-preview-disc.closed.live-b { fill: var(--blue); stroke: var(--blue); }
.bus-preview-disc.closed.live-g { fill: #cfd5de; stroke: #cfd5de; }
.bus-preview-disc.closed.live-r { fill: var(--warn); stroke: var(--warn); }

.bus-preview-label {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}

.bus-preview-caption {
  fill: var(--faint);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bus-preview-hint {
  fill: var(--faint);
  font-family: var(--font);
  font-size: 9.5px;
  font-weight: 500;
}

.bus-target-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 0.45rem;
  padding: 0.45rem 0;
}

.bus-target-row + .bus-target-row {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.bus-target-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.bus-target-toggle {
  display: inline-flex;
  gap: 0.3rem;
  justify-self: center;
}

.choice-btn.compact {
  flex-direction: row;
  gap: 0.3rem;
  padding: 0.38rem 0.55rem;
  min-width: 0;
  border-radius: var(--radius-sm);
}

.choice-btn.compact .choice-symbol {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.choice-btn.compact .choice-label {
  font-size: 0.8rem;
}

html[data-viewmode="mobile"] .switch-choice.bus-layout {
  margin-bottom: 0.75rem;
}

html[data-viewmode="mobile"] .bus-panel {
  flex-direction: row;
  align-items: stretch;
}

html[data-viewmode="mobile"] .bus-preview {
  flex: 0 0 auto;
  width: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom: none;
  padding: 0.4rem 0.35rem 0.4rem 0.3rem;
}

html[data-viewmode="mobile"] .bus-preview-svg {
  width: 96px;
  margin: 0;
}

html[data-viewmode="mobile"] .bus-target-block {
  padding: 0.35rem 0.45rem;
  justify-content: center;
  gap: 0;
}

html[data-viewmode="mobile"] .bus-target-row {
  padding: 0.28rem 0;
  column-gap: 0.35rem;
  grid-template-columns: minmax(0, auto) 1fr;
}

html[data-viewmode="mobile"] .bus-target-name {
  font-size: 0.74rem;
}

html[data-viewmode="mobile"] .bus-target-toggle {
  gap: 0.22rem;
  justify-self: end;
}

html[data-viewmode="mobile"] .choice-btn.compact {
  padding: 0.28rem 0.4rem;
  gap: 0.22rem;
}

html[data-viewmode="mobile"] .choice-btn.compact .choice-symbol {
  width: 14px;
  height: 14px;
}

html[data-viewmode="mobile"] .choice-btn.compact .choice-label {
  font-size: 0.72rem;
}

html[data-viewmode="mobile"] #switch-dialog.bus-mode .modal-card {
  width: min(320px, calc(100vw - 1.5rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  padding: 0.85rem 0.75rem 0.8rem;
}

/* ——— Állomás séma modal ——— */
.station-modal .station-modal-card {
  width: min(960px, calc(100vw - 2rem));
  max-width: 960px;
  max-height: calc(100dvh - 2rem);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 1.25rem 1.2rem;
}

.station-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.station-modal-head .modal-title {
  margin: 0;
}

.station-modal-hint {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.station-schema-host {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #08090c;
  padding: 0.6rem;
}

.station-schema-host.multi-schema {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.75rem;
}

.station-schema-pane {
  min-width: 0;
  flex: 1 1 280px;
}

.station-schema-host.multi-schema .station-schema-pane + .station-schema-pane {
  border-left: 1px dashed rgba(255, 255, 255, 0.14);
  padding-left: 0.75rem;
}

.station-schema-svg {
  width: 100%;
  height: auto;
  display: block;
  min-height: 280px;
  max-height: min(70vh, 640px);
}

.station-schema-svg .st-wire {
  stroke: var(--dead);
  stroke-width: 2.2;
}

.station-schema-svg .st-wire.live-y { stroke: var(--yellow); }
.station-schema-svg .st-wire.live-o { stroke: var(--orange); }
.station-schema-svg .st-wire.live-b { stroke: var(--blue); }
.station-schema-svg .st-wire.live-g { stroke: #cfd5de; }
.station-schema-svg .st-wire.live-r { stroke: var(--warn); }

.station-schema-svg .st-body {
  fill: #07080b;
  stroke: #8b95a3;
  stroke-width: 2;
}

/* Zárt szakaszoló: kitöltve a TV színével */
.station-schema-svg .st-sw.st-closed.live-y .st-body { stroke: var(--yellow); fill: var(--yellow); }
.station-schema-svg .st-sw.st-closed.live-o .st-body { stroke: var(--orange); fill: var(--orange); }
.station-schema-svg .st-sw.st-closed.live-b .st-body { stroke: var(--blue); fill: var(--blue); }
.station-schema-svg .st-sw.st-closed.live-g .st-body { stroke: #cfd5de; fill: #cfd5de; }

/* Nyitott megszakító (áttekintő): üres, csak a keret követi a TV színt — soha ne legyen piros */
.station-schema-svg .st-sw.st-open .st-body {
  fill: #07080b;
}
.station-schema-svg .st-sw.st-open.live-y .st-body { stroke: var(--yellow); }
.station-schema-svg .st-sw.st-open.live-o .st-body { stroke: var(--orange); }
.station-schema-svg .st-sw.st-open.live-b .st-body { stroke: var(--blue); }
.station-schema-svg .st-sw.st-open.live-g .st-body { stroke: #cfd5de; }

.station-schema-svg .st-title {
  fill: var(--text);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
}

.station-schema-svg .st-feed-title {
  fill: #d5dbe4;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
}

.station-schema-svg .st-feed-vert,
.station-schema-svg .st-couple-label {
  fill: #9aa6b5;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.station-schema-svg .st-couple-label {
  fill: #7f8b9a;
  font-size: 9px;
}

.station-schema-svg .st-feed-cell {
  fill: #e8edf5;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.station-schema-svg .st-bay-tag {
  fill: #c5ceda;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
}

/* ═══ Kényszerített MOBIL nézet — a data-viewmode attribútum vezérli, ═══
   ═══ nem viewport-szélesség (a gombbal bármikor átkapcsolható).      ═══ */
html[data-viewmode="mobile"] .topbar {
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  padding: calc(0.5rem + env(safe-area-inset-top, 0px)) 0.75rem 0.5rem;
  position: static;
}

html[data-viewmode="mobile"] .app-title {
  grid-column: 1 / -1;
  grid-row: 1;
  text-align: center;
  font-size: 1.15rem;
}

html[data-viewmode="mobile"] .station-picker {
  grid-column: 1;
  grid-row: 2;
}

html[data-viewmode="mobile"] .topbar-end {
  grid-column: 2;
  grid-row: 2;
  gap: 0.4rem;
}

html[data-viewmode="mobile"] .station-select {
  max-width: 11.5rem;
  font-size: 0.74rem;
  padding: 0.34rem 1.7rem 0.34rem 0.55rem;
}

html[data-viewmode="mobile"] .status-msg {
  max-width: 100%;
}

html[data-viewmode="mobile"] .workspace {
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) minmax(0, 26dvh);
}

html[data-viewmode="mobile"] .main-column {
  min-height: 0;
}

html[data-viewmode="mobile"] .stage {
  min-height: 0;
  height: 100%;
  padding: 0.5rem;
  align-items: stretch;
}

html[data-viewmode="mobile"] .log-panel {
  border-left: none;
  border-top: 1px solid var(--line);
}

html[data-viewmode="mobile"] .log-header {
  padding-top: 0.55rem;
}

html[data-viewmode="mobile"] .log-persist {
  padding: 0.55rem 0.8rem;
  padding-bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
}

html[data-viewmode="mobile"] .log-persist .btn {
  padding: 0.4rem 0.55rem;
  font-size: 0.74rem;
  min-height: 2.35rem;
}

html[data-viewmode="mobile"] .schema-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  padding: 0.55rem;
}

html[data-viewmode="mobile"] #schema {
  min-height: 0;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  max-height: 100%;
  aspect-ratio: auto;
}

html[data-viewmode="mobile"] .log-panel {
  min-height: 0;
}

html[data-viewmode="mobile"] .overview-fab,
html[data-viewmode="mobile"] .viewmode-fab,
html[data-viewmode="mobile"] .reset-fab {
  font-size: 0.74rem;
  padding: 0.4rem 0.65rem;
}

html[data-viewmode="mobile"] .overview-fab,
html[data-viewmode="mobile"] .viewmode-fab {
  bottom: 0.55rem;
}

html[data-viewmode="mobile"] .overview-fab,
html[data-viewmode="mobile"] .reset-fab {
  right: 0.55rem;
}

html[data-viewmode="mobile"] .reset-fab {
  top: 0.55rem;
}

html[data-viewmode="mobile"] .viewmode-fab {
  left: 0.55rem;
}

html[data-viewmode="mobile"] .log-header {
  padding: 0.6rem 0.8rem;
}

html[data-viewmode="mobile"] .event-log {
  padding: 0.5rem 0.65rem 0.75rem;
  font-size: 0.72rem;
}

html[data-viewmode="mobile"] .modal {
  padding: max(0.6rem, env(safe-area-inset-top, 0px))
    max(0.6rem, env(safe-area-inset-right, 0px))
    max(0.6rem, env(safe-area-inset-bottom, 0px))
    max(0.6rem, env(safe-area-inset-left, 0px));
}

html[data-viewmode="mobile"] .modal-card {
  width: calc(100vw - 1.2rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  max-height: calc(100dvh - 1.2rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow: auto;
  padding: 1.05rem 1rem 1rem;
}

html[data-viewmode="mobile"] .switch-choice,
html[data-viewmode="mobile"] .switch-choice.cols-3 {
  grid-template-columns: 1fr;
}

html[data-viewmode="mobile"] .modal.schema-side {
  align-items: flex-end;
  justify-content: center;
  padding: 0.65rem;
}

html[data-viewmode="mobile"] .modal.schema-side .modal-card {
  width: calc(100vw - 1.2rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
}

html[data-viewmode="mobile"] .station-modal .station-modal-card,
html[data-viewmode="mobile"] .overview-modal .overview-modal-card {
  width: calc(100vw - 0.9rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  height: calc(100dvh - 0.9rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 0.9rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  padding: 0.75rem 0.8rem 0.8rem;
}

html[data-viewmode="mobile"] .station-schema-host.multi-schema {
  flex-direction: column;
}

html[data-viewmode="mobile"] .station-schema-host.multi-schema .station-schema-pane + .station-schema-pane {
  border-left: none;
  padding-left: 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.14);
  padding-top: 0.75rem;
}

html[data-viewmode="mobile"] .station-modal-hint {
  font-size: 0.72rem;
  margin-bottom: 0.5rem;
}

html[data-viewmode="mobile"] .overview-stations {
  gap: 0.4rem;
}

html[data-viewmode="mobile"] .station-mini-schema svg.station-schema-svg {
  height: min(110px, 16dvh);
}

html[data-viewmode="mobile"] .station-card.no-schema {
  min-width: 0;
  width: 100%;
}

/* ═══ Mobil FEKVŐ — iPhone 16 Pro (~874×402) és hasonló short-height ═══ */
@media (orientation: landscape) and (max-height: 500px) {
  html[data-viewmode="mobile"] .topbar {
    grid-template-columns: 1fr auto;
    gap: 0.4rem;
    padding: 0.35rem 0.65rem;
    position: sticky;
  }

  html[data-viewmode="mobile"] .app-title {
    font-size: 1rem;
  }

  html[data-viewmode="mobile"] .station-picker-label {
    display: none;
  }

  html[data-viewmode="mobile"] .station-select {
    max-width: 10.5rem;
    font-size: 0.7rem;
    padding: 0.28rem 1.55rem 0.28rem 0.45rem;
  }

  html[data-viewmode="mobile"] .status-msg {
    display: none;
  }

  html[data-viewmode="mobile"] .workspace {
    grid-template-columns: 1fr minmax(200px, 28vw);
    grid-template-rows: 1fr;
    padding-bottom: 0;
  }

  html[data-viewmode="mobile"] .log-panel {
    border-left: 1px solid var(--line);
    border-top: none;
  }

  html[data-viewmode="mobile"] .log-header {
    padding-top: calc(0.35rem + env(safe-area-inset-top, 0px));
  }

  html[data-viewmode="mobile"] .log-persist {
    padding: 0.4rem 0.55rem;
  }

  html[data-viewmode="mobile"] .log-persist .btn {
    padding: 0.28rem 0.45rem;
    font-size: 0.7rem;
    min-height: 0;
  }

  html[data-viewmode="mobile"] .stage {
    min-height: 0;
    height: 100%;
    padding: 0.35rem;
  }

  html[data-viewmode="mobile"] .schema-shell {
    padding: 0.35rem;
    height: 100%;
    min-height: 0;
  }

  html[data-viewmode="mobile"] #schema {
    min-height: 0;
    height: 100%;
    max-height: 100%;
    aspect-ratio: auto;
  }

  html[data-viewmode="mobile"] .overview-fab,
  html[data-viewmode="mobile"] .viewmode-fab,
  html[data-viewmode="mobile"] .reset-fab {
    font-size: 0.68rem;
    padding: 0.28rem 0.5rem;
  }

  html[data-viewmode="mobile"] .overview-fab,
  html[data-viewmode="mobile"] .viewmode-fab {
    bottom: 0.35rem;
  }

  html[data-viewmode="mobile"] .overview-fab,
  html[data-viewmode="mobile"] .reset-fab {
    right: 0.4rem;
  }

  html[data-viewmode="mobile"] .reset-fab {
    top: 0.35rem;
  }

  html[data-viewmode="mobile"] .viewmode-fab {
    left: 0.4rem;
  }

  html[data-viewmode="mobile"] .log-header {
    padding: 0.4rem 0.55rem;
  }

  html[data-viewmode="mobile"] .log-header-title {
    font-size: 0.68rem;
  }

  html[data-viewmode="mobile"] .log-undo-btn {
    padding: 0.2rem 0.45rem;
    font-size: 0.68rem;
  }

  html[data-viewmode="mobile"] .event-log {
    padding: 0.4rem 0.5rem 0.55rem;
  }

  html[data-viewmode="mobile"] .modal {
    padding: 0.4rem;
  }

  html[data-viewmode="mobile"] .modal-card {
    width: min(420px, calc(100% - 0.8rem));
    max-height: calc(100dvh - 0.8rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow: auto;
    padding: 0.85rem 0.9rem 0.85rem;
  }

  html[data-viewmode="mobile"] .modal.schema-side {
    align-items: center;
    justify-content: flex-end;
    padding: 0.4rem;
  }

  html[data-viewmode="mobile"] .modal.schema-side .modal-card {
    width: min(340px, 42vw);
    max-height: calc(100dvh - 0.8rem);
  }

  html[data-viewmode="mobile"] .switch-choice,
  html[data-viewmode="mobile"] .switch-choice.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  html[data-viewmode="mobile"] .station-modal .station-modal-card,
  html[data-viewmode="mobile"] .overview-modal .overview-modal-card {
    width: calc(100% - 0.8rem);
    height: calc(100dvh - 0.8rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 0.8rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding: 0.55rem 0.65rem 0.65rem;
  }

  html[data-viewmode="mobile"] .station-mini-schema svg.station-schema-svg {
    height: min(80px, 22dvh);
  }
}
