/* =====================================================
   پیشخوان کسب‌وکار پارس رسانه
   Managed Business Services Platform
   Persian Gold Business Identity
   ===================================================== */

/* === Design Tokens === */
:root {
    /* Core Palette — Persian Business Identity */
    --ink:         #1B2A4A;
    --ink-light:   #2A3F6A;
    --ink-dark:    #111D35;
    --surface:     #F7F5F0;
    --surface-alt: #EFECE6;
    --gold:        #C4922A;
    --gold-light:  #D4A84A;
    --gold-dark:   #A67B1E;
    --gold-muted:  rgba(196,146,42,0.12);
    --teal:        #2D8B6F;
    --teal-light:  #3AA882;
    --teal-muted:  rgba(45,139,111,0.12);
    --muted:       #8B8680;
    --danger:      #B84233;
    --danger-muted:rgba(184,66,51,0.10);
    --warning:     #D4872A;
    --warning-muted:rgba(212,135,42,0.10);

    /* Semantic Colors */
    --bg-body:     var(--surface);
    --bg:          #FFFFFF;
    --bg-card:     #FFFFFF;
    --bg-sidebar:  var(--ink);
    --bg-header:   #FFFFFF;
    --bg-alt:      var(--surface-alt);
    --primary:     #6366f1;
    --primary-rgb: 99,102,241;
    --primary-bg:  rgba(99,102,241,0.08);
    --primary-hover:#5558e6;
    --text:        var(--ink);
    --text-primary: var(--ink);
    --text-secondary: var(--muted);
    --text-muted:  #ADA8A2;
    --border:      #E8E4DD;
    --border-color: #E8E4DD;
    --border-subtle: #F0EDE8;
    --placeholder:  #c4c0b8;

    /* Shadows */
    --shadow-xs:   0 1px 2px rgba(27,42,74,0.04);
    --shadow-sm:   0 1px 3px rgba(27,42,74,0.06), 0 1px 2px rgba(27,42,74,0.04);
    --shadow-md:   0 4px 6px rgba(27,42,74,0.05), 0 2px 4px rgba(27,42,74,0.04);
    --shadow-lg:   0 10px 15px rgba(27,42,74,0.06), 0 4px 6px rgba(27,42,74,0.04);
    --shadow-gold: 0 4px 14px rgba(196,146,42,0.15);

    /* Layout */
    --radius-xs:   6px;
    --radius-sm:   8px;
    --radius-md:   12px;
    --radius-lg:   16px;
    --radius-xl:   20px;
    --sidebar-width: 260px;
    --header-height: 60px;

    /* Transitions — explicit properties only */
    --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
    --t-color:     color 0.2s var(--ease-out);
    --t-bg:        background-color 0.2s var(--ease-out);
    --t-border:    border-color 0.2s var(--ease-out);
    --t-shadow:    box-shadow 0.2s var(--ease-out);
    --t-transform: transform 0.2s var(--ease-out);
    --t-opacity:   opacity 0.15s var(--ease-out);
}

/* === Text Alignment — Justify for Persian === */
body { direction: rtl; }
p, li, .card-body, .accordion-body-inner, .sp-card { text-align: justify; }


/* === Dark Mode === */
[data-theme="dark"] {
    color-scheme: dark;
    --bg-body:    #0E1219;
    --bg:          #161B26;
    --bg-card:    #161B26;
    --bg-alt:     #1E2536;
    --bg-sidebar: #0A0E14;
    --bg-header:  #161B26;
    --primary:     #818cf8;
    --primary-rgb: 129,140,248;
    --primary-bg:  rgba(129,140,248,0.12);
    --primary-hover:#9196f4;
    --text:        #E8E4DD;
    --text-primary: #E8E4DD;
    --text-secondary: #9A9590;
    --text-muted: #6B6660;
    --border:      #2A3040;
    --border-color: #2A3040;
    --border-subtle: #1E2536;
    --placeholder:  #4A5060;
    --border-color: #2A2F3A;
    --border-subtle: #1E2330;
    --surface:     #0E1219;
    --surface-alt: #1A1F2A;
    --shadow-xs:   0 1px 2px rgba(0,0,0,0.2);
    --shadow-sm:   0 1px 3px rgba(0,0,0,0.3);
    --shadow-md:   0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg:   0 10px 15px rgba(0,0,0,0.4);
    --gold-muted:  rgba(196,146,42,0.15);
    --teal-muted:  rgba(45,139,111,0.15);
    --danger-muted:rgba(184,66,51,0.15);
    --warning-muted:rgba(212,135,42,0.15);
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* === View Transitions (Cross-Document) === */
/* No view-transition — disabled to fix sidebar z-index on mobile */

/* Content: smooth cross-fade */
::view-transition-old(content) {
    animation: vt-fade-out 0.2s var(--ease-out) both;
}
::view-transition-new(content) {
    animation: vt-fade-in 0.25s var(--ease-out) 0.05s both;
}

@keyframes vt-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes vt-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Respect reduced motion for view transitions */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(content),
    ::view-transition-new(content) {
        animation: none;
    }
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 14px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Vazir', 'Tahoma', system-ui, sans-serif;
    direction: rtl;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -100%;
    right: 0;
    background: var(--ink);
    color: #fff;
    padding: 8px 16px;
    z-index: 9999;
    border-radius: 0 0 var(--radius-sm) 0;
    font-size: 13px;
}
.skip-link:focus { top: 0; }

a {
    color: var(--gold-dark);
    text-decoration: none;
    transition: var(--t-color);
}
a:hover { color: var(--gold); }

/* Focus visible */
:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

img { max-width: 100%; height: auto; display: block; }

/* === Layout === */
.app-layout { display: flex; min-height: 100vh; }

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: rgba(255,255,255,0.7);
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 1000;
    transition: transform 0.3s var(--ease-out);
    border-left: 3px solid var(--gold);
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    text-align: center;
}

.sidebar-header .logo {
    max-width: 160px;
    margin: 0 auto 8px;
    display: block;
}

.sidebar-header .app-name {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.sidebar-header .app-version {
    font-size: 10px;
    color: var(--gold);
    font-weight: 500;
    margin-top: 2px;
}

.sidebar-menu { padding: 8px 0; }

.menu-section {
    padding: 16px 20px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: rgba(255,255,255,0.3);
    letter-spacing: 0.08em;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 9px 20px;
    color: rgba(255,255,255,0.6);
    transition: var(--t-color), var(--t-bg);
    border-right: 3px solid transparent;
    font-size: 13px;
    text-decoration: none;
}

.menu-item:hover {
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.9);
}

.menu-item.active {
    background: var(--gold-muted);
    color: var(--gold-light);
    border-right-color: var(--gold);
    font-weight: 500;
}

.menu-item i {
    width: 20px;
    margin-left: 10px;
    font-size: 15px;
    text-align: center;
    opacity: 0.7;
}

.menu-item.active i { opacity: 1; }
.menu-item span { font-size: 13px; }

/* ── Collapsible Menu Groups ── */
.menu-group { }

.menu-group-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 20px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: var(--t-color), var(--t-bg);
    text-align: right;
    font-family: 'Vazir',inherit;
    line-height: 1;
}

.menu-group-toggle:hover {
    background: rgba(255,255,255,0.03);
    color: rgba(255,255,255,0.7);
}

.menu-group-toggle i.group-icon {
    width: 20px;
    margin-left: 8px;
    font-size: 13px;
    text-align: center;
    opacity: 0.6;
}

.menu-group-toggle .group-label {
    flex: 1;
}

.menu-group-toggle .group-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
    opacity: 0.4;
    margin-left: 4px;
}

.menu-group.open > .menu-group-toggle .group-arrow {
    transform: rotate(90deg);
}

.menu-group.open > .menu-group-toggle {
    color: rgba(255,255,255,0.8);
}

.menu-group.open > .menu-group-toggle i.group-icon {
    opacity: 1;
}

.menu-group-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.menu-group.open > .menu-group-items {
    max-height: 600px;
}

.menu-group-items .menu-item {
    padding-right: 36px;
    font-size: 12px;
}

.menu-group-items .menu-item i {
    font-size: 13px;
    width: 18px;
    margin-left: 8px;
}

/* When collapsed, show active item's parent group */
.menu-badge {
    margin-right: auto;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    font-weight: 600;
}

/* === Main Content === */
.main-content {
    margin-right: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Header === */
.top-header {
    height: var(--header-height);
    background: var(--bg-header);
    border-bottom: 2px solid var(--gold-muted);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-xs);
}

.header-right { display: flex; align-items: center; gap: 12px; }
.header-left { margin-right: auto; display: flex; align-items: center; gap: 12px; }

.content-wrapper {
    padding: 24px;
    flex: 1;
}

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

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

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body { padding: 20px; }
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-alt);
}

/* === Stat Cards === */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: var(--t-shadow), var(--t-transform);
}

@media (prefers-reduced-motion: no-preference) {
    .stat-card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-icon.gold {
    background: var(--gold-muted);
    color: var(--gold);
}
.stat-icon.teal {
    background: var(--teal-muted);
    color: var(--teal);
}
.stat-icon.ink {
    background: rgba(27,42,74,0.08);
    color: var(--ink);
}
.stat-icon.danger {
    background: var(--danger-muted);
    color: var(--danger);
}

.stat-info h4 {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.stat-info p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.stat-info .trend {
    font-size: 11px;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}
.stat-info .trend.up { color: var(--teal); }
.stat-info .trend.down { color: var(--danger); }

/* === Tables === */
/* Auto asterisk for required fields */
label:has(+ input[required]),
label:has(+ select[required]),
label:has(+ textarea[required]),
label:has(~ input[required]),
label:has(~ select[required]),
label:has(~ textarea[required]) {
    position: relative;
}
/* Required field asterisks are in HTML labels — no CSS auto-add needed */

/* === Form Grid (responsive) === */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    overflow: visible;
}
.form-grid > div {
    position: relative;
    overflow: visible;
}
.form-grid .form-full {
    grid-column: span 2;
}
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .form-grid .form-full {
        grid-column: span 1;
    }
}

/* === Form Actions (cancel + submit side by side) === */
.form-actions{display:flex;justify-content:flex-end;align-items:center;gap:8px;}

.table-responsive { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.data-table th {
    padding: 10px 16px;
    text-align: right;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 13px;
    vertical-align: middle;
}

.data-table tr:hover td { background: var(--surface-alt); }

.data-table .actions { display: flex; gap: 6px; }

/* === Badges === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.5;
}

.badge-primary { background: rgba(27,42,74,0.08); color: var(--ink); }
.badge-success { background: var(--teal-muted); color: var(--teal); }
.badge-warning { background: var(--warning-muted); color: var(--warning); }
.badge-danger { background: var(--danger-muted); color: var(--danger); }
.badge-info { background: var(--gold-muted); color: var(--gold-dark); }
.badge-secondary { background: var(--surface-alt); color: var(--muted); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Vazir', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--t-bg), var(--t-color), var(--t-shadow), var(--t-transform);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.5;
}

.btn-primary {
    background: var(--ink);
    color: #fff;
}
.btn-primary:hover {
    background: var(--ink-light);
    box-shadow: var(--shadow-md);
    color: #fff;
}

.btn-gold {
    background: var(--gold);
    color: #fff;
}
.btn-gold:hover {
    background: var(--gold-dark);
    box-shadow: var(--shadow-gold);
    color: #fff;
}

.btn-success {
    background: var(--teal);
    color: #fff;
}
.btn-success:hover {
    background: var(--teal-light);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover {
    background: #9E3829;
    color: #fff;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}
.btn-warning:hover {
    background: #B87424;
    color: #fff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: var(--surface-alt);
    border-color: var(--muted);
}

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 11px 24px; font-size: 14px; }

.btn-icon {
    padding: 7px;
    width: 34px;
    height: 34px;
}

/* === Forms === */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 5px;
}

/* === Global font for ALL form elements === */
input, select, textarea, .form-control { font-family: 'Vazir', 'Tahoma', system-ui, sans-serif !important; }

.form-control {
    width: 100%;
    padding: 9px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: 'Vazir', sans-serif;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-card);
    transition: var(--t-border), var(--t-shadow);
    direction: rtl;
    line-height: 1.6;
}

.form-control:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-muted);
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control { min-height: 100px; resize: vertical; }

input[type="time"].form-control {
    font-family: Vazir, sans-serif;
    font-size: 13px;
    padding: 8px 12px;
    direction: ltr;
    text-align: center;
    cursor: pointer;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238B8680' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
    padding-left: 36px;
    position: relative;
    z-index: 10;
}

/* Fix dropdown z-index: selects and datepickers always on top */
/* shamsi-calendar is now appended to body with fixed positioning — no wrapper/override needed */
.card:has(.shamsi-date) { overflow: visible; }
select.form-control:focus, select.form-control:active { z-index: 50; }
.form-row select.form-control, .filter-bar select.form-control { z-index: 10; }
.modal select.form-control { z-index: 2100; }
.modal-overlay select.form-control { z-index: 2100; }
/* Ensure modals and dropdowns stack properly */
.modal-overlay { z-index: 2000; }
.modal { z-index: 2001; }
.modal .form-control, .modal select { z-index: 2100; }

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }

/* === Layout Utilities === */
.max-w-2xl { max-width: 700px; }
.max-w-3xl { max-width: 900px; }
.max-w-4xl { max-width: 1100px; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* === Flex Utilities === */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

/* === Spacing === */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }
.p-16 { padding: 16px; }
.p-20 { padding: 20px; }
.p-24 { padding: 24px; }

/* === Text === */
.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 20px; }
.text-center { text-align: center; }
.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-gold { color: var(--gold); }

/* === Buttons === */
.btn-secondary { background: var(--bg-alt); color: var(--text-muted); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* === Grid === */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* === Card === */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; overflow: visible; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--bg-alt); }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

/* === Modals === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(27,42,74,0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    overscroll-behavior: contain;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: var(--radius-xs);
    transition: var(--t-color);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 20px; }

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: 8px;
    justify-content: flex-start;
}

/* === Toast === */
.toast-container {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 13px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.toast-success { background: var(--teal); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--ink); }

@media (prefers-reduced-motion: no-preference) {
    .toast { animation: toastIn 0.3s var(--ease-out); }
    @keyframes toastIn {
        from { transform: translateX(-100%); opacity: 0; }
        to { transform: translateX(0); opacity: 1; }
    }
}

/* === Pagination === */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 20px;
}

.page-link {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--t-bg), var(--t-color);
    font-variant-numeric: tabular-nums;
}

.page-link:hover {
    background: var(--gold-muted);
    color: var(--gold-dark);
}

.page-item.active .page-link,
.page-link.active {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
}

/* === Progress Bar === */
.progress {
    height: 6px;
    background: var(--surface-alt);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--gold);
    border-radius: 3px;
    transition: width 0.4s var(--ease-out);
}
.progress-bar.success { background: var(--teal); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* === Timeline === */
.timeline { position: relative; padding-right: 28px; }

.timeline::before {
    content: '';
    position: absolute;
    right: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item { position: relative; padding-bottom: 18px; }

.timeline-item::before {
    content: '';
    position: absolute;
    right: -22px;
    top: 4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gold);
    border: 2px solid var(--bg-card);
}

.timeline-item .time {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.timeline-item .content {
    font-size: 13px;
    margin-top: 3px;
}

/* === Breadcrumb === */
.breadcrumb {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 20px;
    font-size: 13px;
}

.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--gold); }
.breadcrumb .separator { color: var(--text-muted); }
.breadcrumb .current { color: var(--text-primary); font-weight: 500; }

/* === Page Title === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* === Filter Bar === */
.filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    align-items: center;
}

.filter-bar .form-control { max-width: 200px; }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 15px;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.empty-state p { font-size: 13px; }

/* === Tabs === */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
    gap: 2px;
}

.tab {
    padding: 10px 18px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--t-color), var(--t-border);
    text-decoration: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab:hover { color: var(--gold); }

.tab.active {
    color: var(--gold-dark);
    border-bottom-color: var(--gold);
    font-weight: 500;
}

/* === Health Card === */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.health-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.health-item .label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 3px;
}

.health-item .status { font-size: 13px; font-weight: 500; }

.health-item.suitable { border-color: var(--teal); background: var(--teal-muted); }
.health-item.needs_review { border-color: var(--warning); background: var(--warning-muted); }
.health-item.needs_action { border-color: var(--danger); background: var(--danger-muted); }
.health-item.critical { border-color: var(--danger); background: var(--danger-muted); }

/* === Grid Utilities === */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.grid-auto-sm { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.grid-auto-xs { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

/* === Alerts === */
.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 12px;
    border: 1px solid;
}

.alert i { font-size: 16px; flex-shrink: 0; }

.alert-success {
    background: var(--teal-muted);
    border-color: var(--teal);
    color: var(--teal);
}

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

.alert-warning {
    background: var(--warning-muted);
    border-color: var(--warning);
    color: var(--warning);
}

.alert-info {
    background: var(--gold-muted);
    border-color: var(--gold);
    color: var(--gold-dark);
}

/* === Avatar === */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }
.avatar-gold { background: var(--gold-muted); color: var(--gold); }
.avatar-teal { background: var(--teal-muted); color: var(--teal); }
.avatar-ink { background: rgba(27,42,74,0.08); color: var(--ink); }

/* === Quick Link Card === */
.quick-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    transition: var(--t-bg);
}

.quick-link:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.quick-link i { font-size: 14px; }

/* === Info List (compact key-value) === */
.info-list { padding: 4px 0; }

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.info-row:last-child { border-bottom: none; }

.info-row .label {
    color: var(--text-muted);
    font-size: 12px;
}

.info-row .value {
    font-weight: 500;
    color: var(--text-primary);
}

/* === Activity Item === */
.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
}

.activity-item .text {
    font-size: 13px;
    font-weight: 500;
}

.activity-item .meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* === Section Header === */
.section-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.section-header a {
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
}

/* === Compact List (for side panels) === */
.compact-list { padding: 4px 0; }

.compact-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 18px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
}

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

/* === Status Dot === */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* === Bar Chart (CSS-only) === */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    height: 140px;
    padding-top: 10px;
}

.bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.bar-value {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
}

.bar-fill {
    width: 100%;
    max-width: 48px;
    border-radius: 6px 6px 2px 2px;
    transition: height 0.4s var(--ease-out);
    min-height: 4px;
}

.bar-label {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* === Progress Row (horizontal bar with label) === */
.progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.progress-row .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.progress-row .name {
    flex: 1;
    font-size: 13px;
}

.progress-row .count {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 50px;
    text-align: left;
}

.progress-row .bar {
    width: 80px;
    height: 6px;
    background: var(--surface-alt);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}

.progress-row .bar-fill {
    height: 100%;
    border-radius: 3px;
}

.progress-row .pct {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 30px;
    text-align: left;
}

/* === Mobile Toggle === */
#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-primary);
    padding: 6px;
    border-radius: var(--radius-xs);
}

/* === Responsive: Tablet (≤768px) === */
@media (max-width: 768px) {
    /* ─── Sidebar: off-canvas drawer ─── */
    .sidebar {
        transform: translateX(100%);
        z-index: 1200;
        width: 280px;
        max-width: 85vw;
        transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
        will-change: transform;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay {
        display: none; position: fixed; inset: 0;
        background: rgba(0,0,0,0.5); z-index: 1100; cursor: pointer;
        -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
    }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-right: 0 !important; width: 100% !important; }
    #sidebar-toggle {
        display: flex !important; align-items:center; justify-content:center;
        width:40px; height:40px; border-radius:10px;
        background:var(--bg-alt); border:1px solid var(--border);
        cursor:pointer; font-size:18px; color:var(--text);
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
    }
    .sidebar-menu {
        max-height: calc(100vh - 120px);
        overflow-y: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        padding-bottom: 40px;
    }
    .sidebar .menu-group-items { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
    .sidebar .menu-group.open .menu-group-items { max-height: 800px !important; overflow: visible !important; }
    .sidebar .menu-item { padding: 10px 16px; font-size: 13px; }
    .sidebar .group-label { font-size: 12px; }
    .sidebar .group-arrow { display: none; }
    .sidebar .menu-group-toggle { padding: 10px 16px; font-size: 12px; }

    /* ─── Header ─── */
    .top-header {
        padding: 8px 10px !important;
        flex-wrap: wrap;
        gap: 6px;
        min-height: 52px;
    }
    .top-header > div:first-child {
        font-size: 11px !important; flex-shrink: 0;
        max-width: none !important;
    }
    .top-header form {
        max-width: none !important; flex: 1; margin: 0 6px !important;
        min-width: 0;
    }
    .top-header form input[type=text] {
        font-size: 13px !important; padding: 7px 10px !important;
        width: 100%;
    }
    .header-left, .header-right { gap: 4px !important; flex-shrink: 0; }
    .user-menu > div:last-child { display: none; }
    .user-menu { gap: 6px !important; }
    .top-header .btn-icon { width: 36px; height: 36px; }

    /* ─── Content ─── */
    .content-wrapper { padding: 10px !important; overflow-x: hidden !important; }
    .page-header {
        flex-direction: column; gap: 10px; align-items: stretch;
    }
    .page-header > div:last-child {
        flex-wrap: wrap; width: 100%; gap: 6px;
    }
    /* Prevent any element from exceeding viewport */
    .main-content { max-width: 100vw; overflow-x: hidden; }

    /* ─── Stat cards → 2 columns ─── */
    .stat-cards { grid-template-columns: 1fr 1fr !important; }

    /* ─── Stat cards → 2 columns (must come BEFORE generic grid reset) ─── */
    .stat-cards { grid-template-columns: 1fr 1fr !important; }

    /* ─── ALL inline grids → single column (except stat-cards) ─── */
    .grid-2, .grid-3, .grid-4, .grid-auto-xs { grid-template-columns: 1fr !important; }
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
    /* Stat cards get 2 columns — high specificity to win */
    .stat-cards,
    .stat-cards[style*="grid-template-columns"] { grid-template-columns: 1fr 1fr !important; }
    [style*="grid-column:span"] { grid-column: span 1 !important; }
    /* Only wrap flex containers that are NOT page headers or action bars */
    div[style*="display:flex"][style*="gap"] { flex-wrap: wrap; }

    /* ─── File inputs — larger touch target ─── */
    input[type=file] { min-height: 44px !important; font-size: 13px !important; }
    /* Doc items — stack on mobile */
    .doc-item > div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; gap: 10px !important; }
    /* Video items — stack on mobile */
    .video-item > div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; gap: 10px !important; }
    /* Image upload sections — stack on mobile */
    div[style*="grid-template-columns:auto 1fr"] { grid-template-columns: 1fr !important; gap: 12px !important; }
    div[style*="grid-template-columns:auto 1fr"] > div:first-child { text-align: center; }
    /* Avatar preview — smaller on mobile */
    div[style*="width:100px"][style*="height:100px"] { width: 72px !important; height: 72px !important; }
    div[style*="width:80px"][style*="height:80px"] { width: 64px !important; height: 64px !important; }

    /* ─── Cards ─── */
    .card { border-radius: 10px; margin-bottom: 10px; overflow: visible; }
    .card-header { padding: 10px 12px; }
    .card-body { padding: 12px; }
    .card-body > div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

    /* ─── Tables — horizontal scroll ─── */
    .table-responsive,
    .card > .table-responsive,
    .card-body > .table-responsive {
        overflow-x: auto; -webkit-overflow-scrolling: touch;
        border-radius: 8px;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .table-responsive::-webkit-scrollbar { height: 4px; }
    table { font-size: 12px !important; white-space: nowrap; min-width: 420px; }
    th, td { padding: 7px 8px !important; }
    th { position: sticky; top: 0; background: var(--bg-alt); z-index: 1; }
    td:first-child, th:first-child { position: sticky; right: 0; z-index: 2; background: var(--bg-card); }
    th:first-child { background: var(--bg-alt); }
    /* Make ALL tables scrollable on mobile — wrap them */
    .card-body > table:not(.table-responsive),
    .card > table:not(.table-responsive) {
        display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
        border: 1px solid var(--border); border-radius: 8px;
    }

    /* ─── Forms — compact on mobile ─── */
    .form-row { grid-template-columns: 1fr !important; gap: 10px !important; }
    .form-group { margin-bottom: 10px !important; }
    .form-label { font-size: 11px !important; margin-bottom: 4px !important; }
    input, select, textarea {
        font-size: 15px !important; padding: 10px 12px !important;
        max-width: 100%; box-sizing: border-box;
    }
    .form-control { width: 100% !important; box-sizing: border-box; }
    textarea.form-control { min-height: 80px !important; }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-control { max-width: 100%; }
    /* Forms with inline grid → stack on mobile */
    form div[style*="display:grid"] { grid-template-columns: 1fr !important; gap: 10px !important; }
    form > div > div[style*="grid-template-columns:span"] { grid-column: span 1 !important; }
    /* All form inputs full width */
    form input[type=text], form input[type=email], form input[type=number],
    form input[type=tel], form input[type=url], form input[type=password],
    form select, form textarea,
    input[type=text], input[type=email], input[type=number],
    input[type=tel], input[type=url], input[type=password],
    select, textarea {
        width: 100% !important; box-sizing: border-box !important;
        max-width: 100% !important;
    }
    /* Prevent form overflow */
    .content-wrapper { overflow-x: hidden; }

    /* ─── Buttons — touch-friendly ─── */
    .btn { padding: 10px 16px !important; font-size: 13px !important; min-height: 42px; }
    .btn-sm { padding: 8px 12px !important; font-size: 11px !important; min-height: 36px; }
    .btn-primary { padding: 12px 20px !important; }
    .page-header .btn { flex: 1; min-width: 0; justify-content: center; }
    /* Action buttons in tables — stack */
    td > div[style*="display:flex"] { flex-wrap: wrap; gap: 4px; }
    td > div[style*="display:flex"] .btn { min-height: 32px; padding: 4px 10px; font-size: 11px; }

    /* ─── Bar chart ─── */
    .bar-chart { height: 120px; }
    /* Datepicker ─── */
    .shamsi-date { font-size: 15px !important; }
    /* Search in header ─── */
    .top-header form { position: relative; }
    /* Tabs / Navs ─── */
    .nav-tabs {
        gap: 4px !important; overflow-x: auto; flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch; padding-bottom: 4px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-link {
        white-space: nowrap; flex-shrink: 0;
        font-size: 12px !important; padding: 8px 12px !important;
    }

    /* ─── Quick links / badges ─── */
    .quick-link { padding: 8px !important; font-size: 11px !important; }
    .badge { font-size: 10px !important; padding: 2px 6px !important; }

    /* ─── Tooltip / dropdown menus ─── */
    .dropdown-menu { min-width: 160px !important; }

    /* ─── Footer in admin ─── */
    .main-content > footer { padding: 8px 12px !important; }

    /* ─── Global overflow protection ─── */
    * { max-width: 100%; }
    img, video { max-width: 100%; height: auto; }
    .card-body > div:not(.table-responsive) { overflow-x: hidden; }
}

/* === Responsive: Mobile (≤480px) === */
@media (max-width: 480px) {
    .sidebar { width: 260px; max-width: 80vw; }
    .stat-cards { grid-template-columns: 1fr !important; }
    .content-wrapper { padding: 8px !important; }
    .card { margin-bottom: 8px !important; }
    .card-header { padding: 8px 10px !important; }
    .card-body { padding: 10px !important; }
    th, td { padding: 6px 8px !important; font-size: 11px !important; }
    .top-header .user-menu > div { display: none !important; }
    .top-header form { margin: 4px 0 !important; max-width: 200px; }
    .page-header { gap: 8px !important; }
    .page-header > div:last-child { gap: 4px !important; }
    .page-header > div:last-child .btn { font-size: 11px !important; padding: 8px 12px !important; }
    .quick-link { padding: 6px !important; font-size: 10px !important; }
    /* Forms — extra compact ─── */
    .form-row { gap: 8px !important; }
    .form-group { margin-bottom: 8px !important; }
    .form-label { font-size: 10px !important; }
    input, select, textarea { font-size: 16px !important; padding: 10px !important; box-sizing: border-box; }
    .form-hint, .form-error { font-size: 10px !important; }
    .card { border-radius: 10px !important; }
    .btn { font-size: 12px !important; padding: 10px 14px !important; min-height: 44px; }
    .btn-sm { min-height: 36px; }
    .btn-group-mobile { flex-direction: column !important; }
    .btn-group-mobile .btn { width: 100% !important; }
    /* Page header buttons — stack ─── */
    .page-header > div:last-child { flex-direction: column !important; width: 100% !important; }
    .page-header > div:last-child .btn { width: 100% !important; }
    /* Section titles ─── */
    h1, h2 { font-size: 16px !important; }
    h3 { font-size: 14px !important; }
    /* Table even more compact ─── */
    table { min-width: 340px; font-size: 11px !important; }
    th, td { padding: 5px 6px !important; font-size: 11px !important; }
    /* Hide less important columns on very small screens, keep actions visible */
    td:nth-child(n+5):not(:last-child) { display: none; }
    th:nth-child(n+5):not(:last-child) { display: none; }
    .data-table .actions { flex-wrap: nowrap; gap: 4px; }
    .data-table .actions .btn { min-width: 32px; min-height: 32px; padding: 4px 6px; }
    td > div[style*="display:flex"] .btn { min-height: 28px; padding: 3px 8px; font-size: 10px; }
    /* User menu — hide name, show avatar only ─── */
    .user-menu > div { display: none !important; }
    .top-header .btn-icon:not(#sidebar-toggle) { width: 32px; height: 32px; font-size: 14px; }
    /* Search bar — full width ─── */
    .top-header form { margin: 0 4px !important; }
}

/* === Print === */
@media print {
    .sidebar, .top-header, .no-print, #sidebar-toggle { display: none !important; }
    .main-content { margin: 0; }
    .content-wrapper { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    body { background: #fff; color: #000; }
    .badge { border: 1px solid currentColor; }
}
