/* =========================================
   BASE RESET & MODERN VARIABLES
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

:root {
    /* Main Theme Colors */
    --primary-color: #6366f1; /* Vibrant Indigo */
    --primary-hover: #4f46e5;
    
    /* Workspace Background */
    --bg-color: #f1f5f9;      
    --border-color: #e2e8f0;
    
    /* Text Colors */
    --text-main: #0f172a;     
    --text-muted: #64748b;
    --danger: #ef4444;
    
    /* Midnight Sidebar & Header Colors */
    --sidebar-bg: #0f172a;
    --sidebar-text: #f8fafc;
    --sidebar-muted: #94a3b8;
    --sidebar-widget-bg: #1e293b;
    --sidebar-widget-border: #334155;
    
    /* Layout & Shadows */
    --radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
}

/* ANIMATED PARTICLES */
@keyframes dataFlow {
    0% { background-position: 0px 0px, 0px 0px; }
    /* One layer moves down-right, the other moves up-left for a 3D effect */
    100% { background-position: 48px 48px, -48px -48px; } 
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    
    /* Two layers of dots (Gray dots + larger Indigo particles) */
    background-image: 
        radial-gradient(#cbd5e1 2.5px, transparent 2.5px),
        radial-gradient(rgba(99, 102, 241, 0.15) 5px, transparent 5px); 
    background-size: 24px 24px, 48px 48px; 
    
    /* Sped up from 20s to 4s so it's instantly visible! */
    animation: dataFlow 4s linear infinite;
}

/* =========================================
   TYPOGRAPHY & BUTTONS
   ========================================= */
h1 { font-size: 1.25rem; font-weight: 700; color: var(--sidebar-text); }
h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 16px;}
h3 { font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 12px; }

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.btn.primary { 
    background-color: var(--primary-color); 
    color: white; 
    box-shadow: var(--shadow-sm);
}
.btn.primary:hover {
    background-color: var(--primary-hover);
    box-shadow: var(--shadow-md);
}

/* Top Nav Buttons */
.btn.secondary { 
    background-color: rgba(255, 255, 255, 0.1); 
    border: 1px solid var(--sidebar-widget-border); 
    color: var(--sidebar-text);
}
.btn.secondary:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: var(--sidebar-muted);
}

/* Modal Buttons */
.modal-content .btn.secondary, .side-panel .btn.secondary {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}
.modal-content .btn.secondary:hover, .side-panel .btn.secondary:hover {
    background-color: #f8fafc;
}

/* =========================================
   LAYOUT (DARK HEADER & SIDEBAR)
   ========================================= */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: var(--sidebar-bg); 
    border-bottom: 1px solid var(--sidebar-widget-border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.workspace {
    display: grid;
    grid-template-columns: 260px 1fr;
    align-items: start;
    min-height: calc(100vh - 73px);
}

.sidebar {
    grid-column: 1;
    position: sticky;
    top: 73px;
    height: calc(100vh - 73px);
    background-color: var(--sidebar-bg); 
    border-right: 1px solid var(--sidebar-widget-border);
    padding: 24px 16px;
    overflow-y: auto;
    color: var(--sidebar-text);
}

.sidebar h3 { color: var(--sidebar-muted); }

.draggable-widget {
    padding: 12px 16px;
    margin-bottom: 12px;
    background-color: var(--sidebar-widget-bg);
    border: 1px solid var(--sidebar-widget-border);
    border-radius: 8px;
    cursor: grab;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--sidebar-text);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
}
.draggable-widget::before {
    content: "⠿"; 
    margin-right: 8px;
    color: var(--sidebar-muted);
    font-size: 1.2rem;
}
.draggable-widget:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}
.draggable-widget:active { cursor: grabbing; transform: translateY(0); }

/* =========================================
   CANVAS & WIDGETS
   ========================================= */
.canvas-area {
    grid-column: 2;
    padding: 40px; 
    display: flex;
    flex-direction: column;
}

#date-filter-bar {
    display: flex;
    justify-content: flex-end; 
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
    background: white;
    padding: 12px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

#date-filter {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    font-weight: 500;
    cursor: pointer;
}

.grid-canvas {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(60px, auto);
    gap: 24px; 
    background-color: transparent;
    border: 2px dashed transparent;
    min-height: 400px;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.grid-canvas.drag-over {
    border-color: var(--primary-color);
    background-color: rgba(99, 102, 241, 0.1);
}

.dashboard-widget {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s;
}
.dashboard-widget:hover { box-shadow: var(--shadow-lg); }

.widget-header {
    padding: 16px 20px;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

.widget-content {
    padding: 20px;
    height: calc(100% - 53px); 
    display: flex;
    flex-direction: column;
    justify-content: center; 
    align-items: center;     
    width: 100%;
    background: white; 
}
.widget-content canvas {
    width: 100% !important;
    height: 100% !important;
}

.widget-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    opacity: 0; 
    transition: opacity 0.2s;
}
.dashboard-widget:hover .widget-actions { opacity: 1; }

.icon-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    padding: 6px 8px;
    box-shadow: var(--shadow-sm);
    transition: background 0.2s;
}
.icon-btn:hover { background: #f8fafc; }
.icon-btn.delete:hover { background: #fef2f2; color: var(--danger); }

/* =========================================
   FORMS & MODALS 
   ========================================= */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.2s;
}
.modal.hidden { display: none !important; }

.modal-content {
    background-color: white;
    width: 100%;
    max-width: 650px;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.side-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 400px;
    background-color: white;
    box-shadow: -4px 0 25px rgba(0,0,0,0.1);
    z-index: 900;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background-color: white;
}

.panel-body { padding: 24px; overflow-y: auto; flex: 1; }

.close-btn {
    background: #f1f5f9;
    border: none;
    width: 32px; height: 32px;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
}
.close-btn:hover { background: #e2e8f0; color: var(--text-main); }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.input-group { display: flex; flex-direction: column; }
.input-group label {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.input-group input, .input-group select, .input-group textarea {
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.875rem;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus, .input-group select:focus, .input-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.readonly-field { background-color: #f8fafc; color: #94a3b8; cursor: not-allowed; }
.divider { border: 0; height: 1px; background-color: var(--border-color); margin: 32px 0; }
.required { color: var(--danger); }

/* =========================================
   TABLES & CONTEXT MENU
   ========================================= */
.order-table-section {
    grid-column: 2;
    padding: 0 40px 100px 40px; 
}

.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    background: white;
}

table { width: 100%; border-collapse: collapse; }

th, td {
    padding: 16px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    background: white;
}

th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border-color);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f8fafc; } 

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}
.action-btn:hover { background-color: #e2e8f0; color: var(--text-main); }

.context-menu {
    position: absolute;
    background: white;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
    padding: 8px 0;
    min-width: 140px;
    z-index: 2000;
}

.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s;
}
.context-menu-item:hover { background-color: var(--bg-color); }
.context-menu-item.delete { color: var(--danger); }
.context-menu-item.delete:hover { background-color: #fef2f2; }

/* =========================================
   AUTH & LOADER SCREENS
   ========================================= */
.auth-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--sidebar-bg);
    background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1.5px, transparent 1.5px);
    background-size: 24px 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999; /* Always on top */
    transition: opacity 0.4s ease;
}

.auth-card {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.auth-logo {
    width: 48px;
    height: 48px;
    background: var(--primary-color);
    color: white;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    margin: 0 auto 20px auto;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.auth-card h2 { color: var(--text-main); margin-bottom: 8px; }
.auth-card p { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 24px; }
.auth-card .input-group { text-align: left; margin-bottom: 16px; }

/* CSS Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(99, 102, 241, 0.2);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =========================================
   NEW AUTHENTICATION STYLES
   ========================================= */
.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper input {
    width: 100%;
    padding-right: 60px; /* Leave space for the toggle button */
}

.password-toggle {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}

.password-toggle:hover {
    color: var(--primary-color);
}

.auth-links {
    margin-top: 24px;
    font-size: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-links .text-muted {
    color: var(--text-muted);
}

.auth-links a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.auth-links a:hover {
    color: var(--primary-hover);
}

/* =========================================
   MISCELLANEOUS / UTILS
   ========================================= */
.hidden { display: none !important; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 1rem; background: white; border-radius: var(--radius); }

#order-modal { z-index: 9999 !important; }
#order-modal .modal-content { position: relative; z-index: 10000 !important; pointer-events: auto !important; }
#create-order-form input, #create-order-form select { pointer-events: auto !important; user-select: text !important; }

.widget-table-container { width: 100%; height: 100%; overflow: auto; border-radius: 0 0 var(--radius) var(--radius); }
.widget-table th { position: sticky; top: 0; padding: 12px; color: white; border-bottom: none;}
.multi-select-box { border: 1px solid var(--border-color); border-radius: 6px; max-height: 120px; overflow-y: auto; padding: 12px; }
.multi-select-box label { display: block; margin-bottom: 8px; font-weight: 500; cursor: pointer; color: var(--text-main); }
