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

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e4e7eb;
    --text: #1a1f2c;
    --text-muted: #6b7380;
    --primary: #2b6cb0;
    --primary-hover: #2354a0;
    --status-draft-bg: #fff4e0;
    --status-draft-fg: #b46a00;
    --status-published-bg: #e3f5e8;
    --status-published-fg: #1b7a3b;
    --status-update-bg: #fde4e4;
    --status-update-fg: #b3261e;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-hover: 0 8px 24px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 14px 32px;
    display: flex;
    align-items: center;
    gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.5px;
}
.brand-name { font-weight: 600; font-size: 16px; }

.topbar-search { flex: 1; max-width: 480px; }
.topbar-search input {
    width: 100%;
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.15s, background 0.15s;
}
.topbar-search input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}

.topbar-user { margin-left: auto; }
.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #d8dde4;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 36px 32px 80px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 28px;
    gap: 16px;
}
.page-header h1 { font-size: 28px; font-weight: 700; }
.subtitle { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s;
    font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn:disabled,
.btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}
.btn:disabled:hover,
.btn[disabled]:hover {
    background: var(--primary);
}
.btn.is-loading {
    cursor: progress;
    opacity: 0.9;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn.is-loading:disabled,
.btn.is-loading[disabled] { opacity: 0.9; }
.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spinner-spin 0.7s linear infinite;
}
@keyframes btn-spinner-spin {
    to { transform: rotate(360deg); }
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.project-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow 0.18s, transform 0.18s, border-color 0.18s;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.project-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: #cfd5dd;
}

.card-thumb {
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.95);
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 1px;
    position: relative;
}
.card-thumb-placeholder { font-size: 13px; opacity: 0.85; font-weight: 500; }

.card-body {
    padding: 16px 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
}
.card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-progress { font-size: 13px; color: var(--text-muted); }

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.status-draft { background: var(--status-draft-bg); color: var(--status-draft-fg); }
.status-published { background: var(--status-published-bg); color: var(--status-published-fg); }
.status-needs-update { background: var(--status-update-bg); color: var(--status-update-fg); }

.card-footer {
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 4px;
}

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

.login-body {
    background: linear-gradient(135deg, #eef2f7 0%, #e3e9f2 100%);
    min-height: 100vh;
}
.login-main {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 36px 32px 28px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}
.login-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
}
.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 24px;
}
.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.field-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.field input[type="text"],
.field input[type="password"] {
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
}
.field input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.12);
}
.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
}
.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    cursor: pointer;
}
.checkbox input { accent-color: var(--primary); }
.link-muted {
    color: var(--text-muted);
    text-decoration: none;
}
.link-muted:hover { color: var(--primary); text-decoration: underline; }
.link-primary {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.link-primary:hover { text-decoration: underline; }
.link-loading {
    opacity: 0.6;
    pointer-events: none;
}
.link-loading::after {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-left: 6px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: bb-spin 0.7s linear infinite;
    vertical-align: -1px;
}
@keyframes bb-spin {
    to { transform: rotate(360deg); }
}
.btn-block {
    width: 100%;
    height: 44px;
    padding: 0;
    margin-top: 4px;
}
.login-footnote {
    text-align: center;
    margin-top: 22px;
    font-size: 13px;
    color: var(--text-muted);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    font-size: 14px;
    color: var(--text-muted);
}
.crumb { color: var(--text-muted); text-decoration: none; }
.crumb:hover { color: var(--primary); }
.crumb-current { color: var(--text); font-weight: 500; }
.crumb-sep { color: #c7ccd4; }

.tagging-main {
    max-width: 920px;
    margin: 0 auto;
    padding: 48px 32px 80px;
}

.upload-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 36px 36px 28px;
    box-shadow: var(--shadow);
}
.upload-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 6px;
}
.upload-title span { color: var(--primary); }
.upload-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 28px;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin-bottom: 22px;
}
@media (max-width: 720px) {
    .upload-grid { grid-template-columns: 1fr; }
}

.dropzone {
    border: 2px dashed #cfd5dd;
    border-radius: 12px;
    background: var(--bg);
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    min-height: 170px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.dropzone:hover {
    border-color: var(--primary);
    background: #eef4fb;
}
.dropzone.dropzone-hover {
    border-color: var(--primary);
    background: #e3edf8;
}
.dropzone.dropzone-loaded {
    border-style: solid;
    border-color: #7fc89a;
    background: #f1faf3;
}
.dropzone-icon {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    color: var(--primary);
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.dropzone-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}
.dropzone-hint {
    font-size: 13px;
    color: var(--text-muted);
}
.link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
}
.link-btn:hover { text-decoration: underline; }

.dropzone-status {
    font-size: 12.5px;
    margin-top: 6px;
    min-height: 18px;
}
.dropzone-status[data-kind="ok"] { color: #1b7a3b; }
.dropzone-status[data-kind="error"] { color: #b3261e; }
.dropzone-status[data-kind="pending"] { color: var(--text-muted); }

.upload-summary {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 20px;
}
.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 14px;
}
.summary-row + .summary-row { border-top: 1px dashed var(--border); }
.summary-label { color: var(--text-muted); }
.summary-label.warn { color: #b46a00; font-weight: 600; }
.summary-value { font-weight: 600; }

.upload-actions { margin-bottom: 14px; }
.upload-help {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

.upload-format-help {
    margin-top: 32px;
    padding: 22px 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.6;
}
.upload-format-help h3 {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 10px;
    font-weight: 600;
}
.upload-format-help p { margin-bottom: 8px; }
.upload-format-help code {
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12.5px;
}
.upload-format-help pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    margin: 10px 0;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12.5px;
    color: var(--text);
    overflow-x: auto;
}

.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 14px 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
    z-index: 500;
    max-width: 90%;
    display: flex;
    align-items: center;
    gap: 14px;
}
.toast-text { line-height: 1.3; }
.toast-action {
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-family: inherit;
    flex-shrink: 0;
    transition: background 0.1s, border-color 0.1s;
}
.toast-action:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}
.toast-info { background: #1f2433; color: #fff; }
.toast-success { background: #1b7a3b; color: #fff; }
.toast-error { background: #b3261e; color: #fff; }

body.canvas-mode { overflow: hidden; }

.canvas-workspace {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: 280px 1fr 270px;
    background: #f0f2f5;
}

.left-sidebar,
.right-sidebar {
    background: var(--surface);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}
.left-sidebar { border-right: 1px solid var(--border); }
.right-sidebar { border-left: 1px solid var(--border); }

.canvas-center {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.sidebar-header {
    padding: 14px 16px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}
.sidebar-count {
    font-size: 12px;
    font-weight: 700;
    background: var(--bg);
    color: var(--text);
    padding: 2px 9px;
    border-radius: 999px;
    min-width: 22px;
    text-align: center;
}
.sidebar-search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-search input {
    width: 100%;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.12s, background 0.12s;
}
.sidebar-search input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}

.plot-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px 12px;
}
.plot-row,
.tagged-row {
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 2px;
    border: 1px solid transparent;
    transition: background 0.1s, border-color 0.1s;
}
.plot-row:hover { background: #eef2f7; }
.plot-row:focus { outline: none; border-color: #c5d8ee; }
.plot-row-active {
    background: #e3edf8 !important;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px rgba(43, 108, 176, 0.18);
}
.plot-row-num,
.tagged-row-num {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.plot-row-meta,
.tagged-row-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.tagged-row {
    background: #f1faf3;
    border-color: #c8e6d2;
    margin-bottom: 4px;
}
.tagged-row:hover {
    background: #e3f5e8;
    border-color: #7fc89a;
}

.sidebar-empty {
    padding: 30px 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
.sidebar-empty p { margin-bottom: 6px; }
.sidebar-empty-hint { font-size: 12px; opacity: 0.8; }

.canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
    flex-shrink: 0;
}
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-spacer { flex: 1; }
.toolbar-progress {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}
.toolbar-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 6px;
}

.tool-btn {
    height: 32px;
    min-width: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, border-color 0.12s;
}
.tool-btn:hover { background: #eef2f7; border-color: #c5cdd6; }
.tool-btn:active { background: #e2e8f0; }
.tool-btn-ghost { border-color: transparent; background: transparent; }
.tool-btn-ghost:hover { background: #eef2f7; border-color: var(--border); }

.tool-btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    padding: 0 14px;
    font-weight: 600;
}
.tool-btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}
.tool-btn-primary:disabled {
    background: #b9c3cf;
    border-color: #b9c3cf;
    color: #fff;
    opacity: 1;
}

.zoom-label {
    font-size: 13px;
    color: var(--text);
    min-width: 50px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    user-select: none;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}

.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.tool-btn:disabled:hover {
    background: var(--surface);
    border-color: var(--border);
}

.save-status {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 6px;
    margin-right: 8px;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.save-status:empty { display: none; }
.save-status-unsaved { color: #b46a00; background: #fff4e0; }
.save-status-saving { color: var(--text-muted); }
.save-status-saved { color: #1b7a3b; background: #e3f5e8; }
.save-status-error { color: #b3261e; background: #fde4e4; }

.canvas-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
      linear-gradient(45deg, #e6e9ee 25%, transparent 25%),
      linear-gradient(-45deg, #e6e9ee 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #e6e9ee 75%),
      linear-gradient(-45deg, transparent 75%, #e6e9ee 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    cursor: default;
}
.canvas-viewport.canvas-pan-mode { cursor: grab; }
.canvas-viewport.canvas-panning { cursor: grabbing; }

.canvas-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    background: var(--surface);
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.12);
    will-change: transform;
}
.canvas-stage > svg { display: block; }

.bb-path {
    fill: #d8dde4 !important;
    stroke: #6b7380 !important;
    stroke-width: 1.5 !important;
    cursor: pointer;
}
.bb-path:not(.bb-path-tagged).bb-path-hover {
    fill: #c5dcf5 !important;
    stroke: #2b6cb0 !important;
    stroke-width: 2 !important;
    stroke-dasharray: 5 4 !important;
}
.canvas-viewport.mode-plot-active { cursor: crosshair; }
.canvas-viewport.mode-plot-active .bb-path:not(.bb-path-tagged).bb-path-hover {
    fill: #b6d3f0 !important;
    stroke: #1d4f8c !important;
    stroke-width: 3 !important;
}

.bb-path-tagged {
    fill: #58b07a !important;
    stroke: #1b7a3b !important;
    stroke-width: 1.2 !important;
    cursor: pointer;
}
.bb-path-tagged.bb-path-hover {
    fill: #4a9d6c !important;
    stroke: #145c2c !important;
}

@keyframes bb-path-flash {
    0%   { fill: #ffe28a !important; stroke: #b46a00 !important; }
    100% { fill: #58b07a !important; stroke: #1b7a3b !important; }
}
.bb-path-flash {
    animation: bb-path-flash 0.8s ease-out;
}

.bb-label {
    fill: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-weight: 700;
    pointer-events: none;
    user-select: none;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, 0.35);
    stroke-width: 2;
}

.active-chip {
    position: fixed;
    z-index: 200;
    background: var(--primary);
    color: #fff;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.25);
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.active-chip-label {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bb-path-selected,
.bb-path-selected:hover {
    fill: #ffe28a !important;
    stroke: #b46a00 !important;
    stroke-width: 3 !important;
    stroke-dasharray: none !important;
}

.path-dropdown {
    position: fixed;
    z-index: 300;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18), 0 2px 6px rgba(15, 23, 42, 0.06);
    width: 280px;
    max-height: 380px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.path-dropdown[hidden] { display: none; }

.path-dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
}
.path-dropdown-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    transition: background 0.1s, color 0.1s;
}
.path-dropdown-close:hover {
    color: var(--text);
    background: rgba(15, 23, 42, 0.06);
}

.path-dropdown-search {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.path-dropdown-search input {
    width: 100%;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
}
.path-dropdown-search input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.12);
}

.path-dropdown-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 6px 8px;
}
.path-dropdown-item {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 1px;
    transition: background 0.08s;
}
.path-dropdown-item:hover,
.path-dropdown-item-active {
    background: #e3edf8;
}
.dropdown-item-num {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.dropdown-item-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.path-dropdown-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.context-menu {
    position: fixed;
    z-index: 310;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 32px rgba(15, 23, 42, 0.18), 0 2px 6px rgba(15, 23, 42, 0.06);
    padding: 4px;
    min-width: 180px;
    display: flex;
    flex-direction: column;
}
.context-menu-item {
    background: none;
    border: none;
    padding: 8px 14px;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    border-radius: 5px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.08s, color 0.08s;
}
.context-menu-item:hover { background: #eef2f7; }
.context-menu-icon {
    width: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    flex-shrink: 0;
}
.context-menu-item:hover .context-menu-icon { color: var(--text); }
.context-menu-danger { color: #b3261e; }
.context-menu-danger:hover { background: #fde4e4; color: #8c1c14; }
.context-menu-danger .context-menu-icon,
.context-menu-danger:hover .context-menu-icon { color: #b3261e; }
.context-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 6px;
}

.conflicts-panel {
    border-bottom: 1px solid var(--border);
    background: #fff8f1;
    flex-shrink: 0;
}
.conflicts-header {
    padding: 10px 16px 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.conflicts-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #b46a00;
}
.conflicts-count {
    font-size: 11px;
    font-weight: 700;
    background: #fde4e4;
    color: #b3261e;
    padding: 2px 8px;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
}
.conflicts-list {
    padding: 4px 8px 12px;
    max-height: 240px;
    overflow-y: auto;
}
.conflict-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 2px;
    border: 1px solid transparent;
    transition: background 0.1s, border-color 0.1s;
}
.conflict-item:hover {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(180, 106, 0, 0.2);
}
.conflict-icon {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: #fff;
}
.conflict-duplicate .conflict-icon { background: #b3261e; }
.conflict-stranger .conflict-icon { background: #b46a00; }
.conflict-body { flex: 1; min-width: 0; }
.conflict-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conflict-meta {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 1px;
}

.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: bb-fade-in 0.15s ease-out;
}
@keyframes bb-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25), 0 6px 12px rgba(15, 23, 42, 0.08);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 18px 22px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 {
    font-size: 17px;
    font-weight: 700;
    margin: 0;
}
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 28px;
    height: 28px;
    border-radius: 5px;
    transition: background 0.1s, color 0.1s;
}
.modal-close:hover {
    color: var(--text);
    background: rgba(15, 23, 42, 0.06);
}
.modal-body { padding: 18px 22px; }
.modal-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.55;
}
.modal-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}
.modal-field-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.modal-field select {
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
}
.modal-field select:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.12);
}
.modal-preview {
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    margin-top: 4px;
}
.preview-main { color: var(--text); line-height: 1.5; }
.preview-main.muted { color: var(--text-muted); }
.preview-warn {
    color: #b46a00;
    margin-top: 8px;
    font-size: 12.5px;
}
.modal-footer {
    padding: 14px 22px 18px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border);
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 6px;
}

.project-header {
    display: flex;
    align-items: center;
    gap: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 26px;
    margin-bottom: 32px;
    box-shadow: var(--shadow);
}
.project-header-thumb {
    width: 72px;
    height: 72px;
    border-radius: 14px;
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.project-header-info { flex: 1; min-width: 0; }
.project-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.2;
}
.project-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}
.project-meta-sep { opacity: 0.5; }
.project-header-actions { flex-shrink: 0; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}
.section-title {
    font-size: 20px;
    font-weight: 700;
}
.section-count {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 8px;
}

.siteplans-list { display: flex; flex-direction: column; gap: 12px; }

.siteplan-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
    box-shadow: var(--shadow);
}
.siteplan-row:hover {
    box-shadow: var(--shadow-hover);
    border-color: #cfd5dd;
    transform: translateY(-1px);
}
.siteplan-main {
    flex: 1;
    min-width: 0;
}
.siteplan-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
}
.siteplan-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}
.siteplan-meta-sep { opacity: 0.5; }
.siteplan-bar {
    margin-top: 10px;
    height: 4px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    max-width: 320px;
}
.siteplan-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #58b07a 0%, #2b6cb0 100%);
    border-radius: 999px;
    transition: width 0.25s ease;
}
.siteplan-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.siteplans-empty {
    text-align: center;
    padding: 56px 24px;
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: 14px;
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}
.empty-desc {
    color: var(--text-muted);
    margin-bottom: 22px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.55;
    font-size: 14px;
}

.modal-error {
    background: #fde4e4;
    color: #8c1c14;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    margin-top: 4px;
}
.modal-field input[type="text"] {
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.modal-field input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.12);
}

.status-ready {
    background: #e3edf8;
    color: #1d4f8c;
}

.canvas-workspace.canvas-workspace-preview {
    grid-template-columns: 1fr;
}
.canvas-viewport-preview {
    background:
      linear-gradient(45deg, #e6e9ee 25%, transparent 25%),
      linear-gradient(-45deg, #e6e9ee 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #e6e9ee 75%),
      linear-gradient(-45deg, transparent 75%, #e6e9ee 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.bb-plot {
    fill: #d8dde4 !important;
    stroke: #6b7380 !important;
    stroke-width: 1 !important;
    stroke-dasharray: none !important;
    cursor: pointer;
    transition: filter 0.12s, stroke-width 0.12s;
}
.bb-plot-background { pointer-events: none; }

.bb-plot--available { fill: #34a853 !important; stroke: #1e7a3c !important; }
.bb-plot--held      { fill: #f59e0b !important; stroke: #b46a00 !important; }
.bb-plot--booked    { fill: #2b6cb0 !important; stroke: #1d4f8c !important; }
.bb-plot--sold      { fill: #6b7380 !important; stroke: #444a55 !important; }

.bb-plot:hover {
    filter: brightness(1.12);
    stroke-width: 2.5 !important;
}

@keyframes bb-plot-flash {
    0%   { filter: brightness(1.8) saturate(1.5); }
    100% { filter: brightness(1); }
}
.bb-plot-flash { animation: bb-plot-flash 0.8s ease-out; }

.refresh-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 6px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.status-legend {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    padding: 10px 14px 12px;
    z-index: 200;
    min-width: 210px;
}
.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.legend-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}
.legend-action {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 5px;
    line-height: 1;
}
.legend-action:hover { background: var(--bg); color: var(--text); }
.legend-items { display: flex; flex-direction: column; gap: 2px; }
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 4px;
    font-size: 13px;
    line-height: 1;
}
.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.legend-item--available .legend-swatch { background: #34a853; }
.legend-item--held .legend-swatch      { background: #f59e0b; }
.legend-item--booked .legend-swatch    { background: #2b6cb0; }
.legend-item--sold .legend-swatch      { background: #6b7380; }
.legend-name { flex: 1; color: var(--text); }
.legend-count {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    min-width: 24px;
    text-align: right;
}

.checklist-card {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    z-index: 200;
    min-width: 250px;
    max-width: 380px;
    overflow: hidden;
}
.checklist-summary {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    user-select: none;
}
.checklist-summary:hover { background: var(--bg); }
.checklist-summary:focus { outline: none; background: var(--bg); }
.checklist-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #fff;
    flex-shrink: 0;
}
.checklist-summary--ok .checklist-icon { background: #34a853; }
.checklist-summary--warn .checklist-icon { background: #f59e0b; }
.checklist-label { flex: 1; }
.checklist-toggle {
    color: var(--text-muted);
    font-size: 10px;
}
.checklist-body {
    padding: 10px 14px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.check-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 12.5px;
    color: var(--text);
    line-height: 1.4;
}
.check-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #fff;
    margin-top: 1px;
}
.check-ok .check-icon { background: #34a853; }
.check-warn .check-icon { background: #f59e0b; }
.check-info .check-icon { background: #6b7380; }

.plot-tooltip {
    position: fixed;
    z-index: 250;
    background: #1f2433;
    color: #fff;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.3);
    pointer-events: none;
    min-width: 180px;
    max-width: 280px;
}
.tt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}
.tt-num { font-size: 15px; font-weight: 700; }
.tt-fields {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
}
.tt-field {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}
.tt-key { color: rgba(255, 255, 255, 0.55); }
.tt-val { color: #fff; font-weight: 500; }
.plot-tooltip .status-badge {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.status-available { background: rgba(52, 168, 83, 0.15); color: #1e7a3c; }
.status-held      { background: rgba(245, 158, 11, 0.18); color: #b46a00; }
.status-booked    { background: rgba(43, 108, 176, 0.15); color: #1d4f8c; }
.status-sold      { background: rgba(107, 115, 128, 0.18); color: #444a55; }

.modal-details {
    max-width: 460px;
}
.modal-details .modal-header { align-items: flex-start; }
.details-header-text { flex: 1; min-width: 0; }
.modal-subtitle {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 3px;
}
.details-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}
.details-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 6px;
    font-size: 13.5px;
}
.details-row dt { color: var(--text-muted); font-weight: 500; }
.details-row dd { font-weight: 600; color: var(--text); }

.publish-main {
    max-width: 760px;
}
.publish-hero {
    text-align: center;
    padding: 36px 20px 32px;
    margin-bottom: 8px;
}
.publish-icon {
    font-size: 52px;
    margin-bottom: 10px;
    line-height: 1;
}
.publish-title {
    font-size: 30px;
    font-weight: 800;
    margin-bottom: 8px;
    letter-spacing: -0.2px;
}
.publish-subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 16px;
    line-height: 1.5;
}
.publish-meta {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-muted);
    flex-wrap: wrap;
    justify-content: center;
}
.publish-meta-sep { opacity: 0.5; }

.publish-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.publish-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.publish-card-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
    line-height: 1.3;
}
.publish-card-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.55;
    margin: 0;
}

.code-block {
    background: #1f2433;
    color: #e8e9ea;
    border-radius: 8px;
    padding: 14px 16px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
    margin: 0 0 14px;
    border: 1px solid #2a3142;
}
.code-block-inline {
    padding: 10px 14px;
    margin-bottom: 0;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow-x: auto;
}

.publish-link-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 18px;
}
.publish-link-row .btn { flex-shrink: 0; }

.publish-qr {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 14px 18px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}
.publish-qr img {
    width: 140px;
    height: 140px;
    border-radius: 6px;
    background: #fff;
    padding: 6px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}
.publish-qr-body { flex: 1; min-width: 0; }
.publish-qr-hint {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0;
}

.publish-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 28px;
    gap: 12px;
    padding-bottom: 24px;
}

.trace-workspace {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: 340px 1fr;
    background: #f0f2f5;
}
.trace-panel {
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 20px 22px 32px;
}
.trace-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin: 22px 0 10px;
}
.trace-section-title:first-child { margin-top: 0; }

.preset-list { display: flex; flex-direction: column; gap: 8px; }
.preset-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}
.preset-item:hover { background: var(--bg); }
.preset-item:has(input:checked) {
    border-color: var(--primary);
    background: #eef4fb;
}
.preset-item input { margin-top: 3px; accent-color: var(--primary); }
.preset-body { display: flex; flex-direction: column; gap: 3px; }
.preset-name { font-size: 14px; font-weight: 600; color: var(--text); }
.preset-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.custom-params {
    margin-top: 14px;
    padding: 14px;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.param-row { display: flex; flex-direction: column; gap: 6px; }
.param-label {
    font-size: 12.5px;
    color: var(--text);
    display: flex;
    justify-content: space-between;
}
.param-label em {
    font-style: normal;
    font-weight: 700;
    color: var(--primary);
}
.param-row input[type="range"] { width: 100%; accent-color: var(--primary); }

.btn-block { width: 100%; }
#runTraceBtn { margin-top: 22px; }
.trace-wasm-status {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}
.trace-wasm-status.is-ready { color: #1b7a3b; }
.trace-wasm-status.is-error { color: #b3261e; }

.trace-result {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.trace-result-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.toggle-group {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
}
.toggle-btn {
    border: none;
    background: var(--surface);
    color: var(--text-muted);
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.toggle-btn + .toggle-btn { border-left: 1px solid var(--border); }
.toggle-btn.is-active { background: var(--primary); color: #fff; }
.trace-metrics {
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.trace-stage {
    flex: 1;
    position: relative;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
      linear-gradient(45deg, #e6e9ee 25%, transparent 25%),
      linear-gradient(-45deg, #e6e9ee 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #e6e9ee 75%),
      linear-gradient(-45deg, transparent 75%, #e6e9ee 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    padding: 24px;
}
.trace-empty {
    text-align: center;
    color: var(--text-muted);
    max-width: 320px;
}
.trace-empty-icon { font-size: 44px; margin-bottom: 12px; }
.trace-empty p { font-size: 14px; line-height: 1.5; }

.trace-progress {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 24px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    z-index: 5;
    min-width: 260px;
    text-align: center;
}
.trace-progress-label {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}
.trace-progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
}
.trace-progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #58b07a, #2b6cb0);
    border-radius: 999px;
    transition: width 0.15s ease;
}

.trace-canvas-wrap {
    background: #fff;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.12);
}
.trace-canvas-wrap canvas,
.trace-canvas-wrap svg {
    display: block;
    max-width: calc(100vw - 340px - 80px);
    max-height: calc(100vh - 60px - 53px - 60px);
    width: auto;
    height: auto;
}

.mode-toggle { margin-bottom: 22px; }
.toggle-group-block { display: flex; width: 100%; }
.toggle-group-block .toggle-btn { flex: 1; padding: 9px 8px; }
.mode-hint {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.trace-svg-preview {
    background: #fff;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.12);
    max-width: calc(100vw - 340px - 80px);
    max-height: calc(100vh - 60px - 53px - 60px);
    overflow: auto;
}
.trace-svg-preview svg {
    display: block;
    width: auto;
    height: auto;
    max-width: calc(100vw - 340px - 80px);
    max-height: calc(100vh - 60px - 53px - 60px);
}

.tagging-mobile-block {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg);
    z-index: 1000;
    padding: 32px;
    align-items: center;
    justify-content: center;
    text-align: center;
}
@media (max-width: 1023px) {
    .tagging-mobile-block { display: flex; }
}
.mobile-block-content { max-width: 380px; }
.mobile-block-emoji { font-size: 48px; margin-bottom: 14px; }
.mobile-block-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}
.mobile-block-text {
    color: var(--text-muted);
    margin-bottom: 22px;
    line-height: 1.55;
    font-size: 14px;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.loading-overlay[hidden] { display: none; }
.loading-overlay-content { text-align: center; }
.loading-overlay-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #d8dde4;
    border-top-color: #2b6cb0;
    border-radius: 50%;
    margin: 0 auto;
    animation: loading-overlay-spin 0.8s linear infinite;
}
.loading-overlay-text {
    font-size: 15px;
    color: #2c3242;
    margin-top: 14px;
}
.loading-overlay-hint {
    font-size: 12px;
    color: #6b7380;
    margin-top: 6px;
}
@keyframes loading-overlay-spin {
    to { transform: rotate(360deg); }
}


/* ---------- Phase 10: migration banner ---------- */
.migration-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 20px;
    background: #fff8e1;
    border: 1px solid #f7d774;
    border-radius: 8px;
    color: #5a4400;
    font-size: 14px;
}
.migration-banner .migration-progress {
    flex: 1;
    color: #6b5800;
    font-size: 13px;
}

/* ---------- Phase 4: login page ---------- */
.login-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f6f8;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    padding: 20px;
}
.login-card {
    background: #ffffff;
    padding: 36px 40px;
    border-radius: 12px;
    box-shadow: 0 2px 20px rgba(15, 23, 42, 0.08);
    width: 100%;
    max-width: 380px;
    box-sizing: border-box;
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}
.login-title {
    margin: 0 0 24px;
    font-size: 22px;
    color: #111;
}
.login-field {
    display: block;
    margin-bottom: 16px;
}
.login-label {
    display: block;
    font-size: 13px;
    color: #444;
    margin-bottom: 6px;
}
.login-field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d4d8df;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
    background: #fff;
}
.login-field input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.login-error {
    background: #fef0f0;
    border: 1px solid #f5c6c6;
    color: #a02020;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 14px;
    font-size: 13px;
}
.login-submit {
    width: 100%;
    padding: 11px;
    font-size: 14px;
}

/* avatar becomes clickable on every admin page */
.topbar-user.is-clickable { cursor: pointer; }
.topbar-user.is-clickable:hover .user-avatar {
    transform: scale(1.05);
    transition: transform 80ms ease-out;
}
