/* ============================================================
   TunerBox — Professional calibration workbench
   Dense, dark-first engineering UI. Light theme via [data-theme="light"].
   Accent amber #F0A500 reserved for active / selected / primary only.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* ---- Dark (default) ---- */
    --bg:          #0f1115;   /* app background */
    --panel:       #171a21;   /* panel background */
    --panel-2:     #1f232c;   /* secondary panel / raised rows */
    --panel-3:     #262b35;   /* hover */
    --border:      #2a2f3a;   /* 1px borders */
    --border-2:    #353c49;   /* stronger borders (inputs/focus) */
    --text:        #e7eaf0;
    --text-muted:  #8b93a3;
    --text-dim:    #626a78;

    --accent:      #F0A500;
    --accent-2:    #ffb724;
    --accent-dim:  rgba(240,165,0,0.14);
    --accent-line: rgba(240,165,0,0.55);
    --on-accent:   #1a1205;

    --danger:      #d65a52;
    --danger-dim:  rgba(214,90,82,0.14);
    --success:     #4caf7d;
    --success-dim: rgba(76,175,125,0.14);

    /* Map table chrome */
    --axis-bg:     #1b1f27;
    --axis-text:   #aab2c0;
    --corner-bg:   #151820;
    --canvas-dot:  #1c2029;   /* subtle workspace dot grid */

    --scrollbar:       #353c49;
    --scrollbar-hover: #454d5c;

    --mono: 'Cascadia Mono','JetBrains Mono','Fira Code','Consolas','Courier New',monospace;
    --ui:   system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue',sans-serif;

    /* Metrics */
    --h-menubar: 30px;
    --h-toolbar: 44px;
    --h-tabbar:  34px;
    --h-status:  26px;
    --w-browser: 264px;
    --w-inspector: 324px;

    --r-sm: 4px;
    --r:    6px;
    --r-lg: 8px;

    --focus: 0 0 0 2px var(--accent-dim), 0 0 0 1px var(--accent-line);
}

[data-theme="light"] {
    --bg:          #e9ebf0;
    --panel:       #ffffff;
    --panel-2:     #f3f5f8;
    --panel-3:     #e9edf3;
    --border:      #dce0e8;
    --border-2:    #c6ccd8;
    --text:        #1b1f27;
    --text-muted:  #5b6472;
    --text-dim:    #98a0ae;

    --accent:      #d99000;
    --accent-2:    #F0A500;
    --accent-dim:  rgba(240,165,0,0.18);
    --accent-line: rgba(217,144,0,0.6);
    --on-accent:   #1a1205;

    --danger:      #c5413a;
    --danger-dim:  rgba(197,65,58,0.12);
    --success:     #1f9d62;
    --success-dim: rgba(31,157,98,0.12);

    --axis-bg:     #eef1f6;
    --axis-text:   #3a4250;
    --corner-bg:   #e4e8f0;
    --canvas-dot:  #d6dbe4;   /* subtle workspace dot grid (light) */

    --scrollbar:       #c5ccd8;
    --scrollbar-hover: #a9b2c1;
}

html { font-size: 13px; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--ui);
    font-size: 13px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); background-clip: padding-box; }

a { color: inherit; text-decoration: none; }
b { font-weight: 600; }

/* The HTML `hidden` attribute must win over our display:flex/grid rules. */
[hidden] { display: none !important; }

/* ============================================================
   Buttons / controls (consistent sizes)
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 32px; padding: 0 12px;
    font-family: var(--ui); font-size: 12.5px; font-weight: 500;
    border: 1px solid var(--border-2); border-radius: var(--r-sm);
    background: var(--panel-2); color: var(--text);
    cursor: pointer; white-space: nowrap; user-select: none;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn .ico { width: 15px; height: 15px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11.5px; gap: 4px; }
.btn-full { width: 100%; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

button:disabled, .btn:disabled, .is-disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.menu-item.is-disabled { pointer-events: auto; cursor: not-allowed; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; padding: 0;
    border: 1px solid transparent; border-radius: var(--r-sm);
    background: transparent; color: var(--text-muted); cursor: pointer;
    transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn .ico { width: 16px; height: 16px; }

/* Segmented control */
.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: var(--r-sm); overflow: hidden; background: var(--panel-2); }
.seg button {
    display: inline-flex; align-items: center; gap: 5px;
    height: 28px; padding: 0 10px; border: none; background: transparent;
    color: var(--text-muted); font-family: var(--ui); font-size: 12px; cursor: pointer;
    border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button .ico { width: 14px; height: 14px; }
.seg button:hover { background: var(--panel-3); color: var(--text); }
.seg button.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.seg-block { display: flex; width: 100%; }
.seg-block button { flex: 1; justify-content: center; }

/* Switch (checkbox label) */
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 14px; height: 14px; }
.switch-block { display: flex; margin-top: 8px; }

.count-pill {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px;
    font-size: 11px; font-weight: 600; border-radius: 999px;
    background: var(--panel-3); color: var(--text-muted);
}

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--r-sm); font-size: 11px; font-weight: 600; }
.badge-modified { background: var(--accent-dim); color: var(--accent); }
.badge-pending { background: var(--panel-3); color: var(--text-muted); }

.muted { color: var(--text-muted); font-size: 12px; }
.panel-hint { color: var(--text-muted); font-size: 12px; padding: 12px; line-height: 1.6; }
.panel-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

/* ============================================================
   Fields
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; color: var(--text-muted); }
.field label small { color: var(--text-dim); }
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; min-width: 0; }
.field-check { flex-direction: row; align-items: center; gap: 6px; align-self: flex-end; height: 30px; font-size: 12px; color: var(--text); cursor: pointer; }
.field-check input { accent-color: var(--accent); }

input[type="text"], input[type="number"], input[type="email"], input[type="password"], select, textarea {
    width: 100%; height: 30px; padding: 0 9px;
    font-family: var(--ui); font-size: 12.5px;
    color: var(--text); background: var(--bg);
    border: 1px solid var(--border-2); border-radius: var(--r-sm);
    outline: none; transition: border-color .12s, box-shadow .12s;
}
select { cursor: pointer; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-line); box-shadow: var(--focus); }
input::placeholder { color: var(--text-dim); }

/* ============================================================
   App shell layout
   ============================================================ */
.editor-page { overflow: hidden; }
.app-shell {
    display: grid;
    grid-template-rows: var(--h-menubar) var(--h-toolbar) var(--h-tabbar) 1fr var(--h-status);
    height: 100vh; width: 100vw;
}

/* 1. Menu bar */
.menubar {
    display: flex; align-items: stretch;
    height: var(--h-menubar);
    background: var(--panel); border-bottom: 1px solid var(--border);
    padding: 0 8px;
}
.menu-logo { display: flex; align-items: center; gap: 6px; padding: 0 10px 0 4px; font-weight: 600; }
.menu-logo .logo-mark { color: var(--accent); font-size: 15px; }
.menu-logo .logo-name { font-size: 13px; letter-spacing: .01em; }
.menubar-menus { display: flex; align-items: stretch; }
.menu { position: relative; display: flex; align-items: stretch; }
.menu-btn {
    background: transparent; border: none; color: var(--text-muted);
    font-family: var(--ui); font-size: 12.5px; padding: 0 11px; cursor: pointer;
}
.menu-btn:hover, .menu.is-open .menu-btn { background: var(--panel-2); color: var(--text); }
.menu-dropdown {
    position: absolute; top: 100%; left: 0; z-index: 200;
    min-width: 220px; padding: 4px;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    display: none;
}
.menu.is-open .menu-dropdown { display: block; }
.menu-item {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%;
    padding: 6px 9px; border: none; border-radius: var(--r-sm);
    background: transparent; color: var(--text); font-family: var(--ui); font-size: 12.5px;
    text-align: left; cursor: pointer;
}
.menu-item:hover:not(:disabled) { background: var(--accent-dim); color: var(--accent); }
.menu-item .shortcut { font-size: 11px; color: var(--text-dim); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu-static { padding: 6px 9px; font-size: 11px; color: var(--text-dim); }

.menubar-spacer { flex: 1; }
.menubar-right { display: flex; align-items: center; gap: 6px; }

/* Profile */
.profile { position: relative; }
.profile-btn { display: flex; align-items: center; background: transparent; border: none; cursor: pointer; padding: 2px; }
.profile-avatar {
    width: 24px; height: 24px; border-radius: var(--r-sm);
    background: var(--accent); color: var(--on-accent);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
}
.profile-menu {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 200;
    min-width: 200px; padding: 4px;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
    box-shadow: 0 8px 24px rgba(0,0,0,.4); display: none;
}
.profile-menu.is-open { display: block; }
.profile-menu-head { padding: 8px 9px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.profile-menu-name { font-weight: 600; }
.profile-menu-sub { font-size: 11px; color: var(--text-muted); }
.profile-menu a { display: block; padding: 6px 9px; border-radius: var(--r-sm); font-size: 12.5px; }
.profile-menu a:hover { background: var(--accent-dim); color: var(--accent); }

/* 2. Toolbar */
.toolbar {
    display: flex; align-items: center; gap: 4px;
    height: var(--h-toolbar);
    background: var(--panel); border-bottom: 1px solid var(--border);
    padding: 0 8px; overflow-x: auto;
}
.toolbar::-webkit-scrollbar { height: 0; }
.tb-group { display: flex; align-items: center; gap: 3px; }
.tb-divider { width: 1px; align-self: stretch; margin: 8px 5px; background: var(--border); }
.tb-spacer { flex: 1; }
.tb-trailing { gap: 6px; }
.tb-label { font-size: 11px; color: var(--text-muted); margin: 0 1px; }
.tb-btn {
    display: inline-flex; align-items: center; gap: 6px;
    height: 32px; padding: 0 10px;
    border: 1px solid transparent; border-radius: var(--r-sm);
    background: transparent; color: var(--text); font-family: var(--ui); font-size: 12px;
    cursor: pointer; white-space: nowrap; transition: background .12s;
}
.tb-btn:hover:not(:disabled) { background: var(--panel-2); }
.tb-btn:active { transform: translateY(1px); }
.tb-btn .ico { color: var(--text-muted); }
.tb-btn:hover:not(:disabled) .ico { color: var(--text); }
.tb-btn.icon-only { padding: 0 8px; }
.tb-btn.active { background: var(--accent-dim); }
.tb-btn.active .ico, .tb-btn.active span { color: var(--accent); }

/* 3. Tab bar */
.tabbar { display: flex; align-items: stretch; height: var(--h-tabbar); background: var(--bg); border-bottom: 1px solid var(--border); }
.tabbar-scroll { display: flex; align-items: stretch; overflow-x: auto; }
.tabbar-scroll::-webkit-scrollbar { height: 0; }
.tab {
    display: flex; align-items: center; gap: 6px;
    padding: 0 12px; min-width: 0; max-width: 220px;
    background: transparent; border-right: 1px solid var(--border);
    color: var(--text-muted); font-size: 12px; cursor: pointer; user-select: none;
    border-top: 2px solid transparent;
}
.tab .ico { width: 14px; height: 14px; }
.tab:hover { background: var(--panel); color: var(--text); }
.tab.active { background: var(--panel); color: var(--text); border-top-color: var(--accent); }
.tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-close {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: var(--r-sm); font-size: 13px;
    color: var(--text-dim); margin-left: 2px;
}
.tab-close:hover { background: var(--panel-3); color: var(--text); }

/* 4. Workbench */
.workbench {
    display: grid;
    grid-template-columns: var(--w-browser) 1fr var(--w-inspector);
    min-height: 0; overflow: hidden;
}

/* Left: map browser */
.map-browser { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--border); }
.browser-head { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.browser-search { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.browser-search .ico { color: var(--text-dim); flex-shrink: 0; }
.browser-search input { height: 28px; border-color: transparent; background: var(--panel-2); }
.browser-list { flex: 1; overflow-y: auto; min-height: 0; padding: 4px; }
.browser-foot { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.browser-foot .btn { flex: 1; }

.map-item {
    position: relative; display: grid;
    grid-template-columns: 1fr auto; gap: 2px 6px;
    padding: 7px 8px 7px 10px; border-radius: var(--r-sm); cursor: pointer;
    border: 1px solid transparent;
}
.map-item:hover { background: var(--panel-2); }
.map-item.active { background: var(--accent-dim); border-color: var(--accent-line); }
.map-item.active::before { content: ''; position: absolute; left: 0; top: 4px; bottom: 4px; width: 2px; border-radius: 999px; background: var(--accent); }
.map-item-name { grid-column: 1; font-size: 12.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-item-desc { grid-column: 1; font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-item-meta { grid-column: 1; font-family: var(--mono); font-size: 10.5px; color: var(--text-dim); display: flex; gap: 6px; align-items: center; }
.map-item-meta .mi-mod { color: var(--accent); font-family: var(--ui); font-weight: 600; }
.map-item-side { grid-column: 2; grid-row: 1 / span 3; display: flex; flex-direction: column; align-items: center; gap: 4px; justify-content: flex-start; }
.map-item-actions { display: none; gap: 2px; }
.map-item:hover .map-item-actions { display: flex; }
.mi-star { background: transparent; border: none; cursor: pointer; color: var(--text-dim); padding: 2px; line-height: 0; }
.mi-star .ico { width: 14px; height: 14px; }
.mi-star.on { color: var(--accent); }
.mi-star.on .ico { fill: var(--accent); }
.mi-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* Center: editor — dotted canvas lives on .editor-main, BEHIND the editor group */
.editor-main {
    display: flex; flex-direction: column; min-width: 0; min-height: 0;
    padding: 12px;
    background-color: var(--bg);
    background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px);
    background-size: 16px 16px; background-position: -1px -1px;
}
/* One connected editor surface: header → edit toolbar → table inside a single
   subtle bordered panel. Not a SaaS card — 1px border, small radius, no shadow. */
.editor-group {
    flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0;
    background: var(--panel);
    border: 1px solid var(--border); border-radius: var(--r);
    overflow: hidden;
}
.map-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.mh-info { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex-wrap: wrap; }
.mh-name { background: transparent; border: none; color: var(--text); font-family: var(--ui); font-size: 14px; font-weight: 600; cursor: pointer; padding: 0; }
.mh-name:hover { color: var(--accent); }
.mh-desc { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.mh-desc:empty { display: none; }
/* Separator dot before the technical meta string so name/desc/meta read as one line */
.mh-meta { font-family: var(--mono); font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.mh-meta:not(:empty)::before { content: '·'; margin-right: 10px; color: var(--border-2); }
.mh-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Table zoom controls (top-right of the editor panel header) */
.zoom-ctl { display: inline-flex; align-items: stretch; border: 1px solid var(--border-2); border-radius: var(--r-sm); overflow: hidden; background: var(--panel-2); }
.zoom-ctl button { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-family: var(--ui); font-size: 12px; padding: 0 8px; height: 26px; }
.zoom-ctl button:hover { background: var(--panel-3); color: var(--text); }
.zoom-btn { font-size: 15px; font-weight: 600; line-height: 1; min-width: 26px; }
.zoom-val { font-family: var(--mono); font-size: 11px; min-width: 46px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.zoom-fit { font-size: 11px; border-left: 1px solid var(--border); }
.zoom-fit.active { background: var(--accent-dim); color: var(--accent); }

/* Local edit toolbar — permanent strip; reserves a fixed row above the table so
   the table never shifts when a selection is made/cleared. */
.edit-toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; overflow-x: auto;
    min-height: 38px; padding: 6px 12px;
    background: var(--panel-2); border-bottom: 1px solid var(--border);
}
.et-count {
    font-size: 12px; font-weight: 600; color: var(--accent);
    flex: 0 0 140px; width: 140px;                 /* fixed width → controls never shift */
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.et-op { display: flex; align-items: center; gap: 5px; }
.et-op label { font-size: 11px; color: var(--text-muted); }
.et-op input { width: 72px; height: 26px; }
.et-sep { width: 1px; align-self: stretch; margin: 2px 2px; background: var(--border); }

/* Inactive state — no cells selected. Dim the whole strip so it reads as a
   passive helper row rather than an active action bar. */
.edit-toolbar.is-inactive { opacity: 0.62; }
.edit-toolbar.is-inactive .et-count { color: var(--text-muted); font-weight: 500; }

/* Tab panels */
.tab-panels { flex: 1; min-height: 0; position: relative; }
.tab-panel { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }
.tab-panel[hidden] { display: none; }

/* Right: inspector */
.inspector-panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--border); }
.insp-tabs { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.insp-tab {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; background: transparent; border: none; border-bottom: 2px solid transparent;
    color: var(--text-muted); font-family: var(--ui); font-size: 12px; cursor: pointer;
}
.insp-tab:hover { color: var(--text); background: var(--panel-2); }
.insp-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.insp-tab .count-pill { background: var(--panel-3); }
.insp-body { flex: 1; overflow-y: auto; min-height: 0; padding: 10px; }
.insp-body[hidden] { display: none; }

/* Properties form */
.prop-form { display: flex; flex-direction: column; gap: 12px; }
.prop-section { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.prop-section:last-of-type { border-bottom: none; }
.prop-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.field-derived { display: flex; gap: 14px; font-size: 11px; color: var(--text-muted); }
.field-derived b { color: var(--text); }
.field-formula-label { font-size: 11px; color: var(--text-dim); font-style: italic; }
details.axis-section { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px; gap: 8px; }
details.axis-section summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-muted); list-style: none; }
details.axis-section summary::before { content: '▸ '; color: var(--text-dim); }
details.axis-section[open] summary::before { content: '▾ '; }
details.axis-section[open] { gap: 8px; }
details.axis-section[open] > *:not(summary) { margin-top: 8px; }
.prop-actions { display: flex; gap: 8px; position: sticky; bottom: -10px; background: var(--panel); padding: 8px 0 2px; }

/* Changes tab */
.changes-summary { display: flex; gap: 10px; margin-bottom: 10px; }
.cs-stat { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--r-sm); }
.cs-num { font-family: var(--mono); font-size: 18px; font-weight: 700; color: var(--accent); }
.cs-label { font-size: 10.5px; color: var(--text-muted); }
.changes-actions { display: flex; gap: 6px; margin-bottom: 10px; }
.changes-list { display: flex; flex-direction: column; gap: 6px; }
.change-row { padding: 7px 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--r-sm); }
.change-row.sel { border-color: var(--accent-line); }
.cr-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cr-name { font-size: 12px; font-weight: 600; }
.cr-coords { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.cr-vals { font-family: var(--mono); font-size: 11.5px; margin-top: 3px; }
.cr-vals .old { color: var(--text-muted); }
.cr-vals .new { color: var(--text); font-weight: 600; }
.cr-delta { font-family: var(--mono); font-size: 11px; margin-top: 2px; }
.cr-delta.up { color: var(--success); }
.cr-delta.down { color: var(--danger); }
.cr-revert { background: transparent; border: none; color: var(--text-dim); cursor: pointer; font-size: 11px; padding: 2px 4px; border-radius: var(--r-sm); }
.cr-revert:hover { color: var(--danger); background: var(--danger-dim); }

/* 5. Status bar */
.statusbar {
    display: flex; align-items: center; gap: 0;
    height: var(--h-status);
    background: var(--panel); border-top: 1px solid var(--border);
    padding: 0 6px; font-size: 11.5px; color: var(--text-muted); overflow: hidden;
}
.sb-item { padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-item b { color: var(--text); font-weight: 600; }
.sb-cell, #sb-offset, #sb-delta { font-family: var(--mono); }
.sb-sep { width: 1px; height: 14px; background: var(--border); flex-shrink: 0; }
.sb-spacer { flex: 1; }
.sb-pending.dirty { color: var(--accent); font-weight: 600; }
.sb-checksum { color: var(--text-dim); }

/* ============================================================
   Hex editor
   ============================================================ */
.hex-editor { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--bg); font-family: var(--mono); }
.hex-row { display: flex; align-items: center; height: 22px; font-size: 12px; }
.hex-header { height: 26px; background: var(--panel); border-bottom: 1px solid var(--border); color: var(--text-muted); font-size: 11px; position: sticky; top: 0; z-index: 2; }
.hex-offset { width: 88px; flex-shrink: 0; padding-left: 12px; color: var(--text-dim); }
.hex-header .hex-offset { color: var(--text-muted); font-weight: 600; }
.hex-cols { display: flex; align-items: center; }
.hex-byte { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 20px; border-radius: 3px; cursor: pointer; }
.hex-byte:hover { background: var(--accent-dim); box-shadow: inset 0 0 0 1px var(--accent-line); }
.hex-colhead { color: var(--text-dim); cursor: default; font-weight: 600; }
.hex-colhead:hover { background: transparent; box-shadow: none; }
.hex-byte[data-zero="1"] { color: var(--text-dim); }
.hex-byte-empty { visibility: hidden; }
.hex-byte-cursor { background: var(--accent-dim); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.hex-byte-found { background: rgba(76,175,125,.22); box-shadow: inset 0 0 0 1px var(--success); }
.hex-gap { width: 10px; flex-shrink: 0; }
.hex-ascii { display: flex; align-items: center; padding: 0 12px 0 14px; color: var(--text-muted); }
.hex-ascii-head { color: var(--text-muted); font-weight: 600; }
.hex-char { display: inline-flex; align-items: center; justify-content: center; width: 9px; }
.hex-row-alt { background: rgba(255,255,255,.012); }
[data-theme="light"] .hex-row-alt { background: rgba(0,0,0,.018); }
.hex-viewport { flex: 1; overflow-y: auto; position: relative; min-height: 0; outline: none; }
.hex-spacer { width: 1px; }
.hex-rows { position: absolute; top: 0; left: 0; right: 0; will-change: transform; }
.hex-byte-input {
    width: 26px; height: 20px; padding: 0; text-align: center;
    font-family: var(--mono); font-size: 12px; color: var(--accent);
    background: var(--panel); border: 1px solid var(--accent); border-radius: 3px;
}

/* Data inspector strip */
.inspector-strip {
    display: flex; align-items: center; gap: 0; flex-wrap: wrap;
    min-height: 30px; padding: 0 8px;
    background: var(--panel); border-top: 1px solid var(--border);
    font-family: var(--mono); font-size: 11.5px;
}
.inspector-empty { color: var(--text-dim); padding: 6px; font-family: var(--ui); }
.inspector-offset { color: var(--accent); padding: 0 10px 0 4px; font-weight: 600; }
.insp-item { display: inline-flex; align-items: center; gap: 5px; padding: 0 9px; border-left: 1px solid var(--border); height: 18px; }
.insp-label { color: var(--text-dim); }
.insp-value { color: var(--text); }

/* ============================================================
   Map viewer / table
   ============================================================ */
.map-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
/* Table workspace — solid panel surface inside the editor group (the dotted
   canvas sits outside the group, on .editor-main). Table stays top-left.
   Cell metrics are driven by CSS vars so zoom can scale them without breaking
   sticky headers, selection box-shadows, or hit-testing (no transform: scale). */
.map-table-scroll {
    flex: 1; overflow: auto; min-width: 0; min-height: 0; padding: 14px;
    background: var(--panel);
    --cell-w: 60px; --cell-h: 28px; --axis-w: 72px; --cell-fs: 12px; --corner-fs: 10px;
}
.map-loading, .map-error { padding: 16px; color: var(--text-muted); font-size: 12px; }
.map-error { color: var(--danger); }

/* The table reads as a contained object placed top-left in the workspace:
   a closed 1px border (cells only draw right/bottom). */
.map-table {
    border-collapse: separate; border-spacing: 0; font-family: var(--mono);
    width: max-content; table-layout: fixed;
    background: var(--panel); border-top: 1px solid var(--border); border-left: 1px solid var(--border);
}
.map-table th, .map-table td {
    width: var(--cell-w); min-width: var(--cell-w); max-width: var(--cell-w);
    height: var(--cell-h); line-height: var(--cell-h); box-sizing: border-box;
    text-align: center; font-size: var(--cell-fs); padding: 0;
    border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-axis-top, .map-axis-left, .map-axis-corner {
    background: var(--axis-bg); color: var(--axis-text); font-weight: 600; position: sticky; z-index: 1;
}
.map-axis-top { top: 0; }
.map-axis-left { left: 0; width: var(--axis-w); min-width: var(--axis-w); max-width: var(--axis-w); }
.map-axis-corner { top: 0; left: 0; z-index: 2; background: var(--corner-bg); width: var(--axis-w); min-width: var(--axis-w); max-width: var(--axis-w); font-size: var(--corner-fs); font-weight: 500; line-height: 1.3; }
.axis-corner-x { display: block; color: var(--text-muted); }
.axis-corner-y { display: block; color: var(--text-dim); }
.map-axis-top.is-editable, .map-axis-left.is-editable { cursor: pointer; }
.map-axis-top.is-editable:hover, .map-axis-left.is-editable:hover { background: var(--panel-3); color: var(--text); }

.map-cell { background: var(--panel); color: var(--text); cursor: cell; position: relative; }
.map-cell:hover { box-shadow: inset 0 0 0 1px var(--border-2); }
.map-cell.selected { box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-dim); }
.map-cell.editing { box-shadow: inset 0 0 0 2px var(--accent); }
.cell-num { display: inline-block; }
.cell-num.is-pending { color: var(--accent); font-weight: 700; }
.cell-num.is-saved { color: var(--success); font-weight: 600; }

/* Heatmap on: explicit bg set inline; keep text white & legible */
.map-table-scroll.heat-on .map-cell { color: #fff; }
.map-table-scroll.heat-on .map-cell.selected { box-shadow: inset 0 0 0 2px #fff; }
.map-table-scroll.heat-on .cell-num.is-pending { color: #ffe39a; }
.map-table-scroll.heat-on .cell-num.is-saved { color: #c8f5dd; }

/* Changed-from-stock: primary = clean inset amber outline (no layout shift),
   secondary = sharp top-right corner triangle. Number stays fully readable. */
.map-cell.changed-from-stock {
    box-shadow: inset 0 0 0 2px var(--accent);
}
.map-cell.changed-from-stock::after {
    content: ''; position: absolute; top: 0; right: 0;
    width: 0; height: 0;
    border-top: 7px solid var(--accent);
    border-left: 7px solid transparent;
}
/* Selected AND changed: keep both signals visible — outer selection ring +
   inner amber outline so the change indicator is never hidden. */
.map-cell.changed-from-stock.selected {
    box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 4px var(--accent-dim);
}
/* On the heatmap, use white so the marker reads over any band colour. */
.map-table-scroll.heat-on .map-cell.changed-from-stock {
    box-shadow: inset 0 0 0 2px #fff;
}
.map-table-scroll.heat-on .map-cell.changed-from-stock::after { border-top-color: #fff; }
.map-table-scroll.heat-on .map-cell.changed-from-stock.selected {
    box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px rgba(0,0,0,.35);
}

/* Delta view colouring is applied inline via heat too; stock view dims editing */
.map-table-scroll.viewing-stock .map-cell { cursor: default; }

.map-cell-inline-input {
    /* Absolutely fill the cell so the input is taken out of layout flow — an
       inline input's baseline/descender would otherwise grow the cell + row
       height. inset:0 pins it to the cell's fixed box without resizing it. */
    position: absolute; inset: 0; display: block;
    width: 100%; height: 100%; box-sizing: border-box; padding: 0 4px; margin: 0;
    text-align: center; font-family: var(--mono); font-size: var(--cell-fs); line-height: var(--cell-h);
    color: var(--accent); background: var(--panel); border: none; outline: none;
}
.map-table-scroll.heat-on .map-cell-inline-input { background: rgba(0,0,0,.45); color: #fff; }

.stock-badge {
    position: absolute; top: 8px; right: 18px; z-index: 5;
    padding: 3px 9px; border-radius: 999px;
    background: var(--panel-3); border: 1px solid var(--border-2);
    color: var(--text-muted); font-size: 11px; font-weight: 600;
}
.map-panel-body { display: flex; flex: 1; min-width: 0; min-height: 0; }
.map-workspace-frame { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; }

/* ============================================================
   Overlays / modals
   ============================================================ */
.overlay {
    position: fixed; inset: 0; z-index: 500;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,.55); padding: 20px;
}
.overlay.is-visible { display: flex; }
.overlay-box {
    width: 100%; max-width: 440px; padding: 22px;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.overlay-icon { font-size: 30px; color: var(--accent); margin-bottom: 8px; }
.overlay-box h2 { font-size: 16px; margin-bottom: 10px; }
.overlay-box p { color: var(--text-muted); font-size: 12.5px; margin-bottom: 8px; line-height: 1.6; }
.overlay-actions { display: flex; gap: 8px; margin-top: 14px; }

.import-box { max-width: 820px; max-height: 80vh; display: flex; flex-direction: column; padding: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-sub { font-size: 11.5px; color: var(--text-muted); }
.import-search { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.import-search input { flex: 1; }
.import-search select { width: 160px; }
.import-results { flex: 1; overflow-y: auto; min-height: 0; padding: 8px 16px; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); }
.modal-foot-actions { display: flex; gap: 8px; }
.import-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.import-table th { text-align: left; padding: 6px 8px; color: var(--text-muted); font-weight: 600; font-size: 11px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.import-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.import-row { cursor: pointer; }
.import-row:hover { background: var(--panel-2); }
.import-row.selected { background: var(--accent-dim); }
.import-idname, .import-addr, .import-size { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.import-folder { color: var(--text-dim); font-size: 11px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-truncated { color: var(--text-dim); font-size: 11px; padding: 4px 0 8px; }

/* Toasts */
.toast-wrap { position: fixed; bottom: 34px; left: 50%; transform: translateX(-50%); z-index: 600; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
    padding: 9px 16px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: var(--r);
    color: var(--text); font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
    animation: toast-in .18s ease;
}
.toast.err { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Auth pages
   ============================================================ */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 360px; padding: 28px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg); }
.auth-logo { display: flex; align-items: center; gap: 8px; justify-content: center; margin-bottom: 18px; }
.auth-logo .logo-mark { color: var(--accent); font-size: 22px; }
.auth-logo .logo-name { font-size: 18px; font-weight: 600; }
.auth-card h1 { font-size: 18px; margin-bottom: 16px; text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card .field input { height: 34px; }
.auth-card .btn { height: 36px; margin-top: 4px; }
.auth-alt { margin-top: 14px; text-align: center; font-size: 12.5px; color: var(--text-muted); }
.auth-alt a { color: var(--accent); }
.alert { padding: 9px 12px; border-radius: var(--r-sm); font-size: 12.5px; margin-bottom: 12px; }
.alert-error { background: var(--danger-dim); color: var(--danger); border: 1px solid var(--danger); }
.alert-success { background: var(--success-dim); color: var(--success); border: 1px solid var(--success); }

/* ============================================================
   Dashboard (projects)
   ============================================================ */
.dashboard-page { min-height: 100vh; }
.appbar { background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar { display: flex; align-items: center; height: 48px; padding: 0 16px; gap: 12px; }
.topbar-brand a { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.topbar-brand .logo-mark { color: var(--accent); font-size: 17px; }
.topbar-brand .logo-name { font-size: 15px; }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle { width: 30px; height: 30px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--panel-2); cursor: pointer; font-size: 14px; }
.theme-toggle:hover { background: var(--panel-3); }

.dashboard-main { max-width: 1100px; margin: 0 auto; padding: 28px 20px; }
.dashboard-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dashboard-header h1 { font-size: 20px; }
.quota-bar-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.quota-bar-track { flex: 1; height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.quota-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.quota-bar-fill.quota-warn { background: var(--danger); }
.quota-label { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }

.upload-panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px; margin-bottom: 22px; }
.upload-panel h2 { font-size: 15px; margin-bottom: 12px; }
.drop-zone { border: 1.5px dashed var(--border-2); border-radius: var(--r); padding: 28px; text-align: center; color: var(--text-muted); cursor: pointer; transition: border-color .12s, background .12s; }
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); background: var(--accent-dim); }
.upload-form-row { display: flex; flex-direction: column; gap: 4px; margin: 14px 0; }
.upload-form-row label { font-size: 11px; color: var(--text-muted); }
.upload-actions { display: flex; gap: 8px; }
.upload-status-info, .upload-status-ok, .upload-status-error { padding: 8px 12px; border-radius: var(--r-sm); font-size: 12.5px; margin-bottom: 10px; }
.upload-status-info { background: var(--panel-2); color: var(--text-muted); }
.upload-status-ok { background: var(--success-dim); color: var(--success); }
.upload-status-error { background: var(--danger-dim); color: var(--danger); }

.empty-state { padding: 50px; text-align: center; color: var(--text-muted); border: 1px dashed var(--border); border-radius: var(--r-lg); }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 12px; }
.project-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); padding: 14px; transition: border-color .12s; }
.project-card:hover { border-color: var(--border-2); }
.project-card-name { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.project-card-meta { display: flex; gap: 10px; font-size: 11.5px; color: var(--text-muted); font-family: var(--mono); margin-bottom: 4px; }
.project-card-date { font-size: 11px; color: var(--text-dim); margin-bottom: 12px; }
.project-card-actions { display: flex; gap: 8px; }
.project-card-actions .btn { flex: 1; }
