@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css');

:root {
    --bg: #f2f4fb;
    --surface: #ffffff;
    --surface-2: #f7f8fd;
    --border: #e6e8f2;
    --text: #1c2333;
    --text-muted: #6b7385;
    --primary: #2f6fed;
    --primary-dark: #1f52c4;
    --primary-soft: #eaf0ff;
    --primary-2: #7c3aed;
    --green: #14a35f;
    --green-soft: #e3f9ee;
    --red: #e0374a;
    --red-soft: #fde9ec;
    --amber: #e08a0c;
    --amber-soft: #fdf3e0;
    --teal: #0891a8;
    --teal-soft: #e2f6fa;
    --pink: #db2777;
    --pink-soft: #fdeaf3;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 1px 3px rgba(20, 24, 40, 0.08);
    --shadow-lg: 0 10px 30px rgba(30, 40, 90, 0.10);
    --sidebar-w: 250px;
    --sidebar-bg: linear-gradient(190deg, #1a1f3a 0%, #241a45 100%);
    --sidebar-bg-solid: #1a1f3a;
    --sidebar-text: #c7cbe8;
    --modal-backdrop: rgba(15, 18, 30, .5);
}

/* ---------------- تم تیره ---------------- */
html[data-mode="dark"] {
    --bg: #10131c;
    --surface: #171b28;
    --surface-2: #1e2333;
    --border: #2a3042;
    --text: #e7e9f0;
    --text-muted: #9199b0;
    --primary-soft: #1e2b4d;
    --green-soft: #10301f;
    --red-soft: #3a1720;
    --amber-soft: #362a10;
    --teal-soft: #0f2c33;
    --pink-soft: #3a1329;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 1px 3px rgba(0,0,0,.4);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.45);
    --sidebar-bg: linear-gradient(190deg, #0a0c15 0%, #140f28 100%);
    --sidebar-bg-solid: #0a0c15;
    --sidebar-text: #a4aac4;
    --modal-backdrop: rgba(0, 0, 0, .65);
}
html[data-mode="dark"] input, html[data-mode="dark"] select, html[data-mode="dark"] textarea {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}
html[data-mode="dark"] .modal { background: var(--surface); }
html[data-mode="dark"] .login-card { background: var(--surface); }

/* ---------------- تم‌های رنگی (روی حالت روشن و تیره هر دو اعمال می‌شود) ---------------- */
html[data-accent="green"] {
    --primary: #17924f;
    --primary-dark: #0f7038;
    --primary-soft: #e6f7ee;
}
html[data-mode="dark"][data-accent="green"] { --primary-soft: #10301f; }

html[data-accent="purple"] {
    --primary: #7c3aed;
    --primary-dark: #5f27c9;
    --primary-soft: #f1ebfe;
}
html[data-mode="dark"][data-accent="purple"] { --primary-soft: #2a1d4d; }

html[data-accent="blue"] {
    --primary: #2f6fed;
    --primary-dark: #1f52c4;
    --primary-soft: #eaf0ff;
}
html[data-mode="dark"][data-accent="blue"] { --primary-soft: #1e2b4d; }

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    direction: rtl;
    font-size: 14px;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------------- Layout ---------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 20;
    box-shadow: 4px 0 24px rgba(20,10,50,.12);
}

.sidebar-brand {
    padding: 22px 18px;
    font-size: 17px;
    font-weight: 800;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    letter-spacing: .3px;
}
.sidebar-brand span {
    background: linear-gradient(90deg, #6f9dff, #b98bff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.nav-group-title {
    font-size: 10.5px;
    color: #8a90b8;
    padding: 18px 18px 6px;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 700;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    margin: 2px 10px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: 13.5px;
    cursor: pointer;
    transition: background .15s, transform .15s;
}
.nav-link:hover { background: rgba(255,255,255,0.07); color: #fff; transform: translateX(-2px); }
.nav-link.active {
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
    color: #fff;
    box-shadow: 0 4px 14px rgba(90, 70, 230, .35);
}
.nav-link .ic { width: 18px; text-align: center; opacity: .95; }

.main {
    margin-right: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 62px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 rgba(20,24,40,.02);
}

.topbar-title {
    font-size: 17px;
    font-weight: 800;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-muted);
}
.topbar-user .btn-logout {
    color: var(--red);
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 13px;
}

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

/* ---------------- Cards / KPIs ---------------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--primary);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    transition: transform .15s, box-shadow .15s;
    position: relative;
    overflow: hidden;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-card .kpi-label { color: var(--text-muted); font-size: 12.5px; margin-bottom: 8px; font-weight: 600; }
.kpi-card .kpi-value { font-size: 23px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-card .kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }
.kpi-card.pos { border-inline-start-color: var(--green); }
.kpi-card.pos .kpi-value { color: var(--green); }
.kpi-card.neg { border-inline-start-color: var(--red); }
.kpi-card.neg .kpi-value { color: var(--red); }
/* رنگ‌های چرخشی برای کارت‌های KPI متوالی وقتی رنگ خاصی مشخص نشده */
.kpi-grid .kpi-card:nth-child(4n+2):not(.pos):not(.neg) { border-inline-start-color: var(--teal); }
.kpi-grid .kpi-card:nth-child(4n+3):not(.pos):not(.neg) { border-inline-start-color: var(--primary-2); }
.kpi-grid .kpi-card:nth-child(4n+4):not(.pos):not(.neg) { border-inline-start-color: var(--pink); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
}
.card-header h3 { margin: 0; font-size: 15px; font-weight: 700; }
.card-body { padding: 18px; }

/* ---------------- Buttons ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.btn:hover { background: var(--surface-2); transform: translateY(-1px); }
.btn-primary {
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
    border-color: transparent; color: #fff;
    box-shadow: 0 4px 12px rgba(90, 70, 230, .25);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 6px 16px rgba(90, 70, 230, .35); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-soft { background: var(--primary-soft); border-color: var(--primary-soft); color: var(--primary-dark); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------------- Tables ---------------- */

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
    text-align: right;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 12px;
    padding: 11px 12px;
    border-bottom: 2px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}
table.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data-table tbody tr:hover { background: var(--surface-2); }
table.data-table tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }
.table-empty { text-align: center; padding: 40px; color: var(--text-muted); }

.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.money.pos { color: var(--green); }
.money.neg { color: var(--red); }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-gray { background: var(--surface-2); color: var(--text-muted); }

/* ---------------- Forms ---------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 12.5px; color: var(--text-muted); }
.form-field.full { grid-column: 1 / -1; }
input, select, textarea {
    font-family: inherit;
    font-size: 13.5px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 70px; }

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.toolbar input[type=text], .toolbar select { width: auto; min-width: 180px; }
.spacer { flex: 1; }

/* ---------------- Modal ---------------- */

.modal-backdrop {
    position: fixed; inset: 0; background: var(--modal-backdrop);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal {
    background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 620px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-footer {
    display: flex; justify-content: flex-start; gap: 10px;
    padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ---------------- Tabs ---------------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
    padding: 10px 16px; border: none; background: none; cursor: pointer;
    font-size: 13.5px; color: var(--text-muted); border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-color: var(--primary); font-weight: 700; }

/* ---------------- Misc ---------------- */

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.toast-wrap {
    position: fixed; bottom: 20px; left: 20px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    background: #1c2333; color: #fff; padding: 12px 18px; border-radius: var(--radius-sm);
    font-size: 13px; box-shadow: var(--shadow); animation: toast-in .2s ease;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

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

.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #14192b, #1f2c4f);
}
.login-card {
    background: var(--surface); border-radius: var(--radius); padding: 34px 30px; width: 360px;
    max-width: calc(100vw - 32px);
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p { color: var(--text-muted); font-size: 13px; margin: 0 0 24px; }
.login-card .form-field { margin-bottom: 14px; }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 10px; min-height: 18px; }

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

/* ---------------- تنظیمات نمایش (تم تیره/روشن و رنگ) ---------------- */
.theme-switcher { display: flex; align-items: center; gap: 8px; }
.theme-switcher .mode-toggle {
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    width: 30px; height: 30px; border-radius: 999px; cursor: pointer; font-size: 14px;
    display: inline-flex; align-items: center; justify-content: center;
}
.theme-switcher .accent-dot {
    width: 18px; height: 18px; border-radius: 999px; cursor: pointer; border: 2px solid transparent;
    padding: 0;
}
.theme-switcher .accent-dot.active { border-color: var(--text); }
.theme-switcher .accent-dot[data-accent="blue"] { background: #2f6fed; }
.theme-switcher .accent-dot[data-accent="green"] { background: #17924f; }
.theme-switcher .accent-dot[data-accent="purple"] { background: #7c3aed; }

.menu-toggle {
    display: none; border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text);
}

/* ---------------- واکنش‌گرا برای موبایل ---------------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(100%); transition: transform .2s; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-right: 0; }
    .menu-toggle { display: inline-flex !important; }
}

@media (max-width: 640px) {
    .content { padding: 12px; }
    .topbar { padding: 0 12px; height: 54px; }
    .topbar-title { font-size: 14px; }
    .topbar-user span { display: none; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .kpi-card { padding: 12px; }
    .kpi-card .kpi-value { font-size: 17px; }
    .dash-cols { grid-template-columns: 1fr !important; }
    .form-grid { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar input[type=text], .toolbar select { width: 100%; min-width: 0; }
    .toolbar .spacer { display: none; }
    .card-header { flex-direction: column; align-items: stretch; gap: 10px; }
    .card-header .flex { flex-wrap: wrap; }
    .modal-backdrop { padding: 0; align-items: stretch; }
    .modal { max-width: 100%; width: 100%; min-height: 100vh; border-radius: 0; display: flex; flex-direction: column; }
    .modal-body { flex: 1; max-height: none; }
    .modal-footer { flex-wrap: wrap; }
    .modal-footer .btn { flex: 1; justify-content: center; }
    table.data-table { font-size: 12px; }
    table.data-table th, table.data-table td { padding: 8px 8px; }
    .tabs { overflow-x: auto; flex-wrap: nowrap; }
    .tab-btn { white-space: nowrap; }
    .theme-switcher .accent-dot { width: 16px; height: 16px; }
}

/* ---------------- ورودی تاریخ شمسی ---------------- */
.jdate-wrap { position: relative; width: 100%; }
.jdate-input {
    font-family: inherit;
    font-size: 13.5px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    width: 100%;
    cursor: pointer;
    text-align: left;
}
html[data-mode="dark"] .jdate-input { background: var(--surface-2); color: var(--text); }
.jdate-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.jdate-pop {
    position: absolute;
    z-index: 500;
    width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 12px;
}
.jdate-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.jdate-title { font-weight: 700; font-size: 13.5px; }
.jdate-nav {
    border: none; background: var(--surface-2); color: var(--text);
    width: 26px; height: 26px; border-radius: 999px; cursor: pointer; font-size: 15px;
    display: inline-flex; align-items: center; justify-content: center;
}
.jdate-nav:hover { background: var(--primary-soft); color: var(--primary-dark); }
.jdate-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.jdate-weekdays { margin-bottom: 4px; }
.jdate-cell {
    text-align: center; font-size: 12.5px; padding: 7px 0; border-radius: 8px; cursor: pointer;
    color: var(--text);
}
.jdate-cell.wd { color: var(--text-muted); font-weight: 700; cursor: default; font-size: 11px; }
.jdate-cell.empty { cursor: default; }
.jdate-cell:not(.wd):not(.empty):hover { background: var(--primary-soft); }
.jdate-cell.sel { background: var(--primary); color: #fff; font-weight: 700; }
.jdate-foot { display: flex; justify-content: space-between; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.jdate-foot button {
    border: none; background: none; color: var(--primary); font-size: 12px; cursor: pointer; font-family: inherit; font-weight: 600;
}
.jdate-foot .jdate-clear { color: var(--text-muted); }

/* ---------------- منبع خرید (کارخانه/شخص) ---------------- */
.source-toggle { display: flex; gap: 8px; }
.source-toggle label {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; color: var(--text-muted); font-weight: 600;
    transition: all .15s;
}
.source-toggle input { width: auto; accent-color: var(--primary); }
.source-toggle label.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

.money-field { text-align: left; font-variant-numeric: tabular-nums; }

.badge-teal { background: var(--teal-soft); color: var(--teal); }
.badge-pink { background: var(--pink-soft); color: var(--pink); }


@media (pointer: coarse) {
    .btn { padding: 10px 14px; }
    .btn-sm { padding: 7px 11px; }
    input, select, textarea { padding: 10px 12px; }
}
