:root {
  --navy: #14335c;
  --navy-light: #1e4a80;
  --green: #16a34a;
  --green-bg: #e8f7ee;
  --red: #dc2626;
  --red-bg: #fdeaea;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
}
@font-face {
  font-family: Vazirmatn;
  src: url('fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url('fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url('fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url('fonts/Vazirmatn-ExtraBold.woff2') format('woff2');
  font-weight: 800; font-display: swap;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: Vazirmatn, Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 84px;
}

/* ---------- هدر ---------- */
.topbar {
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(20,51,92,.25);
}
.topbar h1 { font-size: 17px; font-weight: 700; }
.today { font-size: 12px; opacity: .85; }

/* ---------- محتوا ---------- */
main { padding: 14px 14px 8px; max-width: 560px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ---------- هیرو داشبورد ---------- */
.hero {
  background: linear-gradient(135deg, var(--green), #22c55e);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: 0 6px 18px rgba(22,163,74,.3);
}
.hero-label { display: block; font-size: 13px; opacity: .9; margin-bottom: 6px; }
.hero-amount { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.hero-unit { font-size: 12px; opacity: .85; margin-right: 4px; }

/* ---------- کارت‌ها ---------- */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  border-right: 4px solid transparent;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.card-label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.card-amount { font-size: 17px; font-weight: 700; }
.card-green { border-color: var(--green); }
.card-navy { border-color: var(--navy); }
.card-red { border-color: var(--red); }
.card-gray { border-color: #94a3b8; }

/* ---------- نزدیک‌ترین سررسید ---------- */
.nextdue {
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.nd-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.nd-body { font-size: 14.5px; font-weight: 700; color: var(--navy); }

.statusbox {
  margin-top: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 13px;
  line-height: 2;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.st-row { display: flex; align-items: center; gap: 7px; }
.st-row::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}
.st-row.st-green::before { background: var(--green); }
.st-row.st-navy::before { background: var(--navy); }
.statusbox b.green { color: var(--green); }
.statusbox b.navy { color: var(--navy); }

/* ---------- سربرگ بخش‌ها ---------- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 16px; }
.btn-add {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 13px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-add:active { transform: scale(.96); }

/* ---------- لیست‌ها ---------- */
.list { display: flex; flex-direction: column; gap: 9px; }
.item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 14px;
  border: 1px solid var(--border);
}
.item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.item-title { font-size: 14px; font-weight: 700; }
.item-amount { font-size: 14.5px; font-weight: 800; color: var(--navy); white-space: nowrap; }
.item-meta {
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.item-actions { display: flex; gap: 6px; margin-top: 9px; }
.iconbtn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 5px 11px;
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
  color: var(--navy);
}
.iconbtn.danger { color: var(--red); border-color: #fecaca; }
.iconbtn.ok { color: var(--green); border-color: #bbf7d0; }
.iconbtn:active { transform: scale(.95); }

.badge {
  display: inline-block;
  font-size: 10.5px;
  border-radius: 20px;
  padding: 2px 9px;
  font-weight: 600;
}
.badge-paid { background: var(--green-bg); color: var(--green); }
.badge-unpaid { background: var(--red-bg); color: var(--red); }
.badge-recur {
  background: #eef3fa;
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}
.badge-recur svg { flex-shrink: 0; }

/* ---------- پیشنهاد تخصیص ---------- */
.sugg-rows { display: flex; flex-direction: column; margin-top: 10px; }
.sugg-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12.5px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  flex-wrap: wrap;
}
.sugg-row:last-child { border-bottom: none; }

/* نوار پیشرفت قسط */
.prog {
  margin-top: 8px;
  height: 5px;
  background: #eef2f7;
  border-radius: 5px;
  overflow: hidden;
}
.prog > div { height: 100%; background: var(--green); border-radius: 5px; transition: width .3s; }

/* ---------- فیلتر اقساط ---------- */
.filter-row { display: flex; gap: 7px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 20px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- نوار پایین ---------- */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 7px 4px calc(7px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: 560px;
  margin: 0 auto;
}
.navbtn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 10.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 10px;
}
.navbtn .ic { font-size: 18px; }
.navbtn.active { color: var(--navy); font-weight: 700; background: #eef3fa; }

/* ---------- مودال ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.overlay.open { display: flex; }
.modal {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  animation: up .22s ease;
  max-height: 88vh;
  overflow-y: auto;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { font-size: 15.5px; }
.modal-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-family: inherit;
  font-size: 14px;
  background: #fafbfc;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--navy); background: #fff; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-foot { display: flex; gap: 9px; margin-top: 16px; }
.btn {
  flex: 1;
  padding: 12px;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn:active { transform: scale(.98); }
.hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- دکمه خروج ---------- */
.btn-logout {
  position: fixed;
  bottom: 90px;
  left: 12px;
  background: #fff;
  color: var(--red);
  border: 1px solid #fecaca;
  border-radius: 24px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  z-index: 15;
}
.btn-logout svg.ic { width: 15px; height: 15px; }
.btn-logout:active { transform: scale(.95); }

/* ---------- توست ---------- */
.toast {
  position: fixed;
  bottom: 96px; left: 50%;
  transform: translateX(50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 99;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(-6px); }
.toast.err { background: var(--red); }

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

/* ---------- آیکن‌ها ---------- */
svg.ic { width: 20px; height: 20px; display: block; }
svg.ic-sm { width: 14px; height: 14px; display: block; }
svg.ic-lg { width: 26px; height: 26px; display: block; }
.iconbtn { display: inline-flex; align-items: center; gap: 4px; }
.gearbtn { background: none; border: none; color: #fff; cursor: pointer; padding: 4px; opacity: .9; }
.gearbtn:active { transform: scale(.92); }

/* ---------- صفحه ورود ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--navy), var(--navy-light));
}
.login-box {
  background: #fff;
  border-radius: 20px;
  padding: 30px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-logo {
  width: 58px; height: 58px;
  margin: 0 auto 12px;
  background: var(--green-bg);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--green);
}
.login-box h1 { font-size: 18px; margin-bottom: 4px; }
.login-box p { font-size: 12px; color: var(--muted); margin-bottom: 20px; }
.login-box .btn { width: 100%; margin-top: 4px; }
.login-err {
  background: var(--red-bg);
  color: var(--red);
  font-size: 12px;
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 12px;
  display: none;
}
.login-err.show { display: block; }

@media (min-width: 480px) {
  .overlay { align-items: center; padding: 20px; }
  .modal { border-radius: 20px; }
}
