/* ============================================
   Sakkara EMS - Main Stylesheet
   ============================================ */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    --topnav-height: 56px;
    --sidebar-bg: #212529;
    --sidebar-hover: #2c3034;
    --sidebar-active: #0d6efd;
    --sidebar-text: #adb5bd;
    --sidebar-text-active: #ffffff;
}

/* ---- Global ---- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f6f9;
    padding-top: var(--topnav-height);
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    height: calc(100vh - var(--topnav-height));
    position: fixed;
    top: var(--topnav-height);
    left: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
    scrollbar-width: thin;
    scrollbar-color: #495057 var(--sidebar-bg);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-track {
    background: var(--sidebar-bg);
}
.sidebar::-webkit-scrollbar-thumb {
    background-color: #495057;
    border-radius: 3px;
}

.sidebar-content {
    padding: 1rem 0;
}

/* Sidebar Divider */
.sidebar-divider {
    border-color: #495057;
    margin: 0.5rem 1rem;
}

/* Sidebar Links */
.sidebar-link {
    color: var(--sidebar-text) !important;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    white-space: nowrap;
}

.sidebar-link:hover {
    color: var(--sidebar-text-active) !important;
    background-color: var(--sidebar-hover);
    text-decoration: none;
}

.sidebar-link.active {
    color: var(--sidebar-text-active) !important;
    background-color: rgba(13, 110, 253, 0.15);
    border-left-color: var(--sidebar-active);
    font-weight: 600;
}

/* Sidebar Group Header */
.sidebar-group {
    margin-bottom: 0.25rem;
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    color: #6c757d;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: color 0.2s;
}

.sidebar-group-header:hover {
    color: #adb5bd;
}

.sidebar-group-header span {
    display: flex;
    align-items: center;
}

.sidebar-group-header .bi {
    font-size: 0.85rem;
}

/* Chevron rotation */
.sidebar-chevron {
    font-size: 0.65rem;
    transition: transform 0.3s ease;
}

.sidebar-group-header[aria-expanded="true"] .sidebar-chevron {
    transform: rotate(180deg);
}

/* Submenu */
.sidebar-submenu {
    padding-bottom: 0.25rem;
}

.sidebar-submenu .sidebar-link {
    padding-left: 2.5rem;
    font-size: 0.82rem;
}

/* Badge */
.sidebar-badge {
    font-size: 0.65rem;
    padding: 0.2em 0.5em;
}

/* ---- Main Content ---- */
#main-content {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
    min-height: calc(100vh - var(--topnav-height));
}

/* ---- Footer ---- */
.footer {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
}

/* ---- Sidebar Hidden State ---- */
body.sidebar-hidden .sidebar {
    transform: translateX(-100%);
}

body.sidebar-hidden #main-content,
body.sidebar-hidden .footer {
    margin-left: 0;
}

/* ---- Sidebar Overlay (mobile) ---- */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--topnav-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1035;
}

.sidebar-overlay.show {
    display: block;
}

/* ---- Mobile / Off-canvas Sidebar ---- */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    #main-content,
    .footer {
        margin-left: 0 !important;
    }

    /* When sidebar hidden class is set on desktop, don't affect mobile */
    body.sidebar-hidden .sidebar.show {
        transform: translateX(0);
    }
}

/* ---- Cards ---- */
.card {
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    border-radius: 0.5rem;
}

/* ---- Spin animation ---- */
.spin {
    display: inline-block;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ---- Top Navbar ---- */
#topNav {
    z-index: 1050;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Mobile Optimizations
   ============================================ */

/* ---- Tablet (< 992px) ---- */
@media (max-width: 991.98px) {
    /* Reduce content padding */
    #main-content .container-fluid {
        padding: 1rem !important;
    }

    /* Make tables scrollable horizontally */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    /* Stack cards on smaller screens */
    .row .col-md-3,
    .row .col-md-4,
    .row .col-lg-3,
    .row .col-lg-4 {
        margin-bottom: 0.75rem;
    }

    /* Action buttons: stack better */
    .btn-group {
        flex-wrap: wrap;
    }
}

/* ---- Small devices (< 768px) ---- */
@media (max-width: 767.98px) {
    /* Further reduce padding */
    #main-content .container-fluid {
        padding: 0.75rem !important;
    }

    /* Page titles */
    h1, .h1 { font-size: 1.5rem; }
    h2, .h2 { font-size: 1.25rem; }
    h3, .h3 { font-size: 1.1rem; }

    /* Cards: tighter padding */
    .card-body {
        padding: 0.75rem;
    }

    /* Dashboard stat cards: smaller text */
    .card .display-6 {
        font-size: 1.5rem;
    }

    /* Tables: improve readability */
    .table > :not(caption) > * > * {
        padding: 0.4rem 0.5rem;
        font-size: 0.82rem;
    }

    /* Wrap all tables in horizontal scroll */
    .card-body > .table,
    .card-body > .table-responsive {
        font-size: 0.82rem;
    }

    /* Forms: full-width on mobile */
    .row .col-md-6,
    .row .col-md-4,
    .row .col-md-3 {
        margin-bottom: 0.5rem;
    }

    /* Buttons: touch-friendly size */
    .btn {
        min-height: 38px;
        padding: 0.375rem 0.75rem;
    }

    .btn-sm {
        min-height: 32px;
        padding: 0.25rem 0.5rem;
    }

    /* Modal: full-width on mobile */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    /* Badge spacing */
    .badge {
        font-size: 0.7rem;
    }

    /* Navbar brand: truncate long names */
    .navbar-brand {
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.9rem !important;
    }

    /* Navbar buttons: smaller */
    #topNav .btn-sm {
        padding: 0.2rem 0.4rem;
        font-size: 0.75rem;
    }

    /* Hide text in navbar buttons, show icons only */
    .lang-switcher .dropdown-toggle .bi + span,
    .lang-switcher .dropdown-toggle {
        font-size: 0.75rem;
    }

    /* Action column buttons: icon only on mobile */
    .table .btn-sm {
        padding: 0.2rem 0.4rem;
    }

    /* Pagination: compact */
    .pagination .page-link {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
    }

    /* DataTables adjustments */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none !important;
        text-align: center;
        margin-bottom: 0.5rem;
    }

    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: center;
        margin-top: 0.5rem;
    }

    /* Flex column on mobile for filter rows */
    .d-flex.gap-2 {
        flex-wrap: wrap;
    }

    /* Footer */
    .footer {
        text-align: center;
        font-size: 0.8rem;
    }
}

/* ---- Extra small devices (< 576px) ---- */
@media (max-width: 575.98px) {
    /* Even tighter padding */
    #main-content .container-fluid {
        padding: 0.5rem !important;
    }

    /* Stack header actions */
    .d-flex.justify-content-between {
        flex-direction: column;
        gap: 0.5rem;
    }

    .d-flex.justify-content-between > * {
        width: 100%;
    }

    .d-flex.justify-content-between .btn {
        width: 100%;
    }

    /* Navbar: minimal */
    .navbar-brand {
        max-width: 100px;
        font-size: 0.8rem !important;
    }

    .navbar-brand img {
        height: 22px !important;
    }

    /* Hide lang text, show icon only */
    .lang-switcher .dropdown-toggle .me-1 + span {
        display: none;
    }

    /* User dropdown: show icon only */
    #topNav .dropdown .dropdown-toggle .bi-person-circle + span {
        display: none;
    }

    /* Card headers: stack elements */
    .card-header .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Full-width form inputs */
    .form-control,
    .form-select {
        font-size: 0.875rem;
    }

    /* Tab navigation: scrollable */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
        padding: 0.4rem 0.75rem;
        font-size: 0.82rem;
    }

    /* Employee view tabs: scroll */
    .nav-pills {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav-pills .nav-link {
        white-space: nowrap;
        font-size: 0.82rem;
    }

    /* Alert boxes */
    .alert {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
}
