/* ============================================
   FACTORY SCREEN — Modern ERP Design
   ============================================ */

:root {
    --bg-app: #f1f5f9;
    --bg-sidebar: #0f172a;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-sidebar: #94a3b8;
    --border-color: #e2e8f0;
    --primary: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --sidebar-width: 260px;
    --header-height: 70px;
    --radius-lg: 12px;
    --radius-md: 8px;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
}

/* ─── Layout ─── */
.app-layout {
    display: flex;
    height: 100vh;
}

/* ─── Sidebar (Standardized) ─── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 50;
    border-right: 1px solid #1e293b;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
    border-bottom: 1px solid #1e293b;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.logo-text {
    font-weight: 700;
    color: #f8fafc;
    font-size: 16px;
    letter-spacing: -0.5px;
}

.nav-menu {
    flex: 1;
    padding: 24px 16px;
    overflow-y: auto;
}

.nav-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #475569;
    margin-bottom: 8px;
    margin-top: 24px;
    padding-left: 12px;
}

.nav-label:first-child {
    margin-top: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-sidebar);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    font-weight: 500;
    margin-bottom: 4px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #f1f5f9;
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 15px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #1e293b;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    background: #334155;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.details {
    display: flex;
    flex-direction: column;
}

.details .name {
    color: #f1f5f9;
    font-size: 13px;
    font-weight: 500;
}

.details .role {
    font-size: 11px;
    color: #64748b;
}

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Topbar ─── */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    min-height: 56px;
}

.page-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-title h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

@keyframes pulse-live {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.clock-display {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    background: #f8fafc;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.modern-toggle-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-right: 15px;
    cursor: pointer;
    font-size: 1.1rem;
}

.modern-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    color: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
}

.topbar-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-btn:hover {
    background: #f8fafc;
    border-color: var(--primary);
    color: var(--primary);
}

.topbar-btn.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.topbar-btn.primary:hover {
    background: #2563eb;
}

/* ─── Content / Table Area ─── */
.content-area {
    flex: 1;
    overflow: hidden;
    padding: 0;
}

#table-wrapper {
    width: 100%;
    height: 100%;
    overflow: auto;
}

#loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 600;
}

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

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

/* ─── Factory Table ─── */
table {
    border-collapse: collapse;
    width: auto;
    min-width: 100%;
    background: white;
}

th,
td {
    border: 1px solid #e2e8f0;
    text-align: center;
    white-space: nowrap;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 700;
    padding: 5px 10px;
}

td.large-text-cell {
    font-size: 15px;
    font-weight: 700;
    padding: 5px 10px;
    line-height: 1.15;
    vertical-align: middle;
}

th {
    position: sticky;
    top: 0;
    z-index: 10;
    font-size: 12px;
    font-weight: 700;
    padding: 10px 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 1px 0 #e2e8f0;
}

/* Header Color Groups */
th.h-ad {
    background: #1e293b;
    color: white;
}

th.h-eg {
    background: #7c3aed;
    color: white;
}

th.h-hj {
    background: #2563eb;
    color: white;
}

th.h-kt {
    background: #ea580c;
    color: white;
}

th.h-klt {
    background: #fdf2f8;
    color: #db2777;
    border-bottom: 3px solid #db2777;
}

th.h-status {
    background: #334155;
    color: white;
}

/* Cell Color Groups — Alternating */
tr:nth-child(odd) td.g-ad {
    background: #ffffff;
}

tr:nth-child(even) td.g-ad {
    background: #f8fafc;
}

tr:nth-child(odd) td.g-eg {
    background: #f5f3ff;
}

tr:nth-child(even) td.g-eg {
    background: #ede9fe;
}

tr:nth-child(odd) td.g-hj {
    background: #eff6ff;
}

tr:nth-child(even) td.g-hj {
    background: #dbeafe;
}

tr:nth-child(odd) td.g-kt {
    background: #fff7ed;
}

tr:nth-child(even) td.g-kt {
    background: #ffedd5;
}

td.g-status {
    background: #fefce8;
    color: #854d0e;
    padding: 3px 6px;
}

/* Status dropdown */
.status-select {
    background: transparent;
    border: 1px solid rgba(133, 77, 14, 0.2);
    color: #854d0e;
    font-weight: 700;
    font-size: 12px;
    padding: 3px 6px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
}

.status-select:focus {
    outline: none;
    background: white;
    border-color: #854d0e;
}

/* Check / X / Minus marks */
.check-mark {
    color: var(--success);
    font-weight: 800;
    font-size: 24px;
    line-height: 0.8;
    display: block;
}

.x-mark {
    color: var(--danger);
    font-weight: 800;
    font-size: 24px;
    line-height: 0.8;
    display: block;
}

.minus {
    color: #94a3b8;
    font-weight: 800;
    font-size: 26px;
    line-height: 0.7;
    display: block;
}

.na-mark {
    color: var(--danger);
    font-weight: 900;
    font-size: 28px;
    line-height: 0.7;
    display: block;
    text-shadow: 0 0 2px rgba(239, 68, 68, 0.3);
}

/* Clickable toggle cells */
.cell-toggle {
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    position: relative;
}

.cell-toggle:hover {
    box-shadow: inset 0 0 0 2px var(--primary);
    filter: brightness(0.97);
}

.cell-toggle:active {
    transform: scale(0.93);
}

.cell-saving {
    animation: cellPulse 0.3s ease;
}

@keyframes cellPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
        background: rgba(59, 130, 246, 0.08);
    }

    100% {
        transform: scale(1);
    }
}

td.text-left {
    text-align: left;
}

/* ─── Popup Overlay ─── */
#overlay-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.98);
    z-index: 99999;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 2vh 2vw;
    box-sizing: border-box;
}

.popup-header {
    font-size: 5vh;
    font-weight: 900;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 5px;
    border-bottom: 2px solid #334155;
    width: 100%;
    text-align: center;
    padding-bottom: 1.5vh;
}

.popup-abc-row {
    display: flex;
    width: 100%;
    flex: 1;
    justify-content: center;
    align-items: center;
    gap: 2vw;
}

.popup-box {
    flex: 1;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 60%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.popup-label {
    font-size: 2.5vh;
    color: #94a3b8;
    margin-bottom: 1vh;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.popup-value {
    font-size: 6vh;
    font-weight: 900;
    color: #fff;
    line-height: 1.05;
    text-align: center;
}

.popup-detail {
    font-size: 8vh;
    font-weight: 900;
    color: var(--success);
    margin-bottom: 3vh;
    border: 2px solid var(--success);
}

/* ─── Urgent Highlight ─── */
.row-urgent td {
    background-color: #fecaca !important;
    /* light red */
    color: #991b1b !important;
    /* dark red text */
    border-color: #f87171 !important;
}

.row-urgent td.g-ad {
    background-color: #fee2e2 !important;
    font-weight: 800 !important;
}

.row-urgent:hover td {
    background-color: #fca5a5 !important;
}

/* ─── Drag & Drop Reorder ─── */
th.h-drag {
    background: #1e293b;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
}

td.g-drag {
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    padding: 0 6px;
    background: #f8fafc;
}

.drag-handle {
    cursor: grab;
    color: #94a3b8;
    font-size: 14px;
    text-align: center;
    user-select: none;
    transition: color 0.15s;
}

.drag-handle:hover {
    color: var(--primary);
}

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

tr.dragging {
    opacity: 0.4;
    background: #dbeafe !important;
}

tr.dragging td {
    background: #dbeafe !important;
}

tr.drag-over {
    position: relative;
}

tr.drag-over td {
    border-top: 3px solid var(--primary) !important;
}

tr.drag-over-blocked td {
    border-top: 3px solid var(--danger) !important;
}

.row-urgent td.g-drag {
    background-color: #fee2e2 !important;
    color: #b91c1c;
}