:root {
    font: 400 14px/1.5 Inter, "Segoe UI", Arial, sans-serif;
    color: #0f172a;
    background: #f4f6fa;
    --ink: #0f172a;
    --text: #283247;
    --muted: #52647b;
    --primary: #0057b8;
    --primary-hover: #004a9e;
    --primary-soft: #eef6ff;
    --line: #dbe5f0;
    --line-strong: #c9d7e7;
    --surface: #fff;
    --background: #f4f6fa;
    --radius: 8px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    --workspace-row: minmax(280px, 1fr);
    display: grid;
    grid-template-rows: auto auto auto auto var(--workspace-row) auto;
    min-height: 100dvh;
    height: 100dvh;
    margin: 0;
}
body.workspace-compact { grid-template-rows: auto auto var(--workspace-row) auto; }

button, input, select, textarea, summary { font: inherit; }
button, summary, a, label.file { -webkit-tap-highlight-color: transparent; }
a { color: var(--primary); }
.icon { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

h1, h2, p, dl { margin: 0; }
h1 { font-size: 16px; font-weight: 600; white-space: nowrap; }
h2 { font-size: 15px; font-weight: 600; }
kbd { padding: 1px 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--background); }

.control, button, input:not([type="checkbox"]), select, textarea {
    min-height: 36px;
    padding: 6px 11px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
}

button, .control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

button:enabled:hover, summary:hover, a.control:hover, .file:not(:has(:disabled)):hover {
    background: var(--primary-soft);
    border-color: #a8c8eb;
    color: var(--primary);
}

button:disabled, input:disabled, select:disabled, textarea:disabled, .file:has(:disabled) {
    color: #63748a;
    background: #f4f6fa;
    border-color: var(--line);
    cursor: default;
}

button.primary {
    font-weight: 600;
    color: white;
    background: var(--primary);
    border-color: var(--primary);
}

button.primary:enabled:hover {
    color: white;
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

button.primary:disabled { background: #edf2f8; color: #60768f; border-color: var(--line); }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.app-header, .document-bar, .toolbar, .source-strip, .editor-footer {
    padding-inline: 15px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.app-header {
    display: flex;
    min-height: 67px;
    gap: 15px;
    align-items: center;
}

.brand {
    display: inline-flex;
    align-items: center;
    padding-right: 16px;
    border-right: 1px solid var(--line);
}

.brand img { display: block; width: 85px; height: 25px; object-fit: contain; }
.environment { padding: 1px 7px; border-radius: 4px; color: #774700; background: #fff2d8; font-size: 11px; font-weight: 600; }
.app-title { display: flex; align-items: center; gap: 7px; }
.app-heading p { margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 500; }
.session { margin-left: auto; color: var(--muted); font-size: 12px; }
.back-link { display: inline-grid; width: 32px; height: 32px; place-items: center; border-radius: 6px; color: var(--muted); }
.back-link:hover { background: var(--primary-soft); color: var(--primary); }
#login { font-size: 13px; text-underline-offset: 3px; }

.document-bar, .document-heading, .document-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    min-width: 0;
}

.document-bar { flex-direction: column; align-items: stretch; gap: 9px; padding-block: 10px; }
.document-heading { flex-direction: column; align-items: flex-start; gap: 2px; }
.document-file { display: flex; align-items: center; gap: 5px; max-width: 100%; }
#documents { max-width: min(54vw, 530px); min-width: 0; min-height: 25px; padding: 2px 4px; border-color: transparent; font-weight: 600; cursor: pointer; }
#documents:hover { background: var(--primary-soft); border-color: var(--line); }
#documentState { display: flex; align-items: center; gap: 7px; padding-left: 24px; font-size: 12px; color: var(--muted); }
#saveState { display: inline-flex; align-items: center; gap: 6px; }
#saveState::before { content: ''; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
#documentState[data-state="dirty"] #saveState, #documentState[data-state="saving"] #saveState { color: #9b5800; }
#documentState[data-state="error"] #saveState { color: #a72a28; }
.document-actions { flex: none; flex-wrap: wrap; gap: 6px; }
.document-actions #save { margin-left: auto; }
.document-actions :is(.control, button) { min-height: 33px; }
.format-strip { display: inline-flex; flex-wrap: wrap; gap: 4px; }
#export:enabled, .original-link { color: var(--primary); }
.original-link { border-color: transparent; padding-inline: 5px; }

.dropdown, .draw-tools { position: relative; }
.dropdown summary, .draw-tools summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
.dropdown summary::after, .draw-tools summary::after {
    content: "";
    width: 6px;
    height: 6px;
    margin: -3px 1px 0 3px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
}
.dropdown .history-trigger::after { display: none; }

details[open] > summary.control { background: var(--primary-soft); border-color: #b9d5f1; color: var(--primary); }
.popup, #contextMenu {
    padding: 7px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 8px 24px #0f284423;
}

.popup {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    z-index: 8;
    width: min(260px, calc(100vw - 24px));
}

.popup > :is(button, .control) {
    width: 100%;
    justify-content: flex-start;
    padding-inline: 9px;
    border: none;
}
.popup .file { position: relative; }
.popup .file:focus-within { outline: 2px solid var(--primary); outline-offset: -2px; }
.popup .helper { margin: 3px 9px 6px; }
.popup .field { margin: 3px 6px 7px; }
#bridgeActions button { font-size: 13px !important; }
.popup select { width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }

.toolbar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    padding-block: 7px;
    background: #f5f8fc;
}

.tool-group { display: flex; align-items: center; gap: 2px; }
.toolbar > .tool-group + .tool-group, .toolbar > .draw-tools, .toolbar > .draw-tools + .tool-group {
    padding-left: 5px;
    border-left: 1px solid var(--line);
}
.toolbar button { min-height: 33px; padding-inline: 7px; border-color: transparent; background: transparent; }
.toolbar button:disabled { background: transparent; color: #8391a4; }
.toolbar button[aria-pressed="true"] { border-color: #abcbed; background: #e7f2ff; color: var(--primary); font-weight: 600; }
.toolbar .icon-button { width: 33px; padding-inline: 0; }
.tool-options { margin-inline-start: auto; }
.tool-options > summary { min-height: 33px; padding-inline: 7px; background: transparent; font-size: 12px; }
.tool-options .popup { left: auto; right: 0; width: min(220px, calc(100vw - 24px)); }
.draw-tools > summary { display: none; }
.source-strip { display:flex; flex-wrap: wrap; align-items:center; gap:7px 13px; min-height:38px; padding-block:7px; }
#sourceMode { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.workspace-compact .source-strip { padding-block: 3px; }
.compact-document-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-inline-start: auto; }
.compact-document-controls #documentState { padding-inline-start: 0; }
.compact-document-controls button { min-height: 30px; }

.toggle, .grid-step {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 500;
}

.toggle input, .layers input {
    width: 15px;
    height: 15px;
    margin: 0;
    flex: none;
    accent-color: var(--primary);
}

.toggle:has(input:enabled), .layers label:has(input:enabled) { cursor: pointer; }

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(280px, 24vw, 325px);
    min-height: 0;
}

.drawing, .inspector {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    background: var(--surface);
}
.inspector { border-left: 1px solid var(--line); }

#canvasWrap {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

canvas { display: block; width: 100%; height: 100%; touch-action: none; }
canvas:focus-visible { outline-offset: -2px; }
canvas[data-mode="pan"] { cursor: grab; }
canvas[data-mode="pan"]:active { cursor: grabbing; }
canvas[data-mode="select"].over-object { cursor: pointer; }
canvas[data-mode="select"].over-editable { cursor: grab; }
canvas[data-mode="select"].moving-object { cursor: grabbing; }
canvas[data-mode]:not([data-mode="select"], [data-mode="pan"]) { cursor: crosshair; }
.measure-label {
    position: absolute;
    z-index: 2;
    padding: 2px 7px;
    border: 1px solid #abcbed;
    border-radius: 5px;
    background: white;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
    transform: translate(-50%, calc(-100% - 7px));
}
#measurePanel .toggle { margin-top: 9px; }
.measure-value { display: block; margin-block: 8px; color: var(--primary); font-weight: 600; }

.view-tools {
    position: absolute;
    z-index: 3;
    top: 12px;
    right: 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 2px;
    max-width: calc(100% - 24px);
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 2px 9px #182d4c12;
}

.view-tools button { min-height: 30px; padding-inline: 8px; border-color: transparent; background: transparent; font-size: 12px; font-weight: 600; }
.view-tools #plus, .view-tools #minus { min-width: 30px; padding-inline: 5px; font-size: 17px; }
.view-options { position: static; }
.view-options summary { min-height: 30px; padding-inline: 7px; border-color: transparent; font-size: 12px; }
.view-options .popup { left: auto; right: 0; width: min(245px, calc(100vw - 24px)); }
.view-tools #toggleWorkspace { border-color: var(--line); color: var(--primary); }
.view-tools #toggleWorkspace[aria-expanded="false"] { border-color: #abcbed; background: var(--primary-soft); }
#viewSymbols[aria-pressed="true"] { color: var(--primary); }
#viewSymbols[aria-pressed="true"]::before { content: '✓'; width: 13px; text-align: center; }
#viewSymbols[aria-pressed="false"]::before { content: ''; width: 13px; }
.empty-state { position: absolute; top: 42%; left: 50%; width: min(340px, calc(100% - 30px)); text-align: center; transform: translate(-50%, -20%); }
.empty-state h2 { font-size: 18px; }
.empty-state p { margin: 6px 0 14px; color: var(--muted); font-size: 13px; }
.blank-drawing { z-index: 2; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 2px 12px #152c471c; }
.blank-drawing p { margin: 0 0 9px; }
.drawing-hint { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 37px; padding: 3px 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.quiet-button { min-height: 28px; padding: 3px 6px; border-color: transparent; color: var(--primary); font-size: 12px; }
#toolPrompt { overflow-wrap: anywhere; }

.inspector-tabs {
    display: flex;
    flex: none;
    align-items: stretch;
    gap: 2px;
    padding-inline: 4px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
}

.inspector-tabs button {
    flex: 1 0 auto;
    gap: 4px;
    padding: 10px 4px;
    border: 0;
    border-radius: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    font-size: 13px;
}
.inspector-tabs button[aria-selected="true"] { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }
.inspector-tools { padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fbfcfe; }
.symbol-lookup { display: flex; gap: 4px; }
.symbol-lookup input { min-width: 0; width: 100%; min-height: 32px; }
.symbol-lookup button { flex: none; width: 34px; min-height: 32px; padding: 0; }
.inspector-quick-actions { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; }
.inspector-quick-actions button { min-height: 29px; padding-inline: 5px; font-size: 11px; }
#matches:not(:empty) { margin-top: 5px; }
.search-results { list-style: none; padding: 0; margin: 9px 0 0; }
.search-results button { min-height: 28px; width: 100%; justify-content: flex-start; border-color: transparent; font-size: 12px; }
.inspector-pane { flex: 1; min-height: 0; padding: 16px 14px; overflow: auto; }
.selection-heading { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 5px; }
.selection-status { font-size: 14px; font-weight: 600; }
.selection-count { padding: 3px 5px; border-radius: 4px; background: #eff4fb; color: #28476c; font-size: 11px; white-space: nowrap; }
.object-details { margin: 16px 0 7px; padding-top: 11px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.object-details summary { cursor: pointer; }
.property-section + .property-section { margin-top: 13px; }
.drafting-panel, .object-text { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.drafting-panel summary { cursor: pointer; color: var(--text); font-size: 13px; font-weight: 600; }
#newTextPanel { padding-block: 9px; border-top: 1px solid var(--line); border-bottom: 0; }
.object-text { margin: 11px 0; }
.property-section h2 { margin-bottom: 7px; }
.helper { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.field { display: grid; gap: 4px; min-width: 0; margin: 8px 0; color: var(--text); font-size: 12px; font-weight: 500; }
.field :is(input, select, textarea) { min-width: 0; width: 100%; }
.field :is(input, textarea)[readonly] { background: var(--background); }
.field textarea { resize: vertical; }
.coordinates { min-width: 0; padding: 0; margin: 0 0 10px; border: 0; }
.coordinates legend { padding: 0; margin: 0 0 6px; color: #4c6381; font-size: 12px; font-weight: 600; letter-spacing: .055em; text-transform: uppercase; }
.coordinates .field { grid-template-columns: minmax(68px, .44fr) minmax(0, 1fr); align-items: center; gap: 6px; margin-block: 6px; }
.coordinates input { min-height: 34px; }
#properties { margin-top: 18px; }
#propertyNote { margin-bottom: 10px; }
#apply { width: 100%; }
#apply:disabled { color: #63748a; }
#bulk { width: 100%; margin-top: 8px; white-space: normal; text-wrap: balance; color: var(--primary); }
#bulk:disabled { color: var(--muted); }
#editTable { width: 100%; margin-top: 8px; color: var(--primary); }
.unit { color: var(--muted); font-weight: 400; }
.inspector-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-block: 9px; }
.inspector-actions button { min-height: 32px; padding-inline: 8px; font-size: 12px; }
.visibility-actions { border-top: 1px solid var(--line); padding-top: 10px; }
.layers label { display: flex; align-items: flex-start; gap: 7px; padding: 7px 0; font-size: 12px; overflow-wrap: anywhere; border-bottom: 1px solid var(--line); }
.layers input { margin-top: 2px; }

.editor-footer { border-top: 1px solid var(--line); border-bottom: 0; padding-block: 5px; font-size: 12px; }
.cad-state, .notice { display: flex; justify-content: space-between; align-items: center; gap: 5px 12px; min-height: 26px; }
.cad-state { flex-wrap: wrap; color: var(--text); }
.drawing-aids { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 12px; }
#grid { width: 68px; min-height: 28px; padding: 2px 5px; }
.notice { color: var(--muted); }
.notice.error { color: #a72a28; }
#status { min-width: 0; overflow-wrap: anywhere; }
#busy { width: 90px; height: 8px; flex: none; accent-color: var(--primary); }

.info-dialog {
    width: min(520px, calc(100vw - 24px));
    max-height: calc(100dvh - 32px);
    padding: 16px 19px;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    color: var(--ink);
    box-shadow: 0 10px 40px #19334f35;
}
.info-dialog::backdrop { background: #172a46a0; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 9px; }
.info-dialog p { margin: 8px 0; }
.info-dialog dl { display: grid; grid-template-columns: minmax(110px, .75fr) minmax(0, 1fr); gap: 6px 12px; font-size: 13px; }
.info-dialog dd { margin: 0; color: var(--muted); }
.block-picker-content { display: grid; grid-template-columns: minmax(0,1fr) 118px; gap: 10px; align-items: stretch; }
#blockList { min-width: 0; height: 139px; width: 100%; }
#blockList option { padding: 2px 0; }
#blockPreview { width: 100%; height: 139px; border-radius: 6px; border: 1px solid var(--line); background: #f9fbfd; }
#chooseBlock { margin-top: 2px; }
.plot-options { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); column-gap: 10px; align-items: end; }
.plot-preview-frame { background: #eff4f9; border-radius: var(--radius); margin-top: 8px; display: grid; place-items: center; }
#plotPreview { max-width: 100%; width: auto; height: auto; border: 1px solid var(--line-strong); margin-block: 8px; }
.plot-actions { display: flex; flex-wrap: wrap; gap: 7px; }
#plotPrintSheet { display: none; }
@media print {
    body.cad-print-prepared { display: block; min-height: 0; height: auto; padding: 0; margin: 0; background: #fff; }
    body.cad-print-prepared > :not(#plotPrintSheet) { display: none !important; }
    .cad-print-prepared #plotPrintSheet { display: block; position: relative; overflow: hidden; }
    .plot-sheet-drawing { position: absolute; }
    .plot-sheet-drawing svg { width: 100%; height: 100%; display: block; }
}
#cadTableDialog { width: min(680px, calc(100vw - 24px)); }
.table-cell-scroll { max-height: 42dvh; overflow: auto; margin-block: 8px; }
.table-cell-scroll table { border-collapse: separate; border-spacing: 3px; min-width: 100%; }
.table-cell-scroll input { min-width: 90px; width: 100%; min-height: 32px; padding: 4px 6px; }

#bulkDialog {
    width: min(465px, calc(100vw - 24px));
    max-height: calc(100dvh - 32px);
    padding: 17px;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    color: var(--ink);
    box-shadow: 0 10px 40px #19334f35;
}
#bulkDialog::backdrop { background: #172a46a0; }
#bulkDialog .stack { display: block; margin: 8px 0 4px; font-size: 13px; font-weight: 500; }
#bulkDialog .stack input[type="checkbox"] { margin-right: 6px; accent-color: var(--primary); }
#bulkDialog :is(select, textarea, input:not([type="checkbox"])) { width: 100%; }
#bulkDialog p { margin: 7px 0; font-size: 13px; }
#bulkResult { padding: 8px; border-radius: var(--radius); background: var(--primary-soft); }
.bulkActions { display: flex; flex-wrap: wrap; gap: 6px; }

#contextMenu { position: fixed; z-index: 20; width: min(282px, calc(100vw - 12px)); max-height: calc(100dvh - 12px); overflow: auto; }
#contextMenu button { display: flex; justify-content: flex-start; width: 100%; gap: 8px; padding-inline: 7px; border: 0; min-height: 32px; white-space: normal; text-align: left; }
#contextMenu kbd { margin-left: auto; font-size: 11px; white-space: nowrap; }

@media (max-width: 570px) {
    .draw-tools > summary { display: inline-flex; min-height: 33px; }
    .draw-tools > .tool-group {
        position: absolute; z-index: 7; top: calc(100% + 5px); left: 7px;
        display: grid; min-width: 145px; padding: 6px;
        border: 1px solid var(--line-strong); border-radius: var(--radius);
        background: var(--surface); box-shadow: 0 8px 24px #0f284423;
    }
    .draw-tools > .tool-group button { justify-content: flex-start; }
    .block-picker-content { grid-template-columns: minmax(0,1fr) 88px; }
}

@media (max-width: 680px) {
    body { --workspace-row: minmax(570px, 1fr); height: auto; min-height: 100dvh; }
    .app-header, .document-bar, .toolbar, .source-strip, .editor-footer { padding-inline: 10px; }
    .app-header { gap: 7px; flex-wrap: wrap; padding-block: 7px; }
    .brand { padding-right: 7px; }
    .brand img { width: 62px; }
    .app-header .back-link { margin-left: auto; }
    .session { flex-basis: 100%; margin-left: 0; order: 1; }
    .session:empty { display: none; }
    #documents { max-width: calc(100vw - 51px); }
    .document-actions { position: relative; width: 100%; flex-wrap: wrap; gap: 4px; }
    .document-actions .dropdown { position: static; }
    .document-actions .popup { left: 0; right: auto; }
    .document-actions .control, #save { padding-inline: 7px; }
    .document-actions #save { margin-left: auto; }
    .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(340px, 58vh) minmax(210px, 36vh); }
    .workspace-compact .workspace { grid-template-rows: minmax(340px, 69dvh) minmax(210px, 36vh); }
    .inspector { border-left: 0; border-top: 1px solid var(--line); }
    .inspector-tabs button { font-size: 13px; }
}
