/* ========================================
   AudioPlan — Industrial Hardware UI
   8px Grid · Zero Shadows · 2px Max Radius
   ======================================== */

/* ── Default: Deep Dark (Industrial) ── */
:root {
    /* Surfaces */
    --bg-base: #090909;
    --bg-primary: #121212;
    --bg-secondary: #161616;
    --bg-tertiary: #1a1a1a;
    --bg-elevated: #1e1e1e;
    --bg-hover: rgba(255, 255, 255, 0.04);
    --bg-active: rgba(255, 255, 255, 0.06);
    --bg-surface: #0e0e0e;
    --bg-sidebar: #0a0a0a;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.04);
    --bg-sidebar-active: rgba(255, 255, 255, 0.08);
    --row-stripe: rgba(255, 255, 255, 0.02);

    /* Text */
    --text-primary: #e8e8e8;
    --text-secondary: #aaa;
    --text-tertiary: #777;
    --text-muted: #555;
    --text-bright: #f5f5f5;
    --text-sidebar: #707070;
    --text-sidebar-bright: #d0d0d0;

    /* Borders — industrial: #1f1f1f everywhere */
    --border: #1f1f1f;
    --border-light: #1a1a1a;
    --border-focus: #5c7cfa;
    --border-sidebar: #1f1f1f;
    --border-input: #333;

    /* Accent */
    --accent: #5c7cfa;
    --accent-hover: #748ffc;
    --accent-subtle: rgba(92, 124, 250, 0.10);
    --accent-glow: rgba(92, 124, 250, 0.06);

    /* Status */
    --success: #40c463;
    --warning: #f0a030;
    --danger: #f05050;
    --info: #5c7cfa;

    /* Position Group Colors */
    --pos-drums: #40c463;
    --pos-keys: #f0a030;
    --pos-bass: #f0a030;
    --pos-playback: #707070;
    --pos-vocals: #f05050;
    --pos-git: #5c7cfa;
    --pos-monitor: #a060e0;
    --pos-dolly: #5d6d7e;
    --pos-triggers: #f0d030;
    --pos-fx: #30d0a0;
    --pos-atmo: #3060a0;

    /* Loom Colors */
    --loom-black: #333;
    --loom-brown: #8B4513;
    --loom-red: #dc3545;
    --loom-orange: #fd7e14;
    --loom-yellow: #ffc107;
    --loom-green: #28a745;
    --loom-blue: #007bff;
    --loom-violet: #6f42c1;
    --loom-grey: #6c757d;
    --loom-white: #adb5bd;

    /* ── 8px Grid Law ── */
    --grid: 8px;
    --space-xs: 4px;
    /* half-grid exception for tight cells */
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    --font-size-xs: 0.6875rem;
    --font-size-sm: 0.75rem;
    --font-size-base: 0.8125rem;
    --font-size-lg: 0.875rem;
    --font-size-xl: 1rem;
    --font-size-2xl: 1.25rem;

    /* Radius — INDUSTRIAL: max 2px */
    --radius-sm: 2px;
    --radius-md: 2px;
    --radius-lg: 2px;
    --radius-xl: 2px;

    /* Shadows — ZERO */
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;

    /* Transitions */
    --transition-fast: 80ms ease;
    --transition-base: 150ms ease;
    --transition-theme: 250ms ease;

    /* Layout — Fixed Hardware Skeleton */
    --sidebar-width: 240px;
    --header-height: 40px;
    --row-height: 32px;

    /* Focus */
    --focus-glow: none;
    --active-row-border: 2px solid var(--accent);
}

/* ── Light Theme ── */
[data-theme="light"] {
    --bg-base: #f2f2f2;
    --bg-primary: #fff;
    --bg-secondary: #fafafa;
    --bg-tertiary: #f0f0f0;
    --bg-elevated: #fff;
    --bg-hover: rgba(0, 0, 0, 0.03);
    --bg-active: rgba(0, 0, 0, 0.05);
    --bg-surface: #f5f5f5;
    --bg-sidebar: #0a0a0a;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.04);
    --bg-sidebar-active: rgba(255, 255, 255, 0.08);
    --row-stripe: rgba(0, 0, 0, 0.02);
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-tertiary: #777;
    --text-muted: #999;
    --text-bright: #000;
    --text-sidebar: #707070;
    --text-sidebar-bright: #d0d0d0;
    --border: #e0e0e0;
    --border-light: #eaeaea;
    --border-focus: #5c7cfa;
    --border-sidebar: #1f1f1f;
    --border-input: #ccc;
    --accent: #4c6ef5;
    --accent-hover: #3b5bdb;
    --accent-subtle: rgba(76, 110, 245, 0.08);
    --accent-glow: rgba(76, 110, 245, 0.04);
    --success: #2e8b57;
    --warning: #d4930a;
}

/* ========================================
   Reset & Base
   ======================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

html {
    font-size: 16px;
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    transition: background var(--transition-theme), color var(--transition-theme);
}

input,
button,
textarea,
select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    outline: none;
    border: none;
    background: none;
}

/* Ensure dropdown options are always readable */
select option,
datalist option {
    color: var(--text-primary);
    background: var(--bg-primary);
    font-weight: normal;
}

select optgroup {
    color: var(--text-secondary);
    background: var(--bg-secondary);
}

table {
    border-collapse: collapse;
    width: 100%;
}

a {
    color: var(--accent);
    text-decoration: none;
}

/* ========================================
   Sidebar — Icon Rail (48px) + Click Drawers
   ======================================== */
.sidebar {
    width: 48px;
    min-width: 48px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-sidebar);
    display: flex;
    flex-direction: row;
    position: relative;
    z-index: 20;
    flex-shrink: 0;
    color: var(--text-sidebar);
    height: 100%;
}

/* ---- Icon Rail ---- */
.icon-rail {
    width: 48px;
    min-width: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-sm) 0;
    gap: 4px;
    z-index: 22;
    background: var(--bg-sidebar);
}

.rail-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border-radius: 0;
    color: #fff;
    margin-bottom: var(--space-sm);
    flex-shrink: 0;
}

.rail-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-sidebar);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    font-size: 16px;
    flex-shrink: 0;
}

.rail-btn:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.rail-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--accent);
}

.rail-spacer {
    flex: 1;
}

/* ---- Drawer Panels ---- */
.drawer-panel {
    position: absolute;
    top: 0;
    left: 48px;
    bottom: 0;
    width: 220px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-sidebar);
    display: none;
    flex-direction: column;
    z-index: 21;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.4);
}

.drawer-panel.open {
    display: flex;
}

.drawer-header {
    padding: var(--space-md) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-sidebar-bright);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-sidebar);
    flex-shrink: 0;
    height: 40px;
    display: flex;
    align-items: center;
}

.drawer-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.drawer-footer {
    padding: var(--space-sm);
    border-top: 1px solid var(--border-sidebar);
    flex-shrink: 0;
}

.drawer-action {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-sm);
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-sidebar);
    font-size: var(--font-size-sm);
    font-family: inherit;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.12s ease, color 0.12s ease;
    width: 100%;
    text-align: left;
    white-space: nowrap;
}

.drawer-action:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.drawer-action--accent {
    color: #e91e63;
}

.drawer-action--accent:hover {
    background: rgba(233, 30, 99, 0.1);
    color: #e91e63;
}

.drawer-divider {
    height: 1px;
    background: var(--border-sidebar);
    margin: var(--space-xs) 0;
}

.drawer-field {
    padding: var(--space-sm);
}

.drawer-field label {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--text-sidebar);
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.drawer-field input {
    width: 100%;
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-sidebar-hover);
    border: 1px solid var(--border-sidebar);
    border-radius: 2px;
    font-size: var(--font-size-sm);
    font-family: inherit;
    color: var(--text-sidebar-bright);
}

.drawer-field input:focus {
    outline: none;
    border-color: var(--accent);
}

.drawer-section-label {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-sidebar);
    padding: var(--space-sm) var(--space-md) var(--space-xs);
    font-weight: 600;
    flex-shrink: 0;
}

.drawer-action--danger {
    color: var(--danger, #e53935);
}

.drawer-action--danger:hover {
    background: rgba(229, 57, 53, 0.1);
    color: var(--danger, #e53935);
}

/* Rail logo as button */
.rail-logo {
    border: none;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.rail-logo:hover {
    opacity: 0.85;
    transform: scale(1.05);
}

.rail-logo.active {
    opacity: 1;
    filter: drop-shadow(0 0 6px var(--accent));
}

/* ---- Project Items (inside drawer) ---- */
.project-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    height: 32px;
    border-radius: 4px;
    border-left: 2px solid transparent;
    cursor: pointer;
    transition: background 0.12s ease;
    font-size: var(--font-size-sm);
    color: var(--text-sidebar);
}

.project-item:hover {
    background: var(--bg-sidebar-hover);
}

.project-item.active {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-sidebar-bright);
    font-weight: 600;
    border-left-color: var(--accent);
}

.project-item-dot {
    width: 6px;
    height: 6px;
    min-width: 6px;
    border-radius: 50%;
    background: var(--text-sidebar);
    flex-shrink: 0;
}

.project-item.active .project-item-dot {
    background: var(--accent);
}

.project-item-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Drawer backdrop (click to close) ---- */
.drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 19;
    display: none;
}

.drawer-backdrop.open {
    display: block;
}

/* ---- Legacy classes (hidden) ---- */
.sidebar-toggle {
    display: none;
}

/* ========================================
   Main Content
   ======================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    min-height: 0;
    background: var(--bg-base);
    transition: background var(--transition-theme);
}

#welcomeScreen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#tabContentArea {
    flex: 1 1 0;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    transition: background var(--transition-theme);
}

/* Every direct child of tab area fills full height */
#tabContentArea>* {
    flex: 1 1 0;
    min-height: 0;
}

/* Non-position tabs scroll vertically (NOT .patch-page — it manages its own scroll via .patch-scroll) */
#tabContentArea>*:not(.position-page):not(.patch-page) {
    overflow-y: auto;
}


#projectView {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 0;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

#projectView.hidden {
    display: none !important;
}

/* ========================================
   Project Header
   ======================================== */
.project-header {
    background: #121212;
    border-bottom: 1px solid #1f1f1f;
    padding: 0 var(--space-lg);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
}

.header-spacer {
    flex: 1;
    min-width: 0;
}

.header-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.header-dot {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    opacity: 0.4;
    user-select: none;
}

.project-header .project-artist-input {
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--text-primary);
    border: none;
    background: none;
    padding: 0;
    text-align: right;
    width: auto;
    min-width: 80px;
    max-width: 200px;
}

.project-header .project-venue-input {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    border: none;
    background: none;
    padding: 0;
    text-align: left;
    width: auto;
    min-width: 80px;
    max-width: 200px;
    opacity: 0.7;
}

.project-header .project-title-input {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-bright);
    border: none;
    background: none;
    padding: 0;
    text-align: right;
    min-width: 120px;
    max-width: 300px;
}

.project-header .project-title-input:focus,
.project-header .project-artist-input:focus,
.project-header .project-venue-input:focus {
    outline: none;
    border-bottom: 1px solid var(--accent);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.app-version-badge {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 10px;
    letter-spacing: 0.06em;
    white-space: nowrap;
    user-select: none;
    opacity: 0.85;
    transition: opacity 0.15s;
}

.app-version-badge:hover {
    opacity: 1;
}

/* ========================================
   Console Setup Bar
   ======================================== */
.console-setup-bar {
    display: none;
}

.console-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.console-group label {
    font-weight: 600;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    min-width: 32px;
}

.console-group select {
    padding: 3px var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

.console-sb-checks {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.console-sb-checks label {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    min-width: 0;
}

.console-sb-checks input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
}

.console-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
}

/* ========================================
   Tabs
   ======================================== */
.tabs-wrapper {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tabs-container {
    display: flex;
    padding: 0 var(--space-xl);
    gap: 0;
    overflow-x: auto;
}

.tab {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
    white-space: nowrap;
    background: none;
    font-weight: 500;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab.active {
    color: var(--text-bright);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab svg {
    opacity: 0.5;
}

.tab.active svg {
    opacity: 1;
}

.tab-count {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.tab.active .tab-count {
    background: var(--accent-subtle);
    color: var(--accent);
}

/* ========================================
   Tab Content
   ======================================== */
.tab-content {
    display: none;
    padding: var(--space-md) var(--space-xl);
    overflow-y: auto;
    flex: 1 1 0;
    min-height: 0;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Position tabs have their own internal padding in .position-page */
.tab-content.active:has(.position-page) {
    padding: 0;
    overflow: hidden;
}

/* ========================================
   Toolbar
   ======================================== */
.table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.toolbar-right {
    margin-left: auto;
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.toolbar-sb-select {
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    font-weight: 500;
}

/* ========================================
   Buttons — Industrial Hardware Controls
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border-radius: 2px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    line-height: 1;
    height: var(--row-height);
    border: 1px solid #333;
    background: #181818;
    color: var(--text-primary);
}

.btn:hover {
    background: #222;
}

.btn:active {
    border-left: 2px solid var(--accent);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid #333;
}

.btn-ghost:hover {
    background: #1a1a1a;
    color: var(--text-primary);
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    height: 24px;
}

/* ========================================
   Search Input
   ======================================== */
.search-input {
    padding: var(--space-xs) var(--space-md);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-width: 100px;
    max-width: 160px;
    width: 100%;
    transition: border-color var(--transition-fast);
}

.search-input:focus {
    border-color: var(--accent);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* ========================================
   Data Table — Industrial Patch-Grid
   32px rows · Zero radius · Border separation
   ======================================== */
.data-table {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
    border: 1px solid var(--border);
    border-radius: 0;
    background: var(--bg-primary);
    border-collapse: separate;
    border-spacing: 0;
    -webkit-user-select: none;
    user-select: none;
}
.data-table input,
.data-table select,
.data-table textarea {
    -webkit-user-select: text;
    user-select: text;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.data-table thead th {
    background: #161616;
    padding: 0 var(--space-md);
    height: var(--row-height);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    text-align: center;
    border-bottom: 1px solid #444;
    white-space: nowrap;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 2;
}
.data-table thead th:nth-child(-n+4) {
    text-align: left;
}

.data-table tbody td {
    padding: 0;
    height: var(--row-height);
    border-bottom: 1px solid #444;
    vertical-align: middle;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Loom cells need overflow visible for S/R multi-select stacking */
.data-table tbody td[style*="border-left"] {
    overflow: visible;
}
/* Slightly reduce loom select height */
.data-table tbody td[style*="border-left"] select.cell-select {
    height: 22px;
    padding: 0 2px;
    line-height: 22px;
}

/* Zebra-striping */
.data-table tbody tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.015);
}

.data-table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

/* Contextual actions — hidden until hover */
.data-table tbody tr .btn-icon.ctx-action {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.data-table tbody tr:hover .btn-icon.ctx-action {
    opacity: 1;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Group header rows */
.group-row td {
    padding: 0 !important;
    background: #161616 !important;
}

.group-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0 var(--space-md);
    height: var(--row-height);
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.group-color-bar {
    width: 2px;
    height: 16px;
    border-radius: 0;
    background: var(--accent);
}

/* Cell inputs — borderless, 32px height */
.cell-input {
    width: 100%;
    padding: 0 var(--space-sm);
    height: var(--row-height);
    border: none;
    background: transparent;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    outline: none;
}

.cell-input:focus {
    background: rgba(92, 124, 250, 0.04);
    box-shadow: inset 2px 0 0 var(--accent);
}

/* Active row — left accent bar */
.data-table tbody tr:focus-within td:first-child {
    box-shadow: inset 2px 0 0 var(--accent);
}

.data-table tbody tr:focus-within td {
    background: rgba(92, 124, 250, 0.04);
}

textarea.cell-info {
    resize: none;
    overflow: hidden;
    min-height: 22px;
    line-height: 1.3;
    font-size: var(--font-size-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    field-sizing: content;
    width: 100%;
    max-width: 100%;
}

.cell-input::placeholder {
    color: var(--text-muted);
}

.cell-ch {
    text-align: center;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    font-variant-numeric: tabular-nums;
    max-width: 48px;
}

.cell-select {
    width: 100%;
    padding: 0 var(--space-sm);
    height: var(--row-height);
    border: none;
    background: transparent;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    cursor: pointer;
}

.cell-select:focus {
    background: rgba(92, 124, 250, 0.04);
    box-shadow: inset 2px 0 0 var(--accent);
}

/* Center-align Mic, Position, Stand, Kategorie, Direction columns */
.cell-select,
input.cell-input[data-field="mic"],
input.cell-input[data-field="stand"],
input.cell-input[data-field="position"],
input.cell-input[data-field="category"] {
    text-align: center;
    text-align-last: center;
}


.cell-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
}

.checkbox {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Row actions */
.row-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
    color: var(--text-muted);
    cursor: grab;
}

.row-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs);
}

.row-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.row-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.row-action-btn.delete:hover {
    color: var(--danger);
    background: rgba(240, 80, 80, 0.1);
}

/* Loom color cell */
.loom-color-cell {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-left: var(--space-sm);
}

.loom-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

/* Routing type badge */
.routing-badge {
    display: inline-flex;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.routing-badge.split {
    background: rgba(64, 196, 99, 0.12);
    color: var(--success);
}

.routing-badge.loop {
    background: rgba(92, 124, 250, 0.12);
    color: var(--accent);
}

.routing-badge.send {
    background: rgba(240, 160, 48, 0.12);
    color: var(--warning);
}

.routing-badge.direct {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

/* ========================================
   Mic Combo Box
   ======================================== */
.mic-combo {
    position: relative;
    width: 100%;
}

.mic-combo input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: none;
    background: transparent;
    font-size: var(--font-size-base);
    color: var(--text-primary);
}

.mic-combo input:focus {
    background: var(--accent-glow);
    box-shadow: inset 2px 0 0 var(--accent);
}

.mic-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.mic-dropdown.visible {
    display: block;
}

.mic-dropdown-group {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--bg-secondary);
}

.mic-dropdown-item {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.mic-dropdown-item:hover {
    background: var(--accent-subtle);
    color: var(--accent);
}

.mic-dropdown-item.selected {
    background: var(--accent-subtle);
}

/* ========================================
   Patch Overview / Routing
   ======================================== */
.routing-view {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.capacity-dashboard {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.capacity-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    min-width: 200px;
    flex: 1;
}

.capacity-card h4 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
}

.capacity-card .desk-badge {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    margin-bottom: var(--space-sm);
}

.capacity-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
    font-size: var(--font-size-sm);
}

.capacity-row label {
    min-width: 60px;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.capacity-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.capacity-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.capacity-bar-fill.green {
    background: var(--success);
}

.capacity-bar-fill.yellow {
    background: var(--warning);
}

.capacity-bar-fill.red {
    background: var(--danger);
}

.capacity-row .count {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    min-width: 50px;
    text-align: right;
    color: var(--text-secondary);
}

/* Routing comparison */
.routing-compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}

.routing-column {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.routing-column h3 {
    background: var(--bg-secondary);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.patch-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--border-light);
}

.patch-ch {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    min-width: 24px;
    text-align: right;
}

.patch-source {
    flex: 1;
    color: var(--text-primary);
}

.patch-arrow {
    color: var(--text-muted);
    font-size: 10px;
}

.patch-dest {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.patch-group-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: var(--bg-secondary);
}

.patch-group-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.empty-msg {
    padding: var(--space-xl);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

/* ========================================
   History View
   ======================================== */
.history-view,
.notes-view {
    max-width: 700px;
}

.history-view h2,
.notes-view h2 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.history-desc,
.patch-desc {
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
    margin-bottom: var(--space-lg);
}

.history-date {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: var(--space-md) 0 var(--space-xs);
    border-bottom: 1px solid var(--border-light);
    margin-bottom: var(--space-sm);
}

.history-entry {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-xs) 0;
    font-size: var(--font-size-sm);
}

.history-time {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    min-width: 44px;
}

.history-user {
    font-weight: 500;
    color: var(--text-primary);
    margin-right: var(--space-xs);
}

.history-action {
    color: var(--text-secondary);
}

.history-details {
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
}

.history-empty {
    color: var(--text-muted);
    padding: var(--space-xl) 0;
}

/* ========================================
   Notes
   ======================================== */
.notes-textarea {
    width: 100%;
    min-height: 300px;
    padding: var(--space-lg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    line-height: 1.6;
    resize: vertical;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.notes-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

/* ========================================
   Welcome Screen
   ======================================== */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: var(--space-2xl);
    gap: var(--space-lg);
}


.welcome-screen h2 {
    font-size: var(--font-size-2xl);
    font-weight: 600;
    color: var(--text-primary);
}

.welcome-screen p {
    color: var(--text-tertiary);
    font-size: var(--font-size-base);
}

#welcomeNewProject {
    margin-top: var(--space-md);
}

.hidden {
    display: none !important;
}

/* ========================================
   Modals
   ======================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 0;
    width: 90%;
    max-width: 480px;
}

.modal-header {
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: var(--space-xs);
    font-size: 14px;
}

.modal-body {
    padding: var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    overflow-y: auto;
    max-height: calc(85vh - 120px);
}

.modal-body label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.modal-body input,
.modal-body select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body input:focus,
.modal-body select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

.modal-footer {
    padding: var(--space-lg) var(--space-xl);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

/* Projekt Details Modal fields */
.setup-field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setup-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.setup-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-sizing: border-box;
}

.setup-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

/* Template cards */
.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.template-card {
    padding: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: center;
    transition: all var(--transition-fast);
}

.template-card:hover {
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.template-card.active {
    border-color: var(--accent);
    background: var(--accent-subtle);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

.template-card-title {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.template-card-desc {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    margin-top: 2px;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    cursor: pointer;
}

/* ========================================
   Toast
   ======================================== */
.toast-container {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-sm);
}

.toast {
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    border: 1px solid var(--border);
    animation: toastIn 0.2s ease;
}

.toast.error {
    background: var(--danger);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   Rack Designer — Light Mode
   ======================================== */
.rack-designer-container {
    display: flex;
    height: calc(100vh - 200px);
    gap: 0;
    overflow: hidden;
}

.rack-catalog {
    width: 230px;
    min-width: 230px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: var(--space-sm) 0;
}

.rack-catalog-header {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    font-weight: 600;
}

.rack-catalog-section {
    margin-bottom: var(--space-xs);
}

.rack-catalog-section-title {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    user-select: none;
}

.rack-catalog-section-title:hover {
    color: var(--text-primary);
}

.rack-catalog-section-title .chevron {
    transition: transform var(--transition-fast);
    font-size: 10px;
}

.rack-catalog-section-title.collapsed .chevron {
    transform: rotate(-90deg);
}

.rack-catalog-items {
    padding: 0 var(--space-sm);
}

.rack-catalog-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    cursor: grab;
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    transition: background var(--transition-fast);
    user-select: none;
}

.rack-catalog-item:hover {
    background: var(--bg-hover);
}

.rack-catalog-item:active {
    cursor: grabbing;
}

.rack-catalog-item .item-ru {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    min-width: 32px;
    text-align: right;
}

.rack-catalog-item .item-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rack-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.rack-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-lg);
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    flex-wrap: wrap;
}

.rack-toolbar .toolbar-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.rack-toolbar .toolbar-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
}

.rack-toolbar label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.rack-toolbar select,
.rack-toolbar input[type="text"] {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

.rack-toolbar .rack-name-input {
    min-width: 160px;
    font-weight: 500;
}

.rack-view-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.rack-view-toggle button {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
    cursor: pointer;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: none;
    transition: all var(--transition-fast);
}

.rack-view-toggle button.active {
    background: var(--accent);
    color: #fff;
}

.rack-view-toggle button:hover:not(.active) {
    background: var(--bg-hover);
}

.rack-canvas-wrapper {
    flex: 1;
    overflow: auto;
    padding: var(--space-xl);
    display: flex;
    justify-content: center;
    background: var(--bg-secondary);
}

.rack-canvas {
    display: flex;
    gap: var(--space-lg);
    min-width: min-content;
}

.rack-bay {
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    width: 280px;
    box-shadow: var(--shadow-md);
}

.rack-bay-header {
    background: var(--bg-tertiary);
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    text-align: center;
    font-weight: 600;
}

.rack-bay-body {
    position: relative;
}

.rack-ru {
    display: flex;
    align-items: stretch;
    min-height: 28px;
    border-bottom: 1px solid var(--border-light);
    position: relative;
}

.rack-ru:last-child {
    border-bottom: none;
}

.rack-ru-number {
    width: 28px;
    min-width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    border-right: 1px solid var(--border-light);
    background: var(--bg-secondary);
    user-select: none;
}

.rack-ru-content {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0 var(--space-sm);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    cursor: pointer;
    min-height: 28px;
}

.rack-ru-content:hover {
    background: var(--bg-hover);
}

.rack-ru.occupied .rack-ru-content {
    background: var(--bg-secondary);
    cursor: default;
}

.rack-ru.selected .rack-ru-content {
    background: var(--accent-subtle);
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

.rack-ru.drop-target .rack-ru-content {
    background: rgba(41, 128, 185, 0.1);
    outline: 1px dashed var(--info);
    outline-offset: -1px;
}

.rack-ru-empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: var(--font-size-xs);
}

.rack-additionals {
    width: 260px;
    min-width: 260px;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.rack-additionals-header {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.rack-additionals-list {
    flex: 1;
    padding: var(--space-sm);
    overflow-y: auto;
}

.rack-additional-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
}

.rack-additional-item:hover {
    background: var(--bg-hover);
}

.rack-additional-item .qty {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    min-width: 20px;
    text-align: right;
}

.rack-add-additional {
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border);
}

.rack-add-additional input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

.rack-properties {
    border-top: 1px solid var(--border);
    padding: var(--space-md);
}

.rack-properties h4 {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    margin-bottom: var(--space-sm);
}

.rack-prop-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.rack-prop-row label {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    min-width: 50px;
}

.rack-prop-row input,
.rack-prop-row select {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    padding: 3px var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

.rack-list-panel {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    overflow-x: auto;
}

.rack-list-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
}

.rack-list-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.rack-list-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent);
    font-weight: 500;
}

.rack-list-add {
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    border: 1px dashed var(--border);
}

.rack-list-add:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.rack-rear-label {
    color: var(--danger);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ========================================
   Stageplot (keep existing but adapt colors)
   ======================================== */
.stageplot-container {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    min-height: 500px;
}

.sp-context-menu {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-xs);
    z-index: 500;
    box-shadow: var(--shadow-md);
    min-width: 180px;
}

.sp-context-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.sp-context-item:hover {
    background: var(--bg-hover);
}

.sp-context-item.danger {
    color: var(--danger);
}

.sp-context-sep {
    height: 1px;
    background: var(--border-light);
    margin: var(--space-xs) 0;
}

/* ========================================
   Mobile Menu
   ======================================== */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: var(--space-md);
    left: var(--space-md);
    z-index: 20;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    color: var(--text-primary);
    cursor: pointer;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        height: 100vh;
        transition: left 0.2s;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-menu-btn {
        display: block;
    }

    .project-header {
        padding: var(--space-md);
    }

    .tabs-container {
        padding: 0 var(--space-md);
    }

    .tab-content {
        padding: var(--space-md);
    }
}

/* ========================================
   Drag & Drop
   ======================================== */
.data-table tbody tr.dragging {
    opacity: 0.4;
    background: var(--bg-tertiary) !important;
}

.data-table tbody tr.drag-over {
    border-top: 2px solid var(--accent) !important;
}

.data-table tbody tr {
    transition: border-left 0.15s ease;
}

/* ========================================
   Routing Select in Cell
   ======================================== */
.cell-routing {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    min-width: 65px;
    padding: 2px 4px;
    border-radius: 3px;
}

.routing-badge.return {
    background: #e8f5e9;
    color: #1b5e20;
}

/* ========================================
   Stagebox Edit Button
   ======================================== */
.sb-edit-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    padding: 0 4px;
    margin-left: 2px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.sb-edit-btn:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
}

/* ========================================
   Split Tag in Capacity Card
   ======================================== */
.split-tag {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ========================================
   Side-by-Side Stagebox Layout
   ======================================== */
.sb-tab-content {
    padding: var(--space-lg);
}

.sb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.sb-header h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}

.sb-split-layout {
    display: flex;
    gap: var(--space-lg);
    align-items: flex-start;
}

.sb-inputs-section {
    flex: 3;
    min-width: 0;
}

.sb-outputs-section {
    flex: 2;
    min-width: 0;
}

/* Narrower input cells */
.cell-sm {
    max-width: 60px !important;
}

.cell-num {
    text-align: center;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.cell-center {
    text-align: center;
}

.cell-loom {
    border-radius: 3px !important;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cell-mic {
    font-size: 11px;
}

.cell-select {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
}

.cell-select:hover,
.cell-select:focus {
    border-color: var(--border);
    background: var(--bg-secondary);
}

/* Tab divider between stagebox tabs and utility tabs */
.tab-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 8px;
    align-self: center;
}

/* + SB button */
.tab-add {
    color: var(--accent) !important;
    font-weight: 600 !important;
    border: 1px dashed var(--border) !important;
    background: transparent !important;
}

.tab-add:hover {
    background: var(--bg-tertiary) !important;
    border-color: var(--accent) !important;
}

/* ========================================
   Routing Grid
   ======================================== */
.routing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-md);
    margin: var(--space-md) 0;
}

.routing-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--space-md);
}

.routing-card h4 {
    margin: 0 0 var(--space-sm);
    font-size: 14px;
    font-weight: 700;
}

.routing-stat {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: 6px;
    font-size: 12px;
}

.capacity-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.capacity-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.routing-summary {
    margin-top: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 13px;
}

/* ========================================
   Loom Legend
   ======================================== */
.loom-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: var(--space-sm) 0;
}

.loom-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 24px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
}

/* ========================================
   Responsive: Stack tables on narrow screens
   ======================================== */
@media (max-width: 1100px) {
    .position-split-layout {
        flex-direction: column;
    }

    .position-inputs,
    .position-io {
        flex: none;
        width: 100%;
    }
}

/* ========================================
   Position Page Layout
   ======================================== */
.position-page {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.position-header {
    display: none;
}

.position-split-layout {
    display: flex;
    flex-direction: row;
    gap: var(--space-lg);
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

/* Digital Patch patchbay: single-column full-width */
/* Digital Patch full-view container (outside the split grid) */
#dp-fullview {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
}

#dp-fullview thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #1a1a1a;
}

/* Force dp-fullview scroll wrapper and table to always be full width */
#dp-fullview>div {
    width: 100% !important;
    min-width: 0;
}

#dp-fullview table {
    width: 100% !important;
    min-width: 0;
}


.position-split-layout.dp-fullwidth {

    display: flex;
    flex-direction: column;
}

.dp-fullwidth .position-inputs {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
}

.dp-fullwidth .position-inputs>.panel-header {
    grid-column: unset;
    grid-row: unset;
}

.dp-fullwidth .position-inputs>.panel-scroll {
    grid-column: unset;
    grid-row: unset;
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
}

.position-inputs {
    display: flex;
    flex-direction: column;
    flex: 3;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.position-inputs>.panel-header {
    flex-shrink: 0;
    min-width: 0;
    width: 100%;
}

.position-inputs>.panel-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.position-io {
    display: flex;
    flex-direction: column;
    flex: 2;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.position-io>.panel-header {
    flex-shrink: 0;
    min-width: 0;
    width: 100%;
}

.position-io>.panel-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Collapsed: schmaler Streifen */
.position-inputs.collapsed,
.position-io.collapsed {
    flex: 0 0 32px !important;
    overflow: hidden;
    cursor: pointer;
    min-height: 0;
}

.position-inputs.collapsed>.panel-scroll,
.position-io.collapsed>.panel-scroll,
.position-inputs.collapsed>.panel-header,
.position-io.collapsed>.panel-header {
    display: none !important;
}

/* Das nicht-kollabierte Panel nimmt den ganzen Platz ein */
.position-split-layout:has(.position-inputs.collapsed) .position-io:not(.collapsed) {
    flex: 1;
}

.position-split-layout:has(.position-io.collapsed) .position-inputs:not(.collapsed) {
    flex: 1;
}

/* Collapse label — vertical button strip shown when panel is collapsed */
.collapse-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    padding: 16px 0;
    white-space: nowrap;
    cursor: pointer;
    display: none;
    transition: color 0.15s, background 0.15s;
    width: 100%;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-left: 2px solid var(--border);
    border-right: 2px solid var(--border);
    user-select: none;
}

.position-inputs .collapse-label {
    border-left: none;
    border-right: 2px solid var(--border);
}

.position-io .collapse-label {
    border-left: 2px solid var(--border);
    border-right: none;
}

.collapse-label:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

.collapsed .collapse-label {
    display: flex;
}

.io-section {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-sm);
    flex-shrink: 0;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: clip;
}

/* Tables fill the full panel width when panel expands */
.position-inputs .data-table,
.position-io .data-table {
    width: 100%;
    min-width: 0;
}

/* table-scroll must also fill full width otherwise table width:100% has no effect */
.position-inputs .table-scroll,
.position-io .table-scroll {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Smooth panel collapse/expand */
.position-inputs,
.position-io {
    transition: flex 0.2s ease;
}

/* Clickable header hint: section-title with cursor:pointer shows hover state */
#toggleInputs:hover,
#toggleOutputs:hover {
    color: var(--accent);
    transition: color 0.15s;
}

/* Panel collapse caret: simple larger triangle */
.panel-caret {
    margin-left: auto;
    font-size: 18px;
    color: var(--text-secondary);
    flex-shrink: 0;
    padding-left: 8px;
    cursor: pointer;
    transition: color 0.15s;
    user-select: none;
    line-height: 1;
}

#toggleInputs,
#toggleOutputs {
    cursor: pointer;
}

#toggleInputs > .panel-caret,
#toggleOutputs > .panel-caret {
    margin-left: 0;
    margin-right: var(--space-xs);
}

#toggleInputs:hover .panel-caret,
#toggleOutputs:hover .panel-caret {
    color: var(--accent);
}

/* Sticky thead in scrollable panels */
.panel-scroll thead th,
.position-io thead th,
.history-page thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-primary);
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--space-sm);
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--bg-base);
    padding: var(--space-xs) 0;
}

.table-scroll {
    margin: 0 calc(-1 * var(--space-sm));
    padding: 0 var(--space-sm);
    overflow-x: clip;
}

/* Sub-tabs for multiple stageboxes per position */
.sb-subtabs-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
    flex-shrink: 0;
}

.sb-subtabs {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.sb-console-info {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
    padding-right: var(--space-sm);
    letter-spacing: 0.01em;
}

.sb-subtab {
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.sb-subtab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sb-subtab.active {
    background: var(--bg-primary);
    color: var(--accent);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* Compact tables for I/O sections */
.data-table.compact th,
.data-table.compact td {
    padding: 2px 5px;
    font-size: 11px;
}

.data-table.compact .cell-input {
    font-size: 11px;
    padding: 1px 4px;
}

.cell-narrow {
    width: 44px;
    text-align: center;
    font-family: var(--font-mono);
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Hide number input spinners */
.cell-narrow::-webkit-outer-spin-button,
.cell-narrow::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cell-muted {
    color: var(--text-secondary, #666);
    font-family: var(--font-mono);
    font-size: 11px;
    text-align: center;
}

/* ========================================
   Toolbar
   ======================================== */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.search-input {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 12px;
    background: var(--bg-primary);
    width: 160px;
    transition: border-color var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ========================================
   Setup Modal
   ======================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.setup-modal {
    max-width: 680px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
}

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
}


.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-light);
}

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    background: var(--bg-primary);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row {
    display: flex;
    gap: var(--space-md);
}

.form-row .form-group {
    flex: 1;
}

/* Setup sections */
.setup-section {
    margin-bottom: var(--space-lg);
}

.setup-section h4 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.setup-position {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
}

.setup-pos-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.setup-pos-header strong {
    font-size: 13px;
}

.setup-pos-header small {
    color: var(--text-muted);
    font-size: 10px;
    margin-left: 4px;
}

.setup-stageboxes {
    margin-top: var(--space-xs);
}

.setup-sb {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    padding: 3px 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 3px;
}

.setup-sb-card {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xs);
    overflow: hidden;
}

.setup-sb-card .setup-sb {
    border-radius: 0;
    margin-bottom: 0;
}

.setup-slots {
    padding: 4px 6px;
    background: var(--bg-primary);
}

.setup-sbtype {
    font-size: 11px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    flex: 1;
}

/* Column resize handles (via JS) */
.data-table th {
    position: relative;
}

.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    z-index: 2;
}

.col-resize-handle:hover,
.col-resize-handle.active {
    background: var(--accent);
}

/* ========================================
   Capacity Grid
   ======================================== */
.capacity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-md);
}

.capacity-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
}

.capacity-label {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
}

.capacity-text {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ========================================
   Patch Overview
   ======================================== */
.patch-page {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.patch-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    /* NO padding here — padding creates a gap above the sticky header */
}

/* Sticky thead inside .patch-scroll */
.patch-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-table-header, #1e1e1e);
}

/* Inner spacing via table margins */
.patch-scroll>table {
    margin: 0;
}

/* ========================================
   IEM Page
   ======================================== */
.iem-page {
    padding: var(--space-lg);
}

/* Section titles inside IEM page should NOT be sticky (they float visually) */
.iem-page .section-title {
    position: static;
}
/* ========================================
   History & Notes Pages
   ======================================== */
.history-page,
.notes-page {
    padding: var(--space-lg);
}

.history-item {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
}

.history-time {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    min-width: 140px;
}

.history-user {
    color: var(--accent);
    font-weight: 600;
    min-width: 80px;
}

.notes-textarea {
    width: 100%;
    min-height: 300px;
    padding: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 13px;
    resize: vertical;
    background: var(--bg-primary);
}

.notes-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

/* ========================================
   Small Button Variants
   ======================================== */
.btn-xs {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast), background var(--transition-fast);
}

.btn-icon:hover {
    color: var(--danger);
    background: rgba(192, 57, 43, 0.08);
}

.btn-del {
    font-size: 10px;
}

/* ========================================
   Tab Bar
   ======================================== */
.tab-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--space-xs) var(--space-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
}

.tab-bar-spacer {
    flex: 1;
    min-width: var(--space-md);
}

.tab-console-info {
    position: absolute;
    right: var(--space-lg);
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
    letter-spacing: 0.01em;
    pointer-events: none;
}

/* Hide the old position-header info row */
.position-header {
    display: none;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 6px var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border: 1px solid transparent;
    border-bottom: none;
    transition: all var(--transition-fast);
    white-space: nowrap;
    user-select: none;
}

.tab-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tab-item.active {
    background: var(--bg-primary);
    color: var(--text-bright);
    font-weight: 600;
    border-color: var(--border);
    position: relative;
}

.tab-item.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--bg-primary);
}

.tab-icon {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.tab-badge {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 10px;
    font-family: var(--font-mono);
}

.tab-item.active .tab-badge {
    background: var(--accent-subtle);
    color: var(--accent);
}

/* Badge */
.badge {
    display: inline-block;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
    font-family: var(--font-mono);
}

.badge-danger {
    background: rgba(240, 80, 80, 0.12);
    color: var(--danger);
}

.position-inputs .data-table th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-secondary);
    box-shadow: 0 1px 0 var(--border);
}

.data-table.compact th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-secondary);
    box-shadow: 0 1px 0 var(--border);
}

/* Sticky section title + toolbar inside scroll container */
.position-inputs>.section-title {
    position: sticky;
    top: 0;
    z-index: 6;
    background: var(--bg-base);
    padding-top: var(--space-xs);
    padding-bottom: var(--space-xs);
    margin-bottom: 0;
}

.position-inputs>.table-toolbar {
    position: sticky;
    top: 24px;
    z-index: 6;
    background: var(--bg-base);
    padding-bottom: var(--space-xs);
}

/* Context menu */
.ctx-menu {
    position: fixed;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-xs) 0;
    min-width: 200px;
    z-index: 100;
    font-size: var(--font-size-sm);
}

.ctx-item {
    padding: 6px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctx-item:hover {
    background: var(--accent);
    color: #fff;
}

.ctx-danger:hover {
    background: var(--danger);
}

.ctx-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Cell select dropdown in tables */
.cell-select {
    background: transparent;
    border: none;
    padding: 2px 4px;
    font-size: 11px;
    width: 100%;
    cursor: pointer;
    color: inherit;
}

.cell-select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    border-radius: 2px;
}

/* Packlist page */
.packlist-page {
    padding: 0 var(--space-xl) var(--space-xl);
}

.packlist-page h4 {
    padding-top: var(--space-xl);
    margin-bottom: var(--space-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#tabContentArea>.packlist-page thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-table-header, #1e1e1e);
}

.packlist-page .data-table td:last-child {
    text-align: center;
    font-weight: 600;
    font-family: var(--font-mono);
}

/* Multi-select row highlight */
.data-table tbody tr.row-selected td {
    background: rgba(64, 112, 184, 0.12) !important;
    border-top: 1px solid var(--accent) !important;
    border-bottom: 1px solid var(--accent) !important;
}

.data-table tbody tr.row-selected td:first-child {
    border-left: 3px solid var(--accent) !important;
}

/* Custom confirm modal */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.confirm-box {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 24px 28px;
    min-width: 320px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.confirm-box p {
    margin: 0 0 20px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

/* Confirm-actions: standalone (used in overlay dialogs without .confirm-box wrapper too) */
.confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}

.confirm-actions button,
.confirm-box .confirm-actions button {
    min-width: 90px;
    padding: 7px 16px;
    border-radius: 4px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.12s, opacity 0.12s;
    text-align: center;
}

.confirm-box .confirm-actions {
    justify-content: center;
}

.btn-confirm-ok,
.confirm-box .btn-confirm-ok {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-confirm-ok:hover,
.confirm-box .btn-confirm-ok:hover {
    background: var(--accent-hover);
}

.btn-confirm-ok:disabled,
.confirm-box .btn-confirm-ok:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-confirm-cancel,
.confirm-box .btn-confirm-cancel {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-confirm-cancel:hover,
.confirm-box .btn-confirm-cancel:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ========================================
   Loom Planner — Color Chips & Cable Tags
   ======================================== */
.loom-color-chip:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.4) !important;
}

.loom-cable-tag {
    transition: background 0.15s, box-shadow 0.15s;
}

.loom-cable-tag:hover {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    background: var(--bg-hover) !important;
}

.cable-add-btn:hover {
    background: var(--accent-subtle) !important;
    border-color: var(--accent) !important;
}

/* Chevron expand button */
.loom-expand-btn {
    transition: transform 0.2s ease, opacity 0.2s;
    cursor: pointer;
}

/* Tieline rows visual distinction */
.tieline-row td {
    border-bottom: 1px solid #00897b30;
}



/* ========================================
   Theme Transitions — smooth color switch
   ======================================== */
.main-content,
.project-header,
.tab-bar,
.modal,
.modal-overlay,
.io-section,
.data-table,
.cell-input,
.btn {
    transition: background var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme);
}

/* Welcome screen — dark-aware */
#welcomeScreen h2 {
    color: var(--text-bright);
}

#welcomeScreen p {
    color: var(--text-secondary);
}

/* Welcome screen — dark-aware */
#welcomeScreen h2 {
    color: var(--text-bright);
}

#welcomeScreen p {
    color: var(--text-secondary);
}

/* ========================================
   Help Mode System
   ======================================== */

/* Help toggle button — active state */
#helpModeBtn.help-active {
    color: #f0c040;
    background: rgba(240, 192, 64, 0.1);
    border-radius: 4px;
}

#helpModeBtn.help-active svg {
    stroke: #f0c040;
}

/* Floating tooltip panel */
.help-tooltip {
    position: fixed;
    z-index: 9999;
    max-width: 300px;
    min-width: 200px;
    background: var(--bg-elevated, #1e1e1e);
    border: 1px solid rgba(240, 192, 64, 0.4);
    border-left: 3px solid #f0c040;
    border-radius: 4px;
    padding: 10px 14px;
    pointer-events: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    animation: helpTooltipIn 0.12s ease;
}

@keyframes helpTooltipIn {
    from {
        opacity: 0;
        transform: translateY(4px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.help-tooltip-title {
    font-size: 11px;
    font-weight: 700;
    color: #f0c040;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.help-tooltip-body {
    font-size: 12px;
    color: var(--text-secondary, #888);
    line-height: 1.5;
}

.help-tooltip-hint {
    font-size: 10px;
    color: var(--text-muted, #444);
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-style: italic;
}

/* In help mode: highlight hoverable elements with a subtle ring */
body.help-mode [data-help]:hover {
    outline: 1.5px dashed rgba(240, 192, 64, 0.5) !important;
    outline-offset: 2px;
    cursor: help !important;
}

/* Sustained highlight when element has active help shown */
body.help-mode [data-help].help-focused {
    outline: 2px solid rgba(240, 192, 64, 0.7) !important;
    outline-offset: 2px;
}

/* Help mode indicator bar (thin line at very top of sidebar) */
body.help-mode .sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #f0c040, transparent);
    z-index: 100;
}

/* Subtle pulse on the help button itself when in help mode */
@keyframes helpPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(240, 192, 64, 0.3);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(240, 192, 64, 0);
    }
}

#helpModeBtn.help-active {
    animation: helpPulse 2.5s ease-in-out infinite;
}

/* ===== Info Drawer ===== */
.info-mfr-btn.active {
    background: var(--accent-bg);
    color: var(--accent);
    border-left: 2px solid var(--accent);
}

.info-content {
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-primary);
    padding-top: 8px;
}

.info-content p {
    margin: 0 0 6px;
    color: var(--text-secondary);
}

.info-section {
    margin-bottom: 14px;
}

.info-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    margin-bottom: 4px;
}

.info-table th {
    text-align: left;
    padding: 3px 6px;
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 10px;
}

.info-table td {
    padding: 3px 6px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.info-table tr:last-child td {
    border-bottom: none;
}

#infoDrawerList {
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
    margin-bottom: 4px;
}

#infoDrawerContent {
    overflow-y: auto;
    padding: 0 0 16px;
}

/* Info Drawer: overflow:hidden nur wenn offen (kein inline-style) */
#drawer-info.open {
    overflow: hidden;
}

/* ========================================
   Task 9: Tab-Pos vs Tab-Util Styling
   ======================================== */
.tab-item.tab-pos {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    padding: 7px 14px;
}

.tab-item.tab-pos.active {
    background: var(--bg-primary);
    color: var(--accent);
    border-color: var(--border);
    border-bottom-color: var(--bg-primary);
}

.tab-item.tab-pos.active::after {
    background: var(--bg-primary);
}

.tab-item.tab-util {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 5px 10px;
    opacity: 0.85;
}

.tab-item.tab-util:hover {
    opacity: 1;
    color: var(--text-secondary);
}

.tab-item.tab-util.active {
    opacity: 1;
    color: var(--text-primary);
    background: var(--bg-primary);
    border-color: var(--border);
}

.tab-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 6px;
    flex-shrink: 0;
    align-self: center;
}

/* ========================================
   Task 8: Save Button
   ======================================== */
.save-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    opacity: 0.7;
}

.save-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.save-btn.save-dirty {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    animation: savePulse 2s ease-in-out infinite;
}

@keyframes savePulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(var(--accent-rgb, 100, 160, 255), 0.4);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(var(--accent-rgb, 100, 160, 255), 0);
    }
}

/* ========================================
   Task 2: Drag Handle verbessert  
   ======================================== */
.drag-handle {
    cursor: grab !important;
    user-select: none;
    touch-action: none;
    color: var(--text-muted);
    padding: 0 1px;
    font-size: 14px;
    text-align: center;
}

.drag-handle:active {
    cursor: grabbing !important;
}

tr[draggable="true"]:hover .drag-handle {
    color: var(--accent);
}

/* ========================================
   Task 16: Loom-Belegung Grid
   ======================================== */
.loom-belegung-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 0;
}

.loom-belegung-card {
    flex: 0 0 auto;
    min-width: 180px;
    max-width: 220px;
    border: 2px solid;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.loom-belegung-header {
    padding: 6px 10px;
    font-weight: 700;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.loom-belegung-card table {
    width: 100%;
    font-size: 11px;
    border-collapse: collapse;
}

.loom-belegung-card td {
    padding: 2px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* ========================================
   Task 7: Mobile Responsive Improvements
   ======================================== */
@media (max-width: 768px) {

    /* Tab bar wraps */
    .tab-bar {
        flex-wrap: wrap;
        justify-content: flex-start;
        padding: 4px 8px;
        gap: 2px;
    }

    .tab-item {
        padding: 4px 8px;
        font-size: 11px;
    }

    .tab-item.tab-pos {
        font-size: 12px;
        padding: 5px 10px;
    }

    .tab-item.tab-util {
        font-size: 10px;
        padding: 3px 7px;
    }

    /* Header stacks vertically */
    .project-header {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding: var(--space-sm) var(--space-md);
    }

    .header-center,
    .header-right {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    /* Panels full width stacked */
    .position-split-layout {
        flex-direction: column !important;
    }

    .position-inputs,
    .position-io {
        width: 100% !important;
        max-width: none !important;
    }

    /* Tables scroll horizontally */
    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Save button in header */
    .save-btn {
        font-size: 10px;
        padding: 3px 8px;
    }

    /* Sub-tabs wrap */
    .sb-subtabs {
        flex-wrap: wrap;
        gap: 3px;
    }
}

@media (max-width: 480px) {
    .tab-divider {
        display: none;
    }

    .tab-icon {
        display: none;
    }

    .project-header {
        padding: 4px 8px;
    }
}