/* ============================================
   Micro Processing - Main Stylesheet
   ============================================ */

/* --- CSS Variables --- */
:root {
    --bg-primary: #f5f6fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef0f5;
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --text-muted: #95a5a6;
    --border-color: #dee2e6;
    --border-light: #e9ecef;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Status colors */
    --color-blue: #3498db;
    --color-blue-bg: #ebf5fb;
    --color-green: #27ae60;
    --color-green-bg: #eafaf1;
    --color-red: #e74c3c;
    --color-red-bg: #fdedec;
    --color-yellow: #f39c12;
    --color-yellow-bg: #fef9e7;
    --color-purple: #8e44ad;
    --color-purple-bg: #f4ecf7;
    --color-gray: #95a5a6;
    --color-gray-bg: #f2f3f4;

    /* Tab bar */
    --tab-bg: #ffffff;
    --tab-active-color: #3498db;
    --tab-hover-bg: #f0f4f8;

    /* Cards */
    --card-bg: #ffffff;

    /* Log viewer */
    --log-bg: #1a1a2e;
    --log-text: #e0e0e0;
    --log-green: #4ecca3;
    --log-red: #ff6b6b;
    --log-yellow: #ffd93d;
    --log-blue: #6c9bff;

    /* Overlay */
    --overlay-bg: rgba(0, 0, 0, 0.5);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* --- Dark Mode Variables --- */
[data-theme="dark"] {
    --bg-primary: #1a1d23;
    --bg-secondary: #242830;
    --bg-tertiary: #2a2e36;
    --text-primary: #e4e6ea;
    --text-secondary: #a0a4ab;
    --text-muted: #6c717a;
    --border-color: #3a3e47;
    --border-light: #2e323a;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    --color-blue-bg: #1a2a3a;
    --color-green-bg: #1a2e24;
    --color-red-bg: #2e1a1a;
    --color-yellow-bg: #2e2a1a;
    --color-purple-bg: #2a1a2e;
    --color-gray-bg: #2a2e36;

    --tab-bg: #242830;
    --tab-active-color: #5dade2;
    --tab-hover-bg: #2e323a;

    --card-bg: #242830;

    --log-bg: #0d0d1a;

    --overlay-bg: rgba(0, 0, 0, 0.7);
}

/* ============================================
   Base Layout
   ============================================ */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   Tab Bar
   ============================================ */
.tab-bar {
    display: flex;
    background: var(--tab-bg);
    border-bottom: 2px solid var(--border-color);
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    position: sticky;
    top: 0;
    z-index: 100;
}

.tab-bar::-webkit-scrollbar {
    height: 3px;
}

.tab-bar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.tab-btn {
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

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

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

/* ============================================
   Tab Content
   ============================================ */
.tab-content {
    padding: 20px;
    min-height: calc(100vh - 120px);
}

/* ============================================
   Stat Cards (Dashboard)
   ============================================ */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 16px;
    border-left: 4px solid var(--border-color);
    transition: box-shadow var(--transition-normal), transform var(--transition-fast);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card.blue { border-left-color: var(--color-blue); }
.stat-card.green { border-left-color: var(--color-green); }
.stat-card.red { border-left-color: var(--color-red); }
.stat-card.yellow { border-left-color: var(--color-yellow); }
.stat-card.purple { border-left-color: var(--color-purple); }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-card.blue .stat-icon { background: var(--color-blue-bg); color: var(--color-blue); }
.stat-card.green .stat-icon { background: var(--color-green-bg); color: var(--color-green); }
.stat-card.red .stat-icon { background: var(--color-red-bg); color: var(--color-red); }
.stat-card.yellow .stat-icon { background: var(--color-yellow-bg); color: var(--color-yellow); }
.stat-card.purple .stat-icon { background: var(--color-purple-bg); color: var(--color-purple); }

.stat-info {
    flex: 1;
    min-width: 0;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text-primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ============================================
   Section Headers
   ============================================ */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

/* ============================================
   Instance Status Grid (Dashboard)
   ============================================ */
.instance-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.instance-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    transition: box-shadow var(--transition-normal);
}

.instance-card:hover {
    box-shadow: var(--shadow-md);
}

.instance-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.instance-name {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.instance-camera-count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 12px;
}

/* Status dot with pulsing animation */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.green {
    background: var(--color-green);
    box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.4);
    animation: pulse-green 2s infinite;
}

.status-dot.yellow {
    background: var(--color-yellow);
    box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.4);
    animation: pulse-yellow 2s infinite;
}

.status-dot.red {
    background: var(--color-red);
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4);
    animation: pulse-red 2s infinite;
}

.status-dot.gray {
    background: var(--color-gray);
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(39, 174, 96, 0); }
    100% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0); }
}

@keyframes pulse-yellow {
    0% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(243, 156, 18, 0); }
    100% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0); }
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

.instance-camera-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 13px;
    max-height: 150px;
    overflow-y: auto;
}

.instance-camera-list li {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.instance-camera-list li:last-child {
    border-bottom: none;
}

.instance-load-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    margin-top: 12px;
    overflow: hidden;
}

.instance-load-fill {
    height: 100%;
    border-radius: 2px;
    transition: width var(--transition-normal);
}

.instance-load-fill.low { background: var(--color-green); }
.instance-load-fill.medium { background: var(--color-yellow); }
.instance-load-fill.high { background: var(--color-red); }

/* ============================================
   DataTable Customization (Cameras Tab)
   ============================================ */
.camera-table-wrapper {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    overflow-x: auto;
}

.dataTables_wrapper {
    font-size: 14px;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    color: var(--text-secondary) !important;
    padding: 8px 0;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition-fast);
}

.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
    border-color: var(--color-blue);
}

table.dataTable {
    border-collapse: collapse !important;
    width: 100% !important;
}

table.dataTable thead th {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border-color) !important;
}

table.dataTable tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light) !important;
    vertical-align: middle;
    color: var(--text-primary);
}

table.dataTable tbody tr:hover {
    background: var(--tab-hover-bg) !important;
}

/* Row color coding by timestamp freshness */
table.dataTable tbody tr.freshness-fresh {
    border-left: 3px solid var(--color-green);
}

table.dataTable tbody tr.freshness-stale {
    border-left: 3px solid var(--color-yellow);
}

table.dataTable tbody tr.freshness-old {
    border-left: 3px solid var(--color-red);
}

table.dataTable tbody tr.freshness-archived {
    border-left: 3px solid var(--color-gray);
    opacity: 0.7;
}

/* DataTable pagination */
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 4px 12px !important;
    border-radius: var(--radius-sm) !important;
    border: 1px solid var(--border-color) !important;
    background: var(--bg-secondary) !important;
    color: var(--text-secondary) !important;
    margin: 0 2px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--color-blue) !important;
    color: #fff !important;
    border-color: var(--color-blue) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover:not(.current) {
    background: var(--tab-hover-bg) !important;
    color: var(--text-primary) !important;
}

/* Status toggle switch */
.status-toggle {
    position: relative;
    width: 42px;
    height: 22px;
    display: inline-block;
}

.status-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.status-toggle .slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--color-gray);
    border-radius: 22px;
    transition: background var(--transition-fast);
}

.status-toggle .slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.status-toggle input:checked + .slider {
    background: var(--color-green);
}

.status-toggle input:checked + .slider::before {
    transform: translateX(20px);
}

/* ============================================
   Instance Manager (Instances Tab)
   ============================================ */
.instance-manager {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.instance-column {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 2px solid var(--border-light);
    min-height: 300px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.instance-column.drag-over {
    border-color: var(--color-blue);
    box-shadow: var(--shadow-md);
    background: var(--color-blue-bg);
}

.instance-column-header {
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-light);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.instance-column-title {
    font-weight: 600;
    font-size: 14px;
}

.instance-column-count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 10px;
}

.instance-column-body {
    padding: 12px;
    min-height: 200px;
}

/* Draggable camera cards */
.camera-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
    user-select: none;
}

.camera-card:hover {
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.camera-card:active {
    cursor: grabbing;
}

.camera-card .camera-serial {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.camera-card .camera-name {
    font-size: 13px;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sortable ghost/chosen styling */
.sortable-ghost {
    opacity: 0.4;
    background: var(--color-blue-bg) !important;
    border: 2px dashed var(--color-blue) !important;
}

.sortable-chosen {
    box-shadow: var(--shadow-md);
}

.sortable-drag {
    box-shadow: var(--shadow-lg);
}

/* Unassigned pool */
.unassigned-pool {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 2px dashed var(--border-color);
    padding: 16px;
}

.unassigned-pool-header {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.unassigned-pool-body {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 60px;
}

.unassigned-pool .camera-card {
    flex: 0 0 auto;
    margin-bottom: 0;
}

/* Instance load indicator */
.instance-load-indicator {
    padding: 8px 16px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

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

.instance-load-indicator .load-fill {
    height: 100%;
    border-radius: 3px;
    transition: width var(--transition-normal);
}

.instance-load-indicator .load-fill.low { background: var(--color-green); }
.instance-load-indicator .load-fill.medium { background: var(--color-yellow); }
.instance-load-indicator .load-fill.high { background: var(--color-red); }

/* ============================================
   B2 Account Cards
   ============================================ */
.b2-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.b2-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    overflow: hidden;
    transition: box-shadow var(--transition-normal);
}

.b2-card:hover {
    box-shadow: var(--shadow-md);
}

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

.b2-card-name {
    font-weight: 600;
    font-size: 15px;
}

.b2-card-id {
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.b2-card-body {
    padding: 16px;
}

/* Capacity progress bar */
.b2-capacity {
    margin-bottom: 12px;
}

.b2-capacity-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.b2-capacity-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.b2-capacity-fill {
    height: 100%;
    border-radius: 4px;
    transition: width var(--transition-normal);
}

.b2-capacity-fill.green { background: var(--color-green); }
.b2-capacity-fill.yellow { background: var(--color-yellow); }
.b2-capacity-fill.red { background: var(--color-red); }

/* Expandable camera list */
.b2-camera-toggle {
    background: none;
    border: none;
    color: var(--color-blue);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.b2-camera-toggle:hover {
    text-decoration: underline;
}

.b2-camera-toggle .arrow {
    transition: transform var(--transition-fast);
    display: inline-block;
}

.b2-camera-toggle.expanded .arrow {
    transform: rotate(90deg);
}

.b2-camera-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.b2-camera-list.expanded {
    max-height: 500px;
    overflow-y: auto;
}

.b2-camera-list li {
    padding: 4px 0;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
}

.b2-camera-list li:last-child {
    border-bottom: none;
}

/* ============================================
   Log Viewer (Logs Tab)
   ============================================ */
.log-viewer {
    background: var(--log-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.log-filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
}

.log-filter-bar select,
.log-filter-bar input {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--log-text);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
}

.log-filter-bar select:focus,
.log-filter-bar input:focus {
    border-color: var(--color-blue);
}

.log-filter-bar label {
    color: var(--log-text);
    font-size: 13px;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--log-green);
    margin-left: auto;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--log-green);
    animation: pulse-green 1.5s infinite;
}

.live-indicator.paused {
    color: var(--color-gray);
}

.live-indicator.paused .live-dot {
    background: var(--color-gray);
    animation: none;
}

.log-output {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 16px;
    max-height: calc(100vh - 260px);
    min-height: 400px;
    overflow-y: auto;
    color: var(--log-text);
    white-space: pre-wrap;
    word-break: break-all;
}

.log-line {
    padding: 1px 0;
}

.log-line.success { color: var(--log-green); }
.log-line.error { color: var(--log-red); }
.log-line.warning { color: var(--log-yellow); }
.log-line.info { color: var(--log-text); }
.log-line.debug { color: var(--log-blue); }

.log-line .log-timestamp {
    color: rgba(255, 255, 255, 0.4);
    margin-right: 8px;
}

.log-line .log-level {
    font-weight: 600;
    margin-right: 8px;
}

.log-empty {
    text-align: center;
    padding: 60px 20px;
    color: rgba(255, 255, 255, 0.3);
    font-size: 15px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
    white-space: nowrap;
    line-height: 1.4;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: #2980b9;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

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

.btn-success:hover {
    background: #219a52;
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.3);
}

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

.btn-danger:hover {
    background: #c0392b;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

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

/* ============================================
   Modals
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay-bg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-dialog {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform var(--transition-normal);
}

.modal-overlay.visible .modal-dialog {
    transform: translateY(0);
}

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

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ============================================
   Confirm Overlay
   ============================================ */
.confirm-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay-bg);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.confirm-dialog {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    max-width: 420px;
    width: 100%;
    text-align: center;
}

.confirm-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.confirm-message {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.confirm-actions .btn {
    min-width: 100px;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 14px 18px;
    min-width: 280px;
    max-width: 400px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    border-left: 4px solid var(--border-color);
    animation: toast-slide-in 0.3s ease;
    pointer-events: auto;
    position: relative;
    overflow: hidden;
}

.toast.removing {
    animation: toast-slide-out 0.3s ease forwards;
}

.toast.success { border-left-color: var(--color-green); }
.toast.error { border-left-color: var(--color-red); }
.toast.info { border-left-color: var(--color-blue); }
.toast.warning { border-left-color: var(--color-yellow); }

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1;
}

.toast.success .toast-icon { color: var(--color-green); }
.toast.error .toast-icon { color: var(--color-red); }
.toast.info .toast-icon { color: var(--color-blue); }
.toast.warning .toast-icon { color: var(--color-yellow); }

.toast-body {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.toast-message {
    font-size: 13px;
    color: var(--text-secondary);
}

.toast-close {
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    line-height: 1;
}

.toast-close:hover {
    color: var(--text-primary);
}

/* Toast progress bar (auto-dismiss) */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    border-radius: 0 0 0 var(--radius-md);
    animation: toast-progress 5s linear forwards;
}

.toast.success .toast-progress { background: var(--color-green); }
.toast.error .toast-progress { background: var(--color-red); }
.toast.info .toast-progress { background: var(--color-blue); }
.toast.warning .toast-progress { background: var(--color-yellow); }

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-slide-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes toast-progress {
    from { width: 100%; }
    to { width: 0%; }
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
    border-color: var(--color-blue);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================
   Badges & Labels
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-green { background: var(--color-green-bg); color: var(--color-green); }
.badge-red { background: var(--color-red-bg); color: var(--color-red); }
.badge-yellow { background: var(--color-yellow-bg); color: var(--color-yellow); }
.badge-blue { background: var(--color-blue-bg); color: var(--color-blue); }
.badge-purple { background: var(--color-purple-bg); color: var(--color-purple); }
.badge-gray { background: var(--color-gray-bg); color: var(--color-gray); }

/* ============================================
   Toolbar / Action Bar
   ============================================ */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar-spacer {
    flex: 1;
}

.toolbar .search-input {
    max-width: 260px;
}

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

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state-message {
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto;
}

/* ============================================
   Loading State
   ============================================ */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

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

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

.loading-text {
    margin-left: 12px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================
   Cards (generic)
   ============================================ */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}

.card-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
}

.card-body {
    padding: 16px;
}

/* ============================================
   Stats Tab
   ============================================ */
.stats-container {
    padding: 0 20px 20px;
}

.stats-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.stats-kpi-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stats-chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.chart-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.chart-wrap {
    position: relative;
    height: 260px;
}

.chart-wrap-sm {
    height: 220px;
}

.chart-wrap-tall {
    height: 360px;
}

/* ============================================
   Timeline Tab
   ============================================ */
.timeline-container {
    padding: 0 20px 20px;
}

.timeline-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.timeline-toolbar .form-input-sm,
.timeline-toolbar .form-select-sm {
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.timeline-events {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    overflow: hidden;
}

.tl-row {
    display: grid;
    grid-template-columns: 24px 80px 1fr 110px 1fr;
    gap: 8px;
    align-items: center;
    padding: 8px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition-fast);
}

.tl-row:last-child {
    border-bottom: none;
}

.tl-row:hover {
    background: var(--bg-tertiary);
}

.tl-icon {
    text-align: center;
    font-size: 10px;
}

.tl-success .tl-icon { color: var(--color-green); }
.tl-error .tl-icon { color: var(--color-red); }
.tl-warning .tl-icon { color: var(--color-yellow); }
.tl-info .tl-icon { color: var(--color-blue); }

.tl-time {
    color: var(--text-muted);
    font-family: monospace;
    font-size: 12px;
}

.tl-cam {
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tl-status {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    text-align: center;
    font-weight: 500;
}

.tl-success .tl-status { background: var(--color-green-bg); color: var(--color-green); }
.tl-error .tl-status { background: var(--color-red-bg); color: var(--color-red); }
.tl-warning .tl-status { background: var(--color-yellow-bg); color: var(--color-yellow); }
.tl-info .tl-status { background: var(--color-blue-bg); color: var(--color-blue); }

.tl-detail {
    color: var(--text-secondary);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-empty {
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.timeline-footer {
    margin-top: 12px;
    text-align: center;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
    .instance-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .instance-manager {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .tab-bar {
        padding: 0 8px;
    }

    .tab-btn {
        padding: 10px 14px;
        font-size: 13px;
    }

    .tab-content {
        padding: 12px;
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 22px;
    }

    .instance-grid {
        grid-template-columns: 1fr;
    }

    .instance-manager {
        grid-template-columns: 1fr;
    }

    .b2-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .modal-dialog {
        max-width: 100%;
        margin: 0;
        border-radius: var(--radius-md);
    }

    .toast-container {
        left: 12px;
        right: 12px;
        bottom: 12px;
    }

    .toast {
        min-width: auto;
        max-width: 100%;
    }

    .log-filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .live-indicator {
        margin-left: 0;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar .search-input {
        max-width: 100%;
    }

    .stats-kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }
    .stats-chart-grid {
        grid-template-columns: 1fr;
    }
    .tl-row {
        grid-template-columns: 24px 70px 1fr;
    }
    .tl-status,
    .tl-detail {
        display: none;
    }
}

@media (max-width: 480px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 12px;
        gap: 12px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .stat-value {
        font-size: 20px;
    }

    .confirm-dialog {
        padding: 20px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .stats-kpi-row {
        grid-template-columns: 1fr;
    }
    .timeline-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ============================================
   Utility Classes
   ============================================ */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--color-green); }
.text-danger { color: var(--color-red); }
.text-warning { color: var(--color-yellow); }
.text-info { color: var(--color-blue); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.mono {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hidden {
    display: none !important;
}

/* ============================================
   Missing Classes - Bridge between JS and CSS
   ============================================ */

/* Toggle switch for processing enabled/disabled */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--color-gray);
    border-radius: 22px;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--color-green);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* DataTable row color coding */
.row-fresh td { border-left: 3px solid var(--color-green) !important; }
.row-stale td { border-left: 3px solid var(--color-yellow) !important; }
.row-offline td { border-left: 3px solid var(--color-red) !important; }
.row-archived td { opacity: 0.5; border-left: 3px solid var(--color-gray) !important; }
.row-fresh { background-color: rgba(39, 174, 96, 0.05) !important; }
.row-stale { background-color: rgba(243, 156, 18, 0.05) !important; }
.row-offline { background-color: rgba(231, 76, 60, 0.05) !important; }
.row-archived { background-color: rgba(149, 165, 166, 0.05) !important; }
[data-theme="dark"] .row-fresh { background-color: rgba(39, 174, 96, 0.1) !important; }
[data-theme="dark"] .row-stale { background-color: rgba(243, 156, 18, 0.1) !important; }
[data-theme="dark"] .row-offline { background-color: rgba(231, 76, 60, 0.1) !important; }
[data-theme="dark"] .row-archived { background-color: rgba(149, 165, 166, 0.1) !important; }

/* Instances grid */
.instances-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
@media (max-width: 900px) {
    .instances-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 600px) {
    .instances-grid {
        grid-template-columns: 1fr;
    }
}

/* Instance column (drag-and-drop) */
.instance-col-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom: 1px solid var(--border-color);
}
.instance-col-name {
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: capitalize;
}
.instance-col-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.instance-col-cards {
    min-height: 80px;
    padding: 8px;
    background: var(--bg-secondary);
    border: 2px dashed transparent;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    transition: border-color 0.2s;
}
.instance-col-cards.sortable-drag-over {
    border-color: var(--color-blue);
    background: var(--color-blue-bg);
}

/* Load bar */
.load-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}
.load-bar-fill {
    height: 100%;
    background: var(--color-blue);
    border-radius: 2px;
    transition: width 0.3s;
}

/* Capacity bar (B2 accounts) */
.capacity-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 4px;
}
.capacity-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}
.capacity-green .capacity-bar-fill { background: var(--color-green); }
.capacity-yellow .capacity-bar-fill { background: var(--color-yellow); }
.capacity-red .capacity-bar-fill { background: var(--color-red); }

/* Processing enabled dot */
.proc-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.proc-enabled { background: var(--color-green); }
.proc-disabled { background: var(--color-gray); }

/* Stat card type variants */
.stat-camera { border-left-color: var(--color-blue); }
.stat-camera .stat-value { color: var(--color-blue); }
.stat-image { border-left-color: var(--color-green); }
.stat-image .stat-value { color: var(--color-green); }
.stat-error { border-left-color: var(--color-red); }
.stat-error .stat-value { color: var(--color-red); }
.stat-instance { border-left-color: var(--color-purple); }
.stat-instance .stat-value { color: var(--color-purple); }
.stat-processing { border-left-color: var(--color-yellow); }
.stat-processing .stat-value { color: var(--color-yellow); }

/* Dashboard instance status */
.instance-green { border-left: 3px solid var(--color-green); }
.instance-yellow { border-left: 3px solid var(--color-yellow); }
.instance-red { border-left: 3px solid var(--color-red); }

/* Live mode indicator */
.live-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.live-label {
    font-size: 0.85rem;
    font-weight: 500;
}
.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-gray);
    transition: background 0.2s;
}
.live-dot.live-active {
    background: var(--color-green);
    animation: pulse-green 1.5s infinite;
}
@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(39, 174, 96, 0); }
}

/* Unsaved indicator */
.unsaved-indicator {
    color: var(--color-yellow);
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
}
.unsaved-indicator::before {
    content: '●';
}

/* Pool header/cards */
.pool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.pool-header h3 {
    margin: 0;
    font-size: 1rem;
}
.pool-count {
    color: var(--text-secondary);
    font-weight: normal;
}
.pool-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px;
    padding: 8px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
}

/* Camera card top/name/meta */
.camera-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.camera-card-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.camera-card-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* B2 account card details */
.b2-summary {
    display: flex;
    gap: 24px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}
.b2-summary span {
    font-weight: 600;
    font-size: 0.9rem;
}
.b2-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}
.b2-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.b2-account-id {
    font-family: 'SF Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
}
.b2-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
}
.badge-archived {
    background: var(--color-gray-bg);
    color: var(--color-gray);
}
.b2-card-details {
    margin-bottom: 12px;
}
.b2-detail {
    font-size: 0.85rem;
    margin-bottom: 2px;
}
.b2-label {
    color: var(--text-secondary);
}
.b2-capacity {
    margin-bottom: 8px;
}
.b2-capacity-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.b2-camera-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.b2-cameras-list {
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}
.b2-camera-item {
    display: flex;
    gap: 8px;
    padding: 2px 0;
    font-size: 0.8rem;
}
.b2-cam-serial {
    font-family: 'SF Mono', monospace;
    color: var(--color-blue);
}
.b2-cam-name {
    color: var(--text-secondary);
}
.b2-archived {
    opacity: 0.6;
}
.b2-toggle-cameras {
    margin-top: 4px;
}
.b2-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
}

/* Log viewer extras */
.logs-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}
.logs-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.logs-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}
.log-line-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.log-line {
    padding: 2px 8px;
    font-size: 0.85rem;
    line-height: 1.5;
    border-left: 2px solid transparent;
}
.log-line:hover {
    background: rgba(255, 255, 255, 0.05);
}
.log-info { color: var(--log-text); }
.log-success { color: var(--log-green); border-left-color: var(--log-green); }
.log-error { color: var(--log-red); border-left-color: var(--log-red); }
.log-time {
    color: var(--log-blue);
    margin-right: 4px;
}
.log-instance {
    color: var(--log-yellow);
}
.log-camera {
    color: #b39ddb;
}
.log-instance.clickable,
.log-camera.clickable {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
}
.log-instance.clickable:hover,
.log-camera.clickable:hover {
    opacity: 0.8;
}
.log-empty {
    color: var(--text-muted);
    font-style: italic;
}

/* Instances/cameras toolbar */
.instances-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 12px;
}
.cameras-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 12px;
}
.toolbar-left {
    display: flex;
    gap: 8px;
    align-items: center;
}
.toolbar-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* DataTable column alignment */
.col-toggle {
    width: 60px;
    text-align: center;
}

/* Dashboard refresh bar */
.dashboard-refresh-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.refresh-label {
    color: var(--text-secondary);
}

/* Activity feed */
.activity-feed {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}
.activity-item {
    display: flex;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.85rem;
}
.activity-item:last-child {
    border-bottom: none;
}
.activity-time {
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 60px;
}
.activity-msg {
    word-break: break-word;
}
.activity-info { color: var(--text-primary); }
.activity-success .activity-msg { color: var(--color-green); }
.activity-error .activity-msg { color: var(--color-red); }
.activity-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
}

/* Section header */
.section-header {
    margin: 16px 0 8px 0;
}
.section-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

/* Instance detail row */
.instance-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.instance-name {
    font-weight: 600;
    text-transform: capitalize;
}
.instance-detail {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.instance-last-run {
    color: var(--text-muted);
}

/* Error message */
.error-message {
    padding: 16px;
    background: var(--color-red-bg);
    color: var(--color-red);
    border-radius: var(--radius-sm);
    text-align: center;
}

/* ============================================
   Form Inputs & Selects (used in modals/logs)
   ============================================ */
.form-input,
.form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    font-family: inherit;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--color-blue);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

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

.form-select {
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236c757d' stroke-width='2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

/* Form half-width (side-by-side) */
.form-half {
    flex: 1;
    min-width: 0;
}

/* Form actions (modal footer buttons) */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
    margin-top: 8px;
}

/* ============================================
   Button Variants (xs, warning)
   ============================================ */
.btn-xs {
    padding: 3px 8px;
    font-size: 12px;
    line-height: 1.4;
}

.btn-warning {
    background: var(--color-yellow);
    color: #fff;
}

.btn-warning:hover {
    background: #e08e0b;
    box-shadow: 0 2px 8px rgba(243, 156, 18, 0.3);
}

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

.btn:focus {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

/* ============================================
   Dark Mode - Extended Coverage
   ============================================ */
[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a0a4ab' stroke-width='2'/%3E%3C/svg%3E");
}

[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, 0.75);
}

[data-theme="dark"] .modal-dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .modal-header {
    border-bottom-color: var(--border-color);
}

[data-theme="dark"] .confirm-dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] table.dataTable thead th {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-color: var(--border-color) !important;
}

[data-theme="dark"] table.dataTable tbody td {
    color: var(--text-primary);
    border-bottom-color: var(--border-color) !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover {
    background: var(--bg-tertiary) !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    background: var(--bg-tertiary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--color-blue) !important;
    color: #fff !important;
}

[data-theme="dark"] .b2-card {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .instance-card {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .instance-column {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .camera-card {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

[data-theme="dark"] .log-camera {
    color: #ce93d8;
}

[data-theme="dark"] .toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
}

/* ============================================
   Toggle switch keyboard accessibility
   ============================================ */
.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

/* ============================================
   Camera Image Grid (Dashboard)
   ============================================ */
.camera-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.camera-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.camera-controls .form-select-sm {
    width: auto;
    padding: 4px 28px 4px 8px;
    font-size: 12px;
}

.camera-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.camera-image-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    transition: box-shadow var(--transition-normal), transform var(--transition-fast);
}

.camera-image-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.camera-image-card.camera-card-archived {
    opacity: 0.6;
    border-left: 3px solid var(--color-gray);
}

.camera-image-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
    background: var(--bg-tertiary);
}

.camera-card-noimage {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 13px;
}

.camera-image-card .camera-image-info {
    padding: 8px 12px;
}

.camera-card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.camera-image-card .camera-image-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
}

.camera-image-card .camera-image-serial {
    font-size: 11px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-muted);
    margin-top: 2px;
}

.camera-card-bottom {
    margin-top: 4px;
}

.camera-image-card .camera-image-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.camera-card-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.camera-image-card .camera-image-status {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.camera-image-card .camera-image-status.fresh { background: var(--color-green); }
.camera-image-card .camera-image-status.stale { background: var(--color-yellow); }
.camera-image-card .camera-image-status.offline { background: var(--color-red); }

/* Small toggle switch for camera cards */
.toggle-sm {
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}

.toggle-sm .toggle-slider::before {
    width: 12px;
    height: 12px;
}

.toggle-sm input:checked + .toggle-slider::before {
    transform: translateX(14px);
}

[data-theme="dark"] .camera-image-card {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

/* ============================================
   Responsive Improvements
   ============================================ */

/* Touch-friendly inputs on mobile */
@media (max-width: 768px) {
    .form-input,
    .form-select {
        padding: 10px 12px;
        font-size: 16px; /* Prevents iOS zoom */
    }

    .logs-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .logs-filters {
        flex-direction: column;
    }

    .logs-filters .form-input,
    .logs-filters .form-select {
        width: 100%;
    }

    .logs-actions {
        justify-content: space-between;
    }

    .log-output {
        max-height: calc(100vh - 320px);
        min-height: 250px;
    }

    .camera-section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .camera-controls {
        width: 100%;
        justify-content: space-between;
    }

    .camera-images-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 8px;
    }

    .camera-image-card img {
        height: 110px;
    }

    .camera-card-noimage {
        height: 70px;
    }

    .b2-summary {
        flex-wrap: wrap;
        gap: 12px;
    }

    .b2-cards-grid {
        grid-template-columns: 1fr;
    }

    .cameras-toolbar {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    .instances-toolbar {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    .toolbar-right {
        justify-content: flex-end;
    }

    .dashboard-refresh-bar {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .camera-images-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .camera-image-card img {
        height: 90px;
    }

    .camera-card-noimage {
        height: 60px;
        font-size: 11px;
    }

    .camera-image-card .camera-image-info {
        padding: 6px 8px;
    }

    .camera-image-card .camera-image-name {
        font-size: 11px;
    }

    .camera-card-actions .btn-xs {
        padding: 2px 5px;
        font-size: 10px;
    }

    .tab-btn {
        padding: 8px 10px;
        font-size: 12px;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }
}
