:root {
  --bg: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --card: #FFFFFF;
  --card-soft: #F4F6FA;
  --border: #E7EAF1;
  --text: #1A1F2B;
  --text-dim: #8991A4;
  --income: #14A672;
  --income-bg: #E7F9F1;
  --expense: #E14361;
  --expense-bg: #FDEAEF;
  --accent: #4C6FFF;
  --accent-bg: #EEF1FF;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(20, 24, 40, 0.04), 0 2px 8px rgba(20, 24, 40, 0.05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* ===== Top bar ===== */
.app-topbar {
  padding: calc(16px + var(--safe-top)) 20px 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-title {
  font-size: 21px;
  font-weight: 800;
}
.admin-logout-link {
  font-size: 13px;
  font-weight: 700;
  color: var(--expense);
}

.app-content {
  flex: 1;
  padding: 16px 16px calc(100px + var(--safe-bottom));
}

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + var(--safe-bottom));
  z-index: 30;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 12px;
  transition: color .15s ease;
}
.nav-item svg { width: 21px; height: 21px; }
.nav-item.active { color: var(--accent); }
.nav-item.active svg { color: var(--accent); }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
}

/* ===== Day accordion ===== */
.day-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.day-item {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color .2s ease;
}
.day-item.today { border-color: var(--accent); }

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
}
.day-header-info { display: flex; flex-direction: column; gap: 2px; }
.day-name { font-size: 15px; font-weight: 700; }
.day-date { font-size: 12px; color: var(--text-dim); }
.day-header-right { display: flex; align-items: center; gap: 10px; }
.day-net { font-size: 14px; font-weight: 700; }
.day-net.positive { color: var(--income); }
.day-net.negative { color: var(--expense); }
.day-chevron { width: 18px; height: 18px; color: var(--text-dim); transition: transform .2s ease; }
.day-item.open .day-chevron { transform: rotate(180deg); }

.day-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease;
  border-top: 1px solid transparent;
}
.day-item.open .day-body {
  border-top: 1px solid var(--border);
}

.day-body-inner { padding: 14px 16px 16px; }

.day-actions { display: flex; gap: 10px; margin-bottom: 14px; }
.btn-action {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.btn-income { background: var(--income-bg); color: var(--income); }
.btn-expense { background: var(--expense-bg); color: var(--expense); }

.txn-list { display: flex; flex-direction: column; gap: 8px; }
.txn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--card-soft);
}
.txn-info { display: flex; flex-direction: column; gap: 2px; }
.txn-cat { font-size: 13.5px; font-weight: 700; }
.txn-note { font-size: 11.5px; color: var(--text-dim); }
.txn-right { display: flex; align-items: center; gap: 10px; }
.txn-amount { font-size: 14px; font-weight: 800; }
.txn-amount.income { color: var(--income); }
.txn-amount.expense { color: var(--expense); }
.txn-del { color: var(--text-dim); width: 16px; height: 16px; cursor: pointer; }
.empty-hint { color: var(--text-dim); font-size: 13px; text-align: center; padding: 10px 0; }

/* ===== Wallet indicators ===== */
.wallet-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.stat-label { font-size: 12px; color: var(--text-dim); font-weight: 600; margin-bottom: 6px; }
.stat-value { font-size: 20px; font-weight: 800; }
.stat-card.income .stat-value { color: var(--income); }
.stat-card.expense .stat-value { color: var(--expense); }
.stat-card.balance { grid-column: span 2; display: flex; align-items: center; justify-content: space-between; }
.stat-card.balance .stat-value { font-size: 26px; color: var(--accent); }

.filter-chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.chip.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

.section-title { font-size: 14px; font-weight: 800; margin: 18px 0 10px; color: var(--text-dim); }

.cat-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cat-bar-label { font-size: 12.5px; font-weight: 700; width: 90px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-bar-track { flex: 1; height: 8px; border-radius: 6px; background: var(--card-soft); overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 6px; }
.cat-bar-value { font-size: 12px; font-weight: 700; width: 62px; text-align: left; flex-shrink: 0; color: var(--text-dim); }

/* ===== Categories page ===== */
.cat-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.cat-tab {
  flex: 1;
  text-align: center;
  padding: 11px;
  border-radius: var(--radius-md);
  background: var(--card-soft);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
}
.cat-tab.active.income-tab { background: var(--income-bg); color: var(--income); border-color: var(--income); }
.cat-tab.active.expense-tab { background: var(--expense-bg); color: var(--expense); border-color: var(--expense); }

.cat-chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.cat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  font-size: 13.5px;
  font-weight: 600;
}
.cat-chip .del-x { color: var(--expense); cursor: pointer; font-weight: 800; }

.add-cat-form { display: flex; gap: 8px; }
.add-cat-form input { flex: 1; }
.btn-add-cat {
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

/* ===== Reports ===== */
.report-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.report-row:last-child { border-bottom: none; }
.report-label { font-size: 13.5px; color: var(--text-dim); font-weight: 600; }
.report-value { font-size: 15px; font-weight: 800; }
.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 14.5px;
  cursor: pointer;
  margin-top: 6px;
}
.top-cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--expense-bg);
  color: var(--expense);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

/* ===== Inputs ===== */
input, select {
  width: 100%;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-dim); }
label { font-size: 12.5px; color: var(--text-dim); font-weight: 700; margin-bottom: 6px; display: block; }
.form-group { margin-bottom: 12px; position: relative; }

/* ===== Autocomplete ===== */
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  right: 0; left: 0;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-sm);
  max-height: 160px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}
.autocomplete-list.show { display: block; }
.autocomplete-item { padding: 10px 14px; font-size: 13.5px; cursor: pointer; }
.autocomplete-item:hover, .autocomplete-item.highlight { background: var(--card-soft); }

/* ===== Modal (bottom sheet) ===== */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 24, 40, 0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.sheet-overlay.show { opacity: 1; pointer-events: auto; }

.bottom-sheet {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translate(-50%, 100%);
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + var(--safe-bottom));
  z-index: 100;
  transition: transform .25s ease;
  border: 1px solid var(--border);
  border-bottom: none;
  box-shadow: 0 -8px 30px rgba(20,24,40,0.12);
}
.bottom-sheet.show { transform: translate(-50%, 0); }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin: 6px auto 16px;
}
.sheet-title { font-size: 17px; font-weight: 800; margin-bottom: 16px; }
.sheet-title.income-title { color: var(--income); }
.sheet-title.expense-title { color: var(--expense); }

/* ===== Month nav ===== */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.month-nav-btn {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.month-nav-title { font-size: 15px; font-weight: 800; }

.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1A1F2B;
  border: 1px solid #1A1F2B;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  z-index: 200;
  opacity: 0;
  transition: all .25s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Auth pages (login / admin login) ===== */
.auth-body {
  background: var(--card-soft);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cairo', sans-serif;
  padding: 20px;
}
.auth-wrap { width: 100%; max-width: 380px; }
.auth-logo {
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  margin-bottom: 6px;
}
.admin-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 3px 10px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}
.auth-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
  margin-bottom: 24px;
}
.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
}
.auth-error {
  background: var(--expense-bg);
  color: var(--expense);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  text-align: center;
}
.auth-success {
  background: var(--income-bg);
  color: var(--income);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  text-align: center;
}

/* ===== Admin dashboard ===== */
.admin-shell { max-width: 640px; }
.user-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.user-card-name { font-size: 15px; font-weight: 800; }
.user-card-meta { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }
.status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.status-badge.active { background: var(--income-bg); color: var(--income); }
.status-badge.inactive { background: var(--expense-bg); color: var(--expense); }
.user-card-actions { display: flex; gap: 8px; }
.user-card-actions form { flex: 1; }
.btn-small {
  width: 100%;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-soft);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}
.btn-small.btn-danger { color: var(--expense); border-color: var(--expense-bg); background: var(--expense-bg); }

.btn-logout {
  display: block;
  text-align: center;
  color: var(--expense);
  font-weight: 700;
  font-size: 13.5px;
  padding: 14px;
  margin-top: 4px;
}

/* ===== Print (تصدير التقرير) ===== */
@media print {
  .bottom-nav, .app-topbar, .filter-chips, #printReportBtn { display: none !important; }
  body, .app-shell { background: #fff; color: #000; }
  .card, .report-row { border-color: #ccc !important; }
  .app-content { padding-bottom: 20px !important; }
}
