/* =============================================
   Spending Sense — styles.css
   Purple & White Theme
   ============================================= */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --purple:       #7C3AED;
  --purple-dark:  #5B21B6;
  --purple-light: #A78BFA;
  --purple-pale:  #EDE9FE;
  --white:        #FFFFFF;
  --gray-bg:      #F5F3FF;
  --gray-100:     #F3F4F6;
  --gray-200:     #E5E7EB;
  --gray-400:     #9CA3AF;
  --gray-600:     #6B7280;
  --gray-800:     #1F2937;
  --green:        #10B981;
  --red:          #EF4444;
  --orange:       #F59E0B;
  --blue:         #3B82F6;
  --shadow-sm:    0 1px 3px rgba(124,58,237,.08);
  --shadow:       0 4px 12px rgba(124,58,237,.10);
  --shadow-lg:    0 8px 24px rgba(124,58,237,.14);
  --radius:       12px;
  --radius-sm:    8px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-bg);
  color: var(--gray-800);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, var(--purple-dark) 0%, var(--purple) 100%);
  color: var(--white);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-lg);
}
.hdr-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex; align-items: center; gap: 24px;
}
.logo {
  font-size: 1.25rem; font-weight: 800;
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
.logo i { font-size: 1.4rem; }

/* Nav */
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: .9rem; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  cursor: pointer;
  transition: all .2s;
}
.nav-link:hover  { background: rgba(255,255,255,.12); color: var(--white); }
.nav-link.active { background: rgba(255,255,255,.20); color: var(--white); font-weight: 700; }

/* Header right */
.hdr-right {
  display: flex; align-items: center; gap: 12px;
  margin-left: auto;
}
#userEmail {
  font-size: .82rem; opacity: .85;
  max-width: 160px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* ── Buttons ── */
.btn-primary, .btn-outline {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 20px;
  border-radius: 8px;
  font-size: .9rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: all .2s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--purple);
  color: var(--white);
}
.btn-primary:hover:not(:disabled) {
  background: var(--purple-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.btn-primary:disabled { opacity: .65; cursor: not-allowed; }

.btn-outline {
  background: var(--white);
  color: var(--purple);
  border: 2px solid var(--purple);
}
.btn-outline:hover { background: var(--purple-pale); }

.btn-add {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--purple-pale);
  color: var(--purple);
  border: none; font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.btn-add:hover { background: var(--purple); color: var(--white); }

.full { width: 100%; justify-content: center; }

/* ── Layout ── */
main { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.container { width: 100%; }
.page { display: none; }
.page.active { display: block; animation: fadeUp .3s ease; }

@keyframes fadeUp {
  from { opacity:0; transform:translateY(12px); }
  to   { opacity:1; transform:translateY(0); }
}

.page-title {
  font-size: 1.6rem; font-weight: 800;
  color: var(--purple);
  margin-bottom: 24px;
}

/* ── Cards ── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  border: 1px solid var(--gray-200);
  overflow: hidden;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--purple-pale);
}
.card-head h3 {
  font-size: 1rem; font-weight: 700; color: var(--purple);
  display: flex; align-items: center; gap: 8px;
}
.card-body { padding: 20px 22px; }

/* ── Summary Cards ── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.sum-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  transition: box-shadow .2s;
}
.sum-card:hover { box-shadow: var(--shadow); }
.sum-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: var(--white); flex-shrink: 0;
}
.sum-card.purple .sum-icon { background: linear-gradient(135deg,var(--purple),var(--purple-light)); }
.sum-card.red    .sum-icon { background: linear-gradient(135deg,#EF4444,#F87171); }
.sum-card.green  .sum-icon { background: linear-gradient(135deg,#10B981,#34D399); }
.sum-card.orange .sum-icon { background: linear-gradient(135deg,#F59E0B,#FBBF24); }
.sum-label { font-size: .8rem; color: var(--gray-600); font-weight: 500; }
.sum-value { font-size: 1.5rem; font-weight: 800; color: var(--gray-800); margin-top: 2px; }

/* ── Income Section ── */
.salary-row {
  display: flex; align-items: flex-end; gap: 14px;
  margin-bottom: 22px;
}
.salary-row .field-wrap { flex: 1; }
.field-wrap label, .form-field label {
  display: block; font-size: .85rem; font-weight: 600;
  color: var(--gray-800); margin-bottom: 6px;
}
.field-wrap input, .form-field input,
.form-field select {
  width: 100%; padding: 10px 13px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: .95rem; color: var(--gray-800);
  background: var(--white);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.field-wrap input:focus, .form-field input:focus,
.form-field select:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(124,58,237,.1);
}

.section-subhead {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px dashed var(--gray-200);
}
.section-subhead span { font-weight: 600; color: var(--gray-600); font-size: .9rem; }

/* ── Expense / Income Row Items ── */
.item-list { display: flex; flex-direction: column; gap: 0; }

.exp-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 4px;
  border-bottom: 1px solid var(--gray-100);
  transition: background .15s;
}
.exp-row:last-child { border-bottom: none; }
.exp-row:hover { background: var(--gray-100); border-radius: var(--radius-sm); }

.income-row { padding: 11px 10px; border-radius: var(--radius-sm); background: #F0FDF4; border-left: 4px solid #10B981; margin-bottom: 6px; border-bottom: none; }
.income-row:hover { background: #DCFCE7; }

.exp-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.exp-dot  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.exp-name { font-weight: 600; font-size: .92rem; color: var(--gray-800); }
.exp-sub  { display: block; font-size: .78rem; color: var(--gray-400); margin-top: 1px; }
.exp-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.exp-amt   { font-weight: 700; font-size: .95rem; color: var(--purple); white-space: nowrap; }
.exp-amt.green { color: var(--green); }

/* Category section header */
.cat-section-hdr {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px 6px;
  margin-top: 8px;
}
.cat-section-hdr:first-child { margin-top: 0; }
.cat-section-icon {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; flex-shrink: 0;
}
.cat-section-label { font-weight: 700; font-size: .9rem; flex: 1; }
.cat-section-total { font-size: .85rem; font-weight: 700; color: var(--gray-600); }

/* Icon action buttons */
.icon-btn {
  width: 30px; height: 30px; border: none; border-radius: 6px;
  cursor: pointer; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.edit-btn { background: #EFF6FF; color: var(--blue); }
.edit-btn:hover { background: var(--blue); color: var(--white); }
.del-btn  { background: #FEF2F2; color: var(--red); }
.del-btn:hover  { background: var(--red);  color: var(--white); }

/* Quick Analysis */
.analysis-grid {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 14px;
}
.analysis-box {
  background: var(--gray-bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex; flex-direction: column; gap: 6px;
  border: 1px solid var(--purple-pale);
}
.alabel { font-size: .8rem; color: var(--gray-600); font-weight: 500; }
.avalue { font-size: 1.3rem; font-weight: 800; color: var(--purple); }

/* Empty hints */
.empty-hint {
  text-align: center; padding: 32px 16px;
  color: var(--gray-400); font-size: .9rem;
}
.empty-hint strong { color: var(--purple); }
.empty-hint-sm { color: var(--gray-400); font-size: .85rem; padding: 8px 0; }

/* ── Modals ── */
.modal-bg {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%; max-width: 480px;
  max-height: 92vh; overflow-y: auto;
  position: relative;
  animation: slideUp .25s ease;
  box-shadow: var(--shadow-lg);
}
.modal-wide { max-width: 620px; }

@keyframes slideUp {
  from { opacity:0; transform:translateY(24px); }
  to   { opacity:1; transform:translateY(0); }
}

.modal-box h2 {
  font-size: 1.15rem; font-weight: 800; color: var(--purple);
  margin-bottom: 4px; display: flex; align-items: center; gap: 8px;
}
.modal-sub { font-size: .85rem; color: var(--gray-600); margin-bottom: 18px; }
.modal-close {
  position: absolute; top: 14px; right: 16px;
  font-size: 1.5rem; line-height: 1;
  background: none; border: none;
  color: var(--gray-400); cursor: pointer;
  transition: color .2s;
}
.modal-close:hover { color: var(--purple); }

.form-field { margin-bottom: 14px; }
.req { color: var(--red); }

.form-row2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}

.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--gray-200);
}

/* ── Category Picker (Step 1) ── */
.cat-grid {
  display: grid; grid-template-columns: repeat(5,1fr); gap: 10px;
  margin-top: 12px;
}
.cat-btn {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  cursor: pointer; font-size: .8rem; font-weight: 600; color: var(--gray-600);
  transition: all .2s;
}
.cat-btn i { font-size: 1.4rem; color: var(--purple); transition: color .2s; }
.cat-btn:hover, .cat-btn.selected {
  border-color: var(--purple);
  background: var(--purple-pale);
  color: var(--purple);
}
.cat-btn:hover i, .cat-btn.selected i { color: var(--purple-dark); }

/* Step 2 back button */
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none;
  color: var(--purple); font-size: .85rem; font-weight: 600;
  cursor: pointer; margin-bottom: 12px; padding: 0;
  transition: opacity .2s;
}
.back-btn:hover { opacity: .7; }

/* Extra fields section */
.extra-fields {
  background: var(--gray-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--purple);
  padding: 14px;
  margin-bottom: 12px;
}

/* EMI calc hint */
.calc-hint {
  font-size: .85rem; font-weight: 600; color: var(--purple-dark);
  background: var(--purple-pale); border-radius: 6px;
  padding: 8px 12px; margin-top: 8px;
  min-height: 0;
}
.calc-hint:empty { display: none; }

/* ── Budget Planner ── */
.budget-grid {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 14px;
  margin-bottom: 20px;
}
.bfield { display: flex; flex-direction: column; gap: 4px; }
.bfield label { font-size: .82rem; font-weight: 600; color: var(--gray-800); }
.bfield input {
  padding: 9px 12px; border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm); font-size: .9rem; outline: none;
  transition: border-color .2s;
}
.bfield input:focus { border-color: var(--purple); }
.bpct { font-size: .75rem; color: var(--purple); font-weight: 600; min-height: 16px; }

.budget-totals {
  display: flex; gap: 20px; margin-bottom: 16px;
  padding: 14px 18px;
  background: var(--purple-pale); border-radius: var(--radius-sm);
}
.btotal { display: flex; flex-direction: column; gap: 3px; }
.btotal span  { font-size: .8rem; color: var(--purple-dark); font-weight: 500; }
.btotal strong { font-size: 1.2rem; font-weight: 800; color: var(--purple-dark); }

.recs-list { display: flex; flex-direction: column; gap: 8px; }
.rec-item {
  padding: 10px 14px;
  background: var(--gray-100); border-radius: var(--radius-sm);
  font-size: .88rem; color: var(--gray-800);
  border-left: 3px solid var(--orange);
}

/* ── Goals ── */
.goals-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 16px; }
.goal-card {
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow-sm); transition: box-shadow .2s;
}
.goal-card:hover { box-shadow: var(--shadow); }
.goal-top   { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.goal-name  { font-weight: 700; font-size: .95rem; color: var(--gray-800); }
.goal-cat   { font-size: .75rem; color: var(--purple); background: var(--purple-pale); padding: 2px 8px; border-radius: 20px; margin-top: 4px; display: inline-block; }
.goal-target { font-size: 1.1rem; font-weight: 800; color: var(--purple); white-space: nowrap; }
.progress-bar-wrap { height: 8px; background: var(--gray-200); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg,var(--purple),var(--purple-light)); border-radius: 4px; transition: width .5s; }
.goal-meta  { display: flex; justify-content: space-between; font-size: .78rem; color: var(--gray-600); margin-bottom: 8px; }
.goal-hint  { font-size: .8rem; color: var(--purple); font-weight: 600; margin-bottom: 10px; }
.goal-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-sm-purple, .btn-sm-green, .btn-sm-edit, .btn-sm-del {
  padding: 5px 10px; border-radius: 6px; font-size: .78rem;
  font-weight: 600; cursor: pointer; border: none;
  display: inline-flex; align-items: center; gap: 4px; transition: all .2s;
}
.btn-sm-purple { background: var(--purple-pale); color: var(--purple); }
.btn-sm-purple:hover { background: var(--purple); color: var(--white); }
.btn-sm-green  { background: #D1FAE5; color: #065F46; }
.btn-sm-green:hover  { background: var(--green); color: var(--white); }
.btn-sm-edit   { background: #EFF6FF; color: var(--blue); }
.btn-sm-edit:hover   { background: var(--blue); color: var(--white); }
.btn-sm-del    { background: #FEF2F2; color: var(--red); }
.btn-sm-del:hover    { background: var(--red);  color: var(--white); }

/* ── Reports ── */
.report-btns { display: flex; gap: 10px; }
.rpt-flex    { display: flex; gap: 28px; align-items: flex-start; }
.pie-wrap    { display: flex; align-items: center; justify-content: center; min-width: 200px; }
.breakdown-list { flex: 1; }
.bd-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--gray-100); font-size: .88rem; }
.bd-row:last-child { border-bottom: none; }
.bd-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.bd-row span:nth-child(3) { flex: 1; }
.bd-val { font-weight: 700; color: var(--gray-800); }
.bd-pct { font-size: .78rem; color: var(--gray-400); width: 40px; text-align: right; }

.rpt-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.rpt-table th { padding: 10px 14px; background: var(--purple-pale); color: var(--purple-dark); font-weight: 700; text-align: left; }
.rpt-table td { padding: 10px 14px; border-bottom: 1px solid var(--gray-100); }
.rpt-table tr:hover td { background: var(--gray-100); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--gray-800); color: var(--white);
  padding: 12px 24px; border-radius: 24px;
  font-size: .9rem; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: all .3s; z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-success { background: #065F46; }
.toast.toast-error   { background: #991B1B; }

/* ── Footer ── */
.footer {
  background: linear-gradient(135deg, var(--purple-dark), var(--purple));
  color: rgba(255,255,255,.85);
  text-align: center;
  padding: 22px 16px;
  font-size: .88rem;
}
.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.footer-credit {
  font-size: .82rem;
  color: rgba(255,255,255,.7);
}
.footer-credit a {
  color: #C4B5FD;
  text-decoration: none;
  font-weight: 700;
  transition: color .2s;
}
.footer-credit a:hover {
  color: #ffffff;
  text-decoration: underline;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .summary-grid    { grid-template-columns: repeat(2,1fr); }
  .analysis-grid   { grid-template-columns: repeat(2,1fr); }
  .budget-grid     { grid-template-columns: repeat(2,1fr); }
  .goals-grid      { grid-template-columns: 1fr; }
  .cat-grid        { grid-template-columns: repeat(3,1fr); }
}
@media (max-width: 768px) {
  .hdr-inner   { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 10px; }
  .nav         { order: 3; width: 100%; gap: 2px; }
  .nav-link    { font-size: .8rem; padding: 5px 10px; }
  main         { padding: 18px 14px 40px; }
  .salary-row  { flex-direction: column; align-items: stretch; }
  .form-row2   { grid-template-columns: 1fr; }
  .cat-grid    { grid-template-columns: repeat(3,1fr); }
  .rpt-flex    { flex-direction: column; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .summary-grid  { grid-template-columns: 1fr; }
  .analysis-grid { grid-template-columns: 1fr 1fr; }
  .budget-grid   { grid-template-columns: 1fr; }
  .cat-grid      { grid-template-columns: repeat(2,1fr); }
  .goal-actions  { justify-content: flex-start; }
}

/* =============================================
   AUTH MODAL
   ============================================= */
.auth-box { max-width: 420px; padding: 32px; }

.auth-logo {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 1.4rem; font-weight: 800; color: var(--purple);
  margin-bottom: 4px;
}
.auth-logo i { font-size: 1.8rem; }
.auth-tagline {
  text-align: center; font-size: .82rem;
  color: var(--gray-400); margin-bottom: 20px;
}

/* Tabs */
.auth-tabs {
  display: flex; background: var(--gray-100);
  border-radius: 10px; padding: 4px;
  margin-bottom: 20px; gap: 4px;
}
.auth-tab {
  flex: 1; padding: 9px;
  border: none; border-radius: 8px;
  font-size: .9rem; font-weight: 600;
  cursor: pointer; background: transparent;
  color: var(--gray-600); transition: all .2s;
}
.auth-tab.active {
  background: var(--white);
  color: var(--purple);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

/* Error */
.auth-error {
  background: #FEF2F2; color: #991B1B;
  border: 1px solid #FECACA;
  border-radius: 8px; padding: 10px 14px;
  font-size: .85rem; font-weight: 500;
  margin-bottom: 14px;
  display: flex; align-items: flex-start; gap: 8px;
}
.auth-error::before { content: '⚠️'; flex-shrink: 0; }

/* Input with icon */
.input-icon-wrap {
  position: relative; display: flex; align-items: center;
}
.input-icon-wrap > i:first-child {
  position: absolute; left: 12px;
  color: var(--gray-400); font-size: .9rem; pointer-events: none;
}
.input-icon-wrap input {
  padding-left: 36px !important;
  padding-right: 40px;
}
.toggle-pass {
  position: absolute; right: 10px;
  background: none; border: none;
  color: var(--gray-400); cursor: pointer;
  font-size: .9rem; padding: 4px;
  transition: color .2s;
}
.toggle-pass:hover { color: var(--purple); }

/* Submit button */
.auth-submit {
  width: 100%; justify-content: center;
  padding: 12px; font-size: 1rem;
  margin-top: 4px; margin-bottom: 0;
  border-radius: 10px;
}

/* Divider */
.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0; color: var(--gray-400); font-size: .82rem;
}
.auth-divider::before,
.auth-divider::after {
  content: ''; flex: 1;
  height: 1px; background: var(--gray-200);
}

/* Google button */
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px;
  border: 2px solid var(--gray-200);
  border-radius: 10px; background: var(--white);
  font-size: .92rem; font-weight: 600;
  color: var(--gray-800); cursor: pointer;
  transition: all .2s;
}
.btn-google:hover {
  border-color: #4285F4;
  background: #F8F9FF;
  box-shadow: 0 2px 8px rgba(66,133,244,.15);
}
