/* ============================================
   CSM — Cleaning Services Management
   Professional Corporate Banking Theme
   ============================================ */

:root {
    --primary: #0a1628;
    --primary-light: #1a2d4a;
    --primary-dark: #060e1a;
    --accent: #00bcd4;
    --accent-hover: #00a5bb;
    --accent-light: rgba(0, 188, 212, 0.1);
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --orange: #f97316;
    --indigo: 5241ff;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --header-height: 60px;
    --bg-body: #f0f4f8;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    overflow-x: hidden;
}

[dir="rtl"] body {
    font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
}

a {
    text-decoration: none;
    color: var(--accent);
    transition: var(--transition);
}

a:hover {
    color: var(--accent-hover);
}

/* ============ Sidebar ============ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-light) 100%);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
    will-change: transform;
}

[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    gap: 12px;
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 188, 212, 0.35);
}

.brand-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 1px;
}

/* Nav Sections */
.nav-section {
    padding: 18px 20px 6px;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.35);
    font-weight: 600;
}

/* Nav Links */
.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: rgba(255,255,255,0.7);
    font-size: 0.875rem;
    font-weight: 400;
    gap: 12px;
    transition: var(--transition);
    border-radius: 0;
    position: relative;
}

.sidebar-nav .nav-link i:first-child {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.06);
}

.sidebar-nav .nav-link.active {
    color: #fff;
    background: rgba(0, 188, 212, 0.15);
    border-right: 3px solid var(--accent);
}

[dir="rtl"] .sidebar-nav .nav-link.active {
    border-right: none;
    border-left: 3px solid var(--accent);
}

/* Submenu */
.nav-group .nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
}

.nav-group.open .nav-submenu {
    max-height: 300px;
}

.nav-group .toggle-icon {
    margin-left: auto;
    font-size: 0.7rem;
    transition: transform 0.3s ease;
}

[dir="rtl"] .nav-group .toggle-icon {
    margin-left: 0;
    margin-right: auto;
}

.nav-group.open .toggle-icon {
    transform: rotate(180deg);
}

.nav-submenu .nav-link {
    padding-left: 54px;
    font-size: 0.82rem;
}

[dir="rtl"] .nav-submenu .nav-link {
    padding-left: 20px;
    padding-right: 54px;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* ============ Sidebar Collapsed State (Desktop) ============ */
.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-collapsed .brand-text,
.sidebar-collapsed .nav-section,
.sidebar-collapsed .nav-link span,
.sidebar-collapsed .toggle-icon,
.sidebar-collapsed .sidebar-footer .user-details,
.sidebar-collapsed .nav-submenu {
    display: none;
}

.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 18px 0;
}

.sidebar-collapsed .sidebar-nav .nav-link {
    justify-content: center;
    padding: 12px 0;
}

/* ============ Main Content ============ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

[dir="rtl"] .main-content {
    margin-left: 0;
    margin-right: var(--sidebar-width);
}

.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

[dir="rtl"] .sidebar-collapsed .main-content {
    margin-left: 0;
    margin-right: var(--sidebar-collapsed-width);
}

/* ============ Header ============ */
.top-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow-sm);
}

.sidebar-toggle {
    color: var(--text-secondary) !important;
    padding: 0 !important;
    border: none;
    background: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: var(--bg-body);
    color: var(--accent) !important;
}

.sidebar-toggle:active {
    transform: scale(0.92);
}

.sidebar-toggle i {
    transition: var(--transition);
    font-size: 1.5rem;
}

.header-search .input-group {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-body);
}

.header-search .form-control {
    border: none;
    background: transparent;
    font-size: 0.875rem;
    padding: 6px 12px;
}

.header-search .input-group-text {
    border: none;
    padding: 6px 12px 6px 14px;
}

.header-search .form-control:focus {
    box-shadow: none;
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.notification-dropdown {
    width: 320px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.notification-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.avatar-placeholder {
    width: 32px;
    height: 32px;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

/* ============ Content ============ */
.content-wrapper {
    padding: 24px;
    flex: 1;
}

.content-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--primary);
}

.breadcrumb {
    font-size: 0.8rem;
}

.breadcrumb-item a {
    color: var(--text-secondary);
}

.breadcrumb-item.active {
    color: var(--text-muted);
}

/* ============ Cards ============ */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--bg-card);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Stat Cards */
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

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

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    border-radius: 4px 0 0 4px;
}

[dir="rtl"] .stat-card::before {
    left: auto;
    right: 0;
    border-radius: 0 4px 4px 0;
}

.stat-card.primary::before { background: var(--accent); }
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.info::before { background: var(--info); }
.stat-card.orange::before { background: var(--orange); }

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============ Tables ============ */
.table {
    font-size: 0.875rem;
}

.table thead th {
    background: var(--bg-body);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    padding: 12px 16px;
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr:hover {
    background: rgba(0, 188, 212, 0.03);
}

/* ============ Buttons ============ */
.btn {
    font-size: 0.875rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 188, 212, 0.35);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
}

.btn-success:hover {
    background: #16a34a;
    border-color: #16a34a;
    transform: translateY(-1px);
}

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

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
    transform: translateY(-1px);
}

.btn-outline-primary {
    color: var(--accent);
    border-color: var(--accent);
}

.btn-outline-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* ============ Badges ============ */
.badge {
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
}

.badge.bg-indigo {
    background: var(--indigo) !important;
    color: #fff;
}
.badge.bg-orange {
    background: var(--orange) !important;
    color: #fff;
}

/* ============ Forms ============ */
.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    padding: 10px 14px;
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.15);
}

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

/* ============ Footer ============ */
.main-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    margin-top: auto;
}

/* ============ Status Badge Colors ============ */
.status-not_started { background: #94a3b8 !important; }
.status-started { background: var(--info) !important; }
.status-before_uploaded { background: var(--accent) !important; }
.status-in_progress { background: var(--warning) !important; }
.status-after_uploaded { background: #8b5cf6 !important; }
.status-submitted { background: var(--orange) !important; }
.status-under_review { background: #6366f1 !important; }
.status-approved { background: var(--success) !important; }
.status-rejected { background: var(--danger) !important; }

/* ============ Login Page ============ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, var(--accent) 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}

.login-card .login-brand {
    text-align: center;
    margin-bottom: 32px;
}

.login-card .login-brand .brand-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    font-size: 1.5rem;
}

.login-card .login-brand h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-card .login-brand p {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ============ Sidebar Overlay (Mobile) ============ */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
}

/* ============ DataTables Overrides ============ */
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 0.85rem;
}

.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
}

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

/* Tablet & Mobile: sidebar slides from off-screen */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    /* When sidebar-open is on body, slide sidebar in */
    .sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }

    [dir="rtl"] .sidebar-open .sidebar {
        box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    }

    /* Main content always full-width on mobile */
    .main-content {
        margin-left: 0 !important;
    }

    [dir="rtl"] .main-content {
        margin-right: 0 !important;
    }

    /* Override desktop collapsed state on mobile */
    .sidebar-collapsed .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }

    [dir="rtl"] .sidebar-collapsed .sidebar {
        transform: translateX(100%);
    }

    .sidebar-collapsed .main-content {
        margin-left: 0 !important;
    }

    [dir="rtl"] .sidebar-collapsed .main-content {
        margin-right: 0 !important;
    }

    /* Restore hidden elements in mobile (undo collapsed overrides) */
    .sidebar-collapsed .brand-text,
    .sidebar-collapsed .nav-section,
    .sidebar-collapsed .nav-link span,
    .sidebar-collapsed .toggle-icon,
    .sidebar-collapsed .sidebar-footer .user-details,
    .sidebar-collapsed .nav-submenu {
        display: revert;
    }

    .sidebar-collapsed .sidebar-brand {
        justify-content: flex-start;
        padding: 18px 20px;
    }

    .sidebar-collapsed .sidebar-nav .nav-link {
        justify-content: flex-start;
        padding: 10px 20px;
    }

    /* When sidebar-open AND sidebar-collapsed on mobile, still show full sidebar */
    .sidebar-open.sidebar-collapsed .sidebar {
        transform: translateX(0);
    }

    .content-wrapper {
        padding: 16px;
    }

    .stat-card .stat-value {
        font-size: 1.4rem;
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }
}

@media (max-width: 575.98px) {
    .content-header {
        flex-direction: column;
        gap: 12px;
    }

    .table-responsive {
        font-size: 0.8rem;
    }

    .login-card {
        padding: 24px;
    }

    .top-header {
        padding: 0 12px;
    }

    .content-wrapper {
        padding: 12px;
    }
}

/* ============ Animations ============ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card,
.card {
    animation: fadeInUp 0.4s ease forwards;
}

.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.2s; }
.stat-card:nth-child(4) { animation-delay: 0.3s; }

/* ============ Print ============ */
@media print {
    .sidebar, .top-header, .main-footer, .btn, .breadcrumb {
        display: none !important;
    }
    .main-content {
        margin: 0 !important;
    }
}
