/* ============================================================================
   VictorShop Admin — design system
   Dark (default) + Light themes, purple brand, fully responsive (mobile-first
   off-canvas sidebar). Bootstrap 5.3 components are re-themed via data-bs-theme
   which is kept in sync with data-theme, so existing pages restyle for free.
   ========================================================================== */

/* ---- Design tokens -------------------------------------------------------- */
:root,
:root[data-theme="dark"] {
    --bg: #0b0b14;
    --bg-elev: #101020;
    --surface: #14142280;
    --surface-solid: #161628;
    --surface-2: #1c1c30;
    --sidebar-bg: #0d0d18;
    --topbar-bg: rgba(13, 13, 24, 0.72);
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.13);
    --text: #e9e9f3;
    --text-dim: #a3a3ba;
    --text-mute: #6c6c84;
    --brand: #a855f7;
    --brand-2: #c084fc;
    --brand-ink: #ffffff;
    --brand-soft: rgba(168, 85, 247, 0.14);
    --brand-glow: rgba(168, 85, 247, 0.35);
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --info: #38bdf8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
    --radius: 14px;
    --radius-sm: 10px;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg: #f3f4fb;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --surface-solid: #ffffff;
    --surface-2: #f5f6fc;
    --sidebar-bg: #ffffff;
    --topbar-bg: rgba(255, 255, 255, 0.78);
    --border: rgba(20, 20, 45, 0.09);
    --border-strong: rgba(20, 20, 45, 0.16);
    --text: #191933;
    --text-dim: #5a5a75;
    --text-mute: #8a8aa2;
    --brand: #9333ea;
    --brand-2: #a855f7;
    --brand-ink: #ffffff;
    --brand-soft: rgba(147, 51, 234, 0.10);
    --brand-glow: rgba(147, 51, 234, 0.25);
    --shadow-sm: 0 1px 2px rgba(20, 20, 45, 0.08);
    --shadow: 0 10px 30px rgba(30, 30, 70, 0.10);
    --shadow-lg: 0 20px 50px rgba(30, 30, 70, 0.14);
    color-scheme: light;
}

/* ---- Bootstrap 5.3 bridge — map BS tokens to ours ------------------------- */
[data-bs-theme="dark"],
[data-bs-theme="light"] {
    --bs-primary: var(--brand);
    --bs-primary-rgb: 168, 85, 247;
    --bs-link-color: var(--brand-2);
    --bs-link-hover-color: var(--brand);
    --bs-link-color-rgb: 168, 85, 247;
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--text);
    --bs-border-color: var(--border);
    --bs-border-color-translucent: var(--border);
    --bs-secondary-color: var(--text-dim);
    --bs-tertiary-color: var(--text-mute);
    --bs-emphasis-color: var(--text);
    --bs-heading-color: var(--text);
    --bs-tertiary-bg: var(--surface-2);
    --bs-secondary-bg: var(--surface-2);
}

/* Cards / tables / inputs pick up our surfaces */
[data-bs-theme] .card {
    --bs-card-bg: var(--surface-solid);
    --bs-card-border-color: var(--border);
    --bs-card-cap-bg: transparent;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

[data-bs-theme] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: var(--surface-2);
    --bs-table-striped-color: var(--text);
    --bs-table-hover-bg: var(--brand-soft);
    --bs-table-hover-color: var(--text);
}

[data-bs-theme] .form-control,
[data-bs-theme] .form-select {
    background-color: var(--bg-elev);
    border-color: var(--border-strong);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.8rem;
}

[data-bs-theme] .form-control:focus,
[data-bs-theme] .form-select:focus {
    background-color: var(--bg-elev);
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem var(--brand-glow);
    color: var(--text);
}

[data-bs-theme] .form-control::placeholder { color: var(--text-mute); }
[data-bs-theme] .form-label { font-weight: 600; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.35rem; }

/* ---- Brand buttons -------------------------------------------------------- */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    padding: 0.5rem 1.1rem;
    transition: transform 0.06s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.btn:active { transform: translateY(1px); }
.btn-sm { padding: 0.3rem 0.7rem; border-radius: 8px; }

.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: #9333ea;
    --bs-btn-hover-border-color: #9333ea;
    --bs-btn-active-bg: #7e22ce;
    --bs-btn-active-border-color: #7e22ce;
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    --bs-btn-color: #fff;
    --bs-btn-hover-color: #fff;
    --bs-btn-focus-shadow-rgb: 168, 85, 247;
    box-shadow: 0 6px 18px -6px var(--brand-glow);
}

.btn-primary:hover { box-shadow: 0 10px 24px -6px var(--brand-glow); }

.btn-outline-primary {
    --bs-btn-color: var(--brand-2);
    --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: #7e22ce;
    --bs-btn-active-border-color: #7e22ce;
}

/* ---- Base ----------------------------------------------------------------- */
html, body {
    font-family: Vazirmatn, Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body {
    background-image:
        radial-gradient(1100px 480px at 100% -8%, var(--brand-soft), transparent 60%),
        radial-gradient(900px 420px at -10% 0%, rgba(56, 189, 248, 0.06), transparent 55%);
    background-attachment: fixed;
}

a { text-decoration: none; }
h1, h2, h3, h4, h5 { color: var(--text); font-weight: 700; }

::selection { background: var(--brand-glow); }

/* Thin themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 20px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }

/* ============================================================================
   Shell
   ========================================================================== */
.nav-toggle { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }

.admin-layout {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

/* ---- Sidebar -------------------------------------------------------------- */
.sidebar {
    width: 268px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-inline-start: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 1.25rem;
    color: #fff;
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    box-shadow: 0 8px 20px -6px var(--brand-glow);
    flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-title { font-weight: 800; font-size: 1.02rem; }
.brand-sub { font-size: 0.72rem; color: var(--text-mute); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.75rem 1.5rem;
}

.nav-group { margin-top: 1rem; }
.nav-group:first-child { margin-top: 0.25rem; }

.nav-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text-mute);
    padding: 0 0.75rem 0.4rem;
    text-transform: none;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.62rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 0.9rem;
    font-weight: 600;
    position: relative;
    transition: background-color 0.14s ease, color 0.14s ease;
}

.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; opacity: 0.85; }

.nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-link.active {
    background: var(--brand-soft);
    color: var(--brand-2);
}

.nav-link.active svg { opacity: 1; }

.nav-link.active::before {
    content: "";
    position: absolute;
    inset-inline-start: -0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    border-radius: 3px;
    background: var(--brand);
}

/* ---- Main area ------------------------------------------------------------ */
.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 1.1rem;
    background: var(--topbar-bg);
    backdrop-filter: saturate(140%) blur(12px);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-spacer { flex: 1; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.topbar-user .user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.7rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-weight: 600;
    color: var(--text);
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    flex-shrink: 0;
}

.icon-btn:hover { border-color: var(--brand); color: var(--brand-2); }
.icon-btn svg { width: 20px; height: 20px; }

.top-link {
    color: var(--text-dim);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.4rem 0.6rem;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.top-link:hover { color: var(--brand-2); background: var(--surface-2); }

/* theme toggle icon swap */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }

.hamburger { display: none; }

.content {
    flex: 1;
    padding: 1.6rem 1.6rem 3rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    animation: fade-in 0.25s ease;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* backdrop for mobile drawer */
.backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 39;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* ============================================================================
   Page helpers (headers, stat cards, dashboard) — usable by any page
   ========================================================================== */
.page-head { margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 800; margin: 0; }
.page-subtitle { color: var(--text-dim); font-size: 0.92rem; margin-top: 0.35rem; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.stat-card {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow); }

.stat-card::after {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline-end: 0;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle at top left, var(--brand-soft), transparent 70%);
    pointer-events: none;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand-2);
    margin-bottom: 0.9rem;
}

.stat-icon svg { width: 22px; height: 22px; }
.stat-value { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.stat-label { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.4rem; }

.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.quick-card {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    color: var(--text);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.quick-card:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: var(--shadow); color: var(--text); }
.quick-card .stat-icon { margin-bottom: 0; }
.quick-card .qc-body { display: flex; flex-direction: column; }
.quick-card .qc-title { font-weight: 700; }
.quick-card .qc-sub { font-size: 0.78rem; color: var(--text-mute); }

.section-card {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

/* badges polish */
.badge { font-weight: 600; padding: 0.4em 0.7em; border-radius: 7px; }

/* ============================================================================
   Login
   ========================================================================== */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    position: relative;
}

.login-shell .card {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    border-radius: 18px;
    width: 100%;
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 1.25rem;
}

.login-shell .brand-mark { width: 54px; height: 54px; font-size: 1.5rem; border-radius: 15px; }

.login-theme-toggle {
    position: fixed;
    top: 1rem;
    inset-inline-end: 1rem;
    z-index: 5;
}

/* ============================================================================
   Responsive — off-canvas drawer under 992px
   ========================================================================== */
@media (max-width: 991.98px) {
    /* Off-canvas drawer from the physical right (correct for RTL).
       transform is unaffected by `dir`, so we use physical `right` + translateX(100%). */
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        left: auto;
        height: 100vh;
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        border-inline-start: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
    }

    .backdrop { display: block; }

    .nav-toggle:checked ~ .admin-layout .sidebar { transform: translateX(0); }
    .nav-toggle:checked ~ .admin-layout .backdrop { opacity: 1; }
    .nav-toggle:not(:checked) ~ .admin-layout .backdrop { pointer-events: none; }

    .hamburger { display: grid; }

    .content { padding: 1.15rem 1rem 2.5rem; }

    .topbar { height: 58px; padding: 0 0.8rem; }

    .topbar-user .u-name { display: none; }
}

@media (max-width: 575.98px) {
    .page-title { font-size: 1.25rem; }
    .stat-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }
    .stat-value { font-size: 1.4rem; }
    .top-link .tl-text { display: none; }
    .table { font-size: 0.85rem; }
}

/* ============================================================================
   Blazor error UI / boundary
   ========================================================================== */
#blazor-error-ui {
    color-scheme: light only;
    background: #fff3cd;
    color: #664d03;
    bottom: 0;
    box-shadow: 0 -1px 12px rgba(0, 0, 0, 0.25);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    text-align: center;
    font-size: 0.9rem;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; inset-inline-end: 0.9rem; top: 0.6rem; }
#blazor-error-ui .reload { color: #664d03; font-weight: 700; text-decoration: underline; }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1.25rem;
    color: white;
    border-radius: 10px;
}

.blazor-error-boundary::after { content: "خطایی رخ داد."; }

/* validation */
.valid.modified:not([type=checkbox]) { outline: 1px solid var(--ok); }
.invalid { outline: 1px solid var(--danger); }
.validation-message { color: var(--danger); font-size: 0.85rem; }
