/* ============================================
   Maryg Clinic - Admin Panel Theme
   RTL | Persian | Dark/Light Mode | Customizable Colors
   ============================================ */

/* ========== IranSans Font Faces ========== */
@font-face {
    font-family: 'IRANSansWeb(FaNum)';
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_UltraLight.eot');
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_UltraLight.eot?#iefix') format('embedded-opentype'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_UltraLight.woff2') format('woff2'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_UltraLight.woff') format('woff'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_UltraLight.ttf') format('truetype');
    font-weight: 200;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IRANSansWeb(FaNum)';
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_Light.eot');
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_Light.eot?#iefix') format('embedded-opentype'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Light.woff2') format('woff2'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Light.woff') format('woff'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IRANSansWeb(FaNum)';
    src: url('../fonts/iransans/IRANSansWeb(FaNum).eot');
    src: url('../fonts/iransans/IRANSansWeb(FaNum).eot?#iefix') format('embedded-opentype'),
         url('../fonts/iransans/IRANSansWeb(FaNum).woff2') format('woff2'),
         url('../fonts/iransans/IRANSansWeb(FaNum).woff') format('woff'),
         url('../fonts/iransans/IRANSansWeb(FaNum).ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IRANSansWeb(FaNum)';
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_Medium.eot');
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_Medium.eot?#iefix') format('embedded-opentype'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Medium.woff2') format('woff2'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Medium.woff') format('woff'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IRANSansWeb(FaNum)';
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_Bold.eot');
    src: url('../fonts/iransans/IRANSansWeb(FaNum)_Bold.eot?#iefix') format('embedded-opentype'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Bold.woff2') format('woff2'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Bold.woff') format('woff'),
         url('../fonts/iransans/IRANSansWeb(FaNum)_Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    /* Default Theme Colors */
    --maryg-primary: #4a154b;
    --maryg-primary-light: #6b2d6d;
    --maryg-primary-dark: #2d0d2e;
    --maryg-accent: #e91e63;
    --maryg-accent-light: #f06292;

    /* Light Mode */
    --bg-main: #f5f7fa;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-navbar: var(--maryg-primary);
    --bg-input: #ffffff;
    --bg-hover: #f0f0f5;

    --text-primary: #1a1a2e;
    --text-secondary: #6c757d;
    --text-muted: #999;
    --text-navbar: #ffffff;
    --text-sidebar: #333;
    --text-sidebar-active: var(--maryg-primary);

    --border-color: #e0e0e0;
    --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 8px 30px rgba(0,0,0,0.12);

    /* Spacing */
    --sidebar-width: 260px;
    --navbar-height: 60px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

/* ========== Dark Mode Overrides ========== */
[data-theme="dark"] {
    --bg-main: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-sidebar: #16162b;
    --bg-navbar: #1a1a2e;
    --bg-input: #252540;
    --bg-hover: #252540;

    --text-primary: #e8e8f0;
    --text-secondary: #a0a0b8;
    --text-muted: #777;
    --text-navbar: #e8e8f0;
    --text-sidebar: #c0c0d0;
    --text-sidebar-active: #ffffff;

    --border-color: #2a2a45;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

/* ========== Base Styles ========== */
* { box-sizing: border-box; }

body {
    font-family: 'IRANSansWeb(FaNum)', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    direction: rtl;
    text-align: right;
    transition: background 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

a { color: var(--maryg-primary); text-decoration: none; }
a:hover { color: var(--maryg-primary-light); }

/* ========== Navbar ========== */
.admin-navbar {
    background: var(--bg-navbar);
    color: var(--text-navbar);
    height: var(--navbar-height);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    box-shadow: var(--shadow-md);
    transition: background 0.3s ease;
}

.admin-navbar .brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-navbar);
    text-decoration: none;
    white-space: nowrap;
}

.admin-navbar .brand i { margin-left: 0.5rem; }

.admin-navbar .nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-right: auto;
}

.admin-navbar .user-name {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Theme toggle buttons */
.theme-toggle {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: var(--text-navbar);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}
.theme-toggle:hover { background: rgba(255,255,255,0.3); }

.color-picker-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: var(--text-navbar);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    position: relative;
}

.color-picker-input {
    position: absolute;
    top: 0; left: 0;
    width: 36px; height: 36px;
    opacity: 0;
    cursor: pointer;
    border-radius: 50%;
}

/* ========== Sidebar ========== */
.admin-sidebar {
    position: fixed;
    top: var(--navbar-height);
    right: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 1.25rem 0;
    box-shadow: var(--shadow-sm);
    z-index: 1020;
    transition: background 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}

.sidebar-nav { list-style: none; padding: 0; margin: 0; }

.sidebar-nav .nav-section {
    padding: 0.75rem 1.5rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.5rem;
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s ease;
    border-right: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--bg-hover);
    color: var(--text-sidebar-active);
    border-right-color: var(--maryg-primary-light);
}

.sidebar-nav a.active {
    background: rgba(74, 21, 75, 0.08);
    color: var(--text-sidebar-active);
    border-right-color: var(--maryg-primary);
    font-weight: 600;
}

.sidebar-nav a i { font-size: 1.1rem; width: 20px; text-align: center; }

/* ========== Main Content ========== */
.admin-main {
    margin-right: var(--sidebar-width);
    margin-top: var(--navbar-height);
    padding: 1.75rem;
    min-height: calc(100vh - var(--navbar-height));
    transition: margin 0.3s ease;
}

/* ========== Cards ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    /*justify-content: space-between;*/
}

.card-body { padding: 1.25rem; }

/* Stat Cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    position: absolute;
    left: 1rem;
    top: 1rem;
    font-size: 2.5rem;
    opacity: 0.1;
    color: var(--maryg-primary);
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--maryg-primary);
}

.stat-card .stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* ========== Buttons ========== */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    padding: 0.5rem 1.25rem;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.btn-primary {
    background: var(--maryg-primary);
    border-color: var(--maryg-primary);
}
.btn-primary:hover {
    background: var(--maryg-primary-light);
    border-color: var(--maryg-primary-light);
}

.btn-outline-primary {
    color: var(--maryg-primary);
    border-color: var(--maryg-primary);
}
.btn-outline-primary:hover {
    background: var(--maryg-primary);
    border-color: var(--maryg-primary);
}

.btn-success { background: #28a745; border-color: #28a745; }
.btn-danger { background: #dc3545; border-color: #dc3545; }
.btn-warning { background: #ffc107; border-color: #ffc107; color: #000; }

/* ========== Forms ========== */
.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.form-control, .form-select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--maryg-primary);
    box-shadow: 0 0 0 0.2rem rgba(74, 21, 75, 0.15);
    outline: none;
}

/* ========== Tables ========== */
.table {
    color: var(--text-primary);
    margin: 0;
}

.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom-width: 1px;
    background: var(--bg-hover);
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
    font-size: 0.9rem;
}

/* ========== Alerts ========== */
.alert {
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.9rem;
}

/* ========== Badges ========== */
.badge {
    font-weight: 500;
    padding: 0.35em 0.65em;
    border-radius: var(--radius-sm);
}

/* ========== Modal ========== */
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
}

.modal-footer {
    border-top: 1px solid var(--border-color);
}

/* ========== Pagination ========== */
.pagination .page-link {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.pagination .page-item.active .page-link {
    background: var(--maryg-primary);
    border-color: var(--maryg-primary);
}

/* ========== Search Box ========== */
.search-box {
    position: relative;
}

.search-box .search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-box input {
    padding-right: 2.5rem;
}

/* ========== Empty State ========== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    margin: 0;
    font-size: 1rem;
}

/* ========== Responsive ========== */
@media (max-width: 991px) {
    .admin-sidebar {
        transform: translateX(100%);
    }

    .admin-sidebar.mobile-open {
        transform: translateX(0);
    }

    .admin-main {
        margin-right: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1015;
    }

    .sidebar-overlay.active { display: block; }
}

@media (max-width: 768px) {
    .admin-main { padding: 1rem; }
    .admin-navbar { padding: 0 0.75rem; }
    .admin-navbar .brand { font-size: 0.95rem; }
    .admin-navbar .user-name { display: none; }
    .stat-card .stat-value { font-size: 1.5rem; }
}

/* ========== Mobile Nav Toggle ========== */
.nav-toggle {
    background: none;
    border: none;
    color: var(--text-navbar);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.25rem;
    display: none;
}

@media (max-width: 991px) {
    .nav-toggle { display: block; }
}

/* ========== Theme Color Customizer ========== */
.color-presets {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.color-preset {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.color-preset:hover { transform: scale(1.15); }
.color-preset.active { border-color: var(--text-primary); }

/* ========== Utilities ========== */
.cursor-pointer { cursor: pointer; }
.d-none-rtl { display: none !important; }
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ========== Login Page ========== */
.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    max-width: 420px;
    width: 100%;
    background: var(--bg-card, #fff);
    border-radius: var(--radius-lg);
    padding: 2.25rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    direction: rtl;
    text-align: right;
}

.login-card .clinic-logo {
    width: 70px;
    height: 70px;
    background: var(--maryg-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    color: white;
    font-size: 1.8rem;
}

.login-card h3 {
    text-align: center;
    color: var(--maryg-primary);
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.login-card .clinic-subtitle {
    text-align: center;
    color: var(--text-secondary, #888);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

/* ========== Table Card (data tables wrapper) ========== */
.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-card .table {
    margin-bottom: 0;
}

.table-card .table thead th {
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
}

.table-card .table tbody td {
    vertical-align: middle;
}

.table-card .table tbody tr:hover {
    background: var(--bg-hover);
}

/* ========== Form Card ========== */
.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
}

/* ========== Status Badges ========== */
.status-badge {
    display: inline-block;
    padding: 0.25em 0.7em;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}

.status-Scheduled, .status-Confirmed, .status-Paid, .status-Active {
    background: rgba(25, 135, 84, 0.12);
    color: #198754;
}

.status-Cancelled, .status-Overdue {
    background: rgba(220, 53, 69, 0.12);
    color: #dc3545;
}

.status-Completed {
    background: rgba(13, 110, 253, 0.12);
    color: #0d6efd;
}

.status-Pending, .status-Draft {
    background: rgba(255, 193, 7, 0.15);
    color: #b58900;
}

.status-InProgress {
    background: rgba(23, 162, 184, 0.12);
    color: #17a2b8;
}

.status-NoShow {
    background: rgba(108, 117, 125, 0.15);
    color: #6c757d;
}

/* ========== Document Thumbnail ========== */
.doc-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-hover);
    cursor: pointer;
}

.doc-thumb-lg {
    max-width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-sm);
}

/* ========== Action Button Group in Tables ========== */
.btn-group-actions .btn {
    margin-bottom: 0.2rem;
}

/* ========== Page Action Bar ========== */
.page-actions .btn {
    margin-inline-start: 0.4rem;
}

/* ========== Select2 Overrides (RTL + theme aware) ========== */
.select2-container {
    direction: rtl;
    text-align: right;
    width: 100% !important;
}

.select2-container .select2-selection--single {
    height: calc(1.5em + 1.1rem + 2px) !important; /* matches .form-control padding */
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.select2-container .select2-selection--single:hover {
    border-color: var(--maryg-primary-light);
}

/* Focus ring identical to .form-control:focus */
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--maryg-primary);
    box-shadow: 0 0 0 0.2rem rgba(74, 21, 75, 0.15);
}

.select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 1.5;
    color: var(--text-primary);
    padding: 0;
    padding-left: 24px; /* room for the arrow on the left (RTL) */
    flex: 1;
    text-align: right;
}

.select2-container .select2-selection--single .select2-selection__arrow {
    /* RTL: the dropdown arrow sits at the LEFT end of the control */
    left: 8px;
    right: auto;
    top: 0;
    height: 100%;
    width: 24px;
}

.select2-container .select2-selection--single .select2-selection__arrow b {
    border-color: var(--text-muted) transparent transparent transparent;
    border-width: 5px 4px 0 4px;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--text-muted) transparent;
    border-width: 0 4px 5px 4px;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted);
}

.select2-container--default .select2-selection--single .select2-selection__clear {
    float: left;
    margin-left: 4px;
    color: var(--text-muted);
}

.select2-dropdown {
    direction: rtl;
    text-align: right;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    /* Keep the dropdown above Bootstrap modals (z-index 1055) so the
       patient search results are visible inside the Prescriptions modal. */
    z-index: 2000;
}

.select2-search--dropdown {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.select2-search--dropdown .select2-search__field {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    direction: rtl;
    text-align: right;
    padding: 0.45rem 0.75rem;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.select2-search--dropdown .select2-search__field:focus {
    border-color: var(--maryg-primary);
    box-shadow: 0 0 0 0.2rem rgba(74, 21, 75, 0.15);
}

.select2-results__option {
    color: var(--text-primary);
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--maryg-primary);
    color: #ffffff;
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.select2-container--default .select2-results > .select2-results__options {
    max-height: 260px;
}

/* Loading indicator (AJAX search) */
.select2-container--default .select2-search--inline .select2-search__field {
    color: var(--text-primary);
}

.select2-results__message {
    color: var(--text-muted);
    padding: 0.5rem 0.85rem;
}

/* ========== Submit Button Loading State ==========
   Applied by MarygLoading.begin() while a server-side save/edit
   operation is in flight. The button is disabled so duplicate
   submissions are impossible, and a spinner element is placed
   right after it as the visual loading indicator. */
.btn-loading,
.btn-loading:hover,
.btn-loading:focus {
    opacity: 0.65;
    cursor: progress;
    pointer-events: none;
}

.maryg-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    margin-inline-start: 0.5rem;
    vertical-align: -0.15em;
    border: 2px solid rgba(128, 128, 128, 0.35);
    border-top-color: var(--maryg-primary, #4a154b);
    border-radius: 50%;
    animation: maryg-spin 0.7s linear infinite;
}

@keyframes maryg-spin {
    to { transform: rotate(360deg); }
}
