/* ===== VARIABLES ===== */
:root {
  --bg: #080c0a;
  --bg2: #0f1812;
  --bg3: #162118;
  --card: #111a14;
  --card2: #18231b;
  --border: #1f3025;
  --green: #1B7F3B;
  --green-light: #4CAF6E;
  --green-glow: #00FF7F;
  --white: #f0f5f1;
  --gray: #8a9e8e;
  --gray2: #4a5e4e;
  --red: #e05252;
  --orange: #e08040;
  --yellow: #d4b84a;
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 72px;
  --header-h: 60px;
  --font: 'Cairo', sans-serif;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--white);
  direction: rtl;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  position: relative;
}

/* BG grid texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(27,127,59,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(27,127,59,0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  z-index: 0;
}

/* ===== HEADER ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(8,12,10,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  padding: 0 env(safe-area-inset-right, 0) 0 env(safe-area-inset-left, 0);
}
.header-inner {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
}
.logo-block {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon {
  width: 36px; height: 36px;
  background: var(--green);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 900;
  color: var(--white);
  box-shadow: 0 0 14px rgba(0,255,127,0.3);
}
.logo-ar {
  font-size: 15px; font-weight: 900;
  color: var(--white);
  line-height: 1.2;
}
.logo-sub {
  font-size: 9px; font-weight: 600;
  color: var(--green-glow);
  letter-spacing: 2px;
  opacity: 0.8;
}
.header-month {
  font-size: 12px; font-weight: 600;
  color: var(--gray);
  background: var(--bg3);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ===== MAIN SCREENS ===== */
.screens {
  position: relative;
  z-index: 1;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
.screen {
  display: none;
  animation: fadeIn 0.25s ease;
}
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-scroll {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== GREETING ===== */
.greeting-block { padding: 4px 2px 0; }
.greeting-name {
  font-size: 22px; font-weight: 900;
  color: var(--white);
  line-height: 1.2;
}
.greeting-sub {
  font-size: 13px; font-weight: 400;
  color: var(--gray);
  margin-top: 2px;
}

/* ===== PAGE TITLE ===== */
.page-title {
  font-size: 18px; font-weight: 900;
  color: var(--white);
  padding: 4px 2px 0;
}
.science-note {
  font-size: 11px;
  color: var(--green-light);
  background: rgba(27,127,59,0.1);
  border: 1px solid rgba(27,127,59,0.2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

/* ===== STATUS CARD ===== */
.status-card {
  background: var(--green);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.status-card::before {
  content: '';
  position: absolute;
  top: -30px; left: -30px;
  width: 120px; height: 120px;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
}
.status-label {
  font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.status-value {
  font-size: 28px; font-weight: 900;
  color: #fff;
  line-height: 1.1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.status-desc {
  font-size: 13px; font-weight: 400;
  color: rgba(255,255,255,0.8);
  margin-top: 4px;
}
.status-card.warn { background: linear-gradient(135deg, #8a5a00, #b07000); }
.status-card.danger { background: linear-gradient(135deg, #7a1a1a, #a02020); }
.status-card.critical { background: linear-gradient(135deg, #5a0000, #800000); }
#carStatusCard { background: var(--card); border: 1px solid var(--border); }
#carStatusCard .status-value { color: var(--green-glow); }
#carStatusCard .status-desc { color: var(--gray); }

/* ===== KPI ROW ===== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.kpi-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
}
.kpi-box.surplus { border-color: var(--green); }
.kpi-num {
  font-size: 17px; font-weight: 900;
  color: var(--white);
  line-height: 1.2;
  word-break: break-all;
}
.kpi-box.surplus .kpi-num { color: var(--green-glow); }
.kpi-label {
  font-size: 10px; font-weight: 600;
  color: var(--gray);
  margin-top: 4px;
}

/* ===== SECTION CARD ===== */
.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.section-title {
  font-size: 14px; font-weight: 700;
  color: var(--green-light);
}

/* ===== PRESSURE BAR ===== */
.pressure-bar-wrap {
  display: flex; align-items: center; gap: 10px;
}
.pressure-bar-bg {
  flex: 1; height: 10px;
  background: var(--bg3);
  border-radius: 10px;
  overflow: hidden;
}
.pressure-bar-fill {
  height: 100%; width: 0%;
  background: var(--green-glow);
  border-radius: 10px;
  transition: width 0.6s ease, background 0.4s;
}
.pressure-pct {
  font-size: 14px; font-weight: 900;
  color: var(--white);
  min-width: 40px;
  text-align: left;
}
.pressure-legend {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.leg {
  font-size: 10px; font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
}
.leg.green { background: rgba(0,255,127,0.1); color: var(--green-glow); }
.leg.yellow { background: rgba(212,184,74,0.1); color: var(--yellow); }
.leg.orange { background: rgba(224,128,64,0.1); color: var(--orange); }
.leg.red { background: rgba(224,82,82,0.1); color: var(--red); }

/* ===== DISTRIBUTION LIST ===== */
.dist-list { display: flex; flex-direction: column; gap: 10px; }
.dist-empty { font-size: 13px; color: var(--gray); text-align: center; padding: 10px 0; }
.dist-item {
  display: flex; align-items: center; gap: 10px;
}
.dist-label { font-size: 13px; font-weight: 600; color: var(--white); width: 80px; flex-shrink: 0; }
.dist-bar-wrap { flex: 1; position: relative; }
.dist-bar-bg { height: 8px; background: var(--bg3); border-radius: 8px; overflow: hidden; }
.dist-bar-fill { height: 100%; border-radius: 8px; transition: width 0.5s ease; }
.dist-bar-fill.emergency { background: var(--orange); }
.dist-bar-fill.savings { background: var(--green-light); }
.dist-bar-fill.invest { background: #4ab8e8; }
.dist-bar-fill.flex { background: var(--gray2); }
.dist-amount { font-size: 12px; font-weight: 700; color: var(--white); min-width: 60px; text-align: left; }

/* ===== RECOMMENDATIONS ===== */
.recs-list { display: flex; flex-direction: column; gap: 8px; }
.rec-item {
  font-size: 12px; font-weight: 400;
  color: var(--gray);
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.6;
  border-right: 3px solid var(--green);
}

/* ===== EMERGENCY ===== */
.emergency-row {
  display: grid; grid-template-columns: repeat(3,1fr);
  gap: 8px; text-align: center;
}
.em-label { font-size: 11px; color: var(--gray); margin-bottom: 4px; }
.em-val { font-size: 14px; font-weight: 700; color: var(--white); }
.em-val.green { color: var(--green-glow); }
.em-bar-bg { height: 8px; background: var(--bg3); border-radius: 8px; overflow: hidden; }
.em-bar-fill { height: 100%; background: var(--green-light); border-radius: 8px; transition: width 0.5s; }

/* ===== DISCLAIMER ===== */
.disclaimer {
  font-size: 11px; color: var(--gray2);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.7;
}

/* ===== FORM CARD ===== */
.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 700; color: var(--gray); }
.form-group input,
.form-group select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--white);
  font-family: var(--font);
  font-size: 15px; font-weight: 600;
  padding: 12px 14px;
  outline: none;
  direction: rtl;
  transition: border-color 0.2s;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--green); }
.form-group input::placeholder { color: var(--gray2); }
.form-group select option { background: var(--bg2); }
.form-row-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}

/* ===== SEGMENTED CONTROL ===== */
.seg-control {
  display: flex; gap: 6px;
}
.seg {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--gray);
  font-family: var(--font);
  font-size: 12px; font-weight: 700;
  padding: 10px 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.seg.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--green);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font);
  font-size: 15px; font-weight: 700;
  padding: 14px;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:active { opacity: 0.85; transform: scale(0.98); }
.btn-secondary {
  background: transparent;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--gray);
  font-family: var(--font);
  font-size: 14px; font-weight: 700;
  padding: 14px;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.2s, color 0.2s;
}
.btn-secondary:hover { border-color: var(--green); color: var(--green-light); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--gray);
  font-family: var(--font);
  font-size: 14px; font-weight: 600;
  padding: 12px;
  cursor: pointer;
  flex: 1;
}
.save-feedback {
  font-size: 13px; font-weight: 600;
  color: var(--green-glow);
  text-align: center;
  min-height: 20px;
}

/* ===== COMMITMENTS LIST ===== */
.commit-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.commit-info { flex: 1; }
.commit-name { font-size: 14px; font-weight: 700; color: var(--white); }
.commit-meta { font-size: 11px; color: var(--gray); margin-top: 2px; }
.commit-amount { font-size: 16px; font-weight: 900; color: var(--green-light); }
.commit-del {
  background: none; border: none; color: var(--gray2); font-size: 16px;
  cursor: pointer; padding: 4px;
}
.commit-del:hover { color: var(--red); }
.commit-empty { font-size: 13px; color: var(--gray); text-align: center; padding: 20px 0; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 24px 20px;
  width: 100%;
  max-width: 480px;
  display: flex; flex-direction: column; gap: 14px;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-title { font-size: 17px; font-weight: 900; color: var(--white); }
.modal-actions { display: flex; gap: 10px; }

/* ===== EXPENSES ===== */
.cat-bars { display: flex; flex-direction: column; gap: 10px; }
.cat-row {
  display: flex; align-items: center; gap: 10px;
}
.cat-name { font-size: 12px; font-weight: 700; color: var(--white); width: 60px; flex-shrink: 0; }
.cat-bar-bg { flex: 1; height: 8px; background: var(--bg3); border-radius: 8px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 8px; transition: width 0.5s; }
.cat-essential { background: var(--green-light); }
.cat-flex { background: var(--yellow); }
.cat-luxury { background: var(--red); }
.cat-amt { font-size: 12px; font-weight: 700; color: var(--white); min-width: 55px; text-align: left; }

.exp-list { display: flex; flex-direction: column; gap: 8px; }
.exp-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.exp-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.exp-dot.أساسي { background: var(--green-light); }
.exp-dot.مرن { background: var(--yellow); }
.exp-dot.ترفيهي { background: var(--red); }
.exp-info { flex: 1; }
.exp-desc { font-size: 13px; font-weight: 700; color: var(--white); }
.exp-meta { font-size: 10px; color: var(--gray); margin-top: 2px; }
.exp-amount { font-size: 15px; font-weight: 900; color: var(--white); }
.exp-del {
  background: none; border: none; color: var(--gray2); font-size: 14px; cursor: pointer;
}
.exp-del:hover { color: var(--red); }
.exp-empty { font-size: 13px; color: var(--gray); text-align: center; padding: 20px 0; background: var(--card); border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ===== CAR ===== */
.car-result-list { display: flex; flex-direction: column; gap: 8px; }
.car-result-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.car-result-row span:first-child { color: var(--gray); }
.car-result-row span:last-child { font-weight: 700; color: var(--white); }
.car-total-row {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  font-size: 15px; font-weight: 700;
  color: var(--white);
}
.car-total-val { color: var(--green-glow); font-size: 18px; }

/* ===== LIFE ===== */
.life-grid { display: flex; flex-direction: column; gap: 16px; }
.life-item { display: flex; flex-direction: column; gap: 8px; }
.life-label { font-size: 13px; font-weight: 700; color: var(--white); }
.life-scale {
  display: flex; gap: 4px;
}
.scale-btn {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--gray);
  font-family: var(--font);
  font-size: 11px; font-weight: 700;
  padding: 8px 2px;
  cursor: pointer;
  transition: all 0.15s;
}
.scale-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.life-hint { font-size: 10px; color: var(--gray2); }

.life-history { display: flex; flex-direction: column; gap: 8px; }
.life-hist-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.life-hist-month { font-size: 13px; font-weight: 700; color: var(--white); }
.life-hist-scores {
  display: flex; gap: 8px;
}
.life-score-chip {
  font-size: 10px; font-weight: 700;
  padding: 3px 7px;
  border-radius: 20px;
  background: rgba(27,127,59,0.15);
  color: var(--green-light);
}
.life-hist-empty { font-size: 13px; color: var(--gray); text-align: center; padding: 16px; }

/* Life Analysis */
.life-analysis-card {
  background: var(--bg3);
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.life-analysis-title {
  font-size: 13px; font-weight: 700; color: var(--green-light);
}
.life-motivation {
  font-size: 13px; font-weight: 600;
  color: var(--white);
  background: rgba(27,127,59,0.15);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.6;
}
.life-fields-grid { display: flex; flex-direction: column; gap: 8px; }
.life-field-row {
  display: flex; align-items: center; gap: 8px;
}
.life-field-label { font-size: 12px; font-weight: 700; color: var(--white); width: 75px; flex-shrink: 0; }
.life-field-score {
  font-size: 14px; font-weight: 900; color: var(--green-glow);
  width: 38px; text-align: center; flex-shrink: 0;
}
.life-field-status { font-size: 11px; color: var(--gray); flex: 1; }
.trend-up { color: var(--green-glow); font-weight: 700; }
.trend-down { color: var(--red); font-weight: 700; }
.trend-same { color: var(--gray); }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(8,12,10,0.97);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  background: none; border: none;
  cursor: pointer;
  padding: 8px 2px;
  position: relative;
  transition: opacity 0.2s;
}
.nav-btn::before {
  content: '';
  position: absolute;
  top: 0; left: 50%; transform: translateX(-50%);
  width: 0; height: 2px;
  background: var(--green-glow);
  border-radius: 0 0 4px 4px;
  transition: width 0.25s;
}
.nav-btn.active::before { width: 60%; }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-label {
  font-family: var(--font);
  font-size: 9px; font-weight: 700;
  color: var(--gray2);
  transition: color 0.2s;
}
.nav-btn.active .nav-label { color: var(--green-glow); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== INSTALL PROMPT ===== */
.install-banner {
  background: linear-gradient(135deg, var(--green), #0d5028);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
}
.install-banner.hidden { display: none; }
.install-text { flex: 1; }
.install-title { font-size: 14px; font-weight: 700; color: #fff; }
.install-sub { font-size: 11px; color: rgba(255,255,255,0.7); margin-top: 2px; }
.install-btn {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  color: #fff;
  font-family: var(--font);
  font-size: 12px; font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}

/* Month info box */
.month-info-box {
  background: var(--bg3);
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px; font-weight: 600;
  color: var(--green-light);
  text-align: center;
}
