:root {
    @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');
    /* Color Palette */
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    /* Gradients */
    --grad-primary: linear-gradient(135deg, #6366f1, #10b981);
    --grad-hover: linear-gradient(135deg, #4f46e5, #059669);
    --grad-danger: linear-gradient(135deg, #ef4444, #b91c1c);
    
    /* Utility */
    --radius-lg: 16px;
    --radius-md: 10px;
    --shadow-soft: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Tajawal', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.15), transparent 25%);
    background-attachment: fixed;
}

/* Typography */
h1, h2, h3 { font-weight: 700; color: var(--text-main); }
p { color: var(--text-muted); }

/* Layout - Dashboard */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.sidebar {
    width: 260px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border-left: 1px solid var(--border-color); /* RTL */
    display: flex;
    flex-direction: column;
    padding: 2rem 1rem;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 10;
    transition: var(--transition);
}

.sidebar-header {
    text-align: center;
    margin-bottom: 2rem;
}

.sidebar-header h1 {
    background: var(--grad-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.8rem;
    letter-spacing: 1px;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-links li {
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

.nav-links li:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-links li.active {
    background: var(--grad-primary);
    color: #fff;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.main-content {
    flex: 1;
    margin-right: 260px; /* RTL spacing for sidebar */
    padding: 2rem 3rem;
    display: flex;
    flex-direction: column;
}

/* Topbar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: var(--bg-card);
    padding: 1rem 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

.logout-btn {
    text-decoration: none;
    color: #ef4444;
    font-weight: bold;
    font-size: 0.9rem;
    transition: var(--transition);
}

.logout-btn:hover { color: #f87171; text-shadow: 0 0 8px rgba(239, 68, 68, 0.4); }

/* Tabs Logic */
.tab-content {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Glass Cards */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-soft);
    margin-bottom: 2rem;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

input, select {
    width: 100%;
    padding: 0.9rem 1.2rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
}

input:focus, select:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Custom Input Number Spinners (Hide defaults) */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
}

/* Custom Number Wrapper & Buttons */
.custom-number-wrapper {
    display: flex;
    align-items: center;
    position: relative;
    flex: 1; /* For elements inside .input-with-unit */
    width: 100%;
}

.custom-number-wrapper input {
    flex: 1;
    padding-right: 2.2rem !important; /* Space for Custom Spinners */
}

.num-spinners {
    position: absolute;
    right: 5px;
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: center;
    gap: 2px;
}

.spin-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 4px;
    width: 22px;
    height: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: var(--transition);
}

.spin-btn:hover {
    background: var(--bg-card);
    color: var(--text-main);
}

.spin-btn:active {
    background: var(--grad-primary);
    color: white;
}

.spin-btn svg {
    width: 12px;
    height: 12px;
}

/* Custom Select Dropdown Arrow & Option Colors */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: left 1rem center;
    background-size: 1.2em;
    padding-left: 2.8rem; /* Make room for the arrow */
    cursor: pointer;
}

select option {
    background-color: var(--bg-dark);
    color: var(--text-main);
    padding: 10px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Unit Input Grouping */
.input-with-unit {
    display: flex;
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: rgba(15, 23, 42, 0.6);
    overflow: hidden;
    transition: var(--transition);
}

.input-with-unit:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.input-with-unit input {
    border: none !important;
    background: transparent !important;
    flex: 1;
    padding-left: 0.5rem;
}

.input-with-unit select {
    border: none !important;
    background-color: rgba(255, 255, 255, 0.05) !important;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: left 0.4rem center !important;
    background-size: 0.9em !important;
    width: auto;
    min-width: 80px;
    border-right: 1px solid var(--border-color) !important;
    border-radius: 0;
    padding: 0 0.5rem;
    padding-left: 1.8rem !important;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* Advanced Settings (Burst) */
.advanced-section {
    margin-top: 1rem;
    border-top: 1px dashed var(--border-color);
    padding-top: 1.5rem;
}

.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #818cf8;
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: 1rem;
    font-weight: 500;
    user-select: none;
}

.advanced-toggle:hover { color: #6366f1; }

.advanced-content {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.advanced-content.active { display: block; }

.burst-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    background: rgba(255, 255, 255, 0.02);
    padding: 1.2rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.burst-title {
    grid-column: 1 / -1;
    font-size: 0.85rem;
    font-weight: bold;
    color: #10b981;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 5px;
}


/* Buttons */
.btn-primary {
    background: var(--grad-primary);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn-primary:hover {
    background: var(--grad-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
}

.btn-danger {
    background: var(--grad-danger);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #b91c1c, #991b1b);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.3);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn-warning:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(245, 158, 11, 0.3);
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

th, td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: rgba(15, 23, 42, 0.8);
    font-weight: 600;
    color: var(--text-muted);
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
}

.badge-active { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.badge-inactive { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.badge-info { background: rgba(99, 102, 241, 0.2); color: #818cf8; }

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-weight: 500;
    animation: fadeIn 0.3s;
}

.alert-success { background: rgba(16, 185, 129, 0.1); border: 1px solid #10b981; color: #10b981; }
.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid #ef4444; color: #ef4444; }

/* Toggle Switch container for Auth Type */
.toggle-group {
    display: flex;
    background: rgba(15, 23, 42, 0.8);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.toggle-group label {
    flex: 1;
    text-align: center;
    padding: 0.8rem;
    cursor: pointer;
    font-weight: bold;
    color: var(--text-muted);
    transition: var(--transition);
}

.toggle-group input[type="radio"] { display: none; }
.toggle-group input[type="radio"]:checked + label {
    background: var(--grad-primary);
    color: white;
}

/* Auth View Control */
.auth-view { display: none; }
.auth-view.active { display: block; animation: fadeIn 0.3s; }

/* Checkbox specific */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}
.checkbox-group label {
    cursor: pointer;
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 500;
}

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1; pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 90%; max-width: 400px;
    transform: scale(0.9);
    transition: var(--transition);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content.modal-lg {
    max-width: 600px;
}

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

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.btn-close { background: transparent; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }

/* Global Login Page layout overrides */
.login-container {
    justify-content: center;
    align-items: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

/* Responsive */
@media (max-width: 768px) {
    body { padding-top: 50px; }
    
    .app-container {
        display: block; 
    }
    
    .sidebar {
        transform: translateX(100%);
        width: 260px;
        box-shadow: -5px 0 15px rgba(0,0,0,0.5);
        padding-top: 2rem;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content { margin-right: 0; padding: 0.8rem; }
    
    .topbar {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        padding: 1rem;
        margin-top: 10px;
    }

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

    .glass-card {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    table th, table td {
        padding: 0.8rem 0.5rem;
        font-size: 0.85rem;
    }
    
    .btn-primary, .btn-danger, .btn-warning {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .modal-content {
        padding: 1.5rem 1rem;
    }
    
    .advanced-section {
        padding-top: 1rem;
    }
    
    /* Mobile Toggle */
    .mobile-nav-toggle {
        display: block !important;
        position: fixed; top: 10px; right: 10px; z-index: 1000;
        background: var(--grad-primary); border: none;
        padding: 0.6rem 1rem; border-radius: var(--radius-md); color: white; font-weight: bold;
        box-shadow: 0 4px 10px rgba(0,0,0,0.3);
        cursor: pointer;
    }
}
.mobile-nav-toggle { display: none; }
