:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --success: #0d9488;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Auth */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #e0f2fe 0%, #f0fdf4 100%);
}

.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.logo {
  font-size: 1.75rem;
  text-align: center;
  margin-bottom: 0.25rem;
}

.logo-sm { font-size: 1.25rem; }

.tagline {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tab {
  flex: 1;
  padding: 0.6rem;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
}

.tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #0f766e; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover { background: var(--bg); }

.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

.form-footer {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.form-footer a {
  color: var(--primary);
  text-decoration: none;
}

.info-text {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.message {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.message.success { background: #d1fae5; color: #065f46; }
.message.error { background: #fee2e2; color: #991b1b; }

/* Header */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Main */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* Balance alert */
.balance-alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-weight: 500;
  font-size: 0.95rem;
}

.balance-alert.critical {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.balance-alert.warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.balance-alert.ok {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

/* Cards */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.big-number {
  font-size: 1.75rem;
  font-weight: 700;
}

.balance-card .big-number.positive { color: var(--success); }
.balance-card .big-number.negative { color: var(--danger); }

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.1rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filters input[type="date"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.transactions-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.txn-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 0.75rem;
}

.txn-info {
  flex: 1;
  min-width: 0;
}

.txn-category {
  font-weight: 600;
  font-size: 0.95rem;
}

.txn-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.txn-amount {
  font-weight: 700;
  white-space: nowrap;
}

.txn-amount.income { color: var(--success); }
.txn-amount.expense { color: var(--danger); }

.txn-delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem;
}

.txn-delete:hover { color: var(--danger); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.5rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

.modal-content h2 {
  margin-bottom: 1.25rem;
  font-size: 1.25rem;
}

.report-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.report-controls select,
.report-controls input {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.report-result {
  background: var(--bg);
  border-radius: 8px;
  padding: 1rem;
}

.report-result .stat {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.report-result .stat:last-child { border-bottom: none; }

.report-result .highlight {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #fef3c7;
  border-radius: 6px;
  font-weight: 500;
}

/* Responsive */
@media (max-width: 600px) {
  .header-inner { flex-direction: column; gap: 0.5rem; align-items: flex-start; }
  .dashboard-cards { grid-template-columns: 1fr; }
  .section-header { flex-direction: column; align-items: flex-start; }
}
/* =========================================================
   App shell: header, sidebar, main content
   ========================================================= */
.header-inner {
  max-width: none;
  padding: 0 0.25rem;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text);
  margin-right: 0.5rem;
}

.icon-btn {
  position: relative;
  background: none;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
}

.dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.app-body {
  display: flex;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  overflow-y: auto;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: none;
  border: none;
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.nav-item:hover { background: var(--bg); }

.nav-item.active {
  background: rgba(26, 115, 232, 0.1);
  color: var(--primary);
}

.nav-scrim {
  display: none;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 1.25rem;
}

.view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.view-header h2 {
  font-size: 1.35rem;
}

.view.hidden { display: none; }

/* Grids & layout helpers */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.chart-card canvas {
  max-height: 240px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* =========================================================
   Alerts panel
   ========================================================= */
.alerts-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.alert-item {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}

.alert-item.critical { background: #fee2e2; color: #991b1b; }
.alert-item.warning { background: #fef3c7; color: #92400e; }
.alert-item.info { background: #e0f2fe; color: #075985; }
.alert-item.positive { background: #d1fae5; color: #065f46; }

/* =========================================================
   Dashboard cards
   ========================================================= */
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.4rem;
}

.stat-card .value {
  font-size: 1.4rem;
  font-weight: 700;
}

.stat-card .sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

.value.positive { color: var(--success); }
.value.negative { color: var(--danger); }

/* Progress bars (budgets, goals) */
.progress-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
}

.progress-item .progress-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
}

.progress-item .progress-top strong { font-weight: 600; }

.progress-bar-track {
  background: var(--bg);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.2s;
}

.progress-bar-fill.warning { background: var(--warning); }
.progress-bar-fill.critical,
.progress-bar-fill.exceeded { background: var(--danger); }
.progress-bar-fill.positive { background: var(--success); }

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}

.row-item .row-title { font-weight: 600; }
.row-item .row-sub { color: var(--muted); font-size: 0.78rem; }
.row-item .row-actions { display: flex; gap: 0.4rem; }
.row-actions {
  display: flex;
  gap: 0.4rem;
}
.row-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
}
.row-actions button:hover { color: var(--primary); }
.row-actions button.danger:hover { color: var(--danger); }

.danger-text { color: var(--danger) !important; border-color: #fecaca !important; }
.danger-text:hover { background: #fee2e2 !important; }

/* =========================================================
   Transactions
   ========================================================= */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.filters-bar input,
.filters-bar select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.filters-bar input[type="text"] { min-width: 160px; flex: 1; }

.txn-item {
  cursor: pointer;
}

.txn-item .txn-tags {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.2rem;
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.txn-actions {
  display: flex;
  gap: 0.4rem;
}

.txn-actions button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.05rem;
  padding: 0.2rem;
}

.txn-actions button:hover { color: var(--primary); }
.txn-actions button.danger:hover { color: var(--danger); }

.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* =========================================================
   Account cards
   ========================================================= */
.account-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  border-left: 4px solid var(--primary);
}

.account-card .account-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.account-card .account-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.account-card .account-type {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
}

.account-card .account-balance {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 0.6rem;
}

.account-card .account-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

/* =========================================================
   Category chips
   ========================================================= */
.category-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}

.category-chip .chip-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-chip .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* =========================================================
   Loans
   ========================================================= */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
}
.status-badge.pending { background: #e0f2fe; color: #075985; }
.status-badge.partially_paid { background: #fef3c7; color: #92400e; }
.status-badge.paid { background: #d1fae5; color: #065f46; }
.status-badge.overdue { background: #fee2e2; color: #991b1b; }

/* =========================================================
   Calendar
   ========================================================= */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-dow {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
  padding: 0.25rem 0;
}

.cal-cell {
  min-height: 64px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem;
  cursor: pointer;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.cal-cell.empty { border: none; cursor: default; }
.cal-cell:hover:not(.empty) { border-color: var(--primary); }
.cal-cell.selected { border-color: var(--primary); background: rgba(26,115,232,0.06); }
.cal-cell .cal-date { font-weight: 600; }
.cal-cell .cal-amt.income { color: var(--success); font-size: 0.7rem; }
.cal-cell .cal-amt.expense { color: var(--danger); font-size: 0.7rem; }
.cal-cell .cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--primary); }

/* =========================================================
   Forms (shared across modals)
   ========================================================= */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem 1rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.checkbox-row input { width: auto; }

.danger-zone {
  border: 1px solid #fecaca;
}

.danger-zone h3 { color: var(--danger); }

.file-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.attachment-link {
  font-size: 0.8rem;
  color: var(--primary);
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .nav-toggle { display: inline-block; }

  .app-body { position: relative; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }

  .nav-scrim:not(.hidden) {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
  }

  .main { padding: 0.85rem; }

  .dashboard-cards, .cards-grid { grid-template-columns: 1fr; }

  .filters-bar { flex-direction: column; align-items: stretch; }
  .filters-bar input, .filters-bar select { width: 100%; }

  .header-right .user-email { display: none; }

  .calendar-grid { gap: 2px; }
  .cal-cell { min-height: 48px; padding: 0.2rem; font-size: 0.68rem; }
}

@media (max-width: 480px) {
  .modal-content { padding: 1.1rem; }
  .form-row { grid-template-columns: 1fr; }
}
