/* Layout: kopplingsplåt — palett till vänster, ritytan som ett schemablad i mitten, mätning och händelser till höger */
:root {
  --bg: #e6eae8; --panel: #f4f6f5; --sheet: #fbfcfb; --grid: #cfd6d3; --ink: #1c2326; --muted: #5a6669; --line: #c4ccc8;
  --accent: #dd5f14; --accent-soft: #fbe3d3; --ok: #23824a; --bad: #c42b2b; --bad-soft: #f8dcdc;
  --w-l1: #8a5527; --w-l2: #161616; --w-l3: #8e9599; --w-n: #2a68cf; --w-dead: #b2bbb8; --w-edit: #46525a; --halo: #fbfcfb;
  --w-rd: #d42a2a; --w-og: #ef8a12; --w-wh: #ffffff; --w-ye: #e8b800; --w-gn: #2c9a48; --w-vt: #7d4fcf; --w-case: #5a6669;
  --lamp-g: #28c24c; --lamp-r: #e83a35; --lamp-y: #f4b400; --lamp-w: #f5f2e4;
  --f-disp: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #111517; --panel: #181e20; --sheet: #141a1c; --grid: #263235; --ink: #e2e8e6; --muted: #92a09e; --line: #2d393c;
  --accent: #f27c32; --accent-soft: #3a2416; --ok: #45b56d; --bad: #f05a55; --bad-soft: #3b1a1a;
  --w-l1: #a8693a; --w-l2: #050505; --w-l3: #9aa2a6; --w-n: #4d8ff5; --w-dead: #3f4b4e; --w-edit: #9aa8a6; --halo: #141a1c;
  --w-rd: #ee4a48; --w-og: #f59a2e; --w-wh: #eef1f0; --w-ye: #f2c94c; --w-gn: #4cbc68; --w-vt: #a888ee; --w-case: #8f9b99;
  color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #111517; --panel: #181e20; --sheet: #141a1c; --grid: #263235; --ink: #e2e8e6; --muted: #92a09e; --line: #2d393c;
  --accent: #f27c32; --accent-soft: #3a2416; --ok: #45b56d; --bad: #f05a55; --bad-soft: #3b1a1a;
  --w-l1: #a8693a; --w-l2: #050505; --w-l3: #9aa2a6; --w-n: #4d8ff5; --w-dead: #3f4b4e; --w-edit: #9aa8a6; --halo: #141a1c;
  --w-rd: #ee4a48; --w-og: #f59a2e; --w-wh: #eef1f0; --w-ye: #f2c94c; --w-gn: #4cbc68; --w-vt: #a888ee; --w-case: #8f9b99;
  color-scheme: dark }

html, body { height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.45; }
.app { height: 100%; display: flex; flex-direction: column; min-height: 0; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand h1 { margin: 0; font-family: var(--f-disp); font-weight: 600; font-size: 20px; letter-spacing: .01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; font-family: var(--f-mono); }
.mark { width: 26px; height: 26px; border: 2px solid var(--ink); border-radius: 3px; position: relative; flex: none; }
.mark::before { content: ""; position: absolute; left: 50%; top: 4px; bottom: 4px; width: 2px; margin-left: -1px; background: var(--ink); }
.mark::after { content: ""; position: absolute; left: 50%; top: 5px; width: 9px; height: 2px; background: var(--accent); transform: rotate(-35deg); transform-origin: left; margin-left: -1px; top: 15px; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn { border: 1px solid var(--line); background: var(--sheet); border-radius: 6px; padding: 6px 12px; }
.btn:hover { border-color: var(--muted); }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--sheet); border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.run { background: var(--ok); color: #fff; border-color: transparent; font-weight: 600; min-width: 164px; }
.btn.run.on { background: var(--bad); }
.btn.warn { border-color: var(--bad); color: var(--bad); }
select.btn { padding-right: 8px; }
.colors { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.colors > span { font-size: 12px; color: var(--muted); margin-right: 2px; }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--panel); padding: 0; background: var(--c);
  box-shadow: 0 0 0 1px var(--line); flex: none; }
.sw:hover { box-shadow: 0 0 0 1px var(--muted); }
.sw[aria-checked="true"] { box-shadow: 0 0 0 2px var(--accent); }
.sw:disabled { opacity: .45; cursor: default; }
.sw-name { font-family: var(--f-mono); font-size: 12px; color: var(--muted); min-width: 64px; }
.props .colors { gap: 6px; }
.zoom { display: flex; align-items: center; gap: 4px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.zoom .btn { padding: 4px 10px; }

.work { flex: 1; min-height: 0; display: grid; grid-template-columns: 200px minmax(0, 1fr) 310px; }
.palette { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.palette h2, .side h2 { font-family: var(--f-disp); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 4px 2px; }
.pal { text-align: left; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 7px 8px; display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: center; }
.pal:hover:not(:disabled) { background: var(--sheet); border-color: var(--line); }
.pal:disabled { opacity: .4; cursor: default; }
.pal svg { width: auto; max-width: 48px; height: 36px; justify-self: center; pointer-events: none; }
.pal svg * { vector-effect: non-scaling-stroke; } /* symbolerna skalas ned men behåller linjebredden */
.pal span { font-size: 13px; line-height: 1.25; }

.stage { overflow: auto; background: var(--sheet); position: relative; min-width: 0; touch-action: none; }
.stage.pan { touch-action: pan-x pan-y; }
#svg { display: block; user-select: none; -webkit-user-select: none; }
.hint { position: sticky; left: 12px; top: 12px; display: inline-block; z-index: 2; background: var(--ink); color: var(--sheet); padding: 6px 10px; border-radius: 6px; font-size: 12.5px; margin: 12px; max-width: calc(100% - 24px); }
.hint[hidden] { display: none !important; }

.side { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
[hidden] { display: none !important; }
.card { background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.status { font-family: var(--f-mono); font-size: 12.5px; display: flex; align-items: center; gap: 8px; }
.led { width: 10px; height: 10px; border-radius: 50%; background: var(--w-dead); flex: none; }
.led.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.led.bad { background: var(--bad); }
.props label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.props input, .props select { border: 1px solid var(--line); background: var(--panel); border-radius: 5px; padding: 5px 8px; font-size: 13.5px; }
.props h3 { margin: 0; font-family: var(--f-disp); font-size: 16px; font-weight: 600; }
.props p { margin: 0; font-size: 13px; }
.props .row { display: flex; gap: 8px; flex-wrap: wrap; }
.props label.chk { flex-direction: row; align-items: center; align-self: flex-end; gap: 6px; padding-bottom: 6px; }
.muted { color: var(--muted); }
.meter { font-family: var(--f-mono); }
.meter .read { font-size: 30px; font-weight: 500; letter-spacing: .02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.meter small { font-size: 11.5px; color: var(--muted); display: block; }
.meter .vt { display: flex; gap: 12px; align-items: flex-start; }
.meter .vt svg { flex: none; }
.meter .vt small + small { margin-top: 6px; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.log li { font-size: 12.5px; display: grid; grid-template-columns: 44px 1fr; gap: 6px; }
.log time { font-family: var(--f-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.log li.fel span { color: var(--bad); }
.legend { display: grid; grid-template-columns: repeat(2, auto); gap: 4px 14px; font-size: 12px; justify-content: start; }
.legend i { display: inline-block; width: 22px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 6px; box-shadow: 0 0 0 1px var(--halo); }
.note { font-size: 12px; color: var(--muted); margin: 0; }
.how { margin: 0; padding-left: 18px; font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }

/* SVG */
.grid-dot { fill: var(--grid); }
/* Schemasymboler ritas utan ram (SS-EN 60617); ramen visas bara vid hovring och markering */
.comp .body { fill: transparent; stroke: none; }
.edit .comp:hover .body { stroke: var(--line); stroke-width: 1; stroke-dasharray: 4 3; }
.comp.sel .body { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 5 3; }
.comp.burnt .body { fill: var(--bad-soft); }
.cl { stroke: var(--ink); stroke-width: 1.6; fill: none; stroke-linecap: round; }
.blade { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.blade.closed { stroke: var(--accent); }
.mech { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; fill: none; }
.coil { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.6; }
.coil.on { fill: var(--accent); }
.coil.burnt { fill: var(--bad); }
.xfw.on { fill: var(--accent); fill-opacity: .3; } /* styrtransformatorn ger 24 V */
.burnt .xfw { fill: var(--bad); fill-opacity: .3; }
.tl { font-family: var(--f-mono); font-size: 9.5px; fill: var(--muted); }
.trip { font-family: var(--f-mono); font-size: 11px; fill: var(--ink); }
.mirror { pointer-events: none; }
.mir { font-family: var(--f-mono); font-size: 8.5px; fill: var(--ink); }
.mirl { stroke: var(--ink); stroke-width: 1.1; fill: none; stroke-linecap: round; }
.tag { font-family: var(--f-disp); font-weight: 600; font-size: 15px; fill: var(--ink); }
.sub { font-family: var(--f-mono); font-size: 10px; fill: var(--muted); }
.cap { font-family: var(--f-disp); font-weight: 600; font-size: 13px; fill: var(--ink); }
.cap2 { font-family: var(--f-mono); font-size: 10px; fill: var(--muted); }
.num { font-family: var(--f-mono); font-size: 10.5px; fill: var(--ink); }
.flag { font-family: var(--f-mono); font-size: 10px; font-weight: 500; fill: var(--bad); }
.stat { font-family: var(--f-mono); font-size: 11px; fill: var(--ink); }
.stat.bad { fill: var(--bad); }
.term .hit { fill: transparent; }
.term .dot { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.6; }
.edit .term:hover .dot, .term.pend .dot { fill: var(--accent); stroke: var(--accent); }
.term.p1 .dot { fill: var(--bad); stroke: var(--bad); }
.term.p2 .dot { fill: var(--ink); stroke: var(--ink); }
.edit .term, .meter-on .term { cursor: crosshair; }
.edit .comp { cursor: grab; }
.wire { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.halo { fill: none; stroke: var(--halo); stroke-width: 5.5; stroke-linejoin: round; }
.whit { fill: none; stroke: transparent; stroke-width: 12; }
.edit .whit { cursor: pointer; }
.wcase { fill: none; stroke: var(--w-case); stroke-width: 4.4; stroke-linejoin: round; stroke-linecap: round; }
.halo.sel { stroke: var(--accent); stroke-opacity: .45; stroke-width: 11; }
.wire.dead { stroke-opacity: .4; stroke-dasharray: 2 5; }
.wcase.dead { stroke-opacity: .25; stroke-dasharray: 2 5; }
.wire.short { stroke: var(--bad) !important; stroke-opacity: 1; stroke-dasharray: 6 4; }
/* Samlingsskenor och skyddsjord i schemavyn */
.busline { fill: none; stroke-width: 2.6; stroke-linejoin: round; }
.bushit { fill: none; stroke: transparent; stroke-width: 10; }
.edit .bushit, .meter-on .bushit { cursor: crosshair; }
.edit .bushit:hover, .meter-on .bushit:hover { stroke: var(--accent); stroke-opacity: .25; }
.comp.bus.sel .busline { stroke-width: 4; }
.busdot { fill: var(--ink); }
.pesym { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.pesym circle { fill: var(--sheet); fill-opacity: .01; }
.edit .pesym { cursor: pointer; }
.mech.link { fill: none; pointer-events: none; }
/* Nätmarkering: markerat nät framhävs, övriga ledare tonas ned */
.halo.hl { stroke: var(--accent); stroke-opacity: .35; stroke-width: 9; }
.wire.dim, .wcase.dim, .wstripe.dim, .busline.dim { stroke-opacity: .18; }
.term.hl .dot { fill: var(--accent); stroke: var(--accent); }
.mountlink { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-dasharray: 1 4; stroke-linecap: round; pointer-events: none; }
.rubber { stroke-width: 2.4; stroke-dasharray: 5 4; fill: none; stroke-linecap: round; }
/* Grön/gul PE: grön ledare med gul randning ovanpå */
.wstripe { fill: none; stroke: var(--w-ye); stroke-width: 2.4; stroke-dasharray: 6 6; stroke-linejoin: round; pointer-events: none; }
.wstripe.dead { stroke-opacity: .4; stroke-dasharray: 2 5; stroke-dashoffset: 3.5; }
.pestripe { stroke: var(--w-ye); stroke-width: 3; stroke-dasharray: 3 3; }

/* Övning med automatisk kontroll */
.task h2 { margin: 0 0 6px; }
.task p { margin: 0 0 8px; font-size: 13px; }
.task-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.task-sum { font-weight: 600; }
.task-sum.ok, .task-res .ok > span:first-child { color: var(--ok); }
.task-sum.bad, .task-res .bad > span:first-child { color: var(--bad); }
.task-res { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.task-res li { display: grid; grid-template-columns: 16px 1fr; gap: 6px; }
.task-res small { display: block; color: var(--muted); font-size: 12px; }

/* Varför fungerar det inte? */
.why h2 { margin: 0 0 6px; }
.why ul { margin: 0; padding: 0 0 0 10px; list-style: none; border-left: 3px solid var(--bad); font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.why ul.ok { border-left-color: var(--ok); }

/* Paus, steg och fart under simulering */
.simctl { display: inline-flex; align-items: center; gap: 4px; }

/* Vyväxlare och skåpvy */
.seg { display: inline-flex; }
.seg .btn { border-radius: 0; }
.seg .btn:first-child { border-radius: 6px 0 0 6px; }
.seg .btn:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.chk[hidden] { display: none; }
.sk-plate { fill: url(#sk-plate-pat); stroke: #8d969c; stroke-width: 2; }
.sk-field { fill: none; stroke: var(--line); stroke-width: 1.5; stroke-dasharray: 6 6; }
/* Vyn Rum: tak, vägg med golvlinje och central */
.rm-ceil { fill: #eef0f2; stroke: #c3c9cf; stroke-width: 1.5; }
/* Vyn Ritning: installationsritning i svart på bladet, följer temat */
.pl-wall { fill: var(--sheet); stroke: var(--ink); stroke-width: 8; }
.pl-door { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.pl-gap { stroke: var(--sheet); stroke-width: 10; }
.pl-line { fill: none; stroke: var(--ink); stroke-width: 2.5; }
.pl-hit { fill: none; stroke: transparent; stroke-width: 14; }
.edit .pl-hit { cursor: copy; }
.edit .pl-move { cursor: grab; }
.pl-line.sel { stroke: var(--accent); }
.pl-bend { fill: var(--sheet); stroke: var(--accent); stroke-width: 2; cursor: move; }
.pl-tick { fill: none; stroke: var(--ink); stroke-width: 2; }
.pl-sym { fill: var(--sheet); stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; }
.pl-sym.lit { fill: #ffd84d; }
.pl-dot { fill: var(--ink); }
.pl-tag, .pl-num { font-family: var(--f-mono); font-size: 15px; fill: var(--ink); }
.pl-title { font-family: var(--f-disp); font-size: 26px; font-weight: 600; fill: var(--ink); }
.rm-wall { fill: #ece6da; stroke: #c9c0ae; stroke-width: 1.5; }
.rm-floor { stroke: #a89f8c; stroke-width: 6; }
.rm-cent { fill: #d9dde1; stroke: #8d969c; stroke-width: 2; }
/* Bordslampan i vägguttaget (bildens skala) */
.rm-cord { fill: none; stroke: #1d2124; stroke-width: 10; stroke-linecap: round; }
.rm-lampbase { fill: #4b5258; }
.rm-shade { fill: #e9e2d0; stroke: #b9ae95; stroke-width: 3; }
.rm-shade.lit { fill: #fff1b8; }
.rm-glow { fill: #ffd84d; opacity: .35; }
:root[data-theme="dark"] .rm-ceil { fill: #2a2f33; stroke: #3b4247; }
:root[data-theme="dark"] .rm-wall { fill: #2e2b26; stroke: #463f35; }
:root[data-theme="dark"] .rm-cent { fill: #3a4045; stroke: #59626a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .rm-ceil { fill: #2a2f33; stroke: #3b4247; }
  :root:not([data-theme="light"]) .rm-wall { fill: #2e2b26; stroke: #463f35; }
  :root:not([data-theme="light"]) .rm-cent { fill: #3a4045; stroke: #59626a; } }
.sk-zone { font-family: var(--f-mono); font-size: 12px; fill: var(--muted); }
/* Kabelkanal (grå, halvgenomskinlig så att ledarna syns) och dörrens ledarbunt */
.sk-duct { fill: #9aa3a9; fill-opacity: .45; stroke: #6f787e; stroke-width: 1.2; stroke-dasharray: 10 4; }
.sk-bundle { stroke: #3a4044; stroke-width: 26; stroke-opacity: .18; stroke-linecap: round; }
/* Skåpbilderna har egna färger; markering visas som ram */
.comp.skin .body, .comp.skin.burnt .body { fill: none; stroke: none; }
.comp.skin.sel .body { stroke: var(--accent); stroke-width: 2.4; }
.sk-plunger { fill: #222528; stroke: #111; stroke-width: 2; }
.sk-plunger.on { fill: #5d666e; stroke: #9aa3aa; }
.sk-led { fill: #333; stroke: #111; stroke-width: 1.5; }
.sk-led.on { fill: #3ddc6a; stroke: #1a7a35; }
.sk-mark { font-family: Arial, sans-serif; font-size: 17px; font-weight: 700; fill: #1c2326; }
.sk-burnt { fill: #d42a2a; fill-opacity: .35; }
.sk-txt { font-family: Arial, sans-serif; font-weight: 700; }
.sk-trip { fill: #f59f00; stroke: #7a4f00; stroke-width: 1.5; }
/* Motorn i skåpvyn: fläkthjul, suddig skiva vid full fart, uppvärmning, kopparbyglar i kopplingsfältet */
.sk-blade { fill: #94a3b8; stroke: #475569; stroke-width: 1.5; }
.sk-hub { fill: #cbd5e1; stroke: #475569; stroke-width: 2; }
.sk-blur { fill: #94a3b8; }
.sk-heat { fill: #ef4444; mix-blend-mode: multiply; }
.mbridge { fill: none; stroke: #c2730c; stroke-width: 7; stroke-linecap: round; }
.sk-fault { fill: none; stroke: #ef4444; stroke-width: 12; stroke-linecap: round; stroke-opacity: .85; }
.run-mode .comp.skin .act:hover { fill: #ffffff; fill-opacity: .08; }
.act { cursor: pointer; }
.pbhead { stroke-width: 3; stroke-linecap: round; fill: none; }
.pbhead.go { stroke: var(--ok); } .pbhead.stop { stroke: var(--bad); } .pbhead.sw { stroke: var(--ink); }
.olbtn rect { fill: var(--panel); stroke: var(--line); }
.olbtn text { font-family: var(--f-mono); font-size: 10.5px; fill: var(--ink); }
.run-mode .olbtn:hover rect { stroke: var(--accent); }
.lampglass { stroke: var(--ink); stroke-width: 1.6; fill: var(--sheet); }
.tring { stroke: var(--ink); stroke-width: 1.6; fill: var(--sheet); } /* plint i plintraden */
.tbox { stroke: var(--ink); stroke-width: 1.6; fill: var(--sheet); } /* kopplingsklämma */
.motor-c { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.8; }
.motor-c.fault { stroke: var(--bad); stroke-width: 2.6; }
.rot { stroke: var(--accent); stroke-width: 2.4; fill: none; stroke-linecap: round; }
.mt { font-family: var(--f-disp); font-weight: 600; font-size: 20px; fill: var(--ink); }
.mt2 { font-family: var(--f-mono); font-size: 11px; fill: var(--ink); }
.cue { fill: var(--accent); fill-opacity: .12; }

@media (max-width: 900px) {
  .work { display: flex; flex-direction: column; }
  .palette { flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 10px; flex: none; }
  .palette h2 { display: none; }
  .pal { flex: none; grid-template-columns: 40px auto; }
  .pal svg { max-width: 40px; height: 30px; }
  .pal span { white-space: nowrap; }
  .stage { height: 62vh; flex: none; }
  .side { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .app { height: auto; }
  html, body { height: auto; }
  .btn.run { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
