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

:root {
  --bg: #f5f6fa;
  --card-bg: #ffffff;
  --accent: #7c83fd;
  --accent-light: #e8e9ff;
  --accent-dark: #5a62e0;
  --text: #3a3a4e;
  --text-light: #8e8e9e;
  --danger: #ff6b6b;
  --danger-light: #ffe3e3;
  --shadow: 0 2px 12px rgba(60,60,100,0.08);
  --shadow-soft: 0 1px 6px rgba(60,60,100,0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 64px;
}

body {
  font-family: 'Segoe UI', 'Noto Sans Bengali', 'SolaimanLipi', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* ===== Top Bar ===== */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card-bg);
  padding: 16px 20px;
  box-shadow: var(--shadow-soft);
}
.app-topbar h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== Main Content ===== */
#main {
  padding: 16px 16px calc(var(--nav-h) + 24px);
}

.app-section { display: none; animation: fadeIn 0.25s ease; }
.app-section.active { display: block; }

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

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
}

/* ===== Forms ===== */
label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-light);
  margin: 12px 0 5px;
  font-weight: 500;
}
input, select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #eceef5;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: #fafbff;
  color: var(--text);
  transition: border-color 0.2s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
input::placeholder { color: #c5c7d4; }

.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-top: 18px;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:active { transform: scale(0.98); }

.btn-danger {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--danger);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-danger:active { transform: scale(0.98); }

.inline-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.inline-form input { flex: 1; min-width: 120px; }
.inline-form select { width: auto; min-width: 100px; }
.inline-form .btn-primary {
  width: auto;
  margin-top: 0;
  padding: 12px 20px;
  white-space: nowrap;
}

/* ===== Date Bar (Home) ===== */
.date-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 0 14px;
}
.date-bar span {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 6px 18px;
  border-radius: 20px;
  min-width: 170px;
  text-align: center;
}

/* ===== Add Card ===== */
.add-card h2 { color: var(--accent); }

/* ===== Today / Day Expense List ===== */
.today-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.today-head h2 { margin-bottom: 0; }
.today-total {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
}

.expense-list { display: flex; flex-direction: column; gap: 8px; }

.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #fafbff;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.expense-item:active { background: var(--accent-light); }

.expense-icon {
  font-size: 1.3rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-light);
  border-radius: 50%;
  flex-shrink: 0;
}
.expense-info { flex: 1; min-width: 0; }
.expense-info .desc {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expense-info .cat {
  font-size: 0.75rem;
  color: var(--text-light);
}
.expense-amount {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.expense-actions { display: flex; gap: 6px; flex-shrink: 0; }
.expense-actions button {
  border: none;
  background: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.15s;
}
.expense-actions button:active { background: #e0e0e8; }

.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-light);
  font-size: 0.9rem;
}

/* ===== Monthly View ===== */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 8px 0 18px;
}
.month-nav span {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  min-width: 160px;
  text-align: center;
}
.nav-arrow {
  border: none;
  background: var(--accent-light);
  color: var(--accent);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.nav-arrow:active { background: var(--accent); color: #fff; }

.month-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.month-total {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.day-group {
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.day-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}
.day-group-head .day-date { font-size: 0.92rem; }
.day-group-head .day-subtotal { color: var(--accent); font-weight: 700; }
.day-group-head .day-arrow {
  font-size: 0.8rem;
  color: var(--text-light);
  transition: transform 0.25s;
  margin-left: 8px;
}
.day-group.open .day-arrow { transform: rotate(180deg); }
.day-group-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.day-group.open .day-group-body { max-height: 2000px; }
.day-group-body-inner { padding: 0 14px 14px; }

/* ===== Manage Lists (Settings) ===== */
.manage-list { margin-top: 14px; }
.manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #fafbff;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.manage-item .mi-text { flex: 1; font-weight: 500; font-size: 0.9rem; }
.manage-item button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 6px 8px;
  border-radius: 6px;
}
.manage-item button:active { background: #e0e0e8; }
.manage-item .mi-edit { color: var(--accent); }
.manage-item .mi-del  { color: var(--danger); }

/* ===== Bottom Navigation ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: var(--card-bg);
  display: flex;
  box-shadow: 0 -2px 12px rgba(60,60,100,0.08);
  z-index: 100;
}
.nav-item {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-light);
  transition: color 0.2s;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 1.3rem; }
.nav-label { font-size: 0.68rem; font-weight: 500; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40,40,60,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--card-bg);
  width: 100%;
  max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-head h2 { font-size: 1.1rem; margin: 0; }
.modal-close {
  border: none;
  background: var(--accent-light);
  color: var(--accent);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.88rem;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toastIn 0.3s ease;
}
.toast.hidden { display: none; }
.toast.error { background: var(--danger); }
.toast.success { background: #4ecdc4; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== Login Page ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(160deg, var(--accent-light) 0%, var(--bg) 50%);
}
.login-card {
  background: var(--card-bg);
  border-radius: 24px;
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(60,60,100,0.12);
  text-align: center;
}
.login-logo {
  font-size: 3rem;
  margin-bottom: 8px;
}
.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.login-subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 24px;
}
.login-card form { text-align: left; }
.login-card .btn-primary { margin-top: 22px; }

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 14px;
  text-align: center;
}
.error-msg.hidden { display: none; }

/* ===== Utilities ===== */
.hidden { display: none !important; }

/* ===== Dashboard ===== */
.dash-filters { padding: 14px 18px; }
.filter-row { display: flex; flex-direction: column; gap: 12px; }
.filter-col { flex: 1; }

/* Multi-select category chips (dashboard filter) */
.cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.chip {
  border: 1px solid var(--border, #ddd);
  background: #fff;
  color: var(--text, #333);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip.active {
  background: var(--accent, #7c83fd);
  border-color: var(--accent, #7c83fd);
  color: #fff;
}
.filter-col label { margin-top: 0; }

.dash-stats {
  display: flex;
  gap: 10px;
}
.stat-item {
  flex: 1;
  text-align: center;
  padding: 10px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
}
.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-light);
  margin-bottom: 4px;
}
.stat-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}
.chart-wrap canvas { max-width: 100%; }

.dash-month-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: #fafbff;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.dash-month-item:active { background: var(--accent-light); }
.dash-month-item .dm-name { font-weight: 600; font-size: 0.92rem; }
.dash-month-item .dm-total { color: var(--accent); font-weight: 700; }
.dash-month-item .dm-count { font-size: 0.75rem; color: var(--text-light); margin-left: 6px; }

/* ===== Offline pie fallback ===== */
.bar-offline { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-amt { width: 80%; }
.bar-lbl { font-size: 0.55rem; color: var(--text-light); }

.pie-offline { font-size: 0.85rem; }
.pie-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f0f0f5; }
.pie-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.pie-row span:nth-child(2) { flex: 1; }
.pie-val { font-weight: 600; color: var(--accent); white-space: nowrap; }

/* ===== Network status badge ===== */
.net-badge {
  position: fixed;
  top: 8px;
  right: 12px;
  z-index: 200;
  font-size: 0.68rem;
  padding: 3px 10px;
  border-radius: 12px;
  display: none;
}
.net-badge.offline {
  display: block;
  background: #ffe3e3;
  color: #d63030;
}
.net-badge.syncing {
  display: block;
  background: var(--accent-light);
  color: var(--accent-dark);
}

/* ===== Desktop polish ===== */
@media (min-width: 481px) {
  body { background: #ebedf5; }
  #app {
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
  }
}
