:root {
  --bg: #0e1117;
  --bg2: #151b24;
  --card: #1a222e;
  --card2: #202a38;
  --line: #2b3744;
  --tx: #e7edf5;
  --tx2: #95a3b6;
  --acc: #3b82f6;
  --acc2: #1d4ed8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font-family: Vazirmatn, "IRANSans", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 14px;
  direction: rtl;
}

a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

.num { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; direction: ltr; display: inline-block; }

/* ---------- layout ---------- */
#app { display: flex; min-height: 100vh; }

.side {
  width: 220px; flex: 0 0 220px; background: var(--bg2);
  border-left: 1px solid var(--line); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow: auto;
}
.brand { font-size: 16px; font-weight: 700; padding: 6px 10px 16px; color: #fff; }
.brand small { display: block; font-weight: 400; color: var(--tx2); font-size: 11px; margin-top: 3px; }
.side nav a {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px;
  border-radius: 9px; color: var(--tx2); font-size: 13.5px;
}
.side nav a:hover { background: var(--card); color: var(--tx); text-decoration: none; }
.side nav a.on { background: var(--acc); color: #fff; }
.side .spacer { flex: 1; }
.side .who { border-top: 1px solid var(--line); padding: 12px 10px 2px; font-size: 12px; color: var(--tx2); }

main { flex: 1; padding: 22px 26px 60px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .grow { flex: 1; }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.kpi .label { color: var(--tx2); font-size: 12.5px; margin-bottom: 8px; }
.kpi .val { font-size: 22px; font-weight: 700; }
.kpi .sub { color: var(--tx2); font-size: 11.5px; margin-top: 6px; }

.btn {
  background: var(--acc); color: #fff; border: 0; border-radius: 9px;
  padding: 9px 16px; font: inherit; font-size: 13.5px; cursor: pointer;
}
.btn:hover { background: var(--acc2); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--tx); }
.btn.ghost:hover { background: var(--card2); }
.btn.danger { background: transparent; border: 1px solid #5b2020; color: #f87171; }
.btn.danger:hover { background: #2a1414; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; color: var(--tx2); font-size: 12.5px; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; background: var(--bg); color: var(--tx);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font: inherit; font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--acc); }
input[readonly] { color: var(--tx2); background: #131a23; }
textarea { min-height: 62px; resize: vertical; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--line); }
th { color: var(--tx2); font-weight: 500; font-size: 12px; white-space: nowrap; background: var(--bg2); position: sticky; top: 0; }
tbody tr:hover { background: var(--card2); }
td.l, th.l { text-align: left; }
.tbl-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 11.5px; background: var(--card2); color: var(--tx2); white-space: nowrap;
}
.tag.ok { background: #10361f; color: #6ee7a0; }
.tag.warn { background: #3a2c0c; color: #fbbf24; }
.tag.err { background: #3a1616; color: #fca5a5; }
.tag.info { background: #12294a; color: #93c5fd; }

.pos { color: #4ade80; }
.neg { color: #f87171; }
.muted { color: var(--tx2); }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 150px; }
.row > .fix { flex: 0 0 auto; min-width: 0; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button {
  background: var(--card); border: 1px solid var(--line); color: var(--tx2);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-size: 13px; cursor: pointer;
}
.tabs button.on { background: var(--acc); border-color: var(--acc); color: #fff; }

.msg { padding: 10px 13px; border-radius: 9px; margin-bottom: 14px; font-size: 13px; }
.msg.err { background: #33191a; color: #fca5a5; border: 1px solid #5b2020; }
.msg.ok { background: #14301f; color: #86efac; border: 1px solid #1f5133; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth { width: 100%; max-width: 380px; }

.modal-bg {
  position: fixed; inset: 0; background: #000a; display: grid; place-items: center;
  padding: 20px; z-index: 50; overflow: auto;
}
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: 100%; max-width: 640px; }

.help { font-size: 12px; color: var(--tx2); line-height: 1.7; }
.sep { height: 1px; background: var(--line); margin: 16px 0; }
.toast {
  position: fixed; bottom: 20px; left: 20px; z-index: 99;
  background: var(--card); border: 1px solid var(--line); border-right: 3px solid var(--ok);
  padding: 12px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 30px #0008;
}
.toast.err { border-right-color: var(--err); }

@media (max-width: 760px) {
  #app { flex-direction: column; }
  .side { width: auto; flex: none; height: auto; position: static; flex-direction: row; overflow-x: auto; align-items: center; }
  .side .brand, .side .who, .side .spacer { display: none; }
  .side nav { display: flex; gap: 4px; }
  main { padding: 16px 14px 40px; }
}

/* نتیجه‌ی زنده‌ی تبدیل ارز زیر فیلد مبلغ */
.eq:not(:empty) { display: block; margin-top: 4px; color: var(--ok); direction: ltr; text-align: left; }
.contra { line-height: 1.8; white-space: nowrap; }
.print-head, .print-sign { display: none; }
/* نسخه‌ی انگلیسی صورتحساب: روی صفحه هرگز دیده نمی‌شود */
.print-area-en { display: none; }

/* ------------------------------ چاپ / PDF ------------------------------ */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  :root { --card: #fff; --line: #bbb; --tx: #000; --tx2: #444; }
  html, body { background: #fff !important; color: #000 !important; }
  .side, .no-print, .toast, .tabs, button { display: none !important; }
  #app { display: block; }
  main { padding: 0 !important; overflow: visible !important; }
  .card {
    background: #fff !important; border: none !important; padding: 0 !important;
    box-shadow: none !important; margin: 0 !important;
  }
  .tbl-wrap { overflow: visible !important; }
  table { width: 100%; border-collapse: collapse; font-size: 10px; }
  th, td {
    border: 1px solid #999 !important; padding: 4px 6px !important;
    color: #000 !important; background: #fff !important;
  }
  thead th { background: #eee !important; font-weight: 700; }
  thead { display: table-header-group; }   /* تکرار سرستون در صفحات بعد */
  tr { page-break-inside: avoid; }
  a { color: #000 !important; text-decoration: none !important; }
  .tag {
    background: none !important; border: 1px solid #999 !important;
    color: #000 !important; font-size: 9px !important; padding: 0 3px !important;
  }
  .pos, .neg, .muted { color: #000 !important; }
  .contra { white-space: normal; }

  .print-head { display: block; margin-bottom: 10px; border-bottom: 2px solid #000; padding-bottom: 6px; }
  .print-head .ph-top { display: flex; justify-content: space-between; font-size: 11px; }
  .print-head h2 { margin: 6px 0 2px; font-size: 15px; }
  .print-head .ph-sub { font-size: 11px; color: #333; }
  .print-sign {
    display: flex; justify-content: space-between; margin-top: 18px;
    font-size: 11px; padding-top: 8px; border-top: 1px solid #999;
  }

  /* پیش‌فرض: نسخه‌ی فارسی. با کلاس print-en نسخه‌ی انگلیسی جای آن را می‌گیرد */
  body.print-en .print-area { display: none !important; }
  body.print-en .print-area-en { display: block !important; }
  .print-area-en { direction: ltr; text-align: left; }
  .print-area-en th, .print-area-en td { text-align: left; }
  .print-area-en .l, .print-area-en .num { text-align: right; }
}
