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

:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --soft: #f1f5f9;
  --primary: #059669;
  --primary-dark: #047857;
  --primary-light: #d1fae5;
  --primary-xlight: #ecfdf5;
  --red: #dc2626;
  --red-light: #fee2e2;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 16px rgba(0,0,0,.07), 0 1px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.1), 0 2px 8px rgba(0,0,0,.05);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --sidebar-w: 256px;
  --transition: 0.17s ease;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

button, input, select, textarea { font: inherit; }

/* ─────────────────────────────────────────────────────
   App Shell
───────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ─────────────────────────────────────────────────────
   Sidebar
───────────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px;
  background: #0f172a;
  border-right: 1px solid rgba(255,255,255,.06);
  overflow-y: auto;
  overflow-x: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #fff;
  padding: 4px 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,.09);
  margin-bottom: 10px;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(5,150,105,.45);
}

.brand strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.brand small {
  display: block;
  font-size: 11px;
  color: rgba(255,255,255,.45);
  font-weight: 400;
}

.nav { display: grid; gap: 2px; }

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.55);
  font-weight: 500;
  font-size: 13.5px;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .65;
  transition: opacity var(--transition);
}

.nav a:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.88);
}

.nav a:hover .nav-icon { opacity: .88; }

.nav a.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(5,150,105,.35);
}

.nav a.active .nav-icon { opacity: 1; }

.nav-label { flex: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-footer span {
  font-size: 12.5px;
  color: rgba(255,255,255,.5);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer a {
  font-size: 11.5px;
  font-weight: 600;
  color: rgba(255,255,255,.4);
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 999px;
  white-space: nowrap;
  transition: all var(--transition);
}

.sidebar-footer a:hover {
  color: #fff;
  border-color: rgba(255,255,255,.28);
  background: rgba(255,255,255,.06);
}

/* ─────────────────────────────────────────────────────
   Main
───────────────────────────────────────────────────── */
.main { min-width: 0; padding: 28px 32px; }

/* ─────────────────────────────────────────────────────
   Topbar
───────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.topbar-left { flex: 1; min-width: 0; }

.eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 2px;
}

.topbar h1 {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.02em;
  line-height: 1.2;
}

.menu-button {
  display: none;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.menu-button:hover { background: var(--soft); }

.quick-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 13.5px;
  box-shadow: 0 3px 12px rgba(5,150,105,.32);
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.quick-add:hover {
  background: var(--primary-dark);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(5,150,105,.42);
}

/* ─────────────────────────────────────────────────────
   Stats Grid
───────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px;
  height: 100%;
  background: var(--line);
  border-radius: 4px 0 0 4px;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat-card span {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-card strong {
  display: block;
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.025em;
}

.stat-card.due::before { background: var(--amber); }
.stat-card.due strong { color: var(--amber); }

.stat-card.advance::before { background: var(--primary); }
.stat-card.advance strong { color: var(--primary); }

.stat-card.settled::before { background: var(--muted); }

/* ─────────────────────────────────────────────────────
   Panels
───────────────────────────────────────────────────── */
.panel, .auth-card {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.panel { padding: 24px; margin-bottom: 20px; }
.panel.narrow { max-width: 860px; }

.split-layout {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(320px, .9fr);
  gap: 20px;
  align-items: start;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.section-head h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}

.section-head p {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

/* ─────────────────────────────────────────────────────
   Forms
───────────────────────────────────────────────────── */
.form { display: grid; gap: 16px; }

.form-grid, .filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.filters {
  grid-template-columns: 1.2fr 1fr 1fr 1fr 1fr auto;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 10px 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 14px;
}

textarea { min-height: 84px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
  font-weight: 400;
}

/* ─────────────────────────────────────────────────────
   Type Toggle
───────────────────────────────────────────────────── */
.type-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.type-toggle label {
  position: relative;
  cursor: pointer;
}

.type-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  min-height: unset;
}

.type-toggle span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.type-toggle label:hover span {
  background: var(--soft);
  border-color: #cbd5e1;
}

.type-toggle label:has(input[value="given"]) input:checked + span {
  border-color: var(--amber);
  background: var(--amber-light);
  color: var(--amber);
}

.type-toggle label:has(input[value="received"]) input:checked + span {
  border-color: var(--primary);
  background: var(--primary-xlight);
  color: var(--primary-dark);
}

/* ─────────────────────────────────────────────────────
   Buttons
───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(5,150,105,.28);
}

.btn.primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(5,150,105,.38);
}

.btn.ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text-2);
}

.btn.ghost:hover { background: var(--soft); }

.btn.mini {
  min-height: 30px;
  padding: 0 11px;
  background: var(--soft);
  border-color: var(--line);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.btn.mini:hover {
  background: var(--primary-xlight);
  color: var(--primary-dark);
  border-color: var(--primary-light);
}

.btn.danger {
  background: var(--red-light);
  color: var(--red);
}

.btn.danger:hover { background: #fecaca; }

.btn.full { width: 100%; }

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.form-actions, .filter-actions, .button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-message {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.form-message.success { color: var(--primary); }
.form-message.error { color: var(--red); }

.is-hidden { display: none !important; }

/* ─────────────────────────────────────────────────────
   Tables
───────────────────────────────────────────────────── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
}

.table-wrap.compact table { min-width: 460px; }

table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  background: var(--surface);
}

th, td {
  padding: 11px 15px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--soft);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
}

tr:last-child td { border-bottom: 0; }

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }

.right { text-align: right; white-space: nowrap; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 13.5px;
}

/* ─────────────────────────────────────────────────────
   Pills / Badges
───────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.pill.given { background: var(--amber-light); color: var(--amber); }
.pill.received { background: var(--primary-light); color: var(--primary-dark); }

.tag-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--soft);
  color: var(--muted);
  border: 1px solid var(--line);
}

/* ─────────────────────────────────────────────────────
   Balance
───────────────────────────────────────────────────── */
.balance { font-weight: 700; }
.balance.due { color: var(--amber); }
.balance.advance { color: var(--primary); }
.balance.settled { color: var(--text-2); }

.balance span {
  display: block;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  opacity: .65;
  margin-bottom: 2px;
}

/* ─────────────────────────────────────────────────────
   Name Link
───────────────────────────────────────────────────── */
.name-link {
  color: var(--text);
  font-weight: 600;
  transition: color var(--transition);
}
.name-link:hover { color: var(--primary); }

/* ─────────────────────────────────────────────────────
   Entry Actions
───────────────────────────────────────────────────── */
.entry-actions { display: flex; gap: 6px; white-space: nowrap; }

/* ─────────────────────────────────────────────────────
   Account Stats
───────────────────────────────────────────────────── */
.account-stats { grid-template-columns: repeat(4, minmax(120px, 1fr)); }

/* ─────────────────────────────────────────────────────
   Tabs
───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.tabs a {
  padding: 7px 15px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}

.tabs a:hover { background: var(--soft); color: var(--text); }

.tabs a.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(5,150,105,.3);
}

/* ─────────────────────────────────────────────────────
   Zakat Result Panel
───────────────────────────────────────────────────── */
.result-panel {
  min-height: 200px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 32px 24px;
  text-align: center;
  background: linear-gradient(135deg, var(--primary-xlight) 0%, #fff 100%);
  border-radius: var(--radius);
  border: 1.5px solid var(--primary-light);
}

.result-panel span {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.result-panel p { color: var(--muted); font-size: 13px; }

.result-panel strong {
  color: var(--primary);
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -.03em;
}

/* ─────────────────────────────────────────────────────
   Auth Pages
───────────────────────────────────────────────────── */
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 50%, #f0f9ff 100%);
}

.auth-card {
  width: min(100%, 420px);
  padding: 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.auth-brand .brand-mark {
  background: var(--primary);
  box-shadow: 0 4px 12px rgba(5,150,105,.4);
}

.auth-brand h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.auth-brand p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.auth-link {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
}

/* ─────────────────────────────────────────────────────
   Alerts
───────────────────────────────────────────────────── */
.alert {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert.error {
  background: var(--red-light);
  color: var(--red);
  border: 1.5px solid #fecaca;
}

/* ─────────────────────────────────────────────────────
   Mobile overlay
───────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 19;
  backdrop-filter: blur(2px);
}

body.menu-open .sidebar-overlay { display: block; }

/* ─────────────────────────────────────────────────────
   Mobile Bottom Navigation
───────────────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1.5px solid var(--line);
  padding: 6px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,.08);
}

.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  min-width: 52px;
  transition: color var(--transition);
  text-decoration: none;
}

.bottom-nav-item svg { width: 21px; height: 21px; }

.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item:hover { color: var(--primary); }

.bottom-nav-add {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(5,150,105,.4);
  margin-top: -18px;
  transition: all var(--transition);
  text-decoration: none;
  flex-shrink: 0;
}

.bottom-nav-add:hover {
  background: var(--primary-dark);
  color: #fff;
  transform: scale(1.06);
}

/* ─────────────────────────────────────────────────────
   Responsive — 1200px
───────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
}

/* ─────────────────────────────────────────────────────
   Responsive — 1020px
───────────────────────────────────────────────────── */
@media (max-width: 1020px) {
  .split-layout, .filters { grid-template-columns: 1fr; }
}

/* ─────────────────────────────────────────────────────
   Responsive — 780px (mobile)
───────────────────────────────────────────────────── */
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: 272px;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(.4,0,.2,1);
    height: 100dvh;
    height: 100vh;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0,0,0,.28);
  }

  .main { padding: 16px 16px 84px; }

  .menu-button { display: inline-grid; place-items: center; }

  .topbar h1 { font-size: 22px; }

  .quick-add { min-height: 38px; padding: 0 14px; font-size: 13px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .panel { padding: 18px; }

  .bottom-nav { display: block; }
}

/* ─────────────────────────────────────────────────────
   Responsive — 540px
───────────────────────────────────────────────────── */
@media (max-width: 540px) {
  .topbar { flex-wrap: wrap; }
  .quick-add { display: none; }

  .section-head { flex-direction: column; align-items: flex-start; }

  .form-actions, .button-row {
    flex-direction: column;
    align-items: stretch;
  }

  .btn { width: 100%; }
}

/* ─────────────────────────────────────────────────────
   Responsive — 420px
───────────────────────────────────────────────────── */
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .type-toggle { grid-template-columns: 1fr; }
  .main { padding: 12px 12px 80px; }
}

/* ─────────────────────────────────────────────────────
   Print
───────────────────────────────────────────────────── */
@media print {
  .sidebar,
  .topbar,
  .print-hide,
  .filters,
  .bottom-nav,
  .sidebar-overlay,
  .menu-button {
    display: none !important;
  }

  .app-shell { display: block; }
  .main { padding: 0; }

  .panel {
    box-shadow: none;
    border: 0;
    padding: 0;
    margin-bottom: 16px;
    border-radius: 0;
  }

  body { background: #fff; font-size: 12px; }
  table { min-width: unset; }
  .stat-card { break-inside: avoid; }
}
