:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --text: #1e2230;
  --text-muted: #737a8c;
  --border: #e6e8ef;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --income: #0f9f6e;
  --income-bg: #e3f7ef;
  --expense: #e5484d;
  --expense-bg: #fdecec;
  --installments: #d97706;
  --installments-bg: #fef3e2;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 4px 16px rgba(20, 24, 40, 0.05);
  --shadow-lg: 0 20px 50px rgba(20, 24, 40, 0.18);
  --bottom-nav-h: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  overflow-x: hidden;
  max-width: 100%;
  line-height: 1.5;
}
body.modal-open { overflow: hidden; }

button, input, select { font-family: inherit; }
button { color: inherit; }
h2, h3 { margin: 0; }

.hidden { display: none !important; }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.1rem;
  white-space: nowrap;
}
.brand-icon { font-size: 1.35rem; }

.main-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.15s, color 0.15s;
}
@media (hover: hover) {
  .nav-btn:hover { background: var(--surface-2); color: var(--text); }
}
.nav-btn.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { font-size: 1rem; line-height: 1; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); }

/* ===== Month switcher ===== */
.month-switcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 16px 4px;
}
.month-nav-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-muted);
  flex-shrink: 0;
}
.month-nav-btn:hover { color: var(--primary); border-color: var(--primary); }
/* فلش‌ها در حالت چپ‌به‌راست باید برعکس شوند */
[dir="rtl"] .month-nav-btn { transform: scaleX(-1); }
.current-month-label {
  font-weight: 800;
  font-size: 1.05rem;
  min-width: 140px;
  text-align: center;
  white-space: nowrap;
}

/* ===== Content ===== */
.content {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 20px 110px;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0 14px;
}
.view-header h2 { font-size: 1.3rem; font-weight: 800; }
.view-intro { color: var(--text-muted); font-size: 0.88rem; margin: -6px 0 16px; line-height: 1.8; }

.section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  margin: 22px 4px 10px;
}

/* ===== Hero (balance) card ===== */
.hero-card {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
  border-radius: 24px;
  padding: 22px 22px 18px;
  box-shadow: 0 14px 34px rgba(79, 70, 229, 0.28);
}
.hero-label { font-size: 0.9rem; opacity: 0.85; font-weight: 600; }
.hero-value {
  font-size: 2.1rem;
  font-weight: 800;
  margin: 4px 0 18px;
  letter-spacing: -0.5px;
  word-break: break-word;
}
.hero-value.negative { color: #ffd4d6; }
.hero-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}
.hero-split-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 10px 12px;
  min-width: 0;
}
.hero-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.95);
}
.hero-dot.income { color: var(--income); }
.hero-dot.expense { color: var(--expense); }
.hero-split-label { font-size: 0.78rem; opacity: 0.85; }
.hero-split-value { font-weight: 800; font-size: 0.98rem; line-height: 1.35; }

/* مبالغ فقط بین عدد و واحد پول می‌شکنند، هرگز وسط عدد */
.hero-value, .hero-split-value, .mini-value, .net-strip b, .tx-amount, .item-amount, .detail-value {
  word-break: keep-all;
  overflow-wrap: normal;
}

/* ===== Quick add ===== */
.quick-add {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s;
}
.quick-btn:hover { transform: translateY(-2px); }
.quick-btn:active { transform: scale(0.97); }
.quick-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 800;
}
.quick-btn.expense .quick-icon { background: var(--expense-bg); color: var(--expense); }
.quick-btn.income .quick-icon { background: var(--income-bg); color: var(--income); }
.quick-btn.monthly .quick-icon { background: var(--primary-soft); font-size: 1.1rem; }

/* ===== Mini stat cards ===== */
.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.mini-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  min-width: 0;
}
.mini-card:hover { border-color: var(--primary); }
.mini-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.mini-value { font-weight: 800; font-size: 0.98rem; line-height: 1.35; }
.mini-card.income .mini-value { color: var(--income); }
.mini-card.expense .mini-value { color: var(--expense); }
.mini-card.installments .mini-value { color: var(--installments); }

/* ===== Panels ===== */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel > h3, .panel-title-row h3 { font-size: 1rem; font-weight: 800; margin-bottom: 12px; }
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.panel-title-row h3 { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.income { background: var(--income); }
.dot.expense { background: var(--expense); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.hint-text { font-size: 0.85rem; color: var(--text-muted); margin: 0 0 14px; }

.dashboard-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 22px;
}
.chart-wrap { position: relative; height: 280px; }

.empty-hint {
  color: var(--text-muted);
  text-align: center;
  padding: 18px 8px;
  font-size: 0.88rem;
  margin: 0;
}
.empty-state { text-align: center; color: var(--text-muted); padding: 22px 8px; font-size: 0.9rem; }
.empty-state p { margin: 0; }
.empty-emoji { font-size: 2rem; margin-bottom: 6px; }

/* ===== Filter chips ===== */
.filter-chips { display: flex; gap: 8px; margin-bottom: 12px; }
.chip {
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--text-muted);
}
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ===== Transaction rows ===== */
.tx-list { display: flex; flex-direction: column; }
.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--border);
}
.tx-row:last-child { border-bottom: none; }
.tx-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  background: var(--surface-2);
}
.tx-icon.income { background: var(--income-bg); }
.tx-icon.expense { background: var(--expense-bg); }
.tx-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.tx-title { font-weight: 700; font-size: 0.93rem; overflow-wrap: anywhere; line-height: 1.5; }
.tx-meta { font-size: 0.78rem; color: var(--text-muted); }
.tx-amount { font-weight: 800; font-size: 0.95rem; text-align: end; max-width: 48%; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--text); }
.tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 6px;
  padding: 1px 6px;
  vertical-align: middle;
}

.row-delete-btn {
  background: none;
  border: none;
  color: #b3b8c6;
  cursor: pointer;
  font-size: 0.95rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
}
.row-delete-btn:hover { color: var(--expense); background: var(--expense-bg); }

/* ===== Item cards (monthly / installments) ===== */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px 14px;
}
.item-card.inactive { opacity: 0.55; }
.item-info { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.item-title { font-weight: 800; font-size: 0.95rem; overflow-wrap: anywhere; }
.item-sub { font-size: 0.78rem; color: var(--text-muted); }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; max-width: 48%; }
.item-amount { font-weight: 800; font-size: 0.95rem; text-align: end; }
.item-amount.income { color: var(--income); }
.item-amount.expense { color: var(--expense); }
.item-side-label { font-size: 0.72rem; color: var(--text-muted); }
.item-actions { display: flex; align-items: center; gap: 4px; }
.item-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 4px;
  max-width: 220px;
}
.item-progress-fill { height: 100%; background: var(--installments); border-radius: 999px; }

.installment-card { cursor: pointer; transition: box-shadow 0.15s; }
.installment-card:hover { box-shadow: var(--shadow); }
.installment-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ===== Net strip (monthly view) ===== */
.net-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.net-strip > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  min-width: 0;
}
.net-strip > div + div { border-inline-start: 1px solid var(--border); }
.net-strip span { font-size: 0.76rem; color: var(--text-muted); font-weight: 600; }
.net-strip b { font-size: 1rem; line-height: 1.4; }
.net-strip b.income { color: var(--income); }
.net-strip b.expense { color: var(--expense); }

/* ===== Switch ===== */
.switch { position: relative; display: inline-block; width: 40px; height: 24px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track {
  position: absolute;
  inset: 0;
  background: #cfd3dd;
  border-radius: 999px;
  transition: background 0.2s;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}
.switch input:checked + .switch-track { background: var(--income); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
[dir="rtl"] .switch input:checked + .switch-track::after { transform: translateX(-16px); }

/* ===== Tables (report) ===== */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td {
  padding: 10px 8px;
  text-align: start;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th { color: var(--text-muted); font-weight: 700; font-size: 0.8rem; }
.data-table td.amount-income { color: var(--income); font-weight: 700; }
.data-table td.amount-expense { color: var(--expense); font-weight: 700; }

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.92rem;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--expense-bg); color: var(--expense); }
.btn-soft.income { background: var(--income-bg); color: var(--income); }
.btn-soft.expense { background: var(--expense-bg); color: var(--expense); }
.btn-block { width: 100%; margin-top: 8px; }
.btn-small { padding: 7px 14px; font-size: 0.84rem; border-radius: 10px; margin-bottom: 12px; }
.view-header .btn-small { margin-bottom: 0; }
.btn-lg { padding: 14px 18px; font-size: 1rem; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: 26px;
  inset-inline-end: 26px;
  height: 56px;
  padding: 0 22px 0 18px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(79, 70, 229, 0.4);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1rem;
  animation: fab-pop 0.4s ease-out;
  transition: transform 0.15s;
}
.fab:hover { transform: translateY(-2px); }
.fab-icon { font-size: 1.7rem; line-height: 1; font-weight: 400; }
.fab-label { white-space: nowrap; }

@keyframes fab-pop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ===== Modal (bottom sheet on phones) ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 32, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  animation: fade-in 0.15s ease-out;
}
.modal {
  background: var(--surface);
  border-radius: 22px;
  width: 100%;
  max-width: 440px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  max-height: 92vh;
  overflow-y: auto;
  animation: sheet-up 0.22s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 { font-size: 1.15rem; font-weight: 800; }
.modal-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-2);
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

form label, .field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.field-label { margin-bottom: 8px; }
form input, form select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  width: 100%;
}
form input:focus, form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.amount-label input {
  font-size: 1.6rem;
  font-weight: 800;
  padding: 12px 14px;
  text-align: center;
}

.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.type-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 800;
  font-size: 0.98rem;
  color: var(--text-muted);
}
.tt-icon { font-size: 1.2rem; line-height: 1; }
.type-toggle-btn[data-type="expense"].active { background: var(--expense-bg); color: var(--expense); border-color: var(--expense); }
.type-toggle-btn[data-type="income"].active { background: var(--income-bg); color: var(--income); border-color: var(--income); }

.kind-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.kind-toggle.small { margin-bottom: 14px; }
.kind-toggle-btn {
  flex: 1;
  padding: 9px 6px;
  border-radius: 9px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--text-muted);
}
.kind-toggle-btn.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 4px rgba(20, 24, 40, 0.1); }
.kind-hint { font-size: 0.8rem; color: var(--text-muted); margin: 0 4px 16px; min-height: 1em; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.cat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 4px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  min-width: 0;
}
.cat-chip.active { border-color: var(--primary); background: var(--primary-soft); }
.cat-emoji { font-size: 1.25rem; line-height: 1.2; }
.cat-name { font-size: 0.74rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.field-group { display: block; }

.optional-box {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 12px 2px;
  margin-bottom: 12px;
}
.optional-title { font-size: 0.74rem; font-weight: 700; color: var(--text-muted); margin-bottom: 8px; }
form label.check-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}
form label.check-row input { width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--primary); margin: 0; }
.inst-preview {
  background: var(--installments-bg);
  color: #92400e;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.8;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
}
.inst-preview:empty { display: none; }
.date-select-group { display: flex; gap: 6px; }
.date-select-group select { flex: 1; min-width: 0; }

.form-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 10px; margin-top: 8px; }
.form-success {
  background: var(--income-bg);
  color: var(--income);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.7;
  padding: 10px 12px;
  border-radius: 10px;
  margin: 0 0 8px;
}
.form-error {
  background: var(--expense-bg);
  color: var(--expense);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 10px;
  margin: 0 0 8px;
}

/* ===== Confirm modal ===== */
.modal-confirm { max-width: 380px; }
.confirm-message { color: var(--text); font-size: 0.95rem; line-height: 1.8; margin: 0 0 20px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

/* ===== Installment detail modal ===== */
.detail-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.detail-progress .item-progress { flex: 1; height: 8px; margin: 0; max-width: none; }
.detail-progress-label { font-weight: 800; color: var(--installments); font-size: 0.9rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.detail-item { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.detail-label { font-size: 0.74rem; color: var(--text-muted); margin-bottom: 2px; font-weight: 600; }
.detail-value { font-weight: 800; font-size: 0.95rem; }

/* ===== Report ===== */
.report-header { margin-bottom: 14px; }
.report-header h3 { font-size: 1.05rem; font-weight: 800; }
.report-summary { display: flex; gap: 18px; flex-wrap: wrap; font-size: 0.88rem; color: var(--text-muted); margin-top: 6px; }
.report-summary b { color: var(--text); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + var(--bottom-nav-h));
  transform: translate(-50%, 12px);
  background: var(--text);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== Tablet ===== */
@media (max-width: 1100px) {
  .nav-btn { padding: 8px 10px; }
}
@media (max-width: 900px) {
  .dashboard-bottom { grid-template-columns: minmax(0, 1fr); }
}

/* ===== Phone: bottom tab bar + bottom-sheet modals ===== */
@media (max-width: 900px) {
  :root { --bottom-nav-h: calc(64px + env(safe-area-inset-bottom)); }

  /* backdrop-filter روی والد، position:fixed نوار پایین را به داخل هدر محدود می‌کند؛ پس در موبایل حذفش می‌کنیم */
  .topbar {
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--surface);
  }
  .main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    gap: 0;
    justify-content: space-around;
  }
  .nav-btn {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
    border-radius: 12px;
    font-size: 0.7rem;
    min-width: 0;
  }
  .nav-btn:hover, .nav-btn.active { background: transparent; }
  .nav-btn.active .nav-icon { background: var(--primary-soft); }
  .nav-icon {
    font-size: 1.2rem;
    width: 44px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
  }
  .nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

  .content { padding: 8px 14px calc(100px + var(--bottom-nav-h)); }
  .month-switcher { padding-top: 12px; }

  .fab {
    bottom: calc(16px + var(--bottom-nav-h));
    inset-inline-end: 16px;
    width: 56px;
    padding: 0;
    justify-content: center;
  }
  .fab-label { display: none; }

  .hero-value { font-size: 1.8rem; }
  .mini-grid { gap: 8px; }
  .mini-card { padding: 10px; }
  .mini-value { font-size: 0.88rem; }

  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none;
    border-radius: 22px 22px 0 0;
    max-height: 94vh;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    animation: sheet-up-full 0.25s ease-out;
  }
  @keyframes sheet-up-full { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

/* modal stays centered (not a bottom sheet) on wide-but-short screens such as landscape phones and tablets */
@media (max-width: 900px) and (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 16px; }
  .modal { max-width: 460px; border-radius: 22px; max-height: 94vh; animation: sheet-up 0.22s ease-out; }
}

/* landscape phones: less vertical space */
@media (max-height: 500px) and (orientation: landscape) {
  .hero-card { padding: 14px 18px 12px; }
  .hero-value { font-size: 1.5rem; margin: 2px 0 10px; }
  .quick-btn { flex-direction: row; justify-content: center; padding: 8px; }
  .quick-icon { width: 32px; height: 32px; }
  .nav-btn { flex-direction: row; gap: 4px; }
  .nav-icon { width: auto; height: auto; padding: 2px 6px; }
  :root { --bottom-nav-h: calc(48px + env(safe-area-inset-bottom)); }
}

/* small phones: stack the money boxes so long amounts fit */
@media (max-width: 480px) {
  .hero-split { grid-template-columns: minmax(0, 1fr); }
  .hero-value { font-size: 1.6rem; }
  .mini-grid { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .mini-card { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; }
  .mini-value { font-size: 0.95rem; text-align: end; }
  .net-strip { grid-template-columns: minmax(0, 1fr); }
  .net-strip > div { flex-direction: row; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 14px; }
  .net-strip > div + div { border-inline-start: none; border-top: 1px solid var(--border); }
  .net-strip b { text-align: end; }
  .panel { padding: 14px; }
  .tx-icon { width: 38px; height: 38px; border-radius: 12px; font-size: 1.05rem; }
  /* مبلغ زیر عنوان می‌رود تا عنوان جای کافی داشته باشد */
  .tx-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "icon info del" "icon amount del";
    column-gap: 12px;
    row-gap: 2px;
  }
  .tx-row .tx-icon { grid-area: icon; align-self: start; }
  .tx-row .tx-info { grid-area: info; }
  .tx-row .tx-amount { grid-area: amount; max-width: none; text-align: start; }
  .tx-row .row-delete-btn { grid-area: del; align-self: center; }
  .item-card { flex-wrap: wrap; }
  .item-card .tx-icon { align-self: flex-start; }
  .item-side {
    flex-basis: 100%;
    max-width: none;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-inline-start: 48px;
  }
  .tx-amount, .item-amount { font-size: 0.88rem; }
  .item-card { padding: 11px 12px; gap: 10px; }
  .view-header h2 { font-size: 1.15rem; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 360px) {
  .content { padding-left: 10px; padding-right: 10px; }
  .nav-btn { font-size: 0.64rem; }
  .nav-icon { width: 38px; }
  .quick-btn { font-size: 0.82rem; padding: 12px 4px; }
  .category-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kind-toggle-btn { font-size: 0.8rem; padding: 9px 2px; }
  .amount-label input { font-size: 1.35rem; }
}

/* ===== Account & sync (optional) ===== */
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.sync-btn { position: relative; }
.sync-dot {
  position: absolute;
  top: 5px;
  inset-inline-end: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: transparent;
}
.sync-dot.ok { background: var(--income); }
.sync-dot.warn { background: var(--installments); }
.sync-dot.busy { background: var(--primary); animation: dot-pulse 1s ease-in-out infinite; }
@keyframes dot-pulse { 50% { opacity: 0.3; } }

.settings-sync-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: start;
  background: var(--primary-soft);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
  cursor: pointer;
}
.settings-sync-row:hover { border-color: var(--primary); }
.ssr-icon { font-size: 1.4rem; }
.ssr-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ssr-text small { color: var(--text-muted); font-size: 0.78rem; }
.ssr-arrow { font-size: 1.3rem; color: var(--text-muted); }
.ssr-arrow, .acc-menu-item span:last-child { display: inline-block; }
[dir="rtl"] .ssr-arrow, [dir="rtl"] .acc-menu-item span:last-child { transform: scaleX(-1); }

.account-modal.busy { cursor: progress; }
.account-modal.busy button, .account-modal.busy input { pointer-events: none; opacity: 0.6; }
.acc-intro, .acc-text { color: var(--text-muted); font-size: 0.9rem; line-height: 1.9; margin: 0 0 16px; }
.acc-h { font-size: 1.05rem; font-weight: 800; margin: 0 0 8px; text-align: center; }
.acc-big-icon { font-size: 2.4rem; text-align: center; margin: 4px 0 8px; }
.acc-center { text-align: center; color: var(--text-muted); }
.acc-note { font-size: 0.8rem; color: #92400e; background: var(--installments-bg); border-radius: 10px; padding: 10px 12px; line-height: 1.8; margin: 0 0 12px; }
.acc-link { display: block; margin: 14px auto 0; }
.acc-link.muted { color: var(--text-muted); font-weight: 600; }
.acc-divider { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 0.8rem; margin: 18px 0 14px; }
.acc-divider::before, .acc-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.form-actions.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-bottom: 12px; }
.acc-check { margin: 4px 0 12px; }
.acc-spinner {
  width: 36px; height: 36px; margin: 24px auto 12px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.acc-user { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.acc-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; font-weight: 800; font-size: 1.1rem;
}
.acc-user-info { display: flex; flex-direction: column; min-width: 0; }
.acc-user-info b { overflow-wrap: anywhere; }
.acc-status { font-size: 0.82rem; color: var(--text-muted); }
.acc-menu { margin-top: 14px; border-top: 1px solid var(--border); }
.acc-menu-item {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: none; border: none; border-bottom: 1px solid var(--border);
  padding: 14px 4px; font-weight: 700; font-size: 0.92rem; cursor: pointer; text-align: start;
}
.acc-menu-item span:last-child { color: var(--text-muted); font-size: 1.2rem; }
.acc-menu-item.danger { color: var(--expense); }
.account-modal .btn-block + .btn-block { margin-top: 10px; }

/* ----- Standard sign-in (Google branding guidelines: neutral button) ----- */
.auth-hero { text-align: center; margin: 0 0 18px; }
.auth-hero-icon {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; font-size: 1.7rem;
  background: var(--primary-soft);
}
.auth-hero-title { font-size: 1.1rem; font-weight: 800; margin: 0 0 6px; }
.auth-hero-text { color: var(--text-muted); font-size: 0.86rem; line-height: 1.8; margin: 0; }

.gsi-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; height: 48px; padding: 0 16px;
  background: #fff; color: #1f1f1f;
  border: 1px solid #747775; border-radius: 4px;
  font-family: Roboto, 'Vazirmatn', Arial, sans-serif; font-size: 15px; font-weight: 500; letter-spacing: 0.25px;
  cursor: pointer; transition: background-color 0.2s, box-shadow 0.2s;
}
.gsi-btn:hover { background: #f8f9fa; box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15); }
.gsi-btn:active { background: #eceff1; }
.gsi-btn:focus-visible { outline: 2px solid #1a73e8; outline-offset: 2px; }
.gsi-btn:disabled { opacity: 0.6; cursor: default; box-shadow: none; }
.gsi-icon { display: inline-flex; width: 18px; height: 18px; flex-shrink: 0; }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border); margin: 0 0 16px;
}
.auth-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 10px 4px; margin-bottom: -1px;
  font-weight: 700; font-size: 0.92rem; color: var(--text-muted); cursor: pointer;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.auth-form label { margin-bottom: 12px; }
.pw-field { position: relative; display: block; }
.pw-field input { padding-inline-end: 44px; }
.pw-toggle {
  position: absolute; top: 50%; transform: translateY(-50%); inset-inline-end: 6px;
  width: 34px; height: 34px; border: none; background: none; border-radius: 8px;
  color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.pw-toggle:hover { background: var(--surface-2); }
.pw-toggle.on { color: var(--primary); }
.auth-hint { font-size: 0.78rem; color: var(--text-muted); margin: -6px 2px 12px; }
.auth-forgot-row { display: flex; justify-content: flex-end; margin: -4px 0 8px; }
.auth-forgot-row .link-btn { margin: 0; font-size: 0.82rem; }
.auth-legal { font-size: 0.74rem; color: var(--text-muted); text-align: center; line-height: 1.8; margin: 16px 0 0; }

.acc-provider { font-size: 0.8rem; color: var(--text-muted); }
.sync-card { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 4px; }
.sync-card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sync-card-row .btn-small { margin: 0; flex-shrink: 0; }
.sync-state { font-weight: 700; font-size: 0.88rem; }
.sync-state.ok { color: var(--income); }
.sync-state.error { color: var(--expense); }
.sync-card-note { font-size: 0.76rem; color: var(--text-muted); margin: 6px 0 0; line-height: 1.7; }
.btn-soft-primary { background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; gap: 6px; }
.btn-soft-primary:hover { background: #e2e5ff; }
.sync-icon { display: inline-block; font-size: 1rem; line-height: 1; }
.btn.spinning .sync-icon { animation: spin 0.9s linear infinite; }
