@font-face {
    font-family: VazirmatnFallback;
    src: local("Vazirmatn"), local("Tahoma");
}

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #20242a;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --success: #10b981;
    --warning: #b7791f;
    --danger: #b42318;
    --pak: #006dff;
    --damdaran: #00a86b;
    --sales: #facc15;
    --return: #ef4444;
    --shadow: 0 8px 24px rgba(15, 23, 42, .06);
    --shadow-hover: 0 14px 34px rgba(15, 23, 42, .10);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: VazirmatnFallback, Tahoma, Arial, sans-serif;
    line-height: 1.7;
}

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    gap: 20px;
    align-items: center;
    justify-content: space-between;
    padding: 14px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    font-weight: 800;
    color: var(--primary-strong);
    white-space: nowrap;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.nav a {
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--muted);
    transition: background .2s ease, color .2s ease;
}

.nav a.active,
.nav a:hover {
    background: #e8f2f2;
    color: var(--primary-strong);
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 24px auto;
}

.footer {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto;
    color: var(--muted);
    font-size: 13px;
}

.page-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

h1,
h2,
h3 {
    margin: 0 0 10px;
    line-height: 1.35;
}

h1 {
    font-size: 26px;
}

h2 {
    font-size: 20px;
}

h3 {
    font-size: 17px;
}

.muted {
    color: var(--muted);
}

.grid {
    display: grid;
    gap: 16px;
}

.stats {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.stats-compact {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.two-col {
    grid-template-columns: 1fr 1fr;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.stat-card {
    min-height: 104px;
}

.stat-label {
    color: var(--muted);
    font-size: 13px;
}

.stat-value {
    display: block;
    margin-top: 10px;
    font-size: 24px;
    font-weight: 800;
}

.filters,
.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}

.form-row {
    margin-bottom: 14px;
}

label {
    display: block;
    margin-bottom: 6px;
    color: #374151;
    font-size: 14px;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

input:focus,
select:focus {
    outline: 2px solid rgba(47, 111, 115, .18);
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform .18s ease, filter .18s ease, background .18s ease;
}

.btn.secondary {
    background: #eef2f7;
    color: #334155;
}

.btn.danger {
    background: var(--danger);
}

.btn:disabled {
    cursor: not-allowed;
    filter: grayscale(.5);
    opacity: .55;
    transform: none;
}

.btn:hover {
    filter: brightness(.96);
    transform: translateY(-1px);
}

.btn:disabled:hover {
    filter: grayscale(.5);
    transform: none;
}

.filter-actions,
.row-actions,
.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 850px;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: right;
    vertical-align: middle;
}

th {
    background: #f9fafb;
    color: #374151;
    font-size: 13px;
}

.sort-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #334155;
    font-weight: 900;
    white-space: nowrap;
}

tfoot td {
    background: #f3f6f6;
    font-weight: 800;
}

.badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge-success {
    background: #e8f6ef;
    color: var(--success);
}

.badge-warning {
    background: #fff5df;
    color: var(--warning);
}

.alert {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}

.alert-success {
    border-color: #b7e4cb;
    color: #116149;
}

.alert-danger {
    border-color: #fecaca;
    color: var(--danger);
}

.section {
    margin-top: 22px;
}

.chart-box {
    min-height: 360px;
    overflow-x: auto;
    background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
}

canvas {
    max-width: 100%;
}

.chart-tooltip {
    position: absolute;
    z-index: 4;
    min-width: 138px;
    padding: 8px 10px;
    border: 1px solid rgba(148, 163, 184, .32);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    color: #1f2937;
    font-size: 12px;
    line-height: 1.7;
    box-shadow: var(--shadow-hover);
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity .15s ease, transform .15s ease;
}

.chart-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

.empty {
    padding: 24px;
    color: var(--muted);
    text-align: center;
}

.group-cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.group-card {
    display: grid;
    gap: 14px;
}

.group-metric {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.group-metric span,
.summary-list span {
    color: var(--muted);
    font-size: 13px;
}

.group-metric strong,
.summary-list strong {
    font-size: 16px;
}

.brand-chip {
    display: inline-flex;
    min-width: 58px;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
}

.brand-chip.pak {
    background: rgba(0, 109, 255, .10);
    color: var(--pak);
}

.brand-chip.damdaran {
    background: rgba(0, 168, 107, .12);
    color: var(--damdaran);
}

.inline-form {
    margin: 0;
}

.inline-fields {
    display: flex;
    gap: 8px;
    align-items: center;
}

.inline-fields input {
    min-width: 180px;
}

.compact-form {
    display: grid;
    gap: 10px;
}

.analytics-card {
    box-shadow: none;
    border-color: #dfe7ed;
}

.metric-bars {
    display: grid;
    gap: 12px;
}

.metric-bar {
    --bar-color: #64748b;
    display: grid;
    gap: 7px;
    padding: 10px 0;
}

.metric-bar.pak {
    --bar-color: var(--pak);
}

.metric-bar.damdaran {
    --bar-color: var(--damdaran);
}

.metric-bar.return {
    --bar-color: var(--return);
}

.metric-bar-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #334155;
    font-size: 13px;
}

.metric-bar-head strong {
    color: #111827;
    white-space: nowrap;
}

.metric-bar-track {
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #eef2f7;
}

.metric-bar-track span {
    display: block;
    width: var(--bar-width);
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, color-mix(in srgb, var(--bar-color) 78%, white), var(--bar-color));
    box-shadow: 0 5px 14px color-mix(in srgb, var(--bar-color) 25%, transparent);
    transition: width .45s ease, transform .2s ease;
}

.compare-panel {
    display: grid;
    gap: 16px;
}

.axis-note {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
}

.axis-note span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.axis-note span::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: currentColor;
}

.metric-bar:hover .metric-bar-track span {
    transform: scaleY(1.18);
}

.tabs {
    display: grid;
    gap: 16px;
}

.tab-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px;
    background: #eef2f7;
    border-radius: 8px;
}

.tab-button {
    min-height: 40px;
    padding: 8px 14px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: background .2s ease, color .2s ease, transform .2s ease;
}

.tab-button.active,
.tab-button:hover {
    background: var(--surface);
    color: var(--primary-strong);
    transform: translateY(-1px);
}

.tab-panel {
    display: none;
    animation: fadeUp .25s ease both;
}

.tab-panel.active {
    display: block;
}

.summary-list {
    display: grid;
    gap: 14px;
}

.summary-list div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, .38);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    width: min(440px, 100%);
    animation: fadeUp .2s ease both;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 18% 18%, rgba(250, 204, 21, .18), transparent 28%),
        radial-gradient(circle at 80% 14%, rgba(0, 109, 255, .16), transparent 30%),
        linear-gradient(135deg, #f8fafc 0%, #eef6f1 100%);
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    padding: 34px;
    border: 1px solid rgba(148, 163, 184, .28);
    border-radius: 18px;
    background: rgba(255, 255, 255, .84);
    box-shadow: 0 24px 70px rgba(15, 23, 42, .13);
    backdrop-filter: blur(18px);
}

.login-copy {
    text-align: center;
}

.login-copy p,
.login-hint {
    margin: 0 0 18px;
    color: var(--muted);
    text-align: center;
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-btn {
    width: 100%;
    margin-top: 4px;
    background: linear-gradient(135deg, var(--pak), var(--damdaran));
}

.cow-mark {
    position: relative;
    width: 96px;
    height: 82px;
    margin: 0 auto 18px;
}

.cow-face {
    position: absolute;
    inset: 10px 12px 0;
    border: 2px solid #111827;
    border-radius: 38% 38% 44% 44%;
    background: #fff;
}

.cow-spot {
    position: absolute;
    top: 8px;
    right: 14px;
    width: 24px;
    height: 19px;
    border-radius: 55% 45% 52% 48%;
    background: #111827;
}

.cow-eye {
    position: absolute;
    top: 28px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #111827;
}

.cow-eye.left {
    left: 22px;
}

.cow-eye.right {
    right: 22px;
}

.cow-nose {
    position: absolute;
    left: 50%;
    bottom: 8px;
    width: 34px;
    height: 20px;
    border-radius: 999px;
    background: #f8c8d4;
    transform: translateX(-50%);
}

.cow-ear,
.cow-horn {
    position: absolute;
    top: 22px;
    width: 24px;
    height: 20px;
    border-radius: 60% 40% 60% 40%;
    background: #111827;
}

.cow-ear.left {
    left: 0;
    transform: rotate(-28deg);
}

.cow-ear.right {
    right: 0;
    transform: rotate(28deg) scaleX(-1);
}

.cow-horn {
    top: 0;
    width: 18px;
    height: 26px;
    background: #facc15;
}

.cow-horn.left {
    left: 24px;
    transform: rotate(-20deg);
}

.cow-horn.right {
    right: 24px;
    transform: rotate(20deg) scaleX(-1);
}

@media (max-width: 980px) {
    .topbar,
    .page-head {
        align-items: stretch;
        flex-direction: column;
    }

    .stats,
    .stats-compact,
    .two-col,
    .filters,
    .form-grid,
    .group-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .container,
    .footer {
        width: min(100% - 20px, 1180px);
        margin-top: 14px;
    }

    .stats,
    .stats-compact,
    .two-col,
    .filters,
    .form-grid,
    .group-cards {
        grid-template-columns: 1fr;
    }

    .nav a {
        padding: 7px 9px;
        font-size: 13px;
    }

    .inline-fields {
        align-items: stretch;
        flex-direction: column;
    }
}
