/**
 * Admin UI aligned with BootstrapMade ModernAdmin
 * Reference: https://bootstrapmade.com/content/demo/ModernAdmin/
 * Colors & layout tokens match template main.css (light mode)
 */

:root {
    --ma-font: "Vazirmatn", "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    --radius-sm: 0.125rem;
    --radius-md: 0.25rem;
    --radius-lg: 0.375rem;
    --radius-xl: 0.5rem;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --header-height: 60px;
    --sidebar-width: 280px;
    --background-color: #f0f4f9;
    --default-color: #1e293b;
    --heading-color: #0f172a;
    --accent-color: #1a66c4;
    --surface-color: #ffffff;
    --muted-color: #64748b;
    --light-color: #94a3b8;
    --border-color: #e2e8f0;
    --success-color: #22c55e;
    --success-color-light: #dcfce7;
    --warning-color: #f59e0b;
    --warning-color-light: #fef3c7;
    --danger-color: #ef4444;
    --danger-color-light: #fee2e2;
    --info-color: #06b6d4;
    --info-color-light: #cffafe;
    --header-bg: #ffffff;
    --header-border: var(--border-color);
    --sidebar-bg: #051831;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-text: rgba(255, 255, 255, 0.85);
    --sidebar-text-muted: rgba(255, 255, 255, 0.6);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.08);
    --sidebar-active-bg: rgba(26, 102, 196, 0.25);
    --sidebar-active-text: #ffffff;
    --sidebar-heading-color: rgba(255, 255, 255, 0.4);
    --sidebar-icon-color: rgba(255, 255, 255, 0.7);
    --table-header-bg: #f8fafc;
    --table-hover-bg: #f1f5f9;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body.admin-app {
    margin: 0;
    min-height: 100vh;
    font-family: var(--ma-font);
    font-size: 0.9375rem;
    line-height: 1.6;
    background-color: var(--background-color);
    color: var(--default-color);
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

.text-accent {
    color: var(--accent-color) !important;
}

/* ——— Sidebar (ModernAdmin) ——— */
.sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    max-width: 100%;
    background: var(--sidebar-bg);
    border-inline-end: 1px solid var(--sidebar-border);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-base), width var(--transition-base);
    overflow: hidden;
}

@media (max-width: 1199.98px) {
    .sidebar {
        transform: translateX(100%);
    }

    .admin-app.sidebar-open .sidebar {
        transform: translateX(0);
    }
}

/* Mobile overlay (ModernAdmin-style) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1000;
    cursor: pointer;
}

.admin-app.sidebar-open .sidebar-backdrop {
    display: block;
}

@media (min-width: 1200px) {
    .sidebar-backdrop {
        display: none !important;
    }
}

@media (min-width: 1200px) {
    .sidebar {
        transform: none !important;
    }
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 50px;
    padding: 0 var(--spacing-md);
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1.2rem;
    color: #fff;
    text-decoration: none;
}

.sidebar-logo:hover {
    color: #fff;
}

.sidebar-logo span {
    opacity: 0.85;
    transition: opacity var(--transition-fast);
}

.sidebar-logo:hover span {
    opacity: 1;
}

.sidebar-logo i {
    font-size: 1.25rem;
    opacity: 0.9;
}

.sidebar-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    color: var(--sidebar-text-muted);
    background: none;
    border: none;
    cursor: pointer;
}

.sidebar-close:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
}

@media (max-width: 1199.98px) {
    .admin-app.sidebar-open .sidebar-close {
        display: flex;
    }
}

.sidebar-nav {
    flex: 1;
    padding: var(--spacing-md) var(--spacing-sm);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) rgba(255, 255, 255, 0.05);
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.sidebar .nav-menu,
.sidebar .nav-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar .nav-menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar .nav-heading {
    padding: var(--spacing-xl) var(--spacing-md) var(--spacing-sm);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-heading-color);
}

.sidebar .nav-heading:first-child {
    padding-top: var(--spacing-sm);
}

.sidebar .nav-item > .nav-link {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar .nav-item > .nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
}

.sidebar .nav-item > .nav-link > i:first-child {
    width: 22px;
    margin-inline-end: 12px;
    font-size: 1.35rem;
    text-align: center;
    flex-shrink: 0;
    color: var(--sidebar-icon-color);
    transition: color var(--transition-fast);
}

.sidebar .nav-item > .nav-link:hover > i:first-child {
    color: #fff;
}

.sidebar .nav-arrow {
    font-size: 0.625rem;
    margin-inline-start: auto;
    transition: transform var(--transition-fast);
    color: rgba(255, 255, 255, 0.5);
}

.sidebar .nav-link[aria-expanded="true"] > .nav-arrow,
.sidebar .has-submenu.open > .nav-link > .nav-arrow {
    transform: rotate(180deg);
}

.sidebar .nav-item > .nav-link.active {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
}

.sidebar .nav-item > .nav-link.active > i:first-child {
    color: var(--sidebar-active-text);
}

.sidebar .nav-item.has-submenu.open > .nav-link {
    background-color: var(--sidebar-hover-bg);
    color: #fff;
}

.sidebar .nav-item.has-submenu.open > .nav-link > i:first-child {
    color: #fff;
}

.sidebar .nav-submenu {
    position: relative;
    margin-inline-start: 20px;
    border-inline-start: 1px solid rgba(255, 255, 255, 0.3);
}

.sidebar .nav-submenu.collapse.show {
    margin-top: 4px;
}

.sidebar .nav-submenu > li > .nav-link {
    display: flex;
    align-items: center;
    padding: 8px 12px 8px 17px;
    padding-inline-start: 17px;
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: 0;
    position: relative;
    transition: color var(--transition-fast);
}

.sidebar .nav-submenu > li > .nav-link::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    top: 50%;
    width: 10px;
    height: 1px;
    background: rgba(255, 255, 255, 0.3);
}

.sidebar .nav-submenu > li > .nav-link:hover {
    color: var(--sidebar-active-text);
}

.sidebar .nav-submenu > li > .nav-link.active {
    color: #fff;
}

.sidebar .nav-submenu > li > .nav-link.active::before {
    background: #fff;
}

.ma-nav-logout-wrap {
    border-top: 1px solid var(--sidebar-border);
}

.ma-nav-logout {
    color: #fecaca !important;
}

.ma-nav-logout:hover {
    background: rgba(239, 68, 68, 0.2) !important;
    color: #fff !important;
}

/* ——— Header ——— */
.header {
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    inset-inline-end: 0;
    height: var(--header-height);
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-md);
    z-index: 1000;
    transition: inset-inline-start var(--transition-base);
}

@media (min-width: 576px) {
    .header {
        padding: 0 var(--spacing-lg);
    }
}

@media (min-width: 1200px) {
    .header {
        inset-inline-start: var(--sidebar-width);
    }
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--heading-color);
    text-decoration: none;
}

.header-logo:hover {
    color: var(--accent-color);
}

@media (min-width: 1200px) {
    .header-logo {
        display: none;
    }
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    color: var(--default-color);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar-toggle:hover {
    background: rgba(26, 102, 196, 0.1);
    color: var(--accent-color);
}

.sidebar-toggle i {
    font-size: 1.5rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-inline-start: auto;
    flex-wrap: wrap;
}

.header-meta-time,
.header-meta-user {
    white-space: nowrap;
}

/* ——— Main ——— */
.main {
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    transition: margin-inline-start var(--transition-base);
}

@media (min-width: 1200px) {
    .main {
        margin-inline-start: var(--sidebar-width);
    }
}

.main-content {
    flex: 1;
    padding: var(--spacing-xl);
    padding-bottom: 4rem;
}

@media (max-width: 767.98px) {
    .main-content {
        padding: var(--spacing-md);
        padding-bottom: var(--spacing-xl);
    }
}

/* ——— Page title (ModernAdmin pagetitle) ——— */
.pagetitle {
    margin-bottom: var(--spacing-xl);
}

.ma-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-xs);
    padding: 0;
    margin: 0;
    background: transparent;
    font-size: 0.8125rem;
    list-style: none;
}

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

.ma-breadcrumb .breadcrumb-item a {
    color: var(--muted-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.ma-breadcrumb .breadcrumb-item a:hover {
    color: var(--accent-color);
}

.ma-breadcrumb .breadcrumb-item.active {
    color: var(--default-color);
    font-weight: 600;
}

.ma-breadcrumb .breadcrumb-item + .breadcrumb-item {
    padding-inline-start: var(--spacing-xs);
}

.ma-breadcrumb .breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    float: right;
    padding-inline-end: var(--spacing-xs);
    color: var(--light-color);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--heading-color);
    margin: 0;
}

.page-title .page-title-icon {
    font-size: 1rem;
    opacity: 0.85;
    vertical-align: middle;
}

/* ——— Dashboard stat cards (ModernAdmin) ——— */
.stat-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.stat-card-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted-color);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

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

.stat-card-icon.primary {
    background: rgba(26, 102, 196, 0.1);
    color: var(--accent-color);
}

.stat-card-icon.success {
    background: var(--success-color-light);
    color: var(--success-color);
}

.stat-card-icon.warning {
    background: var(--warning-color-light);
    color: var(--warning-color);
}

.stat-card-icon.info {
    background: var(--info-color-light);
    color: var(--info-color);
}

.stat-card-icon.danger {
    background: var(--danger-color-light);
    color: var(--danger-color);
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--heading-color);
    line-height: 1.2;
    margin-bottom: var(--spacing-xs);
}

.stat-card-change {
    font-size: 0.8125rem;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.stat-card-change span {
    color: var(--muted-color);
}

.stat-card-change i {
    font-size: 0.75rem;
}

.stat-card-change.positive {
    color: var(--success-color);
}

.stat-card-change.negative {
    color: var(--danger-color);
}

/* ——— Dashboard welcome (ModernAdmin index) ——— */
.welcome-card {
    background: linear-gradient(
        135deg,
        rgba(26, 102, 196, 0.14),
        rgba(26, 102, 196, 0.04)
    );
    border: 1px solid rgba(26, 102, 196, 0.18);
}

.welcome-content {
    flex: 1;
}

.welcome-greeting {
    font-size: 0.875rem;
    color: var(--muted-color);
    margin-bottom: var(--spacing-xs);
}

.welcome-name {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--heading-color);
    margin-bottom: var(--spacing-md);
}

.welcome-date {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    color: var(--muted-color);
}

.welcome-date i {
    margin-inline-end: var(--spacing-xs);
    color: var(--accent-color);
}

.welcome-illustration {
    flex-shrink: 0;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
    opacity: 0.35;
    font-size: 4.5rem;
}

@media (max-width: 575.98px) {
    .welcome-illustration {
        display: none;
    }
}

/* ——— Cards & tables ——— */
.card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

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

.card-header {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--heading-color);
}

.table thead th {
    background: var(--table-header-bg);
    color: var(--default-color);
    font-weight: 600;
    font-size: 0.875rem;
    border-color: var(--border-color);
}

.table tbody tr:hover {
    background: var(--table-hover-bg);
}

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

.btn-primary:hover,
.btn-primary:focus {
    background-color: #1558a8;
    border-color: #1558a8;
}

.text-primary {
    color: var(--accent-color) !important;
}

.bg-primary {
    background-color: var(--accent-color) !important;
}

.form-control:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(26, 102, 196, 0.2);
}

.modal-header {
    background: linear-gradient(135deg, var(--accent-color), #1558a8);
    color: #fff;
}

.modal-header .btn-close {
    filter: invert(1);
}

.page-link:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
}

.page-item.active .page-link {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

/* Inner stat cards on subpages (colored) */
.stat-card {
    border: none;
    color: #fff;
    border-radius: var(--radius-xl);
}

.stat-card.info {
    background: linear-gradient(135deg, var(--info-color), #0891b2);
}

.stat-card.success {
    background: linear-gradient(135deg, var(--success-color), #16a34a);
}

.stat-card.warning {
    background: linear-gradient(135deg, var(--warning-color), #d97706);
}

.stat-card.danger {
    background: linear-gradient(135deg, var(--danger-color), #dc2626);
}

.stat-card:not(.info):not(.success):not(.warning):not(.danger) {
    background: linear-gradient(135deg, var(--accent-color), #1558a8);
}

/* Badge soft (toolbar) */
.admin-badge-soft {
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    background: rgba(26, 102, 196, 0.1);
    color: var(--accent-color);
    border: 1px solid rgba(26, 102, 196, 0.2);
    border-radius: 999px;
}

/* Legacy: remove old grid column sidebar */
.col-md-3.col-lg-2.px-0 {
    display: block;
    padding: 0 !important;
}
