/* ========================================
   MG Mold Counter Dashboard - CSS
   Magotteaux Saraburi - Iron Ball Line
   ======================================== */

:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #263548;
    --bg-surface: #1a2332;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;

    --color-primary: #3b82f6;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #06b6d4;

    --color-success-bg: rgba(34, 197, 94, 0.12);
    --color-warning-bg: rgba(245, 158, 11, 0.12);
    --color-danger-bg: rgba(239, 68, 68, 0.15);
    --color-info-bg: rgba(6, 182, 212, 0.12);

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

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

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

/* ==========================================
   Top Bar
   ========================================== */

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.2;
}

.logo small {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.server-time {
    font-size: 1.1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-success);
    letter-spacing: 0.08em;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot-green {
    background: var(--color-success);
    box-shadow: 0 0 8px var(--color-success);
    animation: pulse-dot 2s infinite;
}

.dot-red {
    background: var(--color-danger);
    box-shadow: 0 0 8px var(--color-danger);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-reset:hover {
    border-color: var(--color-warning);
    color: var(--color-warning);
}

/* ==========================================
   Stats Bar
   ========================================== */

.stats-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
    padding: 1rem 1.5rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-primary .stat-icon { background: rgba(59, 130, 246, 0.15); color: var(--color-primary); }
.stat-danger .stat-icon { background: rgba(239, 68, 68, 0.15); color: var(--color-danger); }
.stat-warning .stat-icon { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); }
.stat-success .stat-icon { background: rgba(34, 197, 94, 0.15); color: var(--color-success); }
.stat-info .stat-icon { background: rgba(6, 182, 212, 0.15); color: var(--color-info); }

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.stat-primary .stat-value { color: var(--color-primary); }
.stat-danger .stat-value { color: var(--color-danger); }
.stat-warning .stat-value { color: var(--color-warning); }
.stat-success .stat-value { color: var(--color-success); }
.stat-info .stat-value { color: var(--color-info); }

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ==========================================
   Speed Control
   ========================================== */

.speed-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

.speed-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.speed-buttons {
    display: flex;
    gap: 0.35rem;
}

.speed-btn {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.speed-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.speed-btn.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.speed-current {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--color-primary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    margin-left: auto;
}

/* ==========================================
   Event Ticker
   ========================================== */

.event-ticker {
    display: flex;
    align-items: center;
    margin: 0 1.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
}

.ticker-label {
    flex-shrink: 0;
    padding: 0.25rem 0.75rem;
    background: var(--color-primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 4px;
    letter-spacing: 0.1em;
    margin-right: 1rem;
}

.ticker-content {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.ticker-content .event-item {
    display: inline-block;
    margin-right: 2rem;
    animation: ticker-scroll 20s linear infinite;
}

.event-cycle { color: var(--color-info); }
.event-plc { color: var(--color-danger); font-weight: 600; }
.event-retired { color: var(--color-warning); }
.event-new { color: var(--color-success); }

/* ==========================================
   Main Split Layout
   ========================================== */

.main-split {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 0;
    min-height: 0;
}

/* ==========================================
   Mold Grid — Dual Layout (Large + Small)
   ========================================== */

.mold-grid {
    padding: 1rem 1rem 2rem 1.5rem;
    overflow-y: auto;
}

.grid-section {
    display: grid;
    gap: 0.75rem;
}

.grid-large {
    grid-template-columns: repeat(5, 1fr);
    margin-bottom: 1rem;
}

.grid-small {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.5rem;
}

/* Mold Card — Base */
.mold-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.mold-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.mold-success::before { background: var(--color-success); }
.mold-info::before { background: var(--color-info); }
.mold-warning::before { background: var(--color-warning); }
.mold-danger::before { background: var(--color-danger); }

.mold-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--text-muted);
}

/* ---- Large Card (Top 10) ---- */
.card-lg {
    padding: 1rem;
}

.card-lg .mold-number {
    font-size: 1.35rem;
    font-weight: 800;
}

.card-lg .remaining-value {
    font-size: 2.75rem;
}

/* ---- Small Card (Rest) ---- */
.card-sm {
    padding: 0.5rem 0.6rem;
}

.card-sm .mold-header {
    margin-bottom: 0.3rem;
}

.card-sm .mold-number {
    font-size: 1.1rem;
    font-weight: 800;
}

.card-sm .mold-badge {
    font-size: 0.5rem;
    padding: 0.1rem 0.35rem;
}

.card-sm .mold-remaining {
    margin: 0.3rem 0;
}

.card-sm .remaining-value {
    font-size: 1.5rem;
}

.card-sm .remaining-label {
    font-size: 0.6rem;
}

.card-sm .progress-bar {
    height: 4px;
}

.card-sm .progress-text {
    font-size: 0.6rem;
    margin-top: 0.15rem;
}

.card-sm .mold-footer {
    margin-top: 0.3rem;
    padding-top: 0.3rem;
}

.card-sm .mold-pos {
    font-size: 0.6rem;
}

/* ==========================================
   Manual Reject Button
   ========================================== */

.btn-reject {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: rgba(239, 68, 68, 0.7);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 0.03em;
}

.btn-reject:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.6);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.2);
}

.btn-reject-sm {
    font-size: 0.6rem;
    padding: 0.1rem 0.3rem;
    line-height: 1;
}

/* ==========================================
   Reject Confirm Dialog
   ========================================== */

.reject-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.reject-overlay.active {
    opacity: 1;
}

.reject-dialog {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.reject-overlay.active .reject-dialog {
    transform: scale(1);
}

.reject-dialog-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.reject-dialog-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-danger);
    margin: 0;
}

.reject-icon {
    font-size: 1.3rem;
}

.reject-dialog p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0 0 1rem;
}

.reject-dialog p strong {
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.reject-reason {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 1rem;
    box-sizing: border-box;
}

.reject-reason:focus {
    outline: none;
    border-color: var(--color-danger);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15);
}

.reject-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.reject-btn {
    padding: 0.45rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: all 0.15s;
}

.reject-btn-cancel {
    background: var(--bg-card);
    color: var(--text-secondary);
}

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

.reject-btn-confirm {
    background: var(--color-danger);
    color: white;
    border-color: var(--color-danger);
}

.reject-btn-confirm:hover {
    background: #dc2626;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.3);
}

/* ==========================================
   Report Button & Modal
   ========================================== */

.btn-report {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-report:hover {
    background: rgba(16, 185, 129, 0.25);
    border-color: rgba(16, 185, 129, 0.5);
}

.report-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.report-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.report-modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 95vw;
    max-width: 1100px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.25s;
}

.report-overlay.active .report-modal {
    transform: scale(1);
}

.report-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.report-modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.report-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.report-filter {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
}

.report-filter:focus {
    outline: none;
    border-color: var(--color-primary);
}

.btn-export {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.75rem;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 6px;
    color: #10b981;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-export:hover {
    background: rgba(16, 185, 129, 0.3);
    border-color: rgba(16, 185, 129, 0.5);
}

.btn-close-report {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

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

/* Report stats bar */
.report-stats {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.rstat {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.rstat strong {
    font-size: 1rem;
    color: var(--text-primary);
}

.rstat-active strong { color: var(--color-primary); }
.rstat-danger strong { color: var(--color-danger); }
.rstat-warning strong { color: var(--color-warning); }
.rstat-retired strong { color: var(--color-info); }
.rstat-idle strong { color: var(--text-muted); }

/* Report table */
.report-table-wrap {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.report-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.report-table th {
    background: var(--bg-dark);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.report-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    vertical-align: middle;
}

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

.rt-mold {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.88rem;
}

.rt-num {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.rt-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Report badges */
.rbadge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 55px;
    text-align: center;
}

.rbadge-success { background: rgba(34, 197, 94, 0.15); color: var(--color-success); }
.rbadge-info { background: rgba(6, 182, 212, 0.15); color: var(--color-info); }
.rbadge-warning { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); }
.rbadge-danger { background: rgba(239, 68, 68, 0.15); color: var(--color-danger); }
.rbadge-retired { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }
.rbadge-idle { background: rgba(100, 116, 139, 0.1); color: #64748b; }

/* Report footer */
.report-footer {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 1.25rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ==========================================
   Camera Panel (Right Side)
   ========================================== */

.camera-panel {
    border-left: 1px solid var(--border-color);
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    padding: 0;
}

.cam-section {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.cam-section:last-child {
    border-bottom: none;
}

.cam-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}

.cam-header h3 {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0;
}

.cam-dot-live {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse-live 1.5s infinite;
}

@keyframes pulse-live {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
    50% { box-shadow: 0 0 0 5px rgba(239,68,68,0); }
}

/* Live Viewport */
.cam-viewport {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #0a0f1a;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.cam-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
}

.cam-placeholder span {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.cam-placeholder small {
    font-size: 0.65rem;
    font-family: 'JetBrains Mono', monospace;
    opacity: 0.5;
}

.cam-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.4rem;
}

.cam-tag {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--color-primary);
    background: rgba(59,130,246,0.1);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    letter-spacing: 0.08em;
}

.cam-res {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

/* Capture Grid */
.capture-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.capture-card {
    background: #0a0f1a;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.capture-img-placeholder {
    width: 100%;
    aspect-ratio: 4 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0d1321 0%, #131b2e 100%);
}

.capture-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0.5rem;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.capture-mold {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-primary);
}

.capture-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62rem;
    color: var(--text-muted);
}

/* AI Detection Stats */
.cam-stats {
    flex: 1;
}

.cam-stat-rows {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.cam-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.82rem;
}

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

.cam-stat-row span {
    color: var(--text-muted);
}

.cam-stat-row strong {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--text-primary);
}

.cam-stat-alert {
    color: var(--color-warning) !important;
}

/* Small card specific elements */
.mold-header-sm {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.2rem;
}

.mold-remaining-sm {
    text-align: center;
    margin: 0.2rem 0;
}

.progress-bar-sm {
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.mold-danger {
    background: var(--color-danger-bg);
    border-color: rgba(239, 68, 68, 0.3);
    animation: pulse-danger 2s infinite;
}

.mold-warning {
    background: var(--color-warning-bg);
    border-color: rgba(245, 158, 11, 0.25);
}

@keyframes pulse-danger {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
    50% { box-shadow: 0 0 20px 2px rgba(239, 68, 68, 0.15); }
}

.mold-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.mold-number {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.mold-badge {
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.2);
    color: var(--color-warning);
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.mold-remaining {
    text-align: center;
    margin: 0.75rem 0;
}

.remaining-value {
    font-size: 2.75rem;
    font-weight: 800;
    line-height: 1;
    display: block;
    font-variant-numeric: tabular-nums;
}

.mold-success .remaining-value { color: var(--color-success); }
.mold-info .remaining-value { color: var(--color-info); }
.mold-warning .remaining-value { color: var(--color-warning); }
.mold-danger .remaining-value { color: var(--color-danger); }

.remaining-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: 0.25rem;
    display: block;
}

.mold-progress {
    margin-top: 0.5rem;
}

.progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.progress-success { background: var(--color-success); }
.progress-info { background: var(--color-info); }
.progress-warning { background: var(--color-warning); }
.progress-danger { background: var(--color-danger); }

.progress-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.mold-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.mold-pos {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

/* ==========================================
   Event Log Panel
   ========================================== */

.log-panel {
    position: fixed;
    right: -400px;
    top: 0;
    bottom: 0;
    width: 380px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    z-index: 200;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.log-panel.open {
    right: 0;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.log-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.btn-close-log {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

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

.log-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.log-entry {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
    font-size: 0.78rem;
    line-height: 1.4;
    border-left: 3px solid transparent;
}

.log-entry.log-cycle {
    background: rgba(6, 182, 212, 0.06);
    border-left-color: var(--color-info);
    color: var(--text-secondary);
}

.log-entry.log-plc_signal {
    background: rgba(239, 68, 68, 0.1);
    border-left-color: var(--color-danger);
    color: var(--color-danger);
    font-weight: 500;
}

.log-entry.log-retired {
    background: rgba(245, 158, 11, 0.08);
    border-left-color: var(--color-warning);
    color: var(--color-warning);
}

.log-entry.log-new_mold, .log-entry.log-enter_line {
    background: rgba(34, 197, 94, 0.08);
    border-left-color: var(--color-success);
    color: var(--color-success);
}

.log-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: monospace;
}

.log-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* FAB */
.fab-log {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transition: all 0.2s;
    z-index: 50;
}

.fab-log:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

/* ==========================================
   Mold entering/leaving animations
   ========================================== */

.mold-card.mold-entering {
    animation: card-enter 0.5s ease-out;
}

.mold-card.mold-leaving {
    animation: card-leave 0.5s ease-in forwards;
}

@keyframes card-enter {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes card-leave {
    to {
        opacity: 0;
        transform: scale(0.8) translateY(-20px);
    }
}

.mold-card.mold-cycling {
    animation: card-pulse 0.4s ease;
}

@keyframes card-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

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

@media (max-width: 1200px) {
    .stats-bar {
        grid-template-columns: repeat(3, 1fr);
    }
    .grid-large {
        grid-template-columns: repeat(3, 1fr);
    }
    .main-split {
        grid-template-columns: 1fr 300px;
    }
}

@media (max-width: 768px) {
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }
    .top-bar {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }
    .top-bar-right {
        flex-wrap: wrap;
        justify-content: center;
    }
    .main-split {
        grid-template-columns: 1fr;
    }
    .camera-panel {
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
    .capture-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .mold-grid {
        padding: 0.75rem;
    }
    .grid-large {
        grid-template-columns: repeat(2, 1fr);
    }
    .grid-small {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }
    .log-panel {
        width: 100%;
        right: -100%;
    }
    .speed-control {
        flex-wrap: wrap;
    }
}

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

/* ==========================================
   Scrollbar
   ========================================== */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
