:root {
  --bg: #f1f3f6;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --line: #dfe3e8;
  --text: #14181d;
  --muted: #667181;
  --accent: #d00511;
  --accent-text: #ffffff;
  --focus: #0a6cff;
  --ok: #1f8a4c;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --stage: #e6e9ee;
  --radius: 10px;
  font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --surface: #191d23;
    --surface-2: #20252c;
    --line: #2e353e;
    --text: #e9edf1;
    --muted: #98a3b0;
    --accent: #ff4a54;
    --accent-text: #14181d;
    --focus: #6aa7ff;
    --ok: #55c98a;
    --warn-bg: #3a2f10;
    --warn-text: #ffdf8a;
    --stage: #0b0d10;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); line-height: 1.45; }
h1 { font-size: 20px; margin: 6px 0 4px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
h2:first-child { margin-top: 2px; }
.muted { color: var(--muted); }
.error { color: var(--accent); margin: 10px 0 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.brand { font-weight: 300; font-size: 17px; letter-spacing: 0.02em; white-space: nowrap; }
.brand b { font-weight: 800; color: var(--accent); }
.brand.big { font-size: 26px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 11px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; padding: 9px 16px; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.danger { color: var(--accent); }
.btn.link { border-color: transparent; background: none; color: var(--muted); }
.btn.icon { padding: 4px 9px; font-size: 17px; line-height: 1.2; }
.btn.small { padding: 3px 8px; font-size: 13px; }
.select, .f input, .f select, .f textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 8px; min-width: 0; }

/* Prihlásenie */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.card p { margin: 0; }

/* Rozloženie aplikácie */
.app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top .select { max-width: 200px; }
.spacer { flex: 1; }
.group { display: flex; gap: 4px; }
.who, .save { color: var(--muted); font-size: 13px; white-space: nowrap; }
.save.ok { color: var(--ok); }
.save.bad { color: var(--accent); font-weight: 600; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 6px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--surface-2); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); }
.banner { background: var(--warn-bg); color: var(--warn-text); padding: 8px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.work { flex: 1; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) 320px; }
.tools { background: var(--surface); border-right: 1px solid var(--line); padding: 8px 6px; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.tools button { border: 0; background: none; border-radius: 8px; padding: 8px 12px; text-align: left; cursor: pointer; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tools button kbd { margin-left: auto; padding-left: 10px; font: inherit; font-size: 11px; color: var(--muted); }
.tools button:hover { background: var(--surface-2); }
.tools button.on { background: var(--text); color: var(--bg); }
.tools button.on kbd { color: inherit; opacity: 0.6; }
.tools hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; width: auto; }

.stage { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--stage); }
.toolopts { display: flex; gap: 6px; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; align-items: center; min-height: 42px; }
.toolopts .lbl { color: var(--muted); font-size: 13px; white-space: nowrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 11px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); font-weight: 600; }
.chip svg { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.plan { flex: 1; min-height: 0; width: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; background: #f1f3f6; cursor: default; }
.plan.tool-pan, .plan.panning { cursor: grab; }
.plan.tool-wall, .plan.tool-zone, .plan.tool-object, .plan.tool-columns, .plan.tool-modules { cursor: crosshair; }
.plan [data-handle] { cursor: move; }
.hint { background: var(--surface); border-top: 1px solid var(--line); padding: 5px 12px; font-size: 12.5px; color: var(--muted); min-height: 29px; }
.print-title { display: none; }

.side { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidetabs { display: flex; border-bottom: 1px solid var(--line); }
.sidetabs button { flex: 1; border: 0; background: none; padding: 10px 6px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.sidetabs button.on { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.panel { padding: 14px; overflow-y: auto; flex: 1; min-height: 0; }
.panel p { margin: 0 0 10px; }

.f { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; align-items: center; gap: 6px; margin-bottom: 7px; }
.f > span { color: var(--muted); font-size: 13px; }
.f > i { font-style: normal; color: var(--muted); font-size: 12px; min-width: 14px; }
.f.wide { grid-template-columns: 1fr; }
.f.wide > span { font-size: 13px; }
.f textarea { resize: vertical; min-height: 60px; }
.f input:disabled, .f select:disabled, .f textarea:disabled { background: var(--surface-2); opacity: 1; color: var(--text); }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.pair .f { grid-template-columns: 34px minmax(0, 1fr) auto; }
.note { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 8px 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { padding: 5px 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 8px; }
tr.total td { font-weight: 700; border-bottom: 0; }
.stat { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }

.ver { border-bottom: 1px solid var(--line); padding: 9px 0; }
.ver b { display: block; overflow-wrap: anywhere; }
.ver small { color: var(--muted); }

.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); padding: 22px; width: min(420px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(10, 14, 20, 0.5); }
.dlg h1 { margin-top: 0; }
.dlg .row { justify-content: flex-end; margin: 16px 0 0; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; max-width: calc(100vw - 32px); z-index: 10; }

body.readonly .edit-only { display: none; }

@media (max-width: 900px) {
  .work { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(320px, 58vh) auto; }
  .app { height: auto; min-height: 100%; }
  .tools { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .tools button kbd, .tools hr { display: none; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .panel { overflow: visible; }
  .who { display: none; }
}

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; }
  .top, .tools, .side, .toolopts, .hint, .banner, .toast { display: none !important; }
  .app, .work, .stage { display: block; height: auto; background: #fff; }
  .plan { width: 100%; height: 170mm; background: #fff; }
  .print-title { display: block; color: #000; font-size: 12pt; font-weight: 600; margin-bottom: 4mm; }
}

/* 3D náhľad */
.plan3d { flex: 1; min-width: 0; min-height: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
body.mode3d .tools, body.mode3d .toolopts { opacity: 0.4; pointer-events: none; }
.btn.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Plátno s ovládaním nad výkresom */
.canvas { position: relative; flex: 1; min-height: 0; display: flex; }
.mapctl { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.mapctl .btn { width: 34px; height: 34px; padding: 0; font-size: 18px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); }
.legend { position: absolute; right: 10px; top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); font-size: 13px; max-width: 240px; }
.legend summary { cursor: pointer; padding: 7px 12px; font-weight: 600; user-select: none; }
.legend > div { padding: 0 12px 10px; }
.legend h2 { margin: 8px 0 6px; }
.check { display: flex; align-items: center; gap: 7px; padding: 2px 0; cursor: pointer; }
.leg { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.leg svg { width: 28px; height: 16px; background: #fff; border-radius: 3px; flex: none; }
.tools button svg { width: 17px; height: 17px; flex: none; }
@media (max-width: 900px) {
  .legend { max-width: 200px; }
}
@media print {
  .canvas { display: block; }
  .mapctl, .legend { display: none !important; }
}
