:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --navy: #0b1733;
    --navy-2: #122044;
    --navy-light: #1e293b;
    --success: #10b981;
    --success-dark: #059669;
    --success-soft: #ecfdf5;
    --danger: #e11d48;
    --danger-dark: #be123c;
    --danger-soft: #fff1f2;
    --indigo: #6366f1;
    --indigo-dark: #4f46e5;
    --warning: #f59e0b;
    --warning-soft: #fffbeb;
    --cyan: #06b6d4;
    --pink: #ec4899;
    --text: #0f172a;
    --text-secondary: #334155;
    --muted: #64748b;
    --muted-light: #94a3b8;
    --border: #e2e8f0;
    --border-dark: #cbd5e1;
    --bg: #f4f7fb;
    --background: #f4f7fb;
    --card: #ffffff;
    --shadow: 0 10px 30px rgba(15, 23, 42, .06);
    --shadow-sm: 0 4px 14px rgba(15, 23, 42, .04);
    --radius: 14px;
    --radius-sm: 10px;
    --sidebar-width: 248px;
    --topbar-height: 68px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --font: "Vazirmatn", Tahoma, sans-serif;
}

@font-face {
    font-family: Vazirmatn;
    src: url("fonts/Vazirmatn-Regular.ttf") format("truetype");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: Vazirmatn;
    src: url("fonts/Vazirmatn-Bold.ttf") format("truetype");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

* { box-sizing: border-box; }

html {
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body,
.app-body {
    margin: 0;
    min-height: 100vh;
    max-width: 100%;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
}

button, input, textarea, select { font-family: inherit; }
button, a, label, input, select, summary { -webkit-tap-highlight-color: transparent; }
button, .btn, .sidebar-link, .mobile-nav a, summary { touch-action: manipulation; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.app-body { display: flex; }

.sidebar {
    width: var(--sidebar-width);
    flex: none;
    min-height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    background: linear-gradient(180deg, var(--navy) 0%, #081226 100%);
    color: #cbd5e1;
    z-index: 1200;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 18px;
    color: #fff;
    text-decoration: none;
}

.brand-mark {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
}

.brand-mark svg { width: 22px; height: 22px; }

.brand-name {
    display: block;
    font-size: 18px;
    font-weight: 900;
    line-height: 1.2;
}

.brand-sub {
    display: block;
    color: #7c8aa5;
    font-size: 10px;
    font-weight: 700;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 8px 12px;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 800;
}

.sidebar-link svg { width: 18px; height: 18px; flex: none; }
.sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-link.active { background: var(--primary); color: #fff; }
.sidebar-link:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    padding: 10px;
    border-radius: 14px;
    background: rgba(255,255,255,.05);
}

.sidebar-user-name { color: #fff; font-size: 12px; font-weight: 800; }
.sidebar-user-role { color: #7c8aa5; font-size: 10px; }
.sidebar-logout {
    margin-right: auto;
    border: 0;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
    font-weight: 800;
}

.avatar {
    width: 34px;
    height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 900;
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }

.app-frame {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.app-topbar {
    min-height: var(--topbar-height);
    position: sticky;
    top: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 22px;
    background: rgba(255,255,255,.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.topbar-title { min-width: 0; }
.crumb { color: var(--muted); font-size: 11px; font-weight: 700; }
.topbar-title h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 900;
    line-height: 1.4;
}

.topbar-search {
    flex: 1;
    max-width: 420px;
    position: relative;
    margin-right: auto;
}

.topbar-search svg {
    position: absolute;
    right: 12px;
    top: 50%;
    width: 16px;
    height: 16px;
    transform: translateY(-50%);
    color: var(--muted-light);
}

.topbar-search input {
    width: 100%;
    min-height: 42px;
    padding: 8px 38px 8px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f8fafc;
    outline: none;
}

.topbar-search input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.topbar-meta { display: flex; align-items: center; gap: 8px; }

.rate-chip, .user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
}

.user-chip { background: #f1f5f9; color: var(--text); }

.icon-btn, .sidebar-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    background: #f1f5f9;
    color: var(--text);
    cursor: pointer;
}
.icon-btn svg, .sidebar-toggle svg { width: 18px; height: 18px; }

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(15, 23, 42, .45);
}

.container {
    width: min(1280px, calc(100% - 40px));
    margin: 20px auto 48px;
}

.page-heading { margin-bottom: 16px; }
.page-heading h1 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 900;
    line-height: 1.5;
}
.page-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.9;
}

.btn {
    min-height: 42px;
    padding: 8px 14px;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    text-decoration: none;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 800;
    transition: .18s background, .18s transform;
}
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
    color: #334155;
    background: #f1f5f9;
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: #e2e8f0; }
.btn-success { color: #fff; background: var(--success); }
.btn-success:hover { background: var(--success-dark); }
.btn-indigo { color: #fff; background: var(--indigo); }
.btn-indigo:hover { background: var(--indigo-dark); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }
.btn-dark { color: #fff; background: var(--navy); }
.btn-dark:hover { background: var(--navy-light); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--muted); }

.card {
    margin-bottom: 18px;
    overflow: visible;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
}
.card-head {
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0 0 3px; font-size: 16px; font-weight: 900; }
.card-head p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.8; }
.card-body { padding: 16px 18px; }

.success-message, .alert, .error {
    margin-bottom: 16px;
    padding: 13px 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border-radius: 12px;
    line-height: 1.8;
    font-size: 12px;
}
.success-message, .alert-success {
    color: #047857;
    background: var(--success-soft);
    border: 1px solid #bbf7d0;
}
.error, .alert-error {
    color: #991b1b;
    background: var(--danger-soft);
    border: 1px solid #fecaca;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { min-width: 0; }
.form-group.full { grid-column: 1 / -1; }
.label {
    margin-bottom: 7px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: #334155;
    font-size: 11px;
    font-weight: 800;
}
.label-note { color: var(--muted-light); font-size: 9px; font-weight: 500; }
.form-control {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    outline: none;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    transition: .15s;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .08);
}
textarea.form-control { min-height: 105px; resize: vertical; line-height: 1.9; }
.field-help { margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.7; }

.history-box {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
    padding: 22px;
}
.history-box table { width: 100%; border-collapse: collapse; }
.history-box th, .history-box td {
    padding: 9px;
    border-bottom: 1px solid var(--border);
    text-align: right;
}
.history-chart, #history-chart {
    width: 100%;
    max-height: 280px;
}

.mobile-nav { display: none; }

.filters {
    display: grid;
    grid-template-columns: 1.6fr minmax(140px, .6fr) auto auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 16px;
}
.filters-products { grid-template-columns: 1.6fr minmax(140px, .6fr) auto auto; }
.filter-drawer {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}
.filter-drawer[hidden] { display: none; }

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.toolbar .grow { flex: 1; min-width: 180px; }

.bulk-bar {
    position: sticky;
    bottom: 16px;
    z-index: 20;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--navy);
    color: #fff;
    border-radius: 12px;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .field-help, .bulk-bar .form-control { color: var(--text); }
.bulk-bar .field-help { color: #fff; }

.product-cards { display: none; }
.product-card {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
}
.product-card-head { display: flex; gap: 8px; align-items: flex-start; }
.product-card-price { margin: 8px 0; font-size: 18px; font-weight: 900; }
.price-delta { font-size: 12px; font-weight: 800; }
.price-delta.up { color: var(--success-dark); }
.price-delta.down { color: var(--danger); }
.product-card details summary { cursor: pointer; color: var(--primary); font-weight: 800; font-size: 12px; }

.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}
.data-table th, .data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    vertical-align: middle;
}
.data-table th a { color: inherit; text-decoration: none; }
.data-table tbody tr:hover { background: #f8fafc; }

.pager {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 14px;
}
.pager-links { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
}
.badge-success { background: var(--success-soft); color: var(--success-dark); }
.badge-warn { background: var(--warning-soft); color: #b45309; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions .btn { min-height: 34px; padding: 6px 10px; }

.empty-state { padding: 28px 10px; text-align: center; color: var(--muted); }
.loading-state { padding: 20px; text-align: center; color: var(--muted); }

.stats-grid {
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
.stat-card {
    min-width: 0;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}
.stat-card.accent-blue { background: linear-gradient(180deg, #eff6ff, #fff); }
.stat-card.accent-green { background: linear-gradient(180deg, #ecfdf5, #fff); }
.stat-card.accent-amber { background: linear-gradient(180deg, #fffbeb, #fff); }
.stat-card.accent-pink { background: linear-gradient(180deg, #fdf2f8, #fff); }
.stat-card.accent-cyan { background: linear-gradient(180deg, #ecfeff, #fff); }
.stat-card.accent-indigo { background: linear-gradient(180deg, #eef2ff, #fff); }
.stat-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.stat-value { margin-top: 4px; font-size: 22px; font-weight: 900; }
.stat-value small { font-size: 12px; color: var(--muted); font-weight: 700; }
.stat-sub { margin-top: 4px; color: var(--muted-light); font-size: 11px; }
.stat-sub a { color: var(--primary); text-decoration: none; font-weight: 800; }

.dash-grid {
    display: grid;
    grid-template-columns: 1.6fr .9fr;
    gap: 16px;
}
.dash-side { display: grid; gap: 12px; }
.tools { margin-bottom: 14px; }

.range-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.range-pills a { min-height: 34px; padding: 6px 10px; }

.settings-layout {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 16px;
    align-items: start;
}
.settings-stack { display: grid; gap: 16px; }
.settings-advanced summary {
    cursor: pointer;
    font-weight: 800;
    padding: 8px 0;
}

.wizard-steps {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.wizard-step {
    flex: 1;
    min-width: 120px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #f1f5f9;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-align: center;
}
.wizard-step.active { background: var(--primary-soft); color: var(--primary); }
.wizard-step.done { background: var(--success-soft); color: var(--success-dark); }

.import-file {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}
.dropzone {
    display: grid;
    place-items: center;
    gap: 8px;
    min-height: 180px;
    padding: 24px;
    border: 2px dashed var(--border-dark);
    border-radius: 16px;
    background: #f8fafc;
    text-align: center;
    cursor: pointer;
}
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone strong { display: block; font-size: 15px; }
.dropzone span { color: var(--muted); font-size: 12px; }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 40;
    min-width: 220px;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.menu-panel a, .menu-panel button {
    width: 100%;
    min-height: 36px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    border: 0;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    text-align: right;
    border-radius: 8px;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: #f1f5f9; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(15, 23, 42, .45);
}
.modal[hidden] { display: none; }
.modal-card {
    width: min(420px, 100%);
    padding: 18px;
    background: #fff;
    border-radius: 16px;
}
.modal-card p { margin: 0 0 14px; line-height: 1.8; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-start; }

#toast-root {
    position: fixed;
    right: 12px;
    bottom: 18px;
    left: 12px;
    z-index: 4500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    margin-right: auto;
    max-width: 360px;
    padding: 10px 14px;
    color: #fff;
    background: var(--navy);
    border-radius: 10px;
    font-size: 12px;
}

.app-version {
    margin: 8px auto 32px;
    width: min(1280px, calc(100% - 40px));
    text-align: center;
    color: var(--muted-light);
    font-size: 11px;
    flex: none;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    background: radial-gradient(1200px 600px at 80% -10%, #4f46e5 0%, transparent 45%),
                linear-gradient(160deg, #0b1733 0%, #1d4ed8 55%, #7c3aed 100%);
}
.login-wrap { width: min(420px, 100%); }
.login-card {
    background: #fff;
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .25);
    overflow: hidden;
}
.login-hero {
    padding: 28px 24px 12px;
    text-align: center;
    color: var(--navy);
}
.login-hero .brand-mark { margin: 0 auto 10px; }
.login-hero h1 { margin: 0; font-size: 28px; }
.login-hero p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

@media (max-width: 1100px) {
    .stats-grid, .dash-grid, .settings-layout { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .form-grid, .stats-grid, .dash-grid, .settings-layout { grid-template-columns: 1fr; }
    .filters, .filter-drawer { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        transform: translateX(110%);
        transition: transform .2s ease;
        min-height: 100%;
        box-shadow: none;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: grid; place-items: center; }
    .topbar-search { display: none; }
    .user-chip span:last-child { display: none; }
}

@media (max-width: 700px) {
    body, .app-body {
        padding-bottom: calc(76px + env(safe-area-inset-bottom));
        font-size: 13px;
    }
    input, button, select, textarea { font-size: 16px; }
    .app-topbar { padding: 8px 12px; }
    .container { width: calc(100% - 18px); margin: 14px auto 25px; }
    .page-heading h1 { font-size: 18px; }
    .card { border-radius: 14px; }
    .card-head, .card-body { padding: 14px; }
    .filters, .filters-products, .filter-drawer, .stats-grid { grid-template-columns: 1fr; }
    .data-table { min-width: 680px; }
    .products-table-wrap { display: none; }
    .product-cards { display: grid; gap: 10px; }
    .mobile-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 3000;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        padding: 5px 8px calc(5px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid var(--border);
        box-shadow: 0 -7px 22px rgba(15, 23, 42, .07);
        backdrop-filter: blur(12px);
    }
    .mobile-nav a {
        min-height: 52px;
        padding: 4px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        color: var(--muted);
        text-decoration: none;
        border-radius: 11px;
        font-size: 10px;
        font-weight: 900;
    }
    .mobile-nav svg { width: 20px; height: 20px; }
    .mobile-nav a.active { color: var(--primary); background: var(--primary-soft); }
    .bulk-bar { bottom: calc(84px + env(safe-area-inset-bottom)); }
    .mobile-nav-plus { color: #fff !important; background: var(--primary) !important; border-radius: 16px !important; }
    .mobile-nav a span { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
    #toast-root { bottom: calc(78px + env(safe-area-inset-bottom)); }
    .rate-chip { display: none; }
}

@media (hover: none) {
    .btn:hover { transform: none; }
}

@media (max-width: 320px) {
    .container { width: calc(100% - 12px); }
    .app-topbar { gap: 8px; }
}

.column-menu .menu-panel { display: grid; gap: 8px; min-width: 220px; padding: 12px; }
.column-toggle { display: flex; align-items: center; gap: 8px; }
th[data-column] { cursor: grab; }
th[data-column].dragging { opacity: .45; }
#bulk-price-modal .modal-card { width: min(520px, 100%); }
#bulk-price-modal label { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
