/* Custom CSS for Antibiotic Management System */

:root {
    --primary-color: #5e35b1;
    --secondary-color: #4c2c92;
    --success-color: #198754;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #0dcaf0;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --hospital-gradient: linear-gradient(135deg, #5e35b1 0%, #4c2c92 100%);
    --sidebar-bg: linear-gradient(180deg, #5e35b1 0%, #4c2c92 100%);
    --sidebar-width: 280px;
    --transition: all 0.3s ease;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.88rem;
    background-color: #f0f2f5;
    direction: rtl;
    text-align: right;
    margin: 0;
    overflow-x: hidden;
}

/* Layout */
.main-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.main-content {
    flex: 1;
    margin-right: var(--sidebar-width) !important;
    width: calc(100% - var(--sidebar-width)) !important;
    padding: 1.5rem;
    padding-top: 100px;
    background: #f0f2f5;
    min-height: 100vh;
    transition: var(--transition);
}

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

/* Top Header Bar */
.top-header-bar {
    position: fixed;
    top: 0;
    right: var(--sidebar-width) !important;
    left: 0;
    width: calc(100% - var(--sidebar-width)) !important;
    height: 70px;
    background: white !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    z-index: 1030;
    transition: var(--transition);
    display: flex;
    align-items: center;
    overflow: hidden;
}

.hospital-name-top {
    font-weight: 800;
    color: var(--primary-color);
    margin: 0;
    font-size: 1.15rem;
}

[dir="ltr"] .top-header-bar {
    right: 0 !important;
    left: var(--sidebar-width) !important;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg) !important;
    color: white;
    z-index: 1060;
    transition: var(--transition);
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    overflow: visible;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}

/* Custom Scrollbar for Sidebar (Webkit) */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 20px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

.sidebar #sidebarCloseBtn {
    display: none;
}

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

/* Content Header (The title part inside pages) */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #dee2e6;
    flex-wrap: wrap;
    gap: 1rem;
}

.header h1 {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--dark-color);
    margin: 0;
    line-height: 1.2;
    padding-top: 0.5rem;
}

.header p {
    font-size: 0.8rem;
    color: #6c757d;
    margin: 0.25rem 0 0 0;
}

/* Statistics Grid - Fixing the overlapping */
.stat-box {
    padding: 0.85rem;
    border-radius: 0.85rem;
    color: white !important;
    position: relative;
    overflow: hidden;
    height: 100%;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    transition: var(--transition);
}

.stat-box:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.stat-number {
    font-size: 1.55rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.4rem;
    position: relative;
    z-index: 2;
}

.stat-label {
    font-size: 0.78rem;
    font-weight: 600;
    opacity: 0.9;
    position: relative;
    z-index: 2;
}

.stat-icon {
    position: absolute;
    bottom: -8px;
    left: -8px;
    font-size: 3rem;
    opacity: 0.15;
    transform: rotate(-15deg);
    z-index: 1;
}

/* Colors */
.stat-box.blue { background: linear-gradient(135deg, #26a69a 0%, #00897b 100%) !important; }
.stat-box.orange { background: linear-gradient(135deg, #ff8a65 0%, #f4511e 100%) !important; }
.stat-box.teal { background: linear-gradient(135deg, #4fc3f7 0%, #039be5 100%) !important; }
.stat-box.red { background: linear-gradient(135deg, #ec407a 0%, #d81b60 100%) !important; }
.stat-box.green { background: linear-gradient(135deg, #81c784 0%, #4caf50 100%) !important; }
.stat-box.purple { background: linear-gradient(135deg, #9575cd 0%, #673ab7 100%) !important; }

/* Language Switcher Buttons */
.language-switcher-btns {
    background: #f8f9fa;
    padding: 5px;
    border-radius: 30px;
    border: 1px solid #e9ecef;
}

.language-switcher-btns .btn {
    padding: 5px 15px;
    font-size: 0.85rem;
    border-radius: 20px;
    border: none;
    font-weight: 600;
}

.language-switcher-btns .btn.active {
    background: var(--primary-color) !important;
    color: white !important;
}

/* Buttons */
.btn {
    border-radius: 8px;
    padding: 0.6rem 1.25rem;
    font-weight: 600;
    transition: var(--transition);
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* General Nav Links (like Tabs/Pills) */
.nav-link {
    color: #475569;
    font-weight: 600;
    transition: var(--transition);
}

.nav-link:hover {
    color: var(--primary-color);
}

/* Sidebar Navigation */
.sidebar-nav {
    padding: 1rem 0;
}

/* Sidebar content wrapper */
.sidebar-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Nav sections inside sidebar */
.nav-section {
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.nav-section:last-of-type {
    border-bottom: none;
}

.nav-section-title {
    padding: 0.5rem 1.25rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.45);
}

/* Sidebar footer */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.05);
    z-index: 1050;
    flex-shrink: 0;
}

.sidebar-footer .nav-link {
    border-radius: 8px;
    background: rgba(255,255,255,0.08);
    padding: 0.8rem 1rem !important;
    display: flex !important;
    align-items: center;
    gap: 10px;
    width: 100%;
    transition: var(--transition);
}

.sidebar-footer .nav-link:hover {
    background: rgba(255,255,255,0.15) !important;
}

.sidebar-footer .dropup .dropdown-menu {
    background: white;
    border: none;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    border-radius: 10px;
    min-width: 200px;
    margin-bottom: 0.5rem;
    z-index: 100000 !important; /* Extremely high to stay above sidebar */
}

.sidebar-footer .dropdown-item {
    padding: 0.65rem 1rem;
    font-size: 0.88rem;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-footer .dropdown-item:hover {
    background: #f1f5f9;
    color: var(--primary-color);
}

.sidebar-footer .dropdown-item.text-danger:hover {
    background: #fee2e2;
    color: #dc3545;
}

.sidebar-header {
    padding: 2rem 1rem;
    text-align: center;
    background: rgba(0,0,0,0.1);
    position: relative;
}

.hospital-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.1);
    padding: 10px;
    border-radius: 12px;
    text-decoration: none;
    color: white;
}

.logo-icon {
    width: 45px;
    height: 45px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
}

.logo-icon img { max-width: 100%; }

.sidebar .nav-link {
    color: rgba(255,255,255,0.8) !important;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    transition: var(--transition);
    font-size: 0.9rem;
}

.sidebar .nav-link:hover {
    color: white !important;
    background: rgba(255,255,255,0.1);
}

.sidebar .nav-link.active {
    background: rgba(255,255,255,0.2) !important;
    color: white !important;
    font-weight: 600;
}

/* Tables Style Enhancement */
.table {
    width: 100%;
    margin-bottom: 1rem;
    color: #334155;
    vertical-align: middle;
    border-collapse: separate;
    border-spacing: 0;
    background-color: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    font-size: 0.88rem;
}

.table thead th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.025em;
    padding: 1rem 0.75rem;
    border-bottom: 2px solid #e2e8f0;
    border-top: none;
}

.table tbody td {
    padding: 0.85rem 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    transition: var(--transition);
}

.table tbody tr:hover td {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Badge styles for tables */
.badge {
    padding: 0.5em 0.8em;
    font-weight: 600;
    border-radius: 6px;
}

.bg-success { background-color: #dcfce7 !important; color: #166534; }
.bg-warning { background-color: #fef9c3 !important; color: #854d0e; }
.bg-danger { background-color: #fee2e2 !important; color: #991b1b; }
.bg-info { background-color: #e0f2fe !important; color: #075985; }
.bg-primary { background-color: #ede9fe !important; color: #5b21b6; }

/* Global Header Text Color Fix */
.card-header, 
.table-header-section,
.model-header,
.section-header,
.page-header {
    color: #ffffff !important;
}

.card-header h1, .card-header h2, .card-header h3, .card-header h4, .card-header h5, .card-header h6,
.table-header-section h1, .table-header-section h2, .table-header-section h3, .table-header-section h4,
.model-header h1, .model-header h2, .model-header h3,
.section-header h1, .section-header h2, .section-header h3,
.page-header h1, .page-header h2, .page-header h3 {
    color: #ffffff !important;
}

.card-header small, .table-header-section small, .model-header small, .section-header small, .page-header small,
.card-header p, .table-header-section p, .model-header p, .section-header p, .page-header p {
    color: rgba(255, 255, 255, 0.9) !important;
}

.card-header i, .table-header-section i, .model-header i, .section-header i, .page-header i {
    color: #ffffff !important;
}

/* Mobile Menu Toggle Button Styles */
.mobile-menu-btn {
    position: fixed;
    top: 15px;
    right: 15px;
    width: 45px;
    height: 45px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    display: none; /* Hidden by default, shown in media query */
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    z-index: 10000; /* Higher than sidebar 9999 */
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    cursor: pointer;
    transition: var(--transition);
}

[dir="ltr"] .mobile-menu-btn {
    right: auto;
    left: 15px;
}

.mobile-menu-btn:hover {
    background: var(--secondary-color);
    transform: scale(1.05);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

.sidebar-header .close-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: none; /* Shown only on mobile */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.sidebar-header .close-btn:hover {
    background: rgba(255,255,255,0.25);
}

@media (max-width: 992px) {
    .mobile-menu-btn {
        display: flex;
    }
    
    .sidebar-header {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: flex-start;
        padding: 1rem;
        gap: 0.5rem;
    }

    .sidebar-header .hospital-logo {
        flex: 1;
    }
    
    .sidebar-header .close-btn {
        display: flex;
    }

    .sidebar-header .welcome-msg {
        order: 3;
        width: 100%;
        margin-top: 0.5rem !important;
    }

    .sidebar { 
        transform: translateX(100%); 
        z-index: 1070;
    }
    
    [dir="ltr"] .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.show { 
        transform: translateX(0) !important; 
        box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    }
    
    .top-header-bar { 
        right: 0 !important; 
        left: 0 !important;
        width: 100% !important;
        padding-right: 65px;
        padding-left: 10px;
        height: 60px;
    }
    
    [dir="ltr"] .top-header-bar {
        padding-right: 10px;
        padding-left: 65px;
    }

    .top-header-bar .container-fluid {
        padding: 0 10px !important;
        flex-wrap: nowrap !important;
    }

    .hospital-name-top {
        font-size: 0.85rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }

    .language-switcher-btns {
        padding: 2px;
        flex-shrink: 0;
    }

    .language-switcher-btns .btn {
        padding: 3px 8px;
        font-size: 0.72rem;
    }
    
    .main-content { 
        padding: 0.75rem !important;
        padding-top: 75px !important; 
        margin-right: 0 !important;
        margin-left: 0 !important;
        width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Layout adjustments */
    .header {
        flex-direction: column;
        align-items: flex-start;
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
        gap: 0.75rem;
    }

    .header .d-flex {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .header .d-flex .btn {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
        white-space: nowrap;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    /* Grid adjustments for mobile */
    .row > * {
        padding-right: 0.4rem !important;
        padding-left: 0.4rem !important;
    }

    .row.g-3 {
        --bs-gutter-x: 0.6rem;
        --bs-gutter-y: 0.6rem;
    }
    
    /* Stat boxes: 2 per row on mobile */
    .col-xl-4.col-md-6 {
        width: 50% !important;
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    .stat-box {
        min-height: 85px;
        padding: 0.65rem;
        border-radius: 0.65rem;
    }
    
    .stat-number {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-icon {
        font-size: 2.2rem;
    }
    
    .header h1 {
        font-size: 1.15rem;
    }
    
    /* Table responsive improvements */
    .table-responsive {
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        border: 1px solid #e2e8f0;
        margin-bottom: 1rem;
        -webkit-overflow-scrolling: touch;
    }

    .table thead th {
        padding: 0.65rem 0.4rem;
        font-size: 0.72rem;
        white-space: nowrap;
    }

    .table tbody td {
        padding: 0.65rem 0.4rem;
        font-size: 0.78rem;
    }
    
    .btn-action {
        width: 100%;
        justify-content: center;
    }

    /* Quick actions buttons on mobile */
    .card-body .text-center .btn {
        display: inline-flex;
        margin: 0.25rem;
        font-size: 0.8rem;
        padding: 0.45rem 0.75rem;
    }

    /* Cards */
    .card {
        border-radius: 10px;
    }

    .card-body {
        padding: 0.85rem !important;
    }

    /* Charts */
    .chart-container {
        height: 220px !important;
    }

    /* Col adjustments for dashboard layout */
    .col-lg-8, .col-lg-4 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* Extra small screens (phones < 480px) */
@media (max-width: 480px) {
    .hospital-name-top {
        font-size: 0.78rem !important;
        max-width: 110px;
    }

    .stat-number {
        font-size: 1.1rem;
    }

    .stat-label {
        font-size: 0.65rem;
    }

    .stat-box {
        min-height: 78px;
        padding: 0.55rem;
    }

    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        top: 10px;
        right: 10px;
        font-size: 1.1rem;
    }

    [dir="ltr"] .mobile-menu-btn {
        right: auto;
        left: 10px;
    }

    .top-header-bar {
        padding-right: 58px;
        height: 56px;
    }

    [dir="ltr"] .top-header-bar {
        padding-right: 10px;
        padding-left: 58px;
    }

    .main-content {
        padding-top: 68px !important;
    }
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1055; /* Just below sidebar 1060 */
    display: none;
    backdrop-filter: blur(3px);
    transition: var(--transition);
}

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

/* Fix for Checkboxes hanging or being hard to click */
input[type="checkbox"], 
input[type="radio"] {
    cursor: pointer;
    position: relative;
    z-index: 5;
    width: 1.1rem !important;
    height: 1.1rem !important;
    vertical-align: middle;
    margin: 0;
    pointer-events: auto !important;
    flex-shrink: 0;
}

/* Table Checkbox Alignment Fix */
.table td .form-check {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    min-height: auto;
}

.table td .form-check-input {
    margin: 0 !important;
    float: none;
}

.table td {
    vertical-align: middle;
    text-align: center;
}

/* Ensure patient name and reason columns stay right-aligned in RTL */
[dir="rtl"] .table td:has(input[type="text"]),
[dir="rtl"] .table td:has(select),
[dir="rtl"] .table td:first-child {
    text-align: right;
}

[dir="ltr"] .table td:has(input[type="text"]),
[dir="ltr"] .table td:has(select),
[dir="ltr"] .table td:first-child {
    text-align: left;
}

label {
    cursor: pointer;
    pointer-events: auto !important;
}

/* Modal Z-Index Fix (for custom modals) */
.modal {
    z-index: 2000 !important;
}

.modal-backdrop {
    z-index: 1990 !important;
}

.card-body {
    padding: 1rem !important;
}

.dashboard-card {
    margin-bottom: 1rem !important;
}

.section-title {
    font-size: 0.95rem !important;
    margin-bottom: 1rem !important;
}

/* =============================================
   Dashboard Specific Styles
   ============================================= */

/* Unit cards in dashboard */
.unit-card {
    background: #f8fafc;
    border-radius: 10px;
    padding: 0.85rem;
    margin-bottom: 0.75rem;
    border: 1px solid #e2e8f0;
    transition: var(--transition);
}

.unit-card:hover {
    background: #f1f5f9;
    border-color: var(--primary-color);
}

/* Progress bars */
.progress-bar-custom {
    height: 6px;
    background: #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    margin: 4px 0;
}

.progress-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.6s ease;
}

/* Quick stats */
.quick-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0;
    border-bottom: 1px solid #f1f5f9;
}

.quick-stat:last-child {
    border-bottom: none;
}

.quick-stat-number {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary-color);
}

.quick-stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    text-align: end;
}

/* Antibiotic items */
.antibiotic-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f1f5f9;
}

.antibiotic-item:last-child {
    border-bottom: none;
}

/* Chart container */
.chart-container {
    position: relative;
    height: 280px;
}

/* Badge custom */
.badge-custom {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

/* Mobile dashboard improvements */
@media (max-width: 992px) {
    .unit-card {
        padding: 0.65rem;
    }

    .quick-stat-number {
        font-size: 1.1rem;
    }

    .quick-stat-label {
        font-size: 0.75rem;
        max-width: 55%;
    }

    .antibiotic-item {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    /* Quick actions: wrap nicely on mobile */
    .card-body .text-center {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.4rem;
    }

    .card-body .text-center .btn {
        flex: 1 1 calc(50% - 0.4rem);
        min-width: 130px;
        max-width: 200px;
        margin: 0 !important;
        font-size: 0.78rem;
        padding: 0.5rem 0.5rem;
        text-align: center;
        justify-content: center;
    }
}
