:root {
    --bg: #0b1220;
    --bg-panel: #111c30;
    --bg-raised: #182741;
    --bg-input: #0d1729;
    --border: #23344f;
    --text: #e6edf7;
    --text-dim: #8ea3c0;
    --accent: #38bdf8;
    --accent-soft: rgba(56, 189, 248, .16);
    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #4ade80;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
    overscroll-behavior: none;
}

#app {
    height: 100%;
}

.boot {
    height: 100%;
    display: grid;
    place-items: center;
}

.boot-spinner {
    width: 42px;
    height: 42px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Kostra ---------- */

.app {
    height: 100%;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.app-logo {
    font-weight: 700;
    letter-spacing: .3px;
    white-space: nowrap;
}

.app-logo span {
    color: var(--accent);
}

.spacer {
    flex: 1;
}

.floor-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.workspace {
    display: grid;
    grid-template-columns: 58px 1fr 410px;
    min-height: 0;
}

.status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 6px 14px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
}

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

/* ---------- Ovládací prvky ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--accent);
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #06263a;
    font-weight: 600;
}

.btn.ghost {
    background: transparent;
}

.btn.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.btn.small {
    padding: 3px 7px;
    font-size: 12px;
}

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

input, select {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 8px;
    font: inherit;
    min-width: 0;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

input.plan-name {
    background: transparent;
    border-color: transparent;
    font-weight: 600;
    width: 220px;
}

input.plan-name:hover {
    border-color: var(--border);
}

.field {
    display: grid;
    grid-template-columns: 1fr 96px;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.field label {
    color: var(--text-dim);
    font-size: 13px;
}

.field.wide {
    grid-template-columns: 1fr;
}

/* ---------- Patra ---------- */

.floor-chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.floor-chip.active {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.floor-tab {
    padding: 5px 12px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.floor-chip.active .floor-tab {
    color: var(--text);
}

.floor-remove {
    padding: 5px 9px 5px 4px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
}

.floor-remove:hover {
    color: var(--danger);
}

/* Čím se kreslí nový kabel – v liště pater, ať se kvůli tomu nepřepíná panel. */
.draw-with-label {
    color: var(--text-dim);
    font-size: 12px;
    white-space: nowrap;
}

.draw-with-type {
    max-width: 150px;
    font-size: 13px;
    padding: 4px 6px;
}

.draw-with-tag {
    width: 130px;
    font-size: 13px;
    padding: 4px 6px;
}

.tag-chip {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 11px;
    white-space: nowrap;
}

/* ---------- Nástroje ---------- */

.tools {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
}

.tool {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 19px;
}

.tool:hover {
    background: var(--bg-raised);
    color: var(--text);
}

.tool.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text);
}

.tool-sep {
    width: 26px;
    height: 1px;
    background: var(--border);
    margin: 5px 0;
}

/* ---------- Plátno ---------- */

.canvas-wrap {
    position: relative;
    min-width: 0;
    background:
        linear-gradient(var(--border) 1px, transparent 1px) 0 0 / 40px 40px,
        linear-gradient(90deg, var(--border) 1px, transparent 1px) 0 0 / 40px 40px,
        #0a1020;
    background-blend-mode: soft-light;
    overflow: hidden;
}

svg.canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

svg.canvas.select-mode {
    cursor: default;
}

svg.canvas.panning {
    cursor: grabbing;
}

.canvas-tools {
    position: absolute;
    right: 12px;
    bottom: 12px;
    display: flex;
    gap: 6px;
}

.drop-zone {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 14px;
    text-align: center;
    color: var(--text-dim);
    padding: 24px;
}

.drop-zone h2 {
    margin: 0;
    color: var(--text);
    font-size: 18px;
}

.drop-zone p {
    margin: 0;
    max-width: 380px;
}

.file-button {
    position: relative;
    overflow: hidden;
}

.file-button input[type=file] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* ---------- Prvky v půdorysu ---------- */

.node-shape {
    stroke: #0b1220;
    stroke-width: 1.5;
    cursor: pointer;
}

.node-shape.selected {
    stroke: #fff;
    stroke-width: 2.5;
}

.node-label {
    fill: var(--text);
    paint-order: stroke;
    stroke: #0b1220;
    stroke-width: 3;
    font-size: 11px;
    pointer-events: none;
    user-select: none;
}

.segment-line {
    fill: none;
    stroke: #64748b;
    stroke-linecap: round;
    stroke-linejoin: round;
    cursor: pointer;
}

.segment-line.selected {
    stroke: #fff;
}

.segment-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 14;
    cursor: pointer;
}

.segment-label {
    fill: var(--text-dim);
    paint-order: stroke;
    stroke: #0b1220;
    stroke-width: 3;
    font-size: 10px;
    pointer-events: none;
    user-select: none;
}

/* Úchyty lomových bodů vybrané trasy. Plný = táhni, dutý = vloží nový bod. */
.waypoint-handle {
    fill: #fff;
    stroke: #0b1220;
    stroke-width: 1.5;
    cursor: grab;
}

.waypoint-handle:hover {
    fill: var(--accent);
}

.waypoint-ghost {
    fill: rgba(56, 189, 248, .25);
    stroke: var(--accent);
    stroke-width: 1;
    stroke-dasharray: 3 2;
    cursor: copy;
}

.waypoint-ghost:hover {
    fill: var(--accent);
}

.cable-line {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: .85;
    pointer-events: none;
}

.pending-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 6 5;
    pointer-events: none;
}

.calibration-line {
    stroke: var(--warn);
    stroke-width: 2;
    stroke-dasharray: 5 4;
    pointer-events: none;
}

.calibration-dot {
    fill: var(--warn);
    pointer-events: none;
}

/* ---------- Panel ---------- */

.panel {
    display: grid;
    grid-template-rows: auto 1fr;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    min-height: 0;
}

/* Taby se zalamují do víc řádků. Dřív tu byl overflow-x: auto, což vyrábělo
   scroll kontejner s posuvníkem v obou osách a taby byly půlkou schované. */
.panel-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    padding: 7px 7px 0;
    border-bottom: 1px solid var(--border);
}

.panel-tab {
    padding: 8px 13px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 6px 6px 0 0;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}

.panel-tab:hover {
    background: var(--bg-raised);
    color: var(--text);
}

.panel-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.panel-body {
    padding: 12px;
    overflow: auto;
    min-height: 0;
}

.section-title {
    margin: 16px 0 8px;
    color: var(--text-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .8px;
}

.section-title:first-child {
    margin-top: 0;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.stat {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 9px 11px;
}

.stat-value {
    font-size: 20px;
    font-weight: 600;
}

.stat-value small {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-dim);
    margin-left: 3px;
}

.stat-label {
    color: var(--text-dim);
    font-size: 12px;
}

table.grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table.grid th {
    text-align: left;
    color: var(--text-dim);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
}

table.grid td {
    padding: 5px 6px;
    border-bottom: 1px solid rgba(35, 52, 79, .55);
    vertical-align: middle;
}

table.grid tr.clickable:hover td {
    background: var(--bg-raised);
    cursor: pointer;
}

table.grid tr.selected td {
    background: var(--accent-soft);
}

td.num, th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: baseline;
}

.msg {
    display: flex;
    gap: 8px;
    padding: 7px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-raised);
    font-size: 13px;
    margin-bottom: 6px;
}

.msg.warn {
    border-color: rgba(251, 191, 36, .5);
    color: var(--warn);
}

.msg.error {
    border-color: rgba(248, 113, 113, .5);
    color: var(--danger);
}

.msg.ok {
    border-color: rgba(74, 222, 128, .4);
    color: var(--ok);
}

.empty-state {
    color: var(--text-dim);
    text-align: center;
    padding: 22px 8px;
    font-size: 13px;
}

.hint {
    color: var(--text-dim);
    font-size: 12px;
    margin: 6px 0 0;
}

/* ---------- Dialog ---------- */

.dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(3, 8, 18, .68);
    display: grid;
    place-items: center;
    z-index: 50;
}

.dialog {
    width: min(420px, 92vw);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}

.dialog h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.dialog p {
    margin: 0 0 14px;
    color: var(--text-dim);
    font-size: 13px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* ---------- Chybová lišta Blazoru ---------- */

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 10px 16px;
    background: var(--warn);
    color: #241a00;
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 12px;
    top: 8px;
    cursor: pointer;
}

@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 52px 1fr 300px;
    }
}
