/* ── Base ──────────────────────────────────────────────────────────────────── */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2e3348;
    --text: #e4e6f0;
    --text-dim: #8b8fa8;
    --accent: #4f8cff;
    --accent-hover: #3a7aff;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --radius: 8px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

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

header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header .subtitle {
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    height: calc(100vh - 52px);
    position: relative;
}
.app-layout.sidebar-collapsed {
    grid-template-columns: 0px 1fr;
}

/* ── Sidebar toggle ──────────────────────────────────────────────────────── */
.sidebar-toggle {
    position: absolute;
    left: 340px;
    top: 8px;
    z-index: 20;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-dim);
    font-size: 16px;
    padding: 4px 6px;
    cursor: pointer;
    line-height: 1;
    transition: left 0.2s, background 0.15s;
}
.sidebar-toggle:hover {
    background: var(--accent);
    color: #fff;
}
.app-layout.sidebar-collapsed .sidebar-toggle {
    left: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: padding 0.2s, opacity 0.2s;
    min-width: 0;
}
.app-layout.sidebar-collapsed .sidebar {
    padding: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.sidebar h2 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-bottom: 4px;
}

/* ── Prompt area ──────────────────────────────────────────────────────────── */
.prompt-box {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.prompt-box textarea {
    width: 100%;
    min-height: 100px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
    font-family: inherit;
}

.prompt-box textarea::placeholder {
    color: var(--text-dim);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-sm { padding: 6px 10px; font-size: 0.8rem; }

.btn-success { background: var(--success); color: #000; }
.btn-danger { background: var(--danger); color: #fff; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-group {
    display: flex;
    gap: 8px;
}

/* ── Example cards ────────────────────────────────────────────────────────── */
.example-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.example-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.example-card:hover {
    border-color: var(--accent);
    background: rgba(79, 140, 255, 0.08);
}
.example-card .ec-name {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 2px;
}
.example-card .ec-desc {
    font-size: 0.75rem;
    color: var(--text-dim);
}
.example-card .ec-cat {
    display: inline-block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
    font-weight: 600;
}
.cat-beam { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.cat-frame { background: rgba(79, 140, 255, 0.15); color: var(--accent); }
.cat-truss { background: rgba(251, 191, 36, 0.15); color: var(--warning); }

/* ── Main area ────────────────────────────────────────────────────────────── */
.main-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-left: 36px;
}
.tab {
    padding: 10px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}
.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.tab:hover { color: var(--text); }

/* ── Tab panels ───────────────────────────────────────────────────────────── */
.tab-panel {
    display: none;
    flex: 1;
    overflow: auto;
}
.tab-panel.active {
    display: flex;
    flex-direction: column;
}
#tab-connections.active {
    overflow: hidden; /* conn-layout handles its own overflow */
}

/* ── Canvas editor ────────────────────────────────────────────────────────── */
#editor-panel {
    position: relative;
    flex: 1;
    overflow: hidden;
}

#structureCanvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

.editor-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    display: flex;
    gap: 6px;
    z-index: 10;
}

.editor-info {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(26, 29, 39, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.75rem;
    color: var(--text-dim);
    z-index: 10;
}

/* ── Plot panel ───────────────────────────────────────────────────────────── */
#plot-panel {
    position: relative;
    flex: 1;
    overflow: hidden;
}

#plotCanvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.plot-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    display: flex;
    gap: 6px;
    z-index: 10;
}

.plot-btn {
    background: var(--surface2) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}
.plot-btn.active {
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}

.plot-info {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(26, 29, 39, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.75rem;
    color: var(--text-dim);
    z-index: 10;
}

.scale-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-weight: 600;
}

.scale-slider {
    width: 100px;
    accent-color: var(--accent);
    cursor: pointer;
}

.plot-toggle {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
}
.plot-toggle input {
    accent-color: var(--accent);
    cursor: pointer;
}

/* ── Data panel ───────────────────────────────────────────────────────────── */
#data-panel {
    padding: 16px;
}

.data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.data-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.data-section h3 {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.data-table th,
.data-table td {
    padding: 4px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    color: var(--text-dim);
    font-weight: 600;
}

/* ── Params panel ─────────────────────────────────────────────────────────── */
#params-panel {
    padding: 16px;
}


/* ── Status bar ───────────────────────────────────────────────────────────── */
.status-bar {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 16px;
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}
.status-indicator.loading {
    background: var(--warning);
    animation: pulse 1s infinite;
}
.status-indicator.error {
    background: var(--danger);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Utilization colors ───────────────────────────────────────────────────── */
.util-ok { color: var(--success); }
.util-warn { color: var(--warning); }
.util-fail { color: var(--danger); }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Loading overlay ──────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 23, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    display: none;
}
.loading-overlay.active { display: flex; }

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

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

/* ── Tool options popup ───────────────────────────────────────────────────── */
.tool-options {
    position: absolute;
    top: 42px;
    left: 8px;
    background: rgba(26, 29, 39, 0.95);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    z-index: 15;
    min-width: 220px;
    max-width: 320px;
}
.tool-options label {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
}
.tool-options .to-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.tool-options .to-row input,
.tool-options .to-row select {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
}
.tool-options .to-row input { width: 80px; }
.tool-options .to-row select { width: 140px; }

/* ── Properties panel ─────────────────────────────────────────────────────── */
.properties-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 260px;
    background: rgba(26, 29, 39, 0.95);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    z-index: 10;
    display: none;
}
.properties-panel.visible { display: block; }

.properties-panel h3 {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 8px;
}

.prop-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.8rem;
}

.prop-row label { color: var(--text-dim); }

.prop-row input {
    width: 80px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    padding: 4px 6px;
    font-size: 0.8rem;
    text-align: right;
    font-family: inherit;
    outline: none;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 0.85rem;
    animation: slideIn 0.3s ease;
    max-width: 350px;
}
.toast.toast-error { border-color: var(--danger); }
.toast.toast-success { border-color: var(--success); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Code panel ──────────────────────────────────────────────────────────── */
#code-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.code-toolbar {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.code-hint {
    font-size: 0.72rem;
    color: var(--text-dim);
}

.code-editor {
    flex: 1;
    background: #12141c;
    color: #c9d1d9;
    border: none;
    padding: 16px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    tab-size: 4;
    overflow: auto;
}

/* ── Export panel ─────────────────────────────────────────────────────────── */
#export-panel {
    padding: 24px;
}

.export-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.export-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.15s;
}
.export-card:hover {
    border-color: var(--accent);
    background: rgba(79, 140, 255, 0.08);
}

.export-icon {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 2px;
    font-family: 'JetBrains Mono', monospace;
}

.export-name {
    font-weight: 600;
    font-size: 0.78rem;
}

.export-desc {
    font-size: 0.68rem;
    color: var(--text-dim);
}

.export-section-title {
    color: var(--accent);
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.export-settings-card {
    border-style: dashed;
    opacity: 0.7;
}
.export-settings-card:hover {
    opacity: 1;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 23, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 150;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 400px;
    max-width: 550px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 16px;
}

.modal-input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 10px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    margin-bottom: 12px;
}
.modal-input:focus { border-color: var(--accent); }

.project-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.project-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.project-item:hover {
    border-color: var(--accent);
    background: rgba(79, 140, 255, 0.08);
}

.project-item .pj-name {
    font-weight: 600;
    font-size: 0.85rem;
    flex: 1;
}

.project-item .pj-date {
    font-size: 0.72rem;
    color: var(--text-dim);
}

.project-item .pj-delete {
    color: var(--danger);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
}
.project-item .pj-delete:hover {
    background: rgba(248, 113, 113, 0.15);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}

/* ── Auth & Tier badges ──────────────────────────────────────────────────── */
.tier-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 6px;
}
.tier-badge.free { background: var(--surface2); color: var(--text-dim); }
.tier-badge.basic { background: linear-gradient(135deg, #2563eb, #3b82f6); color: #fff; }
.tier-badge.pro { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }
.tier-badge.max { background: linear-gradient(135deg, #d97706, #f59e0b); color: #fff; }

.model-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    margin-left: 8px;
    background: var(--surface2);
    color: var(--text-dim);
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { color: var(--text-dim); font-size: 13px; }
.auth-form input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    font-size: 14px;
}
.auth-form input:focus { border-color: var(--accent); outline: none; }
.auth-error { color: var(--danger); font-size: 12px; min-height: 16px; }

.feature-locked {
    position: relative;
    opacity: 0.5;
    pointer-events: none;
}
.feature-locked::after {
    content: "PRO";
    position: absolute;
    top: 8px;
    right: 8px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

/* ── Mobile collapse button (hidden on desktop) ──────────────────────────── */
.mobile-collapse-btn {
    display: none;
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 0px 1fr;
    }
    .app-layout .sidebar {
        padding: 0;
        opacity: 0;
        pointer-events: none;
    }
    .sidebar-toggle {
        left: 0;
        border-radius: 0 var(--radius) var(--radius) 0;
    }
    header {
        flex-wrap: wrap;
        gap: 4px;
        transition: margin-top 0.2s ease, opacity 0.15s ease;
    }
    header h1 { font-size: 1rem; }
    header .subtitle { font-size: 0.65rem; }
    .tabs {
        overflow-x: auto;
        transition: max-height 0.2s ease, opacity 0.15s ease;
        max-height: 50px;
    }
    .tab { padding: 8px 12px; font-size: 0.75rem; white-space: nowrap; }

    /* Collapse toggle button — only visible on mobile */
    .mobile-collapse-btn {
        display: block;
        position: fixed;
        top: 4px;
        right: 4px;
        z-index: 60;
        background: var(--surface2);
        border: 1px solid var(--border);
        border-radius: 4px;
        color: var(--text-dim);
        font-size: 12px;
        width: 28px;
        height: 28px;
        padding: 0;
        cursor: pointer;
        line-height: 1;
        transition: transform 0.2s;
    }
    .mobile-collapse-btn:hover { background: var(--accent); color: #fff; }

    /* Collapsed state */
    body.chrome-collapsed header {
        margin-top: -60px;
        opacity: 0;
        pointer-events: none;
    }
    body.chrome-collapsed .tabs {
        max-height: 0;
        opacity: 0;
        overflow: hidden;
        border-bottom: none;
    }
    body.chrome-collapsed .mobile-collapse-btn {
        transform: rotate(180deg);
    }
    body.chrome-collapsed .app-layout {
        height: 100vh;
    }
    body.chrome-collapsed .sidebar-toggle {
        top: 4px;
    }
}

#plotCanvas {
    touch-action: none;
}

/* ── Light mode theme ───────────────────────────────────────────────────── */
body.light-mode {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface2: #eef0f5;
    --border: #d1d5e0;
    --text: #1a1d27;
    --text-dim: #5a6078;
}
body.light-mode .tool-options,
body.light-mode .properties-panel,
body.light-mode .editor-info,
body.light-mode .plot-info,
body.light-mode .settings-dropdown {
    background: rgba(255, 255, 255, 0.95);
}
body.light-mode .code-editor {
    background: #f8f9fc;
    color: #1a1d27;
}
body.light-mode .loading-overlay {
    background: rgba(245, 246, 250, 0.8);
}

/* ── Desktop header collapse ────────────────────────────────────────────── */
header {
    transition: margin-top 0.2s ease, opacity 0.15s ease;
}
.header-collapse-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    line-height: 1;
    transition: transform 0.2s;
    margin-left: 4px;
}
.header-collapse-btn:hover { color: var(--text); }

body.header-collapsed header {
    margin-top: -52px;
    opacity: 0;
    pointer-events: none;
}
body.header-collapsed .app-layout {
    height: 100vh;
}

.header-restore-btn {
    position: fixed;
    top: 4px;
    right: 4px;
    z-index: 50;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-dim);
    font-size: 12px;
    width: 28px;
    height: 28px;
    padding: 0;
    cursor: pointer;
    line-height: 1;
    display: none;
}
.header-restore-btn:hover { background: var(--accent); color: #fff; }
body.header-collapsed .header-restore-btn { display: block; }

/* ── Settings dropdown ──────────────────────────────────────────────────── */
.settings-dropdown {
    position: absolute;
    top: 42px;
    right: 12px;
    background: rgba(26, 29, 39, 0.95);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    z-index: 20;
    min-width: 180px;
}
.settings-dropdown label.settings-title {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    display: block;
    margin-bottom: 6px;
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
}
.settings-row input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

/* ── Project dropdown ──────────────────────────────────────────────────── */
.project-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: rgba(26, 29, 39, 0.97);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 0;
    z-index: 25;
    min-width: 170px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.project-dropdown-item {
    padding: 7px 14px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.12s;
}
.project-dropdown-item:hover {
    background: var(--bg-mid);
}
.project-dropdown-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}
body.light-mode .project-dropdown {
    background: rgba(255, 255, 255, 0.97);
}

/* ── Sketch dropzone ────────────────────────────────────────────────────── */
.sketch-dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.75rem;
    color: var(--text-dim);
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.sketch-dropzone:hover,
.sketch-dropzone.dragover {
    border-color: var(--accent);
    background: rgba(79, 140, 255, 0.06);
}
.sketch-dropzone img {
    max-width: 100%;
    max-height: 160px;
    border-radius: 4px;
    object-fit: contain;
}

/* ── Connection panel ────────────────────────────────────────────────────── */
#connections-panel {
    position: relative;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.connections-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    gap: 6px;
    z-index: 10;
    align-items: center;
    flex-wrap: wrap;
}

.connections-layout {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    margin-top: 48px;
}

#connectionCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

.connections-detail {
    flex: 1;
    max-width: 360px;
    overflow-y: auto;
    border-left: 1px solid var(--border);
    padding: 12px;
    background: var(--surface);
}

.connections-summary {
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 8px 12px;
}

.connections-summary .data-table {
    font-size: 0.75rem;
}

.connections-summary .data-table td {
    cursor: pointer;
}

.connections-summary .data-table tr:hover {
    background: rgba(79, 140, 255, 0.08);
}

.connections-summary .data-table tr.conn-selected {
    background: rgba(79, 140, 255, 0.15);
}

.conn-check-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.conn-check-row .check-name {
    flex: 2;
    color: var(--text);
}

.conn-check-row .check-values {
    flex: 2;
    text-align: right;
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
}

.conn-check-row .check-util {
    flex: 1;
    text-align: right;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
}

.conn-design-info {
    margin-bottom: 12px;
    padding: 8px;
    background: var(--surface2);
    border-radius: var(--radius);
    font-size: 0.75rem;
}

.conn-design-info .design-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.conn-design-info .design-row label {
    color: var(--text-dim);
}

.conn-design-info .design-row span {
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
}

/* ── Connection View Controls ──────────────────────────────────────────────── */
.conn-view-controls {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.conn-view-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 3px 12px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}
.conn-view-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.conn-view-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Batch Edit Bar ────────────────────────────────────────────────────────── */
.batch-edit-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(79, 140, 255, 0.08);
    border-bottom: 1px solid var(--accent);
}

/* ── Connection Editor Panel ───────────────────────────────────────────────── */
.conn-editor-panel { border-top: 1px solid var(--border); padding-top: 8px; }
.conn-editor-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 8px;
    align-items: center;
    font-size: 11px;
}
.conn-editor-grid label { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.conn-editor-grid select,
.conn-editor-grid input {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 11px;
}

/* ── Detailed Calculations ─────────────────────────────────────────────────── */
.conn-calc-details { border-top: 1px solid var(--border); padding-top: 4px; }
.conn-calc-details .calc-table {
    width: 100%;
    font-size: 10px;
    border-collapse: collapse;
    margin-top: 6px;
}
.conn-calc-details .calc-table th,
.conn-calc-details .calc-table td {
    padding: 2px 4px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.conn-calc-details .calc-table th {
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 9px;
}
.conn-calc-details .calc-table td {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text);
}

/* ── Export Report Options ─────────────────────────────────────────────────── */

/* Batch selected row highlight */
#connSummaryBody tr.batch-selected { background: rgba(79, 140, 255, 0.12); }

/* ── Connection tab layout (redesigned) ──────────────────────────────────── */
.conn-layout { display: flex; height: 100%; min-height: 0; overflow: hidden; flex: 1; }
.conn-canvas-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#connViewport { flex: 1; min-height: 200px; position: relative; overflow: hidden; }
.conn-toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #1a1d27; border-bottom: 1px solid #23263a; flex-shrink: 0; }
.conn-select { background: #23263a; color: #e4e6f0; border: 1px solid #3a3e52; border-radius: 4px; padding: 4px 8px; font-size: 12px; min-width: 200px; }
.conn-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #3a3e52; color: #8b8fa8; }
.conn-toolbar-spacer { flex: 1; }
.conn-btn-sm { background: #23263a; color: #8b8fa8; border: 1px solid #3a3e52; border-radius: 4px; padding: 4px 10px; font-size: 11px; cursor: pointer; }
.conn-btn-sm:hover { background: #2d3148; color: #e4e6f0; }
.conn-btn-primary { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.conn-btn-primary:hover { background: #4338ca; }

/* Sidebar */
.conn-sidebar { width: 340px; background: #14161e; border-left: 1px solid #23263a; display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; }
.conn-sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid #23263a; }
.conn-sidebar-header h3 { margin: 0; font-size: 13px; color: #e4e6f0; font-weight: 600; }
.conn-sidebar-close { background: none; border: none; color: #8b8fa8; font-size: 18px; cursor: pointer; padding: 0 4px; }
.conn-sidebar-close:hover { color: #e4e6f0; }
.conn-sidebar-scroll { flex: 1; overflow-y: auto; padding: 0; }

/* Sections (collapsible) */
.conn-section { border-bottom: 1px solid #1e2130; }
.conn-section-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; cursor: pointer; font-size: 11px; font-weight: 600; color: #8b8fa8; text-transform: uppercase; letter-spacing: 0.5px; }
.conn-section-header:hover { color: #e4e6f0; background: #1a1d27; }
.conn-chevron { font-size: 9px; transition: transform 0.2s; }
.conn-section-header.collapsed .conn-chevron { transform: rotate(-90deg); }
.conn-section-body { padding: 6px 14px 12px; }
.conn-section-body.collapsed { display: none; }

/* Status */
.conn-status-row { display: flex; align-items: center; gap: 8px; padding: 8px 14px; }
.conn-status-icon { font-size: 14px; }
.conn-status-icon.ok { color: #22c55e; }
.conn-status-icon.warning { color: #f59e0b; }
.conn-status-icon.failed { color: #ef4444; }
.conn-util-bar-container { height: 4px; background: #23263a; border-radius: 2px; margin: 0 14px 4px; }
.conn-util-bar { height: 100%; border-radius: 2px; background: #22c55e; transition: width 0.3s, background 0.3s; }
.conn-util-bar.warn { background: #f59e0b; }
.conn-util-bar.fail { background: #ef4444; }
.conn-util-label { font-size: 11px; color: #8b8fa8; padding: 0 14px 8px; }

/* Parameter grid */
.conn-param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.conn-param-row { display: contents; }
.conn-param-label { font-size: 11px; color: #8b8fa8; padding: 3px 0; align-self: center; }
.conn-param-value { font-size: 11px; color: #e4e6f0; padding: 3px 0; text-align: right; }
.conn-param-input { background: #23263a; color: #e4e6f0; border: 1px solid #3a3e52; border-radius: 3px; padding: 3px 6px; font-size: 11px; width: 100%; text-align: right; }
.conn-param-input:focus { border-color: #4f46e5; outline: none; }
.conn-input-full { background: #23263a; color: #e4e6f0; border: 1px solid #3a3e52; border-radius: 4px; padding: 4px 8px; font-size: 12px; width: 100%; }
.conn-param-actions { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }

/* Checks table */
.conn-checks-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.conn-checks-table th { text-align: left; color: #8b8fa8; font-weight: 500; padding: 4px 4px; border-bottom: 1px solid #23263a; }
.conn-checks-table td { padding: 4px 4px; color: #e4e6f0; border-bottom: 1px solid #1e2130; }
.conn-checks-table .util-ok { color: #22c55e; }
.conn-checks-table .util-warn { color: #f59e0b; }
.conn-checks-table .util-fail { color: #ef4444; }

/* Details content */
.conn-details-content { font-size: 11px; }
.conn-detail-group { margin-bottom: 8px; }
.conn-detail-group-title { font-size: 10px; color: #6366f1; text-transform: uppercase; font-weight: 600; margin-bottom: 4px; }
.conn-detail-row { display: flex; justify-content: space-between; padding: 2px 0; }
.conn-detail-key { color: #8b8fa8; }
.conn-detail-val { color: #e4e6f0; font-family: monospace; }

/* Error box */
.conn-error-box { background: #2d1215; border: 1px solid #7f1d1d; border-radius: 4px; padding: 8px 12px; color: #fca5a5; font-size: 11px; margin: 8px 14px; }

/* Responsive: narrow sidebar when small */
@media (max-width: 900px) {
  .conn-sidebar { width: 280px; }
}

/* ── Connection Summary Strip ─────────────────────────────────────────────── */
.conn-summary-strip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #111318;
    border-top: 1px solid #23263a;
    flex-shrink: 0;
    overflow-x: auto;
    min-height: 36px;
    max-height: 50px;
    scrollbar-width: thin;
    scrollbar-color: #3a3e52 transparent;
}
.conn-summary-strip::-webkit-scrollbar { height: 4px; }
.conn-summary-strip::-webkit-scrollbar-thumb { background: #3a3e52; border-radius: 2px; }
.conn-summary-label {
    font-size: 10px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0;
}
.conn-summary-items {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
}
.conn-summary-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 7px;
    border-radius: 4px;
    background: #1a1d27;
    border: 1px solid #2d3148;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    font-size: 10px;
    color: #c4c8d8;
    flex-shrink: 0;
}
.conn-summary-chip:hover { background: #23263a; border-color: #4f46e5; }
.conn-summary-chip.active { background: #2d3148; border-color: #6366f1; color: #e4e6f0; }
.conn-summary-chip .chip-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.conn-summary-chip .chip-dot.ok      { background: #22c55e; }
.conn-summary-chip .chip-dot.warning { background: #f59e0b; }
.conn-summary-chip .chip-dot.failed  { background: #ef4444; }
.conn-summary-chip .chip-dot.unknown { background: #6b7280; }
.conn-summary-chip .chip-util {
    font-size: 9px;
    color: #8b8fa8;
}
.conn-summary-chip.active .chip-util { color: #a5b4fc; }
