:root {
    color-scheme: dark;
    --bg: #06101c;
    --panel: #0b1928;
    --panel-2: #102338;
    --panel-3: #142b43;
    --line: #294058;
    --line-strong: #3c5b76;
    --text: #e7eff7;
    --muted: #93a8bd;
    --cyan: #22d3ee;
    --cyan-dark: #083e50;
    --amber: #fbbf24;
    --danger: #fb7185;
    --board: #071522;
    --track: #dbeafe;
    --shadow: 0 18px 50px rgba(0, 0, 0, .34);
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
.hidden { display: none !important; }
.sr-only { position: absolute; overflow: hidden; width: 1px; height: 1px; margin: -1px; clip: rect(0, 0, 0, 0); }
.muted, .help-text { color: var(--muted); }
.help-text { display: block; margin-top: 5px; font-size: 12px; }

.login-page, .setup-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 28px; background: radial-gradient(circle at 50% 10%, #11304a, var(--bg) 52%); }
.login-card, .setup-card { width: 100%; max-width: 430px; padding: 40px; border: 1px solid var(--line); background: rgba(11, 25, 40, .96); box-shadow: var(--shadow); }
.login-card h1, .setup-card h1 { margin: 6px 0 8px; font-size: 26px; }
.login-card .field { margin-top: 18px; }
.login-card .button { margin-top: 20px; }
.setup-card pre { overflow: auto; padding: 12px; border: 1px solid var(--line); background: #050c14; color: var(--cyan); }
.form-error { padding: 10px 12px; border-left: 3px solid var(--danger); background: rgba(251, 113, 133, .1); color: #fecdd3; }

.brand-mark { position: relative; width: 52px; height: 52px; border: 1px solid var(--line-strong); background: #08283a; }
.brand-mark.small { width: 38px; height: 38px; }
.brand-mark span { position: absolute; background: var(--track); }
.brand-mark span:first-child { top: calc(50% - 3px); left: 7px; right: 7px; height: 6px; }
.brand-mark span:last-child { left: calc(50% - 3px); top: 7px; bottom: 7px; width: 6px; }
.brand-mark:after { content: ''; position: absolute; left: calc(50% - 5px); top: calc(50% - 5px); width: 10px; height: 10px; background: var(--cyan); border-radius: 50%; }
.brand-mark.small:after { left: calc(50% - 4px); top: calc(50% - 4px); width: 8px; height: 8px; }
.eyebrow { margin: 0; color: var(--cyan); font-size: 10px; font-weight: bold; letter-spacing: .16em; text-transform: uppercase; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { min-height: 64px; display: grid; grid-template-columns: 240px 1fr auto; align-items: center; gap: 18px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #081522; }
.brand-block { display: flex; align-items: center; gap: 11px; }
.brand-block strong, .brand-block small { display: block; }
.brand-block small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.plan-actions { display: flex; align-items: center; justify-content: center; gap: 8px; }
.plan-actions select { min-width: 220px; }
.logout-form { margin: 0; }

.button, .tool-button, select, input, textarea { border: 1px solid var(--line-strong); color: var(--text); background: var(--panel-2); }
.button { min-height: 36px; padding: 7px 12px; font-weight: bold; }
.button:hover, .tool-button:hover { border-color: #577794; background: var(--panel-3); }
.button.primary { border-color: var(--cyan); background: var(--cyan); color: #052936; }
.button.primary:hover { background: #67e8f9; }
.button.subtle { border-color: transparent; color: var(--muted); background: transparent; }
.button.danger { border-color: rgba(251, 113, 133, .7); color: #fecdd3; background: rgba(127, 29, 50, .22); }
.wide { width: 100%; }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 270px minmax(420px, 1fr) 300px; }
.panel { min-height: 0; background: var(--panel); }
.palette-panel { border-right: 1px solid var(--line); }
.inspector-panel { border-left: 1px solid var(--line); }
.panel-heading { height: 70px; display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 2px 0 0; font-size: 17px; }
.count-badge { min-width: 28px; padding: 3px 7px; text-align: center; border: 1px solid var(--line); color: var(--muted); background: var(--panel-2); }
.palette-tools { display: grid; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
input, select, textarea { width: 100%; min-height: 36px; padding: 7px 9px; border-radius: 0; outline: none; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(34, 211, 238, .17); outline: none; }
.tile-palette { height: calc(100vh - 64px - 70px - 157px); overflow: auto; padding: 8px 10px 24px; }
.palette-category { margin-top: 10px; }
.palette-category-title { margin: 0 4px 6px; color: var(--muted); font-size: 10px; font-weight: bold; letter-spacing: .12em; text-transform: uppercase; }
.palette-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.tile-card { min-width: 0; padding: 7px; border: 1px solid var(--line); background: #0a1725; color: var(--text); text-align: left; }
.tile-card:hover { border-color: var(--line-strong); background: var(--panel-2); }
.tile-card.selected { border-color: var(--cyan); background: rgba(34, 211, 238, .09); box-shadow: inset 0 -2px var(--cyan); }
.tile-card-preview { height: 62px; display: flex; align-items: center; justify-content: center; margin-bottom: 6px; background: var(--board); }
.tile-card svg { max-width: 100%; max-height: 58px; }
.tile-card strong, .tile-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-card strong { font-size: 12px; }
.tile-card small { margin-top: 2px; color: var(--muted); font-size: 10px; }

.board-column { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #030a11; }
.board-toolbar { min-height: 54px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #0a1724; }
.tool-group { display: flex; gap: 6px; }
.tool-group:last-child { justify-content: flex-end; }
.tool-button { min-height: 34px; padding: 5px 9px; font-weight: bold; }
.tool-button span { margin-left: 3px; font-size: 11px; font-weight: normal; }
.board-status { text-align: center; color: var(--muted); font-size: 11px; }
.board-status span, .board-status strong { display: block; }
.board-status strong { color: var(--cyan); }
.board-scroll { flex: 1; min-height: 430px; overflow: auto; padding: 34px; }
.board { position: relative; width: max-content; min-width: 100%; min-height: 100%; }
.board svg { display: block; box-shadow: 0 20px 70px rgba(0, 0, 0, .45); }
.legend-bar { min-height: 38px; display: flex; align-items: center; justify-content: center; gap: 24px; border-top: 1px solid var(--line); color: var(--muted); background: #081522; font-size: 11px; }
.legend-bar i { display: inline-block; vertical-align: middle; margin-right: 5px; }
.legend-line { width: 24px; height: 4px; background: var(--track); }
.legend-port { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); }
.legend-address { min-width: 19px; padding: 1px 3px; border: 1px solid var(--amber); color: var(--amber); font-style: normal; text-align: center; }

.empty-state { padding: 44px 28px; color: var(--muted); text-align: center; }
.empty-symbol { width: 58px; height: 58px; margin: 0 auto 15px; border: 1px solid var(--line); color: var(--line-strong); font-size: 35px; line-height: 54px; }
.inspector-form { padding: 14px; overflow: auto; max-height: calc(100vh - 135px); }
.selection-summary { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 11px; margin-bottom: 17px; padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.selection-summary strong, .selection-summary small { display: block; }
.selection-summary small { margin-top: 4px; color: var(--muted); }
.selected-preview { height: 58px; display: flex; align-items: center; justify-content: center; background: var(--board); }
.selected-preview svg { max-width: 68px; max-height: 54px; }
.field { margin-bottom: 13px; }
.field label { display: block; margin: 0 0 5px; color: #c5d3df; font-size: 11px; font-weight: bold; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.message { position: fixed; right: 18px; bottom: 18px; z-index: 30; max-width: 410px; padding: 11px 14px; border-left: 4px solid var(--cyan); background: #10283b; box-shadow: var(--shadow); }
.message.error { border-left-color: var(--danger); }
.message.success { border-left-color: #34d399; }

.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(1, 6, 11, .82); }
.modal-card { width: min(1100px, 96vw); max-height: 94vh; overflow: auto; border: 1px solid var(--line-strong); background: var(--panel); box-shadow: var(--shadow); }
.modal-card.compact { width: min(470px, 96vw); padding-bottom: 18px; }
.modal-card.compact form { padding: 16px 20px 0; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; min-height: 70px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.modal-heading h2 { margin: 2px 0 0; font-size: 19px; }
.close-button { width: 36px; height: 36px; border: 0; color: var(--muted); background: transparent; font-size: 27px; }
.close-button:hover { color: var(--text); background: var(--panel-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal-actions .push-left { margin-right: auto; }
.tile-editor-layout { display: grid; grid-template-columns: 270px 1fr; min-height: 500px; }
.tile-editor-settings { padding: 18px; border-right: 1px solid var(--line); background: #091624; }
.editor-help { margin-top: 20px; padding: 12px; border-left: 3px solid var(--cyan); color: var(--muted); background: rgba(34, 211, 238, .06); font-size: 12px; }
.editor-help strong { color: var(--text); }
.editor-help ol { margin: 8px 0 0; padding-left: 18px; }
.tile-editor-canvas-column { min-width: 0; padding: 18px; }
.editor-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.tile-editor-board { min-height: 420px; overflow: auto; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: #040c14; }
.tile-editor-board svg { margin: 28px; }

@media (max-width: 1150px) {
    .workspace { grid-template-columns: 235px minmax(390px, 1fr) 270px; }
    .topbar { grid-template-columns: auto 1fr auto; }
    .brand-block div:last-child { display: none; }
    .tool-button span { display: none; }
}

@media (max-width: 850px) {
    .topbar { grid-template-columns: 1fr auto; }
    .plan-actions { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; }
    .plan-actions select { min-width: 180px; }
    .workspace { display: block; }
    .palette-panel, .inspector-panel { border: 0; border-bottom: 1px solid var(--line); }
    .tile-palette { height: auto; max-height: 310px; }
    .palette-grid { grid-template-columns: repeat(4, 1fr); }
    .board-scroll { min-height: 520px; }
    .inspector-form { max-height: none; }
    .tile-editor-layout { grid-template-columns: 1fr; }
    .tile-editor-settings { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 520px) {
    .login-card, .setup-card { padding: 25px; }
    .topbar { padding: 8px; }
    .palette-grid { grid-template-columns: repeat(2, 1fr); }
    .board-toolbar { grid-template-columns: 1fr auto; }
    .board-status { display: none; }
    .board-scroll { padding: 18px; }
    .legend-bar { gap: 10px; flex-wrap: wrap; padding: 8px; }
    .field-row { grid-template-columns: 1fr; gap: 0; }
    .modal { padding: 8px; }
    .editor-toolbar { flex-wrap: wrap; }
}
