/* HesabYar — Persian/Dari RTL accounting UI */
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f3f5f0;
  --panel: #ffffff;
  --ink: #16241f;
  --muted: #6c7a74;
  --line: #e3e7df;
  --line-strong: #cbd4cb;
  --brand: #0d5c53;
  --brand-2: #0a4a43;
  --brand-soft: #e7f1ee;
  --gold: #b3832b;
  --gold-soft: #fbf3e0;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --ok: #067647;
  --ok-soft: #e8f6ef;
  --sidebar: #102a26;
  --sidebar-deep: #0b211e;
  --sidebar-ink: #dbe8e3;
  --sidebar-muted: #8fa8a0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 42, 38, 0.04), 0 10px 30px rgba(16, 42, 38, 0.05);
  --font: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.7;
  min-height: 100vh;
}
::selection { background: var(--brand-soft); color: var(--brand-2); }

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-2); }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.15px; }
p { margin: 0; }
.num, .money {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: embed;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 700; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-deep) 100%);
  color: var(--sidebar-ink);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 16px;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 20px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #d9ae52, #a9771f);
  color: #241a06; font-weight: 700; font-size: 20px;
  box-shadow: 0 6px 18px rgba(179, 131, 43, 0.28);
}
.brand strong { display: block; font-size: 15px; line-height: 1.5; color: #fff; }
.brand span { display: block; font-size: 11.5px; color: var(--sidebar-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; padding-bottom: 12px; }
.nav-group { margin-top: 16px; padding: 0 10px 6px; font-size: 10.5px; letter-spacing: .4px; color: var(--sidebar-muted); }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--sidebar-ink); font-size: 13.5px;
  position: relative; transition: background .15s, color .15s;
}
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: .82; }
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-link.active { background: rgba(255, 255, 255, 0.1); color: #fff; font-weight: 500; }
.nav-link.active::before {
  content: ''; position: absolute; inset-inline-start: -16px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 3px; background: #d9ae52;
}
.sidebar-foot { margin-top: auto; padding: 14px 6px 0; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .who { font-size: 12.5px; color: #fff; }
.sidebar-foot .fy { font-size: 11px; color: var(--sidebar-muted); }
.link-btn {
  background: none; border: none; padding: 0; color: var(--sidebar-muted);
  font: inherit; font-size: 12px; cursor: pointer;
}
.link-btn:hover { color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 30px; background: rgba(243,245,240,.86);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 20px; }
.topbar .crumb { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }
.content { width: 100%; max-width: 1400px; margin: 0 auto; padding: 24px 30px 64px; }

.nav-toggle {
  display: none; width: 38px; height: 38px; border: 1px solid var(--line);
  background: #fff; border-radius: 10px; cursor: pointer; align-items: center; justify-content: center;
}

/* ---------- flash ---------- */
.flash {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; border-radius: 11px; margin-bottom: 18px;
  font-size: 13px; border: 1px solid transparent;
}
.flash.ok { background: var(--ok-soft); color: #04543a; border-color: #c7e9d6; }
.flash.err { background: var(--danger-soft); color: #8a1c15; border-color: #f3cfcb; }
.flash .close { margin-inline-start: auto; background: none; border: 0; cursor: pointer; font-size: 17px; color: inherit; opacity: .65; line-height: 1; }

/* ---------- cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { font-size: 15.5px; }
.card-head .sub { color: var(--muted); font-size: 12px; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .page-title { font-size: 18px; }
.page-head .page-sub { color: var(--muted); font-size: 12.5px; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: 9px;
  border: 1px solid transparent; background: var(--brand); color: #fff;
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-2); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn.secondary { background: #fff; border-color: var(--line-strong); color: var(--ink); }
.btn.secondary:hover { background: #f7f9f5; border-color: #b9c5ba; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.gold { background: var(--gold); }
.btn.gold:hover { background: #9d711f; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8f1d16; }
.btn.small { height: 31px; padding: 0 11px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.icon { width: 34px; height: 34px; padding: 0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link-btn.inline { color: var(--brand); }
.link-btn.inline:hover { color: var(--brand-2); text-decoration: underline; }

/* ---------- statistics ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::after { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); opacity: .7; }
.stat.gold::after { background: var(--gold); }
.stat.warn::after { background: var(--danger); }
.stat .label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 7px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 8px; letter-spacing: -.4px; }
.stat .meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.stat .value .cur { font-size: 12px; color: var(--muted); font-weight: 500; margin-inline-start: 7px; }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: right; font-weight: 600; color: var(--muted);
  background: #f9faf7; border-bottom: 1px solid var(--line);
  padding: 10px 14px; white-space: nowrap; font-size: 12px;
}
.table td { padding: 11px 14px; border-bottom: 1px solid #eef1eb; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fbfcf9; }
.table .num, .table th.num { text-align: left; }
.table .total-row td { background: #f7f9f5; font-weight: 700; border-top: 1px solid var(--line-strong); }
.table .group-row td { background: #f4f7f2; font-weight: 700; color: var(--brand-2); }
.table.compact td { padding: 8px 12px; }
.table input, .table select { height: 34px; font-size: 12.5px; padding: 0 8px; border-radius: 8px; }
.table .line-desc { min-width: 180px; }
.table .line-num { width: 96px; }
.table .row-actions { width: 44px; }
.tfoot-note { color: var(--muted); font-size: 11.5px; padding: 10px 14px; }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 11.5px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 13.5px; color: var(--ink);
  background: #fff; border: 1px solid var(--line-strong);
  border-radius: 9px; padding: 0 11px; height: 40px; width: 100%;
  min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 84px; padding: 10px 11px; line-height: 1.7; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13, 92, 83, 0.1);
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); vertical-align: middle; }
input:disabled, select:disabled { background: #f4f6f2; color: var(--muted); }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; padding-top: 22px; }
.checkline label { color: var(--ink); font-size: 13px; font-weight: 400; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { min-width: 180px; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.form-section-title { font-size: 12px; color: var(--gold); font-weight: 700; letter-spacing: .3px; margin-bottom: 2px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 500;
  background: #f1f3ef; color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--gold-soft); color: #8a621c; }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--brand-soft); color: var(--brand); }

/* ---------- dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; }
.chart { display: flex; align-items: flex-end; gap: 16px; height: 190px; padding: 8px 4px 0; }
.chart-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 8px; min-width: 0; }
.chart-bar {
  width: 100%; max-width: 54px; min-height: 3px; border-radius: 7px 7px 2px 2px;
  background: linear-gradient(180deg, #16897c, #0d5c53);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}
.chart-col .bar-value { font-size: 10.5px; color: var(--muted); direction: ltr; }
.chart-col .bar-label { font-size: 11.5px; color: var(--muted); padding-top: 6px; border-top: 1px solid var(--line); width: 100%; text-align: center; }
.quick-list { display: flex; flex-direction: column; gap: 2px; }
.quick-link { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px; color: var(--ink); font-size: 13px; }
.quick-link:hover { background: #f5f8f4; color: var(--brand); }
.quick-link .qi { width: 32px; height: 32px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.quick-link .qi svg { width: 16px; height: 16px; }
.quick-link .go { margin-inline-start: auto; color: var(--muted); font-size: 16px; }

/* ---------- invoice / journal editors ---------- */
.line-table { min-width: 860px; table-layout: fixed; }
.line-table th { font-size: 11.5px; }
.line-table td { padding: 7px 6px; overflow: hidden; }
.line-table input, .line-table select { width: 100%; min-width: 0; }
.line-table .item-select { min-width: 0; }
.line-table .money-input { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.totals-box { margin-inline-start: auto; width: min(360px, 100%); display: flex; flex-direction: column; gap: 7px; padding: 4px 0; }
.totals-row { display: flex; justify-content: space-between; gap: 18px; font-size: 13px; }
.totals-row .v { font-variant-numeric: tabular-nums; direction: ltr; }
.totals-row.grand { border-top: 1px solid var(--line-strong); padding-top: 9px; margin-top: 4px; font-weight: 700; font-size: 15px; }
.totals-wrap { display: flex; justify-content: flex-end; padding: 14px 18px 4px; }
.balance-pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--danger-soft); color: var(--danger); }
.balance-pill.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- invoice print ---------- */
.invoice-paper { background: #fff; padding: 34px 38px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }
.invoice-top { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; border-bottom: 2px solid var(--brand); padding-bottom: 18px; margin-bottom: 22px; }
.invoice-brand { display: flex; gap: 12px; align-items: center; }
.invoice-brand .mark { width: 46px; height: 46px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 21px; }
.invoice-brand h2 { font-size: 17px; }
.invoice-brand p { color: var(--muted); font-size: 11.5px; }
.invoice-id { text-align: left; }
.invoice-id .no { font-size: 19px; font-weight: 700; color: var(--brand); direction: ltr; }
.invoice-meta { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-bottom: 22px; }
.meta-box { background: #f8faf6; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.meta-box .k { font-size: 11px; color: var(--muted); }
.meta-box .v { font-size: 13px; font-weight: 600; margin-top: 2px; }
.invoice-lines th { background: #f3f6f2; }
.invoice-total-box { display: flex; justify-content: flex-end; margin-top: 16px; }
.invoice-total-inner { width: min(340px, 100%); }
.invoice-notes { margin-top: 26px; padding-top: 14px; border-top: 1px dashed var(--line-strong); color: var(--muted); font-size: 12px; }
.sign-row { display: flex; gap: 40px; margin-top: 44px; color: var(--muted); font-size: 12px; }
.sign-row div { flex: 1; border-top: 1px dashed var(--line-strong); padding-top: 8px; text-align: center; }

/* ---------- reports ---------- */
.report-filter { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.report-filter .field { width: 160px; }
.report-title-block { text-align: center; margin-bottom: 20px; }
.report-title-block h2 { font-size: 17px; }
.report-title-block p { color: var(--muted); font-size: 12px; }
.bs-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.bs-section { margin-bottom: 18px; }
.bs-section h3 { font-size: 13.5px; color: var(--brand-2); border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 6px; }
.bs-line { display: flex; justify-content: space-between; padding: 5px 2px; font-size: 12.5px; gap: 12px; }
.bs-line .v { direction: ltr; font-variant-numeric: tabular-nums; }
.bs-total { display: flex; justify-content: space-between; border-top: 1px solid var(--line-strong); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 13px; }
.bs-total .v { direction: ltr; }
.check-strip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 8px; font-size: 12px; }
.check-strip.ok { background: var(--ok-soft); color: var(--ok); }
.check-strip.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #eef1eb; font-size: 13px; }
.list-plain li:last-child { border-bottom: 0; }
.list-plain .meta { margin-inline-start: auto; color: var(--muted); font-size: 11.5px; }

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 85% 10%, rgba(13, 92, 83, 0.12), transparent 60%),
    radial-gradient(700px 420px at 12% 88%, rgba(179, 131, 43, 0.1), transparent 60%),
    var(--bg);
}
.auth-card { width: min(460px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 34px 34px 28px; box-shadow: 0 24px 60px rgba(16, 42, 38, 0.1); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand .brand-mark { width: 46px; height: 46px; }
.auth-brand h1 { font-size: 17px; }
.auth-brand p { color: var(--muted); font-size: 11.5px; }
.auth-card h2 { font-size: 19px; margin-bottom: 4px; }
.auth-card .lead { color: var(--muted); font-size: 12.5px; margin-bottom: 22px; }
.auth-card .form-grid { gap: 14px; }
.auth-foot { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; text-align: center; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .icon { width: 52px; height: 52px; border-radius: 16px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 0 auto 12px; }
.empty h3 { color: var(--ink); font-size: 14px; margin-bottom: 4px; }
.empty p { font-size: 12.5px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.code-chip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; background: #f3f5f1; border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; direction: ltr; display: inline-block; }
.kv { display: flex; gap: 10px; font-size: 12.5px; padding: 5px 0; }
.kv .k { color: var(--muted); min-width: 92px; }
.warn-box { padding: 12px 14px; border-radius: 10px; background: var(--gold-soft); color: #7a571d; font-size: 12px; border: 1px solid #f0dfb9; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-end: 0; width: 282px;
    transform: translateX(100%); transition: transform .22s ease;
    box-shadow: -20px 0 50px rgba(0,0,0,.18);
  }
  body.nav-open .sidebar { transform: none; }
  .nav-toggle { display: inline-flex; }
  .topbar { padding: 14px 16px; }
  .content { padding: 18px 16px 52px; }
  .topbar h1 { font-size: 17px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .invoice-meta { grid-template-columns: 1fr 1fr; }
  .bs-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .auth-card { padding: 26px 20px 22px; }
  .invoice-paper { padding: 22px 18px; }
  .invoice-top { flex-direction: column; }
  .page-head .actions { width: 100%; }
  .report-filter .field { width: 100%; }
}

/* ---------- print ---------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .no-print, .flash, .page-head .actions, .card-foot { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; max-width: none; }
  .invoice-paper { border: 0; box-shadow: none; padding: 0; border-radius: 0; }
  .card { box-shadow: none; border-color: #ddd; }
  .table th { background: #f4f4f4 !important; }
  a { color: inherit; }
  .badge { border: 1px solid #ccc; }
}
