@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #15201e;
  --muted: #5d6b68;
  --line: #dde4e2;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d9f0ed;
  --good: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 14px rgba(16, 24, 22, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1413;
    --surface: #161e1d;
    --surface-2: #1d2826;
    --text: #e6eeec;
    --muted: #9aaba7;
    --line: #2a3735;
    --primary: #2dd4bf;
    --primary-ink: #04201c;
    --primary-soft: #133a35;
    --good: #4ade80;
    --bad: #f87171;
    --warn: #fbbf24;
    --warn-soft: #3a2e14;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "Vazirmatn", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.4; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { border-radius: 8px; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 6px; color: var(--muted); font-size: 12px;
}
.tabbar a .ico { font-size: 18px; line-height: 1.2; }
.tabbar a.active { color: var(--primary); font-weight: 700; }

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 14px 16px; margin-bottom: 12px;
}
.card h2 { margin-bottom: 8px; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 20px 2px 8px; color: var(--muted); font-size: 13px; font-weight: 700;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
/* عددِ علامت‌دار همیشه چپ‌به‌راست تا منفی «−۵۰۰» خوانده شود، نه «۵۰۰−». */
.signed { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.good { color: var(--good); }
.bad { color: var(--bad); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 19px; font-weight: 700; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 12px; }
.stat.hero { grid-column: 1 / -1; background: var(--primary); color: var(--primary-ink); border: 0; }
.stat.hero .label, .stat.hero .sub { color: inherit; opacity: .85; }
.stat.hero .value { font-size: 26px; }
.stat.hero .good, .stat.hero .bad { color: inherit; }

.alert {
  background: var(--warn-soft); color: var(--text);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid transparent;
}
.alert b { color: var(--warn); }
.alert.ok { background: var(--primary-soft); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 0; color: inherit;
}
.row .main { min-width: 0; }
.row .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 12px; }
.row .end { text-align: left; white-space: nowrap; }

.chip {
  display: inline-block; padding: 1px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 12px;
}
.chip.good { background: var(--primary-soft); color: var(--primary); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.segmented button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 8px; border-radius: 9px; font: inherit; cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: var(--shadow); }

form .field { margin-bottom: 12px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
textarea { min-height: 72px; resize: vertical; }
.hint { font-size: 12px; color: var(--primary); min-height: 18px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details summary { cursor: pointer; color: var(--primary); margin: 4px 0 10px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; cursor: pointer;
  border: 0; border-radius: 12px; padding: 10px 16px; min-height: 44px;
  background: var(--primary); color: var(--primary-ink);
}
button.block, .btn.block { width: 100%; }
button.ghost, .btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--line); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 13px; }
button.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
button.small { min-height: 34px; padding: 4px 12px; font-size: 13px; }
button:disabled { opacity: .6; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.actions > * { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chips button { min-height: 32px; padding: 2px 12px; font-weight: 400; background: var(--surface-2); color: var(--text); }

.fab {
  position: fixed; inset-inline-start: 16px; bottom: calc(86px + env(safe-area-inset-bottom));
  border-radius: 999px; padding: 12px 20px; box-shadow: 0 6px 20px rgba(15, 118, 110, .35);
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: left; font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.empty .big { font-size: 34px; }

.center-screen { min-height: 60vh; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 12px; }

#toast {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); inset-inline: 16px;
  margin: 0 auto; max-width: 480px; z-index: 10;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 16px;
  text-align: center;
}
#toast.error { background: var(--bad); color: #fff; }

.skeleton { height: 80px; border-radius: var(--radius); background: var(--surface-2); margin-bottom: 12px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* --- از حسابیار بپرس --- */
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble {
  max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap;
  border: 1px solid var(--line);
}
.bubble.q { align-self: flex-start; background: var(--primary); color: var(--primary-ink); border-color: transparent; border-end-start-radius: 4px; }
.bubble.a { align-self: flex-end; background: var(--surface); border-end-end-radius: 4px; box-shadow: var(--shadow); }
.bubble.thinking { color: var(--muted); }
.ask-bar {
  position: sticky; bottom: calc(68px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; background: var(--bg); padding: 8px 0;
}
.ask-bar input { flex: 1; }

/* --- حساب و اشتراک --- */
.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.plan { border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; background: var(--surface); cursor: pointer; font: inherit; color: inherit; min-height: 0; display: block; }
.plan.on { border-color: var(--primary); outline: 2px solid var(--primary); }
.plan .price { font-weight: 700; }
.plan .per { font-size: 12px; color: var(--muted); }

/* --- پنلِ مدیریت: نمودار و جدول --- */
.chart { width: 100%; height: auto; display: block; margin: 4px 0 6px; }
.chart .chart-base { stroke: var(--line); stroke-width: 1; }
.chart .chart-axis { fill: var(--muted); font-size: 9px; font-family: inherit; }
.chart .chart-label { fill: var(--text); font-size: 10px; font-weight: 700; font-family: inherit; }
.chart .bar:hover path, .chart .bar:focus path { opacity: .8; }
.chart .bar:focus { outline: none; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: start; color: var(--muted); font-weight: 400; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 6px; border-bottom: 1px solid var(--line); }
.tbl td.num { text-align: center; }
.heat-0 { background: transparent; }
.heat-1 { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.heat-2 { background: color-mix(in srgb, var(--primary) 26%, transparent); }
.heat-3 { background: color-mix(in srgb, var(--primary) 42%, transparent); }
.heat-4 { background: color-mix(in srgb, var(--primary) 60%, transparent); }
@media (prefers-color-scheme: dark) {
  .heat-3 { background: color-mix(in srgb, var(--primary) 28%, transparent); }
  .heat-4 { background: color-mix(in srgb, var(--primary) 38%, transparent); }
}

/* «بگو یا بنویس» و میکروفون */
.quick { margin-bottom: 12px; }
.quick .ask-bar { margin: 0; }
#quick-out:not(:empty) { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
#quick-out p { margin: 4px 0; }
button.mic { min-width: 44px; padding: 0 10px; background: var(--surface-2); color: var(--text); font-size: 18px; }
button.mic.rec { background: var(--bad); color: #fff; animation: mic-pulse 1s ease-in-out infinite; }
.chips button.on { background: var(--primary); color: var(--primary-ink); }
@keyframes mic-pulse { 50% { opacity: .6; } }
@media (prefers-reduced-motion: reduce) { button.mic.rec { animation: none; } }
.inv-opt { display: flex; gap: 8px; align-items: center; margin-top: 6px; color: var(--text); }
.inv-opt input { width: auto; min-height: 0; margin: 0; }
.promo-row { display: flex; gap: 8px; margin: 4px 0 4px; }
.promo-row input { flex: 1; min-width: 0; }
.plan s { color: var(--muted); }
