:root {
    --primary: #FFBE0B;
    --primary-hover: #e0a800;
    --dark-bg: #1e190d;
    --dark: #2A2312;
    --text-main: #fcfcfc;
    --text-muted: #a39c89;
    
    --success: #34d399;
    --danger: #ef4444;
    --warning: #fbbf24;

    --panel-bg: rgba(42, 35, 18, 0.7);
    --border: rgba(255, 190, 11, 0.15);
    
    --font-family: 'Inter', sans-serif;
}

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

body {
    font-size: 11.5px; /* Scaled down base font size to fit more content */
    font-family: var(--font-family);
    background: linear-gradient(135deg, var(--dark-bg) 0%, var(--dark) 100%);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* Custom Premium Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 190, 11, 0.5); /* Primary color with transparency */
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Glassmorphism Panel */
.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px; /* Reduced from 16px */
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    color: var(--text-main);
}
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 0.9rem;
}
.btn-primary {
    background: var(--primary);
    color: var(--dark);
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover {
    background: rgba(255, 190, 11, 0.1);
}
.icon-btn {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.icon-btn:hover {
    background: rgba(255, 190, 11, 0.1);
}

/* Inputs */
input:not([type="checkbox"]), select {
    width: 100%;
    padding: 8px 12px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    transition: border 0.2s;
}
input:not([type="checkbox"]):focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

input[type="date"] {
    color-scheme: dark;
    cursor: pointer;
}

select option {
    background: var(--dark);
    color: var(--text-main);
}

/* Custom Date Picker */
.datepicker-popup {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    width: 260px;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    padding: 16px;
    border-radius: 12px;
}
.dp-days-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.7rem;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 8px;
}
.dp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.dp-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-main);
}
.dp-cell:hover:not(.dp-empty) {
    background: rgba(255, 179, 71, 0.2);
}
.dp-cell.dp-selected {
    background: var(--primary);
    color: var(--dark);
    font-weight: bold;
}
.dp-empty {
    cursor: default;
}

/* Fix native password eye color for dark mode (Edge/Windows) */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
    filter: invert(1) brightness(2);
}

label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Loader */
.loader-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--dark-bg);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease, visibility 0.8s ease, transform 0.8s cubic-bezier(0.5, 0, 0.2, 1);
    transform: scale(1);
}
.loader-container.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(5);
}
.loader-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.loader-icon {
    width: 140px;
    height: 140px;
    color: var(--primary);
    filter: drop-shadow(0 0 20px rgba(255, 190, 11, 0.6));
    animation: pulseGlow 1.5s infinite alternate ease-in-out;
}
@keyframes pulseGlow {
    0% { transform: scale(0.95); filter: drop-shadow(0 0 10px rgba(255, 190, 11, 0.4)); }
    100% { transform: scale(1.05); filter: drop-shadow(0 0 40px rgba(255, 190, 11, 0.9)); }
}

/* Background Particles */
#particles-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* Login Page */
#page-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}
.login-box {
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.login-box h2 {
    margin-bottom: 24px;
    font-size: 2rem;
}
.login-box .input-group {
    text-align: left;
    margin-bottom: 16px;
}
.login-box .btn {
    width: 100%;
    margin-top: 16px;
}
#loginError {
    color: var(--danger);
    font-size: 0.85rem;
    margin-bottom: 16px;
    display: none;
}
#loginError.active {
    display: block;
}

/* Dashboard Layout */
.dashboard-layout {
    display: none; /* hidden by default */
    grid-template-columns: 200px 1fr;
    height: 100vh;
    overflow: hidden;
}
.dashboard-layout.active {
    display: grid;
}

/* Sidebar */
.sidebar {
    background: var(--dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 12px;
    height: 100vh;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
}
.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
    font-weight: 500;
}
.nav-item:hover {
    color: var(--primary);
    background: rgba(255, 190, 11, 0.05);
}
.nav-item.active {
    color: var(--dark);
    background: var(--primary);
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}
.user-info h4 {
    font-size: 0.9rem;
    margin-bottom: 2px;
}
.user-info p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    padding: 12px;
    height: calc(100vh - 40px); /* 40px for margin */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#viewMasterOrders, #viewVendors, #viewUsers {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Top Header */
.dash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}
.header-title h1 {
    font-size: 1.25rem;
    margin-bottom: 2px;
}
.header-title p {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Metrics Row */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
    flex-shrink: 0;
}
.metric-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.metric-card h3 {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.metric-card .value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
}

/* Dashboard Grid (Table + Sidebar) */
.dash-grid {
    display: grid;
    grid-template-columns: 1fr 240px; /* Reduced right sidebar from 260px */
    gap: 12px;
    flex: 1;
    min-height: 0; /* Important for scroll nested in flex/grid */
}

/* Data Table */
.table-container {
    overflow-y: auto;
    height: 100%;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
th, td {
    padding: 6px 8px; /* Compact padding */
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    z-index: 10;
}
tbody tr:hover {
    background: rgba(255, 190, 11, 0.03);
}

/* Status Badges */
.status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status.low { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.status.ok { background: rgba(52, 211, 153, 0.2); color: var(--success); }
.status.pending { background: rgba(251, 191, 36, 0.2); color: var(--warning); }

/* Right Sidebar Forms */
.sidebar-right {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
    overflow-y: auto;
}
.form-section {
    margin-bottom: 0; /* Gap handles spacing */
}
.form-section h3 {
    margin-bottom: 12px;
    font-size: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}
.form-section .input-group {
    margin-bottom: 8px;
}

/* Heatmap */
.heatmap-section {
    margin-top: 32px;
}
.heatmap-table th, .heatmap-table td {
    text-align: center;
}
.heatmap-cell {
    transition: background 0.3s;
}

/* Utility */
.hidden { display: none !important; }
.page:not(.active) { display: none !important; }

/* Responsive Media Queries */
@media (max-width: 1024px) {
    /* Tablet */
    .dashboard-layout {
        grid-template-columns: 180px 1fr;
    }
    .dash-grid {
        grid-template-columns: 1fr; /* Stack add/allocate below table */
        overflow-y: auto;
    }
    .table-container {
        height: auto;
        max-height: 400px; /* Give it a max height so the user can reach the forms */
        overflow-y: auto;
    }
    .sidebar-right {
        height: auto;
        overflow-y: visible;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .form-section {
        flex: 1;
        min-width: 250px;
    }
}

@media (max-width: 768px) {
    /* Mobile */
    .dashboard-layout.active {
        display: flex;
        flex-direction: column;
        height: 100vh;
    }
    .sidebar {
        height: auto;
        flex-direction: row;
        padding: 12px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
        align-items: center;
        flex-shrink: 0;
    }
    .sidebar-logo {
        margin-bottom: 0;
        margin-right: 20px;
        font-size: 1.1rem;
    }
    .nav-menu {
        flex-direction: row;
        margin-right: 20px;
        gap: 8px;
    }
    .nav-item {
        padding: 6px 10px;
        white-space: nowrap;
    }
    .user-profile {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
        margin-left: auto;
    }
    .main-content {
        padding: 12px;
        height: auto;
        flex: 1;
    }
    .metrics-row {
        grid-template-columns: 1fr 1fr;
    }
    .header-title h1 {
        font-size: 1.2rem;
    }
    .dash-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .sidebar-right {
        flex-direction: column;
    }
    .table-container {
        max-height: 300px;
    }
}

/* Fade In Page */
.fade-in-page {
    opacity: 0;
    transition: opacity 0.8s ease 0.3s;
}
.fade-in-page.show {
    opacity: 1;
}
