@import url('https://fonts.googleapis.com/css2?family=Sora:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #F4F6F5;
  --surface: #FFFFFF;
  --surface-sunken: #ECF0EE;
  --ink: #16241F;
  --ink-soft: #55645D;
  --line: #DDE4E1;

  --teal: #0F6D5C;
  --teal-dark: #0B4F42;
  --gold: #C08A2E;
  --gold-soft: #F4E7CE;
  --aed: #2B5F8A;
  --aed-soft: #E4EEF5;
  --inr: #6B4FA0;
  --inr-soft: #EFE9F7;
  --danger: #B3452C;
  --danger-soft: #F6E3DD;

  --display: 'Sora', sans-serif;
  --body: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 36, 31, 0.06), 0 8px 24px -12px rgba(22, 36, 31, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: var(--display);
  letter-spacing: -0.01em;
  margin: 0;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

a { color: inherit; }

button, input, select {
  font-family: inherit;
  font-size: inherit;
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------- Auth screen ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  border: 1px solid var(--line);
}

.auth-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--aed) 0%, var(--teal) 52%, var(--inr) 100%);
  margin-bottom: 20px;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.auth-card p.sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.field input:focus, .field select:focus {
  border-color: var(--teal);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-sunken); }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 4px;
  min-height: 16px;
}

.hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
}

.brand .auth-mark { width: 28px; height: 28px; margin: 0; border-radius: 7px; }
.brand span { font-family: var(--display); font-weight: 700; font-size: 15px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-sunken); }
.nav-item.active { background: var(--teal); color: #fff; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.sidebar-foot .who {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 10px;
  padding: 0 8px;
}

main {
  padding: 28px 32px 60px;
  max-width: 1080px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head p { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Ledger split (signature balance card) ---------- */
.ledger-split {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}

.ledger-half {
  padding: 24px 26px;
}
.ledger-half.aed { border-left: 4px solid var(--aed); }
.ledger-half.inr { border-left: 4px solid var(--inr); }

.ledger-half .tag {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  margin-bottom: 12px;
}
.ledger-half.aed .tag { color: var(--aed); background: var(--aed-soft); }
.ledger-half.inr .tag { color: var(--inr); background: var(--inr-soft); }

.ledger-half .balance {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ledger-half .flows {
  margin-top: 12px;
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--ink-soft);
}
.ledger-half .flows b { color: var(--ink); font-family: var(--mono); font-weight: 500; }

.ledger-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  background: var(--surface-sunken);
  position: relative;
}
.ledger-arrow svg {
  width: 22px;
  height: 22px;
  color: var(--gold);
  transition: transform 0.2s ease;
}
.ledger-split:hover .ledger-arrow svg { transform: scale(1.15) rotate(6deg); }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
}

.stat-num {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
}

.budget-bar {
  height: 8px;
  background: var(--surface-sunken);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 10px;
}
.budget-bar-fill { height: 100%; background: var(--teal); border-radius: 6px; transition: width 0.3s ease; }
.budget-bar-fill.over { background: var(--danger); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
tr:last-child td { border-bottom: none; }
.amt { font-family: var(--mono); font-weight: 500; text-align: right; }
.amt.income { color: var(--teal); }
.amt.expense { color: var(--danger); }

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface-sunken);
  color: var(--ink-soft);
}
.pill.high { background: var(--gold-soft); color: var(--gold); }
.pill.currency-AED { background: var(--aed-soft); color: var(--aed); }
.pill.currency-INR { background: var(--inr-soft); color: var(--inr); }

.row-delete {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
}
.row-delete:hover { color: var(--danger); }

.empty-state {
  padding: 28px 10px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

/* ---------- Forms ---------- */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.toggle-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.toggle-btn {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.toggle-btn.active.income { background: var(--teal); color: #fff; border-color: var(--teal); }
.toggle-btn.active.expense { background: var(--danger); color: #fff; border-color: var(--danger); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  margin: 28px 0 12px;
}
.section-title:first-child { margin-top: 0; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 12px 0 0; }
  .sidebar-foot { display: none; }
  .nav-item { white-space: nowrap; }
  main { padding: 20px 16px 48px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .ledger-split { grid-template-columns: 1fr; }
  .ledger-arrow { padding: 10px 0; }
  .ledger-arrow svg { transform: rotate(90deg); }
}
