:root {
  --bg: #0d1512;
  --surface: #161f1a;
  --surface-alt: #1d2822;
  --surface-raised: #202b25;
  --text: #eef4f0;
  --text-muted: #8ea297;
  --text-faint: #5c6d64;
  --border: #263029;

  --primary: #34d399;
  --primary-dim: #1f7a58;
  --primary-bg: rgba(52, 211, 153, 0.14);

  --income: #34d399;
  --income-bg: rgba(52, 211, 153, 0.14);
  --expense: #fb7185;
  --expense-bg: rgba(251, 113, 133, 0.14);
  --warning: #f5a524;
  --warning-bg: rgba(245, 165, 36, 0.14);

  --cat-1: #f59e0b;
  --cat-2: #38bdf8;
  --cat-3: #a78bfa;
  --cat-4: #fb7185;
  --cat-5: #2dd4bf;
  --cat-6: #f472b6;
  --cat-7: #94a3b8;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);

  --font-display: 'Almarai', -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --font-body: 'Cairo', -apple-system, 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(680px 340px at 100% -8%, rgba(52, 211, 153, 0.10), transparent 60%),
    var(--bg);
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }
::selection { background: var(--primary); color: #06120d; }

.hidden { display: none !important; }

/* ---------- Auth screen ---------- */
#auth-screen, #verify-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
#verify-screen .auth-sub { line-height: 1.8; }
#verify-screen .auth-logo { font-size: 40px; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 34px 28px;
}

.auth-logo {
  text-align: center;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: 0.3px;
}
.auth-logo::after {
  content: '';
  display: block;
  width: 40px;
  height: 3px;
  background: var(--primary);
  border-radius: 3px;
  margin: 10px auto 0;
}

.auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 14px 0 26px;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }

.field-label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.field-label-row label { margin-bottom: 0; }
.mini-link {
  background: none; border: none;
  color: var(--primary);
  font-size: 12px; font-weight: 700;
  padding: 2px 0;
}

.new-category-box {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: -6px 0 14px;
}
.new-category-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  margin-bottom: 10px;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.emoji-grid button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  font-size: 17px;
  padding: 7px 0;
}
.emoji-grid button.active { border-color: var(--primary); background: var(--primary-bg); }

.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus, .field select:focus { border-color: var(--primary); background: var(--surface-raised); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-weight: 700;
  font-size: 14.5px;
  font-family: inherit;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary { width: 100%; background: var(--primary); color: #06120d; }
.btn-primary:hover { opacity: 0.92; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface-alt); color: var(--text-muted); }
.btn-danger { background: var(--expense-bg); color: var(--expense); }

.auth-switch { text-align: center; margin-top: 18px; font-size: 13.5px; color: var(--text-muted); }
.auth-switch a { color: var(--primary); font-weight: 700; cursor: pointer; }

.auth-error {
  background: var(--expense-bg);
  color: var(--expense);
  font-size: 13px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  line-height: 1.5;
}
.auth-notice {
  background: var(--income-bg);
  color: var(--income);
  font-size: 13px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ---------- password field with eye toggle ---------- */
.password-wrap { position: relative; }
.password-wrap input { padding-left: 42px; }
.eye-toggle {
  position: absolute;
  left: 4px; top: 50%;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
}
.eye-toggle:hover { color: var(--text-muted); }
.eye-toggle svg { width: 18px; height: 18px; }

/* ---------- App shell ---------- */
#app-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: 88px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 22px 18px 6px;
}
.header-greeting { font-size: 12.5px; color: var(--text-muted); font-weight: 600; margin-bottom: 2px; }
.app-header h1 { font-size: 21px; margin: 0; color: var(--text); font-family: var(--font-display); font-weight: 800; }

.header-actions { display: flex; gap: 10px; align-items: center; }
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-muted);
}

.view { padding: 10px 18px 18px; }

/* ---------- Hero balance card ---------- */
.hero-card {
  background: linear-gradient(160deg, var(--surface-raised), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 22px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero-card::before {
  content: '';
  position: absolute;
  top: -60px; left: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(52, 211, 153, 0.18), transparent 70%);
  pointer-events: none;
}
.hero-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; margin-bottom: 8px; }
.hero-balance {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 40px;
  line-height: 1.1;
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: flex-end;
}
.hero-balance .cur { font-size: 15px; font-weight: 600; color: var(--text-muted); order: 2; }
.hero-balance.negative { color: var(--expense); }

.hero-stats { display: flex; gap: 18px; margin-top: 16px; }
.hero-stat {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
.hero-stat b { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; }
.hero-stat .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.hero-stat.income .dot { background: var(--income); }
.hero-stat.expense .dot { background: var(--expense); }

/* ---------- Mini stat row ---------- */
.mini-stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.mini-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.mini-stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.mini-stat-value { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; font-family: var(--font-display); }
.mini-stat-value.expense { color: var(--expense); }
.mini-stat-value.warning { color: var(--warning); }

/* ---------- Summary grid (debts view) ---------- */
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.summary-card .label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }
.summary-card .value { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; font-family: var(--font-display); }
.summary-card.income .value { color: var(--income); }
.summary-card.expense .value { color: var(--expense); }

/* ---------- Ring chart card ---------- */
.ring-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.ring-card h3 { font-size: 13.5px; font-weight: 700; margin: 0 0 16px; color: var(--text-muted); }
.ring-card h3 span { color: var(--text); }
.ring-wrap { display: flex; align-items: center; gap: 20px; }

.ring-visual {
  width: 112px; height: 112px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: conic-gradient(var(--surface-alt) 0deg 360deg);
}
.ring-hole {
  width: 74px; height: 74px;
  border-radius: 50%;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; font-family: var(--font-display);
  color: var(--text);
  text-align: center;
  line-height: 1.25;
  direction: ltr;
}

.ring-legend { flex: 1; display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.ring-legend .row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.ring-legend .dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.ring-legend .name { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ring-legend .pct { margin-right: auto; color: var(--text-muted); font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; }

/* ---------- Section titles ---------- */
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 6px 0 10px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.section-title .link { font-size: 12.5px; font-weight: 700; color: var(--primary); cursor: pointer; }
.section-title .hint { font-size: 12px; color: var(--text-faint); font-weight: 600; }

/* ---------- notice banner ---------- */
.notice-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}
.notice-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-chip {
  border: none;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 700;
  background: var(--primary);
  color: #06120d;
}
.btn-chip.ghost { background: var(--surface-alt); color: var(--text-muted); }

/* ---------- filter bar (transactions) ---------- */
.filter-bar { margin-bottom: 6px; }
.filter-bar input[type="text"], .filter-bar input[type="date"], .filter-bar select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-size: 13.5px;
}
.filter-bar input[type="text"] { margin-bottom: 8px; }
.filter-bar .filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--primary); }

/* ---------- chart card header with action ---------- */
.chart-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

/* ---------- budgets ---------- */
.budget-row { margin-bottom: 16px; }
.budget-row:last-child { margin-bottom: 0; }
.budget-row-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 6px; }
.budget-row-top .name { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 6px; }
.budget-row-top .amounts { color: var(--text-muted); font-variant-numeric: tabular-nums; direction: ltr; }
.budget-row-top .amounts b { color: var(--text); }
.budget-track { height: 8px; background: var(--surface-alt); border-radius: 5px; overflow: hidden; }
.budget-fill { height: 100%; border-radius: 5px; background: var(--income); transition: width 0.3s ease; }
.budget-fill.warning { background: var(--warning); }
.budget-fill.over { background: var(--expense); }
.budget-row-actions { display: flex; gap: 10px; margin-top: 4px; }
.budget-row-actions button { background: none; border: none; font-size: 11.5px; color: var(--text-faint); font-weight: 600; padding: 2px 0; }
.budget-row-actions button:hover { color: var(--primary); }

/* ---------- month comparison chart ---------- */
.compare-wrap { display: flex; align-items: flex-end; justify-content: space-around; height: 150px; gap: 18px; padding-top: 10px; }
.compare-group { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; height: 100%; justify-content: flex-end; }
.compare-bars { display: flex; align-items: flex-end; gap: 6px; height: 100%; }
.compare-bar { width: 22px; border-radius: 6px 6px 2px 2px; min-height: 3px; position: relative; }
.compare-bar.income { background: var(--income); }
.compare-bar.expense { background: var(--expense); }
.compare-label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.compare-legend { display: flex; justify-content: center; gap: 18px; margin-top: 14px; font-size: 12px; color: var(--text-muted); }
.compare-legend .row { display: flex; align-items: center; gap: 6px; }
.compare-legend .dot { width: 8px; height: 8px; border-radius: 2px; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.list-item .icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--surface-alt);
}
.list-item.income .icon { background: var(--income-bg); color: var(--income); }
.list-item.expense .icon { background: var(--expense-bg); color: var(--expense); }

.list-item .info { flex: 1; min-width: 0; }
.list-item .info .title { font-weight: 700; font-size: 14.5px; color: var(--text); }
.list-item .info .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-item .amount { font-weight: 800; font-size: 14.5px; white-space: nowrap; font-variant-numeric: tabular-nums; direction: ltr; font-family: var(--font-display); }
.list-item.income .amount { color: var(--income); }
.list-item.expense .amount { color: var(--expense); }

.row-actions { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.list-item .del-btn, .list-item .edit-btn {
  background: none; border: none;
  color: var(--text-faint);
  font-size: 15px; padding: 5px;
  flex-shrink: 0;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.list-item .del-btn:hover { color: var(--expense); background: var(--expense-bg); }
.list-item .edit-btn:hover { color: var(--primary); background: var(--primary-bg); }

.empty-state { text-align: center; color: var(--text-faint); font-size: 13.5px; padding: 34px 10px; }

.badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  border: none;
}
.badge.paid { background: var(--income-bg); color: var(--income); }
.badge.due { background: var(--warning-bg); color: var(--warning); }
.badge.owe { background: var(--expense-bg); color: var(--expense); }
.badge.owed { background: var(--income-bg); color: var(--income); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(22, 31, 26, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  z-index: 20;
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 4px 7px;
  color: var(--text-faint);
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 12px;
}

.nav-btn .nav-icon {
  font-size: 18px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
}
.nav-btn.active { color: var(--primary); }
.nav-btn.active .nav-icon { background: var(--primary-bg); }

.fab {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #06120d;
  border: none;
  font-size: 26px;
  font-weight: 400;
  box-shadow: 0 8px 20px rgba(52, 211, 153, 0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 21;
  max-width: 560px;
}
.fab:active { transform: translateX(-50%) scale(0.94); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 8, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 560px;
  padding: 22px 20px 28px;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-sheet h2 { font-size: 17px; margin: 0 0 18px; color: var(--text); font-family: var(--font-display); }

.type-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.type-toggle button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 11px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-muted);
}
.type-toggle button.active.income { background: var(--income-bg); color: var(--income); border-color: var(--income); }
.type-toggle button.active.expense { background: var(--expense-bg); color: var(--expense); border-color: var(--expense); }

.modal-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- Reports ---------- */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.chart-card h3 { font-size: 13.5px; margin: 0 0 14px; color: var(--text-muted); font-weight: 700; }

.category-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 13px; }
.category-row:last-child { margin-bottom: 0; }
.category-row .cdot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.category-row .name { width: 76px; flex-shrink: 0; color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-row .bar-track { flex: 1; height: 9px; background: var(--surface-alt); border-radius: 5px; overflow: hidden; }
.category-row .bar-fill { height: 100%; border-radius: 5px; }
.category-row .amt { width: 84px; text-align: left; flex-shrink: 0; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; color: var(--text); }

@media (max-width: 420px) {
  .category-row .name, .category-row .amt { width: 62px; }
}

/* ============================================================
   Desktop layout — sidebar nav instead of bottom bar
   ============================================================ */
@media (min-width: 860px) {
  body { background: var(--bg); }

  #app-screen {
    max-width: 640px;
    margin: 0 auto 0 0;
    margin-inline-end: 112px;
    padding-bottom: 40px;
  }

  .app-header { padding-top: 32px; }

  .bottom-nav {
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: 96px;
    height: 100vh;
    max-width: none;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    gap: 10px;
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 24px 10px;
  }
  .nav-btn { flex: none; padding: 12px 4px; border-radius: 14px; }
  .nav-btn .nav-icon { width: 34px; height: 34px; margin: 0 auto; }
  .nav-btn .nav-icon svg { width: 21px; height: 21px; }

  .fab {
    left: auto;
    right: 128px;
    bottom: 32px;
    transform: none;
  }
  .fab:active { transform: scale(0.94); }

  .modal-overlay { align-items: center; }
  .modal-sheet {
    border-radius: var(--radius-lg);
    border-bottom: 1px solid var(--border);
    max-width: 440px;
  }
}
