@font-face { font-family: 'Vazirmatn'; src: url('/fonts/Vazirmatn.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #f6f5f3; --surface: #ffffff; --surface-2: #faf9f7; --sunken: #f0eeea;
  --ink: #1d1b1a; --ink-2: #57534f; --muted: #8b8680; --line: #e6e3de; --line-2: #d6d2cb;
  --accent: #8e3b6a; --accent-ink: #ffffff; --accent-soft: #f6e9f1; --accent-2: #6d2c51;
  --good: #1f7a3a; --good-bg: #e5f4e9; --warn: #8a5a00; --warn-bg: #fff3d6; --serious: #a14a1e; --serious-bg: #fde9df;
  --crit: #b3261e; --crit-bg: #fde7e5; --info: #1d5fa8; --info-bg: #e5effb;
  --series-1: #2a78d6; --grid: #e1e0d9; --axis: #c3c2b7;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1b1b1a; --surface-2: #20201f; --sunken: #262625;
    --ink: #f3f1ee; --ink-2: #c3c0b9; --muted: #8f8a83; --line: #2e2d2b; --line-2: #3b3a37;
    --accent: #d77fb0; --accent-ink: #1b0f16; --accent-soft: #3a2331; --accent-2: #e8a3ca;
    --good: #5cc97a; --good-bg: #183322; --warn: #f0bf4c; --warn-bg: #362b12; --serious: #f08a5d; --serious-bg: #3a2016;
    --crit: #f07470; --crit-bg: #3d1a19; --info: #7fb2f0; --info-bg: #172a40;
    --series-1: #3987e5; --grid: #2c2c2a; --axis: #383835;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1b1b1a; --surface-2: #20201f; --sunken: #262625;
  --ink: #f3f1ee; --ink-2: #c3c0b9; --muted: #8f8a83; --line: #2e2d2b; --line-2: #3b3a37;
  --accent: #d77fb0; --accent-ink: #1b0f16; --accent-soft: #3a2331; --accent-2: #e8a3ca;
  --good: #5cc97a; --good-bg: #183322; --warn: #f0bf4c; --warn-bg: #362b12; --serious: #f08a5d; --serious-bg: #3a2016;
  --crit: #f07470; --crit-bg: #3d1a19; --info: #7fb2f0; --info-bg: #172a40;
  --series-1: #3987e5; --grid: #2c2c2a; --axis: #383835;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Vazirmatn', Tahoma, system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.7; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.4; }
h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
.num, td.n, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-inline-end: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { padding: 16px 18px 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; border-bottom: 1px solid var(--line); margin: 0 12px 4px; }
.brand:hover { text-decoration: none; }
.brand img { width: 128px; height: auto; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; flex: none; }
.brand-name { font-weight: 700; font-size: 13px; line-height: 1.5; }
.nav { padding: 4px 10px 16px; flex: 1; }
.nav-group { font-size: 11px; color: var(--muted); padding: 14px 10px 4px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--sunken); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-inline-start: auto; background: var(--crit); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .title { flex: 1; min-width: 0; }
.menu-btn { display: none; }
.content { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-2); background: var(--surface); padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; min-height: 36px; }
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--crit); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 2px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  border: 1px solid var(--line-2); background: var(--surface); border-radius: 8px; padding: 6px 10px; min-height: 36px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 80px; resize: vertical; }
input.ltr { direction: ltr; text-align: right; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.field .req { color: var(--crit); }
.field input, .field select, .field textarea { color: var(--ink); font-weight: 400; }

/* ---------- jalali date picker */
.jdp { position: fixed; z-index: 300; width: 252px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 10px; direction: rtl; }
.jdp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.jdp-head button, .jdp-foot button { background: none; border: none; cursor: pointer; padding: 2px 10px; border-radius: 6px; font-size: 16px; color: var(--ink-2); }
.jdp-foot button { font-size: 12px; color: var(--accent); }
.jdp-head button:hover, .jdp-foot button:hover { background: var(--sunken); }
.jdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jdp-dow { font-size: 11px; color: var(--muted); padding: 2px 0; }
.jdp-grid button { border: none; background: none; cursor: pointer; border-radius: 6px; padding: 4px 0; font-size: 13px; color: var(--ink); }
.jdp-grid button:hover { background: var(--accent-soft); }
.jdp-grid button.today { outline: 1px solid var(--accent); }
.jdp-grid button.sel { background: var(--accent); color: var(--accent-ink); }
.jdp-foot { display: flex; justify-content: space-between; margin-top: 6px; border-top: 1px solid var(--line); padding-top: 6px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters > * { width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }
.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px 0 var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tabs button { background: none; border: none; padding: 8px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

/* ---------- cards & grid */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--ink-2); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat .delta-up { color: var(--good); }
.stat .delta-down { color: var(--crit); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--ink-2); font-weight: 600; background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.n, th.n { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: left; }
.card .table-wrap { border: none; border-radius: 0; margin: 0 -16px -16px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
table.compact td, table.compact th { padding: 6px 10px; }
tfoot td { font-weight: 700; background: var(--surface-2); }
table input, table select { min-height: 32px; padding: 3px 8px; }

/* ---------- badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 22px; white-space: nowrap; background: var(--sunken); color: var(--ink-2); }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.serious { background: var(--serious-bg); color: var(--serious); }
.badge.crit { background: var(--crit-bg); color: var(--crit); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------- lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 22px 16px 0; border-inline-start: 2px solid var(--line); margin-inline-start: 6px; }
.timeline li::before { content: ''; position: absolute; right: -7px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline .meta { font-size: 12px; color: var(--muted); }

/* ---------- kanban */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(210px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.kcol { background: var(--sunken); border-radius: var(--radius); padding: 10px; min-height: 300px; }
.kcol.over { outline: 2px dashed var(--accent); }
.kcol-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 8px; font-size: 13px; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.kcard .t { font-weight: 600; }

/* ---------- modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: min(720px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.sm { width: min(440px, 100%); }
.modal.lg { width: min(1000px, 100%); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-start; }
.toasts { position: fixed; bottom: 16px; left: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--crit); color: #fff; }

/* ---------- autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; top: 100%; right: 0; left: 0; background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-height: 300px; overflow-y: auto; margin-top: 2px; }
.ac-item { padding: 7px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.ac-item:hover, .ac-item.sel { background: var(--accent-soft); }

/* ---------- charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--series-1); }
.chart .bar-hit { fill: transparent; cursor: default; }
.chart .bar-hit:hover + .bar, .chart .bar.hover { opacity: .8; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow); border-radius: 8px; padding: 6px 10px; font-size: 12px; white-space: nowrap; z-index: 10; transform: translate(-50%, -100%); margin-top: -8px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 140px) 1fr max-content; gap: 10px; align-items: center; padding: 5px 0; }
.hbar .track { height: 10px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 4px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(ellipse 70% 50% at 50% 0%, var(--login-glow), transparent 70%), var(--bg); }
.login { width: min(380px, 100%); }
.login-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.login-logo img { width: min(240px, 70vw); height: auto; }
.login-card { border-top: 3px solid var(--gold); padding: 24px; }
.captcha-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.captcha-img { border-radius: 8px; border: 1px solid var(--line-2); background: #f6f2ea; width: 170px; height: 56px; user-select: none; }
.captcha-row .btn { font-size: 20px; min-width: 40px; }
.logo-dark { display: none; }
:root { --gold: #c9a227; --login-glow: rgba(201, 162, 39, 0.10); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --gold: #d8b64a; --login-glow: rgba(216, 182, 74, 0.08); }
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: block; }
}
:root[data-theme="dark"] { --gold: #d8b64a; --login-glow: rgba(216, 182, 74, 0.08); }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }

/* ---------- invoice / print */
#print-area { display: none; }
.invoice { font-size: 13px; color: #000; background: #fff; padding: 12px; }
.invoice table th, .invoice table td { border: 1px solid #999; padding: 5px 8px; }
.invoice th { background: #eee; color: #000; position: static; }
.invoice h1 { font-size: 18px; }
.invoice .inv-head { display: flex; justify-content: space-between; margin-bottom: 12px; border-bottom: 2px solid #000; padding-bottom: 8px; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  @page { size: A4; margin: 12mm; }
}

/* ---------- responsive */
@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; right: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .filters > * { min-width: 0; flex: 1 1 140px; }
  .filters input[type=search] { min-width: 0; max-width: none; flex-basis: 100%; }
}
