:root {
  --pozadie: #f4f6f8;
  --panel: #ffffff;
  --ciara: #dde2e8;
  --text: #1f2933;
  --text2: #5c6b7a;
  --akcent: #0f766e;
  --akcent2: #e6f4f2;
  --cervena: #c0392b;
  --oranzova: #d97706;
  --modra: #2563eb;
  --mono: "JetBrains Mono", "Fira Code", "DejaVu Sans Mono", "Cascadia Mono", Consolas, monospace;
  --riadok: 20px;
  font-family: "Ubuntu", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--pozadie);
  font-size: 14px;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ horná lišta */
.lista {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--ciara);
  flex-wrap: wrap;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.logo img { width: 26px; height: 26px; }
.doska-vyber { display: flex; align-items: center; gap: 6px; color: var(--text2); }
.doska-vyber select {
  padding: 5px 8px; border: 1px solid var(--ciara); border-radius: 7px; background: #fff; color: var(--text);
}
.skupina { display: flex; gap: 6px; }
.vpravo { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.tl {
  padding: 6px 12px;
  border: 1px solid var(--ciara);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.tl:hover:not(:disabled) { background: #f1f4f7; }
.tl:disabled { opacity: .45; cursor: default; }
.tl.hlavne { background: var(--akcent); border-color: var(--akcent); color: #fff; font-weight: 600; }
.tl.hlavne:hover:not(:disabled) { background: #0d6660; }
.tl.ikona { padding: 6px 10px; }
.tl.vypnute { opacity: .5; }
.stav {
  padding: 4px 10px; border-radius: 99px; background: #eef1f4; color: var(--text2); font-size: 13px;
  white-space: nowrap;
}
.stav.bezi { background: #dcfce7; color: #166534; }
.stav.chyba { background: #fde2e1; color: #9b1c1c; }
.stav.pripravuje { background: #fef3c7; color: #92400e; }

.menu-obal { position: relative; }
.menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  min-width: 260px; max-height: 70vh; overflow: auto;
  background: #fff; border: 1px solid var(--ciara); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .14);
  padding: 6px;
}
.menu button {
  display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none;
  border-radius: 6px; cursor: pointer;
}
.menu button:hover { background: var(--akcent2); }
.menu button small { display: block; color: var(--text2); font-size: 12px; }
.menu h4 { margin: 8px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); }
.menu hr { border: 0; border-top: 1px solid var(--ciara); margin: 6px 4px; }

.banner {
  padding: 8px 14px; background: #fff7e6; border-bottom: 1px solid #f5d9a8; color: #7a4b00; font-size: 13px;
}

/* ------------------------------------------------------------ rozloženie */
.plocha { flex: 1; display: flex; min-height: 0; }
.panel { background: var(--panel); min-width: 0; position: relative; }
.kod { width: 38%; display: flex; flex-direction: column; border-right: 1px solid var(--ciara); }
.platna-obal { flex: 1; overflow: hidden; }
.delic { background: transparent; flex: none; z-index: 5; }
.delic.zvisly { width: 6px; margin: 0 -3px; cursor: col-resize; }
.delic.vodorovny { height: 6px; margin: -3px 0; cursor: row-resize; }
.delic:hover { background: rgba(15, 118, 110, .25); }

/* ------------------------------------------------------------ karty súborov a editor */
.karty {
  display: flex; align-items: stretch; gap: 2px; padding: 6px 8px 0; background: #f7f9fb;
  border-bottom: 1px solid var(--ciara); overflow-x: auto; flex: none;
}
.karta {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid transparent;
  border-bottom: 0; border-radius: 7px 7px 0 0; cursor: pointer; color: var(--text2); white-space: nowrap;
  font-family: var(--mono); font-size: 12.5px;
}
.karta.aktivna { background: #fff; border-color: var(--ciara); color: var(--text); margin-bottom: -1px; }
.karta .x { border: 0; background: none; cursor: pointer; color: #9aa5b1; padding: 0 2px; font-size: 14px; }
.karta .x:hover { color: var(--cervena); }
.karta.nova { color: var(--akcent); font-weight: 700; }

.editor-obal { flex: 1; min-height: 0; position: relative; }
.ed { position: absolute; inset: 0; display: flex; font-family: var(--mono); font-size: 13.5px; line-height: var(--riadok); }
.ed-gutter {
  width: 48px; flex: none; overflow: hidden; background: #fafbfc; border-right: 1px solid #eef1f4;
  color: #a0aab4; text-align: right; position: relative;
}
.ed-gutter pre { margin: 0; padding: 10px 8px 10px 0; font: inherit; position: absolute; top: 0; right: 0; }
.ed-gutter .cislo-chyba { color: #fff; background: var(--cervena); border-radius: 3px; padding: 0 3px; }
.ed-main { flex: 1; position: relative; overflow: hidden; }
.ed-vrstva { position: absolute; top: 0; left: 0; pointer-events: none; }
.ed-hl, .ed textarea {
  margin: 0; padding: 10px 14px; font: inherit; line-height: var(--riadok); tab-size: 4;
  white-space: pre; border: 0; letter-spacing: 0;
}
.ed-hl { color: #24292f; min-width: 100%; }
.ed textarea {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; outline: none;
  background: transparent; color: transparent; caret-color: #111; overflow: auto;
}
.ed textarea::selection { background: rgba(37, 99, 235, .22); color: transparent; }
.ed-chyba {
  position: absolute; left: 0; right: -4000px; height: var(--riadok);
  background: rgba(192, 57, 43, .12); border-left: 3px solid var(--cervena);
}
.t-kom { color: #6a737d; font-style: italic; }
.t-str { color: #0a7d32; }
.t-cis { color: #b45309; }
.t-kw { color: #a21caf; font-weight: 600; }
.t-bi { color: #0369a1; }
.t-dek { color: #b45309; }
.t-fn { color: #1d4ed8; font-weight: 600; }
.t-self { color: #be185d; }

/* ------------------------------------------------------------ montážna platňa */
.platna-scroll { position: absolute; inset: 0; overflow: auto; background: #cfd5db; }
.platna {
  position: relative; width: 1800px; height: 1200px; transform-origin: 0 0;
  background-color: #dfe4e8;
  background-image:
    radial-gradient(circle at 12px 12px, #b9c1c9 2.6px, rgba(0, 0, 0, 0) 3.2px),
    linear-gradient(180deg, rgba(255, 255, 255, .35), rgba(255, 255, 255, 0) 40%);
  background-size: 24px 24px, 100% 100%;
  border: 1px solid #aab3bc;
  box-shadow: inset 0 0 0 6px #e9edf0, inset 0 0 0 7px #c5ccd3;
}
.kable { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; overflow: visible; }
.sucastka.pole-karta { z-index: 2; }   /* kábliky idú nad nepájivé pole, ale pod ostatné karty */
.kable path { fill: none; stroke-linecap: round; }
.kable .obrys { stroke: rgba(255, 255, 255, .85); stroke-width: 5.5; }
.kable .drot { stroke-width: 3; opacity: .92; }
.kable .drot.zvyrazneny { stroke-width: 4.5; opacity: 1; }
.kable .koncovka { stroke: #fff; stroke-width: 1.4; }

.doska {
  position: absolute; z-index: 2; cursor: grab; user-select: none;
  filter: drop-shadow(0 6px 10px rgba(15, 23, 42, .28));
}
.doska:active { cursor: grabbing; }
.doska svg { display: block; }
.bpin { cursor: crosshair; }
.bpin circle.plosky { fill: #c9a227; stroke: #8a6d12; stroke-width: 1; }
.bpin.hi circle.plosky { fill: #ffe14d; stroke: #f59e0b; filter: drop-shadow(0 0 4px #ffd400); }
.bpin.lo circle.plosky { fill: #6b5a1d; }
.bpin.pwm circle.plosky { fill: #fb923c; stroke: #c2410c; }
.bpin.vstup circle.plosky { fill: #93c5fd; stroke: #1d4ed8; }
.bpin.vstup.hi circle.plosky { fill: #3b82f6; }
.bpin.pripojeny text { font-weight: 700; fill: #fff; }
.bpin.zvyrazneny circle.plosky { stroke: #fff; stroke-width: 3; }
.dtl { cursor: pointer; }
.dtl:hover rect { fill: #4b5563; }
.dtl.stlacene rect { fill: #111827; }

.sucastka {
  position: absolute; z-index: 4; background: #fff; border: 1px solid #c3cad2; border-radius: 10px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .14); user-select: none; min-width: 90px;
}
.sucastka.vybrana { outline: 2.5px solid var(--akcent); outline-offset: 1px; }
.sucastka.konflikt { border-color: var(--cervena); }
.s-hlava {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; cursor: grab;
  border-bottom: 1px solid #edf0f3; font-size: 12.5px; font-weight: 600; color: #334155;
}
.s-hlava:active { cursor: grabbing; }
.s-hlava .meno { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-hlava button {
  border: 0; background: none; cursor: pointer; color: #64748b; font-size: 15px; padding: 0 3px; line-height: 1;
}
.s-hlava button:hover { color: var(--akcent); }
.s-telo { padding: 8px; display: flex; justify-content: center; align-items: center; }
.s-telo canvas { display: block; image-rendering: pixelated; }
.s-svorky {
  display: flex; flex-wrap: wrap; gap: 3px 4px; padding: 4px 6px 6px; border-top: 1px dashed #e2e8f0;
  justify-content: center;
}
.svorka {
  display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; color: #475569;
  background: #f1f5f9; border-radius: 4px; padding: 1px 5px 1px 3px; font-family: var(--mono);
}
.svorka i { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; display: inline-block; }
.svorka b { color: #0f172a; }
.svorka.nezapojena { opacity: .5; }

/* prvky súčiastok */
.tlacidlo-cap {
  width: 54px; height: 54px; border-radius: 50%; border: 3px solid #475569; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #fff8 0, #fff0 45%), var(--farba, #e11d48);
  box-shadow: 0 4px 0 #1e293b, 0 6px 10px rgba(0, 0, 0, .25); transition: transform .05s, box-shadow .05s;
  touch-action: none;
}
.tlacidlo-cap.stlacene { transform: translateY(3px); box-shadow: 0 1px 0 #1e293b, 0 2px 4px rgba(0, 0, 0, .25); }
.prepinac { width: 64px; height: 30px; border-radius: 15px; background: #cbd5e1; position: relative; cursor: pointer; border: 2px solid #64748b; }
.prepinac::after { content: ""; position: absolute; top: 2px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: left .12s; }
.prepinac.zap { background: #22c55e; }
.prepinac.zap::after { left: 35px; }
.popis-male { font-size: 11px; color: var(--text2); text-align: center; font-family: var(--mono); }
.stlpec { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.gomb { touch-action: none; cursor: ns-resize; }
.klavesnica { display: grid; grid-template-columns: repeat(4, 34px); gap: 5px; padding: 6px; background: #1e293b; border-radius: 8px; }
.klavesnica button {
  height: 32px; border: 0; border-radius: 6px; background: #e2e8f0; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 0 #64748b; touch-action: none;
}
.klavesnica button.stlacene { background: #fbbf24; transform: translateY(2px); box-shadow: none; }
.klavesnica button.pismeno { background: #fecaca; }

/* ------------------------------------------------------------ zoom a panel nastavení */
.zoom {
  position: absolute; right: 12px; bottom: 12px; z-index: 10; display: flex; align-items: center; gap: 2px;
  background: #fff; border: 1px solid var(--ciara); border-radius: 8px; padding: 3px; box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.zoom button { border: 0; background: none; width: 28px; height: 26px; cursor: pointer; border-radius: 5px; font-size: 15px; }
.zoom button:hover { background: #f1f4f7; }
.zoom span { min-width: 46px; text-align: center; font-size: 12px; color: var(--text2); }

.nastavenia {
  position: absolute; top: 10px; right: 10px; bottom: 54px; width: 310px; z-index: 20; overflow: auto;
  background: #fff; border: 1px solid var(--ciara); border-radius: 12px; box-shadow: 0 12px 32px rgba(15, 23, 42, .18);
  padding: 14px 16px;
}
.nastavenia h3 { margin: 0 0 2px; font-size: 16px; }
.nastavenia .podnadpis { color: var(--text2); font-size: 12.5px; margin-bottom: 12px; }
.nastavenia .zatvorit { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 20px; cursor: pointer; color: #94a3b8; }
.nastavenia label { display: block; font-size: 12.5px; color: var(--text2); margin: 10px 0 3px; }
.nastavenia select, .nastavenia input[type=text], .nastavenia input[type=number] {
  width: 100%; padding: 6px 8px; border: 1px solid var(--ciara); border-radius: 7px; background: #fff;
}
.nastavenia .riadok-pinu { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 8px; margin: 5px 0; }
.nastavenia .riadok-pinu span { font-family: var(--mono); font-size: 12.5px; }
.nastavenia .sekcia { margin-top: 14px; padding-top: 10px; border-top: 1px solid #eef1f4; font-weight: 600; font-size: 13px; }
.nastavenia .varovanie { margin-top: 10px; padding: 8px 10px; background: #fef2f2; color: #991b1b; border-radius: 8px; font-size: 12.5px; }
.nastavenia .poznamka { margin-top: 10px; padding: 8px 10px; background: #f0f9ff; color: #075985; border-radius: 8px; font-size: 12.5px; }
.nastavenia .tl-odstranit { margin-top: 16px; width: 100%; color: var(--cervena); }

/* ------------------------------------------------------------ spodný panel */
.spodok { height: 230px; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--ciara); flex: none; }
.spodok-karty { display: flex; gap: 2px; padding: 4px 8px 0; border-bottom: 1px solid var(--ciara); background: #f7f9fb; }
.spodok-karty button {
  border: 1px solid transparent; border-bottom: 0; background: none; padding: 5px 14px; cursor: pointer;
  border-radius: 7px 7px 0 0; color: var(--text2);
}
.spodok-karty button.aktivna { background: #fff; border-color: var(--ciara); color: var(--text); margin-bottom: -1px; font-weight: 600; }
.spodok-karty .medzera { flex: 1; }
.spodok-karty .male { font-size: 12.5px; }
.spodok-obsah { flex: 1; min-height: 0; position: relative; }
.karta-obsah { position: absolute; inset: 0; display: flex; flex-direction: column; }
.konzola {
  flex: 1; overflow: auto; padding: 8px 12px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; background: #fcfcfd;
}
.konzola .err { color: #b91c1c; }
.konzola .info { color: #0369a1; }
.konzola .rada { color: #92400e; background: #fffbeb; display: block; padding: 2px 6px; border-radius: 4px; margin: 2px 0; }
.konzola .oddelovac { color: #94a3b8; }
.konzola .repl-vstup { color: #64748b; }
.repl { display: flex; align-items: center; gap: 8px; padding: 5px 12px; border-top: 1px solid var(--ciara); font-family: var(--mono); }
.repl span { color: var(--akcent); font-weight: 700; }
.repl input { flex: 1; border: 0; outline: none; font-family: var(--mono); font-size: 12.5px; background: none; }
#graf { flex: 1; width: 100%; min-height: 0; }
.graf-pomoc { padding: 4px 12px 6px; font-size: 12px; color: var(--text2); }
.tabulka-pinov { overflow: auto; padding: 6px 12px; }
.tabulka-pinov table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.tabulka-pinov th, .tabulka-pinov td { padding: 4px 10px; border-bottom: 1px solid #eef1f4; text-align: left; }
.tabulka-pinov th { color: var(--text2); font-weight: 600; position: sticky; top: 0; background: #fff; }
.tabulka-pinov .uroven { display: inline-block; min-width: 18px; text-align: center; border-radius: 4px; font-family: var(--mono); }
.tabulka-pinov .u1 { background: #fde68a; }
.tabulka-pinov .u0 { background: #e2e8f0; }

/* ------------------------------------------------------------ modálne okno */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-okno {
  position: relative; background: #fff; border-radius: 14px; max-width: 760px; width: calc(100% - 40px);
  max-height: 85vh; overflow: auto; padding: 22px 26px; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.modal-zavriet { position: absolute; top: 10px; right: 14px; border: 0; background: none; font-size: 24px; cursor: pointer; color: #94a3b8; }
.modal-okno h2 { margin-top: 0; }
.modal-okno h3 { margin-bottom: 4px; }
.modal-okno p, .modal-okno li { line-height: 1.55; }
.modal-okno code, .modal-okno kbd { font-family: var(--mono); background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

/* modul z knižnice (bez simulácie) */
.modul-telo { min-width: 150px; max-width: 210px; border-radius: 6px; padding: 10px 12px 8px; color: #e5e7eb;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); position: relative; }
.modul-cip { width: 34px; height: 22px; background: #0b0f14; border-radius: 3px; margin-bottom: 8px;
  box-shadow: 0 0 0 2px #0b0f14, 0 0 0 3px #94a3b8; }
.modul-meno { font-weight: 700; font-size: 13px; line-height: 1.25; color: #fff; }
.modul-info { font-size: 11px; color: #cbd5e1; margin-top: 3px; font-family: var(--mono); }
.modul-spodok { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.modul-stitok { font-size: 10px; background: rgba(255,255,255,.16); color: #f1f5f9; border-radius: 99px; padding: 1px 7px; }
.modul-odkaz { color: #e2e8f0; text-decoration: none; font-size: 14px; }
.modul-odkaz:hover { color: #fff; }

/* voľné kábliky */
.kable .kabel-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.kable .docasny { fill: none; stroke-width: 3; stroke-dasharray: 6 4; }
.kable .drot.vybrany { stroke-width: 5.5; filter: drop-shadow(0 0 3px rgba(15, 118, 110, .8)); }
.svorka { cursor: crosshair; }

/* nepájivé pole */
svg.pole { display: block; }
svg.pole .otvor { fill: #3f3f46; cursor: crosshair; }
svg.pole .otvor:hover { fill: #0f766e; }
svg.pole .otvor.v-sieti { fill: #10b981; }
svg.pole .vlozena { cursor: grab; }
svg.pole .vlozena:active { cursor: grabbing; }
svg.pole [data-akcia] { cursor: pointer; }
.nastavenia .riadok-tl { display: flex; gap: 6px; margin-top: 8px; }

/* oživené moduly */
.senzor { width: 196px; background: var(--pcb); border-radius: 6px; padding: 8px 10px 6px; color: #e5e7eb; font-size: 11px; }
.senzor-cip { display: inline-block; background: #0b0f14; color: #d1d5db; font-family: var(--mono); font-size: 10px; border-radius: 3px; padding: 3px 7px; margin-bottom: 6px; }
.senzor-riadok { display: grid; grid-template-columns: 1fr auto; gap: 0 6px; margin-top: 4px; cursor: default; }
.senzor-riadok b { color: #fff; font-variant-numeric: tabular-nums; }
.senzor-riadok input { grid-column: 1 / -1; width: 100%; margin: 2px 0 0; accent-color: #fbbf24; }
.senzor-viz { background: rgba(0,0,0,.25); border-radius: 5px; padding: 6px; margin: 2px 0 4px; text-align: center; }
.pir { display: flex; align-items: center; gap: 8px; text-align: left; }
.pir-tl { padding: 3px 8px; font-size: 12px; }
.pir-stav.aktiv { color: #fde047; font-weight: 700; }
.hodiny b { display: block; font-family: var(--mono); font-size: 20px; color: #a7f3d0; letter-spacing: 1px; }
.hodiny small { color: #cbd5e1; }
.motor-text, .pca-text, .ssr-text { font-size: 10.5px; color: #e5e7eb; margin-top: 3px; }
.uln-led { display: flex; justify-content: center; gap: 6px; margin-bottom: 4px; }
.uln-led i, .hc595 .ledky i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: #450a0a; font-style: normal; font-size: 8px; line-height: 11px; color: #fca5a5; }
.uln-led i.on, .hc595 .ledky i.on { background: #ef4444; box-shadow: 0 0 6px #f87171; color: #fff; }
.pca-stlpce { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; height: 46px; align-items: end; }
.pca-stlpce div { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.pca-stlpce i { width: 7px; background: #60a5fa; border-radius: 2px 2px 0 0; height: 0; }
.pca-stlpce small { font-size: 7px; color: #94a3b8; }
.hc595 .ledky { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 5px; }
.hc595 .ledky span { display: flex; flex-direction: column; align-items: center; }
.hc595 .ledky small { font-size: 7.5px; color: #cbd5e1; }
.senzor-riadok.z-obvodu b { color: #fde047; }
.senzor-riadok.z-obvodu input { opacity: .35; }
