:root {
    --bg:         #0a0a0f;
    --surface:    #11111a;
    --surface2:   #18182a;
    --border:     #1e1e30;
    --text:       #d8d8f0;
    --muted:      #5a5a80;
    --blue:       #4d9fff;
    --orange:     #ff8c42;
    --green:      #4dff91;
    --yellow:     #ffd700;
    --purple:     #b47eff;
    --red:        #ff4d4d;
    --red-bg:     rgba(255, 77, 77, 0.08);
    --yellow-bg:  rgba(255, 215, 0, 0.07);
    --green-bg:   rgba(77, 255, 145, 0.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

header h1 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--blue);
}

header span {
    font-size: 12px;
    color: var(--muted);
}

.app-header > div {
    display: flex;
    align-items: baseline;
    gap: 14px;
}

.app-header nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-header nav a,
.app-header nav button {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    text-decoration: none;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.app-header nav a:hover,
.app-header nav button:hover,
.app-header nav a.active {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface2);
}

.app-header nav form { display: inline-flex; }

/* ── Map workspace ───────────────────────────────────────── */
.workspace {
    width: min(1800px, 100%);
    margin: 0 auto;
    padding: 24px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.panel-heading,
.map-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.panel-heading h2,
.map-titlebar h2 {
    font-size: 17px;
    line-height: 1.3;
}

.map-titlebar h2 small {
    margin-left: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
}

.eyebrow {
    margin-bottom: 3px;
    color: var(--blue);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 15px;
    border: 1px solid #2e2e48;
    border-radius: 6px;
    background: var(--surface2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.button:hover:not(:disabled) {
    border-color: var(--muted);
    background: #20203a;
}

.button-primary {
    border-color: var(--blue);
    background: var(--blue);
    color: #07101c;
}

.button-primary:hover { filter: brightness(1.08); }

.bin-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bin-actions select {
    width: min(360px, 36vw);
}

.empty-state {
    padding: 28px 18px;
    color: var(--muted);
    text-align: center;
}

.bin-details,
.metadata-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1px;
    background: var(--border);
}

.bin-details > div,
.metadata-grid > div {
    min-width: 0;
    padding: 12px 16px;
    background: var(--surface);
}

.bin-details span,
.metadata-grid span {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.bin-details strong,
.metadata-grid strong {
    display: block;
    overflow: hidden;
    font-size: 12px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hash-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 10px !important;
}

.project-bar {
    display: grid;
    grid-template-columns: minmax(260px, 420px) minmax(240px, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: rgba(77, 159, 255, 0.025);
}

.project-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.project-selector > span {
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.project-summary {
    color: var(--muted);
    font-size: 11px;
}

.project-actions,
.editor-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.map-layout {
    display: grid;
    grid-template-columns: 350px minmax(0, 1fr);
    gap: 18px;
    margin-top: 18px;
    min-height: 680px;
}

.map-sidebar,
.map-viewer {
    min-width: 0;
    overflow: hidden;
}

.map-sidebar {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 225px);
}

.map-list-heading { flex: 0 0 auto; }

.count-badge,
.status-badge {
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 11px;
}

.map-filters {
    display: grid;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.map-scope-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--bg);
}

.map-scope-tabs button {
    min-height: 30px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
}

.map-scope-tabs button.active {
    background: var(--surface2);
    color: var(--text);
}

.map-scope-tabs span {
    margin-left: 3px;
    color: var(--blue);
}

input,
select {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

input:focus,
select:focus { border-color: var(--blue); }

.map-list {
    flex: 1 1 auto;
    min-height: 200px;
    overflow-y: auto;
}

.map-list-item {
    display: flex;
    width: 100%;
    align-items: stretch;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
}

.map-list-item:hover { background: rgba(77, 159, 255, 0.05); }
.map-list-item.selected {
    border-left: 3px solid var(--blue);
    background: rgba(77, 159, 255, 0.09);
}

.map-open-button {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 3px;
    padding: 11px 8px 11px 13px;
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.map-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.map-item-top strong { font-size: 12px; }
.map-item-top code,
.scalar-value code {
    color: var(--blue);
    font-size: 10px;
}

.map-item-name {
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-item-original {
    overflow: hidden;
    color: #444460;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-item-meta {
    color: #42425f;
    font-size: 10px;
}

.favorite-button {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}

.favorite-button:hover,
.favorite-button.active {
    border-color: rgba(255, 215, 0, 0.5);
    color: var(--yellow);
}

.map-item-favorite {
    width: 38px;
    flex: 0 0 38px;
    margin: 9px 9px 9px 0;
    border-color: transparent;
    font-size: 19px;
}

.map-title-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.favorite-button-large {
    min-height: 31px;
    padding: 0 10px;
    font-size: 11px;
}

.map-original-name {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.list-empty {
    padding: 28px 16px;
    color: var(--muted);
    text-align: center;
}

.pagination {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 10px;
}

.pagination button {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.pagination button:disabled { cursor: default; opacity: 0.35; }

.viewer-placeholder {
    display: grid;
    min-height: 300px;
    place-items: center;
}

.metadata-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    border-bottom: 1px solid var(--border);
}

.inline-warning {
    margin: 14px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 6px;
    background: var(--yellow-bg);
    color: var(--yellow);
    font-size: 12px;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(77, 159, 255, 0.025);
}

.editor-toolbar strong {
    display: block;
    margin-bottom: 2px;
    font-size: 12px;
}

.editor-toolbar span {
    color: var(--muted);
    font-size: 11px;
}

.editor-toolbar .button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 11px;
}

.button:disabled {
    cursor: default;
    filter: none;
    opacity: 0.35;
}

.map-table-wrap {
    max-width: 100%;
    padding: 16px;
    overflow: auto;
}

.map-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
}

.map-table th,
.map-table td {
    min-width: 74px;
    padding: 7px 9px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
}

.map-table thead th {
    position: sticky;
    z-index: 2;
    top: 0;
    background: var(--surface2);
    color: var(--orange);
}

.map-table tbody th {
    position: sticky;
    z-index: 1;
    left: 0;
    background: var(--surface2);
    color: var(--orange);
}

.map-table .axis-corner {
    z-index: 3;
    left: 0;
    max-width: 180px;
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
}

.map-table td { color: #c9d8ed; }
.map-table tbody tr:hover td { background: rgba(77, 159, 255, 0.05); }

.map-table td.modified-cell {
    background: rgba(255, 140, 66, 0.08);
}

.map-table td.pending-cell {
    background: rgba(255, 215, 0, 0.1);
}

.map-cell-button,
.scalar-edit-button {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: right;
    cursor: pointer;
}

.map-cell-button.modified .cell-value {
    color: var(--orange);
}

.map-cell-button.pending .cell-value,
.scalar-edit-button.pending .cell-value {
    color: var(--yellow);
}

/* When showing stock values, all cells look the same — no color distinction */
.map-table-wrap.showing-stock .map-cell-button .cell-value {
    color: #c9d8ed;
}

.button.active {
    background: rgba(77, 159, 255, 0.15);
    border-color: var(--blue);
    color: var(--blue);
}

.map-cell-input {
    min-width: 82px;
    height: 30px;
    min-height: 30px;
    padding: 3px 5px;
    border-color: var(--yellow);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    text-align: right;
}

.scalar-value {
    display: flex;
    min-height: 260px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.scalar-value strong {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: clamp(40px, 8vw, 84px);
    letter-spacing: -0.06em;
}

.scalar-value span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 14px;
}

.scalar-value code { margin-top: 12px; }

.scalar-edit-button {
    width: auto;
    color: var(--text);
    text-align: center;
}

.scalar-edit-button strong {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: clamp(40px, 8vw, 84px);
    letter-spacing: -0.06em;
}

.project-dialog {
    width: min(480px, calc(100% - 32px));
    margin: auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
}

.project-dialog::backdrop {
    background: rgba(5, 5, 10, 0.78);
}

.project-dialog form {
    display: grid;
    gap: 18px;
    padding: 24px;
}

.project-dialog h2 {
    margin-bottom: 6px;
    font-size: 20px;
}

.project-dialog p,
.dialog-warning {
    color: var(--muted);
    font-size: 12px;
}

.project-dialog label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
}

.dialog-warning {
    padding: 10px 12px;
    border: 1px solid rgba(255, 215, 0, 0.25);
    border-radius: 6px;
    background: var(--yellow-bg);
    color: var(--yellow);
}

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

.page-error {
    margin: 0 0 16px !important;
}

/* ── Login ───────────────────────────────────────────────── */
.login-body {
    display: grid;
    padding: 24px;
    place-items: center;
}

.login-card {
    width: min(410px, 100%);
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.login-card h1 {
    margin-bottom: 6px;
    color: var(--text);
    font-size: 26px;
}

.login-copy {
    margin-bottom: 24px;
    color: var(--muted);
}

.login-card form {
    display: grid;
    gap: 16px;
}

.login-card label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.login-error {
    margin-bottom: 18px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 77, 77, 0.3);
    border-radius: 6px;
    background: var(--red-bg);
    color: var(--red);
    font-size: 12px;
}

@media (max-width: 900px) {
    .app-header { align-items: flex-start; gap: 12px; }
    .app-header,
    .app-header > div { flex-direction: column; }
    .workspace { padding: 14px; }
    .panel-heading { align-items: flex-start; }
    .map-titlebar { align-items: flex-start; flex-direction: column; }
    .project-bar { grid-template-columns: 1fr; }
    .project-actions { justify-content: flex-start; }
    .editor-toolbar { align-items: flex-start; flex-direction: column; }
    .bin-actions { width: 100%; flex-direction: column; align-items: stretch; }
    .bin-actions select { width: 100%; }
    .bin-details,
    .metadata-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .map-layout { grid-template-columns: 1fr; }
    .map-sidebar { max-height: 600px; }
    .viewer-placeholder { min-height: 300px; }
}

/* ── Drop zone ───────────────────────────────────────────── */
#dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 60px auto;
    max-width: 480px;
    height: 220px;
    border: 2px dashed var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    color: var(--muted);
}

#dropzone:hover,
#dropzone.dragover {
    border-color: var(--blue);
    background: rgba(77, 159, 255, 0.04);
    color: var(--text);
}

#dropzone svg { opacity: 0.4; }
#dropzone:hover svg { opacity: 0.8; }

#dropzone p { font-size: 15px; }
#dropzone small { font-size: 12px; }

/* ── Dashboard ───────────────────────────────────────────── */
#dashboard { display: none; padding: 0 24px 48px; }

/* file info bar */
#fileInfo {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.file-name {
    font-weight: 600;
    color: var(--text);
    overflow-wrap: anywhere;
}

.file-stat {
    font-size: 12px;
    color: var(--muted);
    background: var(--surface2);
    padding: 3px 8px;
    border-radius: 4px;
}

#newFileBtn {
    margin-left: auto;
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: border-color 0.2s, color 0.2s;
}
#newFileBtn:hover { border-color: var(--blue); color: var(--blue); }

/* ── Alerts ──────────────────────────────────────────────── */
#alertsContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px 0 8px;
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid;
    flex: 1 1 280px;
    min-width: 240px;
}

.alert-danger  { background: var(--red-bg);    border-color: rgba(255,77,77,0.3);    }
.alert-warning { background: var(--yellow-bg); border-color: rgba(255,215,0,0.3);   }
.alert-ok      { background: var(--green-bg);  border-color: rgba(77,255,145,0.3);  }

.alert-icon {
    font-size: 18px;
    line-height: 1;
    margin-top: 1px;
}

.alert-danger  .alert-icon { color: var(--red);    }
.alert-warning .alert-icon { color: var(--yellow); }
.alert-ok      .alert-icon { color: var(--green);  }

.alert-title   { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.alert-message { font-size: 12px; color: var(--muted); }

/* ── Stats ───────────────────────────────────────────────── */
#statsContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 0;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 18px;
    min-width: 100px;
    text-align: center;
    flex: 1 1 100px;
}

.stat-card.stat-highlight {
    border-color: rgba(255, 77, 77, 0.4);
    background: var(--red-bg);
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 2px;
}

/* ── Chart sections ──────────────────────────────────────── */
.chart-section {
    display: none;
    margin-top: 28px;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.chart-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}

.reset-zoom {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 3px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: border-color 0.2s, color 0.2s;
}
.reset-zoom:hover { border-color: var(--blue); color: var(--blue); }

.chart-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    height: 280px;
    position: relative;
}

.chart-hint {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 10px;
    color: var(--muted);
    opacity: 0.6;
    pointer-events: none;
}

/* ── Channel explorer ────────────────────────────────────── */
#explorerSection {
    display: none;
    margin-top: 28px;
}

#channelCheckboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 0 16px;
}

.channel-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 12px;
    transition: border-color 0.2s;
    user-select: none;
    overflow-wrap: anywhere;
}

.channel-checkbox:hover { border-color: var(--blue); }

.channel-checkbox input[type="checkbox"] {
    accent-color: var(--blue);
    cursor: pointer;
}

.channel-checkbox em {
    color: var(--muted);
    font-style: normal;
    font-size: 11px;
}

/* ── Loading / error ─────────────────────────────────────── */
#loadingOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.8);
    align-items: center;
    justify-content: center;
    z-index: 100;
    flex-direction: column;
    gap: 14px;
    color: var(--muted);
    font-size: 13px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

#errorMsg {
    display: none;
    margin: 16px 24px;
    padding: 12px 16px;
    background: var(--red-bg);
    border: 1px solid rgba(255, 77, 77, 0.3);
    border-radius: 8px;
    color: var(--red);
    font-size: 13px;
}
