:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --border: #dde1e7;
    --text: #1d2430;
    --muted: #6b7482;
    --accent: #1f3a5f;
    --accent-soft: #e6edf6;
    --danger: #b42318;
    --warning: #b54708;
    --ok: #067647;

    --pick: #3b82f6;
    --pick-stroke: #1d4ed8;
    --bulk: #f59e0b;
    --bulk-stroke: #b45309;
    --staging: #10b981;
    --staging-stroke: #047857;
    --dock: #6366f1;
    --route: #e11d48;
    --hall: #fbfbfc;
    --aisle: #e8ebf0;
    --aisle-main: #dfe6ef;

    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 13px;
    color: var(--text);
    color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--accent); }
code { font-family: Consolas, ui-monospace, monospace; font-size: 12px; }

.app-shell { height: 100vh; }
.app-loading, .page-message { padding: 48px; color: var(--muted); font-size: 15px; }

/* ----- Buttons and fields ----- */
.btn {
    display: inline-flex; align-items: center; gap: 4px;
    height: 30px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--panel); color: var(--text);
    font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #b8c0cc; background: #f8f9fb; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #284a76; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.tiny { height: 20px; padding: 0 6px; font-size: 11px; }
.btn.tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; min-width: 0; flex: 1; }
.field-label { font-size: 11px; color: var(--muted); }
.field-input { display: flex; align-items: center; gap: 4px; }
.field-input em { font-style: normal; font-size: 11px; color: var(--muted); }
.field input, .field select, .quick-input, .plan-name, .new-plan input, .inline-field select {
    width: 100%; min-width: 0; height: 28px; padding: 0 7px;
    border: 1px solid var(--border); border-radius: 5px; background: #fff;
    font: inherit; color: var(--text);
}
.field input:focus, .field select:focus, .quick-input:focus, .plan-name:focus { outline: 2px solid #9db5d3; outline-offset: -1px; border-color: var(--accent); }
.field-row { display: flex; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; cursor: pointer; }
.check.inline { font-size: 11px; color: var(--muted); }
.inline-field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.inline-field select { width: auto; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 10px; line-height: 1.4; }
.hint.ok { color: var(--ok); }
.muted { color: var(--muted); }
.row { display: flex; gap: 6px; align-items: center; }
.error-text { color: var(--danger); }

/* ----- Home ----- */
.home { max-width: 980px; margin: 0 auto; padding: 40px 24px; }
.home h1 { margin: 0 0 6px; font-size: 26px; color: var(--accent); }
.home-head p { margin: 0; color: var(--muted); max-width: 680px; line-height: 1.5; font-size: 14px; }
.home-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 28px 0 20px; align-items: center; }
.new-plan { display: flex; gap: 6px; }
.new-plan input { width: 260px; height: 30px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.empty { padding: 32px; border: 1px dashed var(--border); border-radius: 10px; background: var(--panel); color: var(--muted); }
.plan-list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.plan-list th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fafbfc; }
.plan-list td { padding: 10px 14px; border-bottom: 1px solid #eef0f3; }
.plan-list tbody tr { cursor: pointer; }
.plan-list tbody tr:hover { background: #f7f9fc; }
.plan-list .name { font-weight: 600; }
.plan-list .actions { text-align: right; width: 1%; white-space: nowrap; }

/* ----- Designer layout ----- */
.designer {
    display: grid; height: 100vh;
    grid-template-columns: 290px minmax(0, 1fr) 360px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "tool tool tool" "left canvas right" "status status status";
}
.toolbar {
    grid-area: tool; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.toolbar .btn { padding: 0 8px; }
.toolbar { gap: 4px; }
.toolbar .grow, .statusbar .grow { flex: 1; }
.plan-name { width: 220px; font-weight: 600; border-color: transparent; }
.plan-name:hover { border-color: var(--border); }
.tool-group { display: inline-flex; gap: 3px; }

.sidebar { overflow-y: auto; background: var(--panel); }
.sidebar.left { grid-area: left; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar.right { grid-area: right; border-left: 1px solid var(--border); }
.panel-section { padding: 12px 14px; border-bottom: 1px solid #eef0f3; }
.panel-section h3 { margin: 0 0 10px; font-size: 13px; font-weight: 650; display: flex; align-items: center; gap: 6px; }
.panel-section h4 { margin: 14px 0 8px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.section-head h3 { margin: 0; }
.head-actions { display: flex; gap: 4px; }
.grow-section { flex: 1; }
.quick-input { height: auto; padding: 6px 7px; resize: vertical; line-height: 1.4; margin-bottom: 6px; }
.help { margin: 8px 0 0; padding-left: 16px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.help code { color: var(--text); }
.add-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.add-grid .btn { justify-content: center; }
.rule-summary { margin: 0 0 12px; padding: 7px 9px; background: var(--accent-soft); border-radius: 6px; color: var(--accent); font-size: 12px; line-height: 1.4; }

.tree { list-style: none; margin: 0; padding: 0; }
.tree li { padding: 5px 6px; border-radius: 5px; cursor: pointer; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree li.child { padding-left: 18px; }
.tree li:hover { background: #f3f5f8; }
.tree li.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.kind-chip { display: inline-block; font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 4px; background: #eceff3; color: #4b5563; text-transform: uppercase; letter-spacing: .03em; flex: none; }
.kind-chip.kind-hall { background: #eef2f7; color: #334155; }
.kind-chip.kind-aisle, .kind-chip.kind-rack { background: #dbeafe; color: #1e40af; }
.kind-chip.kind-location { background: #e0ecff; color: #1d4ed8; }
.kind-chip.kind-block { background: #fef3c7; color: #92400e; }
.kind-chip.kind-dock { background: #e0e7ff; color: #3730a3; }
.kind-chip.kind-path, .kind-chip.kind-routenode { background: #ffe4e6; color: #9f1239; }

.badge { font-size: 11px; padding: 0 6px; border-radius: 9px; background: #eceff3; color: var(--muted); }
.badge.ok { background: #dcfae6; color: var(--ok); }
.badge.warning { background: #fef0c7; color: var(--warning); }
.badge.error { background: #fee4e2; color: var(--danger); }
.issue-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.issue-list li { padding: 5px 6px 5px 10px; border-left: 3px solid #cbd5e1; margin-bottom: 4px; font-size: 12px; line-height: 1.35; cursor: pointer; border-radius: 0 4px 4px 0; }
.issue-list li:hover { background: #f6f7f9; }
.issue-list li.error { border-color: var(--danger); }
.issue-list li.warning { border-color: #f79009; }
.issue-list li.info { color: var(--muted); }

.props { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 8px; font-size: 12px; }
.props dt { color: var(--muted); display: flex; align-items: center; gap: 5px; }
.props dd { margin: 0; }
.props.stats dd { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.edge-list { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.edge-list li { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.edge-list li > span:first-child { flex: 1; }
table.levels { width: 100%; border-collapse: collapse; font-size: 12px; margin: 6px 0 10px; }
table.levels th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 4px; border-bottom: 1px solid var(--border); }
table.levels td { padding: 3px 4px; border-bottom: 1px solid #f0f2f5; font-variant-numeric: tabular-nums; }
.usage-dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.statusbar {
    grid-area: status; display: flex; gap: 12px; align-items: center;
    padding: 5px 12px; background: var(--panel); border-top: 1px solid var(--border);
    font-size: 12px; color: var(--muted);
}
.status-message { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }

/* ----- Canvas ----- */
.canvas-area { grid-area: canvas; position: relative; overflow: hidden; background: #eef0f3; }
.plan-canvas { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; cursor: grab; }
.plan-canvas.tool-drawhall, .plan-canvas.tool-routenode { cursor: crosshair; }
.plan-canvas.tool-connect, .plan-canvas.tool-routetest { cursor: pointer; }
.plan-canvas rect, .plan-canvas line, .plan-canvas circle, .plan-canvas polyline { vector-effect: non-scaling-stroke; }
.grid-line { stroke: #dfe3e8; }

.hall { fill: var(--hall); stroke: #5b6574; stroke-width: 2px; }
.aisle { stroke: none; }
.aisle-rack { fill: var(--aisle); }
.aisle-main { fill: var(--aisle-main); }
.loc { stroke-width: .75px; cursor: move; }
.u-pick { fill: var(--pick); stroke: var(--pick-stroke); background: var(--pick); }
.u-bulk { fill: var(--bulk); stroke: var(--bulk-stroke); background: var(--bulk); }
.u-staging { fill: var(--staging); stroke: var(--staging-stroke); background: var(--staging); }
.u-none { fill: #e5e7eb; stroke: #cbd5e1; background: #e5e7eb; }
.u-blocked { fill: #9ca3af; stroke: #6b7280; background: #9ca3af; }
.loc.u-pick, .loc.u-bulk, .loc.u-staging { fill-opacity: .82; }
.dock { fill: var(--dock); stroke: #3730a3; stroke-width: 1px; cursor: move; }
.dock-inbound { fill: #818cf8; }
.dock-outbound { fill: #4f46e5; }
.edge-route { stroke: var(--route); stroke-width: 1.6px; stroke-opacity: .75; }
.edge-route.manual { stroke-dasharray: 5 3; }
.edge-access { stroke: #94a3b8; stroke-width: .7px; stroke-dasharray: 2 2; }
.arrow-head { fill: var(--route); }
.rn { fill: #fff; stroke: var(--route); stroke-width: 1.5px; cursor: pointer; }
.rn-entry { fill: var(--route); }
.rn-junction { fill: #fda4af; }
.rn.manual { stroke: #7c2d12; fill: #fed7aa; }

.lbl { pointer-events: none; text-anchor: middle; dominant-baseline: central; font-family: "Segoe UI", system-ui, sans-serif; }
.hall-lbl { text-anchor: start; dominant-baseline: auto; fill: #475467; font-weight: 600; }
.aisle-lbl { fill: #94a3b8; font-weight: 700; opacity: .55; }
.loc-lbl { fill: #fff; font-weight: 600; }
.dock-lbl { fill: #fff; font-weight: 700; }
.preview-lbl { fill: var(--accent); font-weight: 600; }

.sel-node { fill: none; stroke: #111827; stroke-width: 2.5px; pointer-events: none; }
.sel-rule { fill: none; stroke: var(--accent); stroke-width: 1.5px; stroke-dasharray: 6 4; pointer-events: none; }
.pending { fill: none; stroke: #f97316; stroke-width: 3px; pointer-events: none; }
.route-path { fill: none; stroke: #f97316; stroke-width: 5px; stroke-linejoin: round; stroke-linecap: round; stroke-opacity: .9; pointer-events: none; }
.hall-preview { fill: rgba(31, 58, 95, .06); stroke: var(--accent); stroke-width: 2px; stroke-dasharray: 8 4; }

.scale-bar { position: absolute; left: 12px; bottom: 10px; display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: #475467; pointer-events: none; }
.scale-bar span { display: block; height: 6px; border: 1.5px solid #475467; border-top: none; }
.legend { position: absolute; right: 12px; bottom: 10px; display: flex; gap: 10px; padding: 5px 10px; background: rgba(255,255,255,.92); border: 1px solid var(--border); border-radius: 6px; font-size: 11px; color: #475467; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend .dock-swatch { background: var(--dock); }
.legend .route-swatch { height: 3px; background: var(--route); }

/* ----- Elevations ----- */
.elevation { display: block; margin: 4px 0 6px; max-width: 320px; }
.elevation .floor { stroke: #475467; stroke-width: 2; }
.elevation .beam { stroke: #f97316; stroke-width: 2.5; }
.elevation .level { stroke-width: 1; fill-opacity: .85; }
.elev-lbl { font-size: 11px; font-weight: 600; fill: #fff; }
.elev-side { font-size: 10px; fill: var(--muted); }
.rack-elevation { margin: 10px 0; }
.rack-title { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.rack-title span { font-weight: 400; color: var(--muted); margin-left: 6px; }
.rack-elevation svg { display: block; max-height: 160px; }
.rack-elevation .cell { stroke-width: .5; cursor: pointer; fill-opacity: .8; }
.rack-elevation .cell:hover { fill-opacity: 1; }
.rack-elevation .cell.selected { stroke: #111827; stroke-width: 1.5; fill-opacity: 1; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 16px; background: #fff3cd; border-top: 1px solid #f0c36d; z-index: 1000; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* ----- Underlay and import ----- */
.underlay { pointer-events: none; image-rendering: auto; }
.has-underlay .hall { fill-opacity: .06; }
.has-underlay .aisle-rack, .has-underlay .aisle-main { fill-opacity: .45; }
.plan-canvas.tool-calibrate { cursor: crosshair; }
.plan-canvas.tool-moveunderlay { cursor: move; }
.calibration { stroke: #db2777; stroke-width: 2.5px; stroke-dasharray: 6 3; pointer-events: none; }
.calibration-point { fill: #fff; stroke: #db2777; stroke-width: 2.5px; pointer-events: none; }
.import-preview { fill: rgba(219, 39, 119, .12); stroke: #db2777; stroke-width: 1.5px; stroke-dasharray: 5 3; pointer-events: none; }
.hint.warn { color: var(--warning); }
.row.wrap { flex-wrap: wrap; margin-bottom: 8px; }
.underlay-file { margin: 0 0 6px; font-weight: 600; word-break: break-all; }
.underlay-file .muted { font-weight: 400; margin-left: 6px; }
.calibrate-box { background: #fdf2f8; }
.import-rows { list-style: none; margin: 0 0 12px; padding: 0; }
.import-rows li { display: flex; flex-direction: column; gap: 1px; padding: 4px 0; border-bottom: 1px solid #f0f2f5; font-size: 12px; }
.import-rows li .check span { color: var(--muted); margin-left: 6px; }
.import-rows li > .muted { padding-left: 22px; font-size: 11px; }
details summary { cursor: pointer; margin: 4px 0; }
input[type=range] { width: 100%; }

/* ----- Route ends: green when connected to the rest of the network, red when loose ----- */
.rn.end-connected { fill: #16a34a; stroke: #14532d; stroke-width: 1.5px; }
.rn.end-open { fill: #dc2626; stroke: #7f1d1d; stroke-width: 1.5px; }
.legend .end-swatch { border-radius: 50%; }
.legend .end-swatch.end-connected { background: #16a34a; }
.legend .end-swatch.end-open { background: #dc2626; }

/* ----- Pick route ----- */
.plan-canvas.tool-picklist { cursor: pointer; }
.pick-leg { fill: none; stroke: #7c3aed; stroke-width: 3.5px; stroke-linejoin: round; stroke-linecap: round; stroke-opacity: .85; pointer-events: none; }
.pick-arrow { fill: #7c3aed; }
.pick-stop { fill: #7c3aed; stroke: #fff; stroke-width: 2px; pointer-events: none; }
.pick-start { fill: #111827; stroke: #fff; stroke-width: 2px; pointer-events: none; }
.pick-no { fill: #fff; font-weight: 700; }
.pick-summary { display: flex; gap: 12px; align-items: center; padding: 8px 10px; margin: 8px 0; background: #f5f3ff; border-radius: 6px; font-size: 12px; line-height: 1.45; }
.pick-total { font-size: 20px; font-weight: 700; color: #5b21b6; white-space: nowrap; }
.pick-order { margin: 4px 0 0; padding-left: 0; list-style: none; counter-reset: stop; font-size: 12px; max-height: 320px; overflow-y: auto; }
.pick-order li { padding: 2px 0; }
.pick-order li:not(.muted)::before { counter-increment: stop; content: counter(stop) ". "; color: #7c3aed; font-weight: 700; }

/* ----- Bulk trips and the chosen dock ----- */
.bulk-trip { fill: none; stroke: #ea580c; stroke-width: 3px; stroke-dasharray: 7 5; stroke-linejoin: round; stroke-opacity: .9; pointer-events: none; }
.bulk-stop { fill: #ea580c; stroke: #fff; stroke-width: 2px; pointer-events: none; }
.order-dock { fill: none; stroke: #111827; stroke-width: 3px; pointer-events: none; }
.bulk-list { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.bulk-list li { padding: 2px 0; }
.bulk-list li::before { content: "■ "; color: #ea580c; }

/* ----- Versions ----- */
.version-list { list-style: none; margin: 0; padding: 0; }
.version-list li { padding: 8px 0; border-bottom: 1px solid #eef0f3; }
.version-head { display: flex; align-items: center; gap: 6px; }
.version-no { font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 0 6px; font-size: 12px; }
.version-label { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.version-meta { font-size: 11px; margin: 3px 0 5px; }
.version-note { font-size: 12px; margin-bottom: 6px; color: #3a4556; }
.version-diff { margin-top: 8px; padding: 8px 10px; background: #f7f9fc; border-radius: 6px; }
.diff-counts { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 0 0 6px; font-size: 12px; font-weight: 600; }
.diff-counts .muted { font-weight: 400; }
.diff-counts .green { color: var(--ok); }
.diff-counts .red { color: var(--danger); }
.diff-list { font-size: 12px; margin-bottom: 4px; }
.diff-list p { margin: 3px 0 6px; color: #3a4556; line-height: 1.45; overflow-wrap: anywhere; }

/* ----- Location list ----- */
.check.block { display: flex; padding: 2px 0; white-space: normal; }
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; margin-bottom: 8px; }
.rule-filter { margin-bottom: 8px; }
.rule-filter .row { margin: 4px 0; }

/* ----- Product requirements ----- */
.requirements { margin: 2px 0 8px; }
.requirement-row { display: grid; grid-template-columns: 1fr 86px auto; gap: 4px; margin-bottom: 4px; align-items: center; }
.requirement-row input, .requirement-row select { height: 26px; padding: 0 6px; border: 1px solid var(--border); border-radius: 5px; font: inherit; font-size: 12px; background: #fff; color: var(--text); min-width: 0; }
.pick-stop.first { fill: #0f766e; }
.pick-stop.last { fill: #db2777; }
.req-chip { font-size: 10px; font-weight: 600; padding: 0 5px; border-radius: 4px; }
.req-chip.first { background: #ccfbf1; color: #0f766e; }
.req-chip.last { background: #fce7f3; color: #be185d; }

.pick-actions { margin-bottom: 10px; }
.pick-settings { margin-top: 12px; padding-top: 8px; border-top: 1px solid #eef0f3; }

/* ----- Account (web app) ----- */
.home-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.account-menu { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.account-menu .who { font-weight: 600; color: var(--text); }
.account-menu form { display: inline; }
.account-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.account-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px 30px; box-shadow: 0 10px 30px rgba(15, 23, 42, .06); }
.account-card.wide { max-width: 760px; }
.account-card h1 { margin: 0 0 4px; font-size: 22px; color: var(--accent); }
.account-card > p { margin: 0 0 18px; color: var(--muted); }
.account-card .field input { height: 34px; }
.account-card .btn.primary { height: 34px; padding: 0 16px; }
.account-card .error-text, .account-card .validation-message { color: var(--danger); font-size: 12px; margin: 4px 0 8px; }
.account-card .ok-text { color: var(--ok); font-size: 12px; margin: 4px 0 8px; }
.account-card table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0 18px; }
.account-card th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.account-card td { padding: 6px 4px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.account-card td.actions { text-align: right; white-space: nowrap; }
.account-links { margin-top: 18px; font-size: 13px; }
