:root {
  --g900: #0b3b1f; --g800: #14532d; --g700: #166534; --g600: #16a34a; --g100: #dcfce7; --g50: #f0fdf4;
  --orange: #f97316; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0; --bg: #f8fafc; --card: #fff;
  --red: #b91c1c; --red100: #fee2e2; --sel: #f97316;
  --radius: 10px; --shadow: 0 1px 2px #0000000d, 0 6px 20px #0000000d;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--g700); }

button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 13px; cursor: pointer; line-height: 1.2; white-space: nowrap; }
button:hover { border-color: #cbd5e1; background: var(--g50); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
button.primary { background: var(--g700); border-color: var(--g700); color: #fff; }
button.primary:hover { background: var(--g800); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: #eef2f7; }
button.danger { color: var(--red); }
button.icon { padding: 6px 9px; min-width: 34px; }
button.small { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { border: 1px solid #cbd5e1; border-radius: 8px; padding: 7px 9px; background: #fff; width: 100%; }
textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
input[type=checkbox] { width: auto; accent-color: var(--g700); }
input[type=color] { width: 38px; height: 32px; padding: 2px; }
label.lbl { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin: 10px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; margin: 10px 0 0; }

/* Yläpalkki */
.top { display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 18px; background: var(--g800); color: #ecfdf5; flex: none; }
.brand { display: flex; align-items: center; gap: 9px; color: #fff; text-decoration: none; font-weight: 600; font-size: 15.5px; }
.crumbs { display: flex; align-items: center; gap: 8px; color: #bbf7d0; min-width: 0; }
.crumbs b { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.who { font-size: 12.5px; color: #bbf7d0; display: flex; gap: 10px; align-items: center; }
.who button { background: transparent; color: #fff; border-color: #ffffff44; padding: 4px 10px; font-size: 12.5px; }
.who button:hover { background: #ffffff1a; }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Kirjautuminen */
.gate { margin: auto; width: min(420px, 92vw); background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 32px; text-align: center; }
.gate img { width: 64px; height: 64px; }
.gate h1 { margin: 12px 0 6px; font-size: 22px; }
.gate form { margin-top: 18px; display: grid; gap: 10px; text-align: left; }
.gate .err { color: var(--red); background: var(--red100); border-radius: 8px; padding: 8px 10px; text-align: left; }

/* Projektit */
.page { padding: 24px 28px; overflow: auto; flex: 1; }
.pageHead { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.pageHead h1 { font-size: 21px; margin-right: auto; }
.pageHead input[type=search] { width: 240px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.proj { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; cursor: pointer; transition: border-color .12s, transform .12s; overflow: hidden; }
.proj:hover { border-color: var(--g600); transform: translateY(-1px); }
.proj .thumb { height: 120px; background: var(--g50) radial-gradient(#d1fae5 1px, transparent 1px) 0 0 / 14px 14px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--line); }
.proj .thumb svg { max-width: 92%; max-height: 104px; }
.proj .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.proj h3 { font-size: 15px; }
.proj .meta { display: flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 6px; }
.badge { font-size: 11px; background: var(--g100); color: var(--g800); border-radius: 10px; padding: 1px 7px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* Editori */
.editor { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 330px; grid-template-rows: auto 1fr; }
.tools { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tools .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.tools input[type=search] { width: 190px; padding: 6px 9px; }
.zoomVal { min-width: 46px; text-align: center; font-size: 12.5px; color: var(--muted); }
.saveState { font-size: 12px; color: var(--muted); margin-left: 6px; }
.saveState.err { color: var(--red); font-weight: 600; }
.canvas { position: relative; overflow: hidden; background: #f8fafc radial-gradient(#dbe3ec 1px, transparent 1px) 0 0 / 20px 20px; cursor: grab; touch-action: none; outline: none; }
.canvas.panning { cursor: grabbing; }
.canvas svg { width: 100%; height: 100%; display: block; user-select: none; }
.canvasEmpty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; pointer-events: none; color: var(--muted); }
.canvasEmpty > * { pointer-events: auto; }
.side { border-left: 1px solid var(--line); background: #fff; overflow: auto; padding: 14px 16px 30px; }
.side h2 { font-size: 15px; margin: 2px 0 4px; }
.side h3 { font-size: 13px; margin: 18px 0 4px; color: #334155; }
.side .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0 4px; }
.side .acts button { width: 100%; }
.side hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.kbd { display: inline-block; border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; background: #f8fafc; }
.units { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.units li { display: grid; grid-template-columns: 38px 1fr 30px; gap: 6px; align-items: center; }
.units input[type=text] { padding: 5px 8px; }
.shareBox { display: flex; gap: 6px; margin-top: 6px; }
.shareBox input { font-size: 12px; }

/* Kaavion solmut */
.node { cursor: pointer; }
.node .box { fill: #fff; stroke: #cbd5e1; stroke-width: 1.2; }
.node:hover .box { stroke: #94a3b8; }
.node.sel .box { stroke: var(--sel); stroke-width: 2.5; }
.node.vacant .box { stroke-dasharray: 5 4; fill: #fafafa; }
.node.drop .box { stroke: var(--g600); stroke-width: 3; fill: var(--g50); }
.node .name { font-size: 14px; font-weight: 600; fill: #0f172a; }
.node.vacant .name { font-style: italic; fill: #64748b; }
.node .title { font-size: 12.3px; fill: #334155; }
.node .unit { font-size: 11px; fill: #64748b; }
.node .tog circle { fill: #fff; stroke: #94a3b8; }
.node .tog text { font-size: 12px; fill: #334155; font-weight: 600; }
.node .tog:hover circle { stroke: var(--g700); fill: var(--g50); }
.edge { fill: none; stroke: #94a3b8; stroke-width: 1.4; }
.ghost { opacity: .6; pointer-events: none; }

/* Ikkunat ja ilmoitukset */
.dlg { border: 0; border-radius: 14px; padding: 22px 24px; width: min(560px, 94vw); box-shadow: 0 20px 60px #0004; }
.dlg::backdrop { background: #0f172a66; }
.dlg h2 { font-size: 17px; margin-bottom: 10px; }
.dlg p { margin: 6px 0; line-height: 1.5; }
.dlg .row.end { margin-top: 18px; }
.dlg textarea.import { min-height: 220px; font-family: Consolas, monospace; font-size: 12.5px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.err { background: var(--red); }
.vlist { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.vlist li { display: flex; gap: 10px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); }
.vlist li:first-child { border-top: 0; }
.menu { position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 40; display: grid; min-width: 190px; }
.menu button { border: 0; text-align: left; background: transparent; }
.menu button:hover { background: var(--g50); }

.printArea { display: none; }
@media print {
  @page { size: landscape; margin: 10mm; }
  body > *:not(.printArea) { display: none !important; }
  .printArea { display: block; }
  .printArea h1 { font-size: 16pt; margin: 0 0 6mm; }
  .printArea svg { width: 100%; height: auto; max-height: 170mm; }
}
@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); max-height: 42vh; }
  .crumbs b { max-width: 30vw; }
}
