:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-glow: rgba(79, 70, 229, 0.25);

  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --info: #0284c7;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.12);

  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  --radius-sm: 0.5rem;
  --radius-md: 0.875rem;
  --radius-lg: 1.125rem;
  --radius-xl: 1.5rem;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 24px -8px rgba(15, 23, 42, 0.12), 0 4px 8px -4px rgba(15, 23, 42, 0.06);
  --shadow-xl: 0 20px 40px -12px rgba(15, 23, 42, 0.18);

  --bs-primary: #4f46e5;
  --bs-primary-rgb: 79, 70, 229;
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-border-color: var(--border);
  --bs-link-color: var(--primary);
  --bs-link-hover-color: var(--primary-hover);
}

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

body.app-body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(79, 70, 229, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(14, 165, 233, 0.08), transparent),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main.app-main {
  padding-top: 1.75rem;
  padding-bottom: 2.5rem;
}

.app-container {
  max-width: 1200px;
}

/* Navbar */
.navbar-app {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.navbar-app .navbar-brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  color: var(--text) !important;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.navbar-app .navbar-brand i {
  color: var(--primary);
  font-size: 1.25rem;
}

.navbar-app .nav-link {
  color: var(--text-muted) !important;
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.45rem 0.75rem !important;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.navbar-app .nav-link:hover,
.navbar-app .nav-link:focus {
  color: var(--text) !important;
  background: rgba(15, 23, 42, 0.04);
}

.navbar-app .dropdown-menu {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.4rem;
}

.navbar-app .dropdown-item {
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  padding: 0.45rem 0.75rem;
}

.navbar-app .dropdown-item.active,
.navbar-app .dropdown-item:active {
  background: var(--primary-soft);
  color: var(--primary);
}

.navbar-app .navbar-toggler {
  border-color: var(--border-strong);
  padding: 0.35rem 0.55rem;
}

/* Footer */
.site-footer {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  color: var(--text-subtle);
  font-size: 0.8125rem;
}

/* Typography & page chrome */
main h1,
main .h1,
main h2.h4 {
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

main h1.h3 i,
main .page-title i {
  color: var(--primary);
  margin-right: 0.35rem;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
}

/* Cards */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.card.shadow-sm {
  box-shadow: var(--shadow-sm);
}

.card:hover {
  border-color: var(--border-strong);
}

.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  font-weight: 600;
}

.card-header h5 {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-body {
  padding: 1.25rem;
}

/* Stat cards */
.stat-card {
  border: 1px solid var(--border);
  border-left: none;
  overflow: hidden;
  position: relative;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--stat-accent, var(--primary));
}

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

.income-card {
  --stat-accent: var(--success);
}

.income-card .card-body i {
  background: var(--success-soft);
  color: var(--success);
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem !important;
  opacity: 1 !important;
}

.expense-card {
  --stat-accent: var(--danger);
}

.expense-card .card-body i {
  background: var(--danger-soft);
  color: var(--danger);
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem !important;
  opacity: 1 !important;
}

.balance-card {
  --stat-accent: var(--primary);
}

.balance-card .card-body i {
  background: var(--primary-soft);
  color: var(--primary);
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem !important;
  opacity: 1 !important;
}

.stat-card h3 {
  font-weight: 700;
  letter-spacing: -0.03em;
}

/* Buttons */
.btn {
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  border: none;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-primary:hover,
.btn-primary:focus {
  background: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-outline-primary {
  border-color: rgba(79, 70, 229, 0.35);
  color: var(--primary);
}

.btn-outline-primary:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-hover);
}

.btn-outline-secondary {
  border-color: var(--border-strong);
  color: var(--text-muted);
}

.btn-outline-secondary:hover {
  background: rgba(15, 23, 42, 0.04);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-sm {
  font-size: 0.8125rem;
  padding: 0.35rem 0.7rem;
}

.btn-lg {
  padding: 0.65rem 1.35rem;
  border-radius: var(--radius-md);
}

/* Forms */
.form-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.form-control,
.form-select {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  font-size: 0.9rem;
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-group-text {
  border-color: var(--border-strong);
  background: rgba(15, 23, 42, 0.03);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

/* Tables */
.table {
  --bs-table-bg: transparent;
  margin-bottom: 0;
}

.table thead th,
.table-light th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle) !important;
  background: rgba(15, 23, 42, 0.02) !important;
  border-bottom: 1px solid var(--border) !important;
  padding: 0.85rem 1rem;
}

.table tbody td {
  padding: 0.9rem 1rem;
  vertical-align: middle;
  border-color: var(--border);
  font-size: 0.9rem;
}

.table-hover tbody tr:hover {
  background: rgba(79, 70, 229, 0.04);
}

.table-warning {
  --bs-table-bg: #fffbeb;
}

/* Badges */
.badge {
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  padding: 0.35em 0.65em;
  border-radius: 999px;
}

/* Progress */
.progress {
  background: rgba(15, 23, 42, 0.06);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  border-radius: 999px;
}

/* Alerts */
.alert {
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}

.alert-success {
  background: var(--success-soft);
  color: #047857;
}

.alert-danger {
  background: var(--danger-soft);
  color: #b91c1c;
}

/* Hero / landing */
.hero-section {
  text-align: center;
  padding: 3.5rem 1rem 2.5rem;
  max-width: 720px;
  margin: 0 auto;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

.hero-title {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--text) 0%, #334155 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-title i {
  -webkit-text-fill-color: var(--primary);
  font-size: 0.9em;
}

.hero-lead {
  font-size: 1.125rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 2rem;
}

.hero-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.feature-card {
  text-align: center;
  padding: 0.25rem;
}

.feature-card .feature-icon {
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto 1.25rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary-soft) 0%, rgba(99, 102, 241, 0.15) 100%);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.feature-card h5 {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

.feature-card p {
  font-size: 0.9rem;
  line-height: 1.55;
  margin-bottom: 0;
}

/* Auth & form pages */
.auth-shell .card,
.row.justify-content-center .card {
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.auth-shell .card-title,
.auth-shell h2.h4,
.row.justify-content-center h2.h4 {
  font-size: 1.35rem;
}

/* Modals */
.modal-content {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.modal-header {
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.02);
}

/* Calendar */
.calendar-grid {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.calendar-header,
.calendar-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar-day-name {
  padding: 0.75rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  background: rgba(15, 23, 42, 0.03);
  border-bottom: 1px solid var(--border);
}

.calendar-cell {
  min-height: 100px;
  padding: 0.5rem;
  border: 1px solid var(--border);
  vertical-align: top;
  background: var(--surface);
  transition: background 0.15s ease;
}

.calendar-cell.empty {
  background: rgba(15, 23, 42, 0.02);
}

.calendar-cell.today {
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 2px rgba(79, 70, 229, 0.25);
}

.calendar-cell.has-reminders {
  background: rgba(79, 70, 229, 0.04);
}

.calendar-day-num {
  font-weight: 700;
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.calendar-event {
  display: block;
  font-size: 0.68rem;
  margin-bottom: 3px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
}

/* Timeline */
.timeline-item:last-child {
  border-bottom: none !important;
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

/* List groups */
.list-group-item {
  border-color: var(--border);
}

/* Attachment preview */
.attachment-preview-dialog {
  width: min(96vw, 1400px);
  max-width: min(96vw, 1400px);
  height: calc(100vh - 2rem);
  max-height: calc(100vh - 2rem);
  margin: 1rem auto;
}

.attachment-preview-dialog .modal-content {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.attachment-preview-dialog .modal-header,
.attachment-preview-dialog .modal-footer {
  flex-shrink: 0;
}

.attachment-preview-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.03);
}

.attachment-preview-content {
  width: 100%;
  height: 100%;
}

.attachment-preview-content--image {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.attachment-preview-content--pdf {
  display: block;
  overflow: hidden;
}

.attachment-preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  border-radius: var(--radius-sm);
}

.attachment-preview-pdf {
  width: 100%;
  height: 100%;
  min-height: 100%;
  border: 0;
  background: #fff;
  display: block;
}

/* Empty states */
.text-muted a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.text-muted a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Utility polish */
.shadow-sm {
  box-shadow: var(--shadow-sm) !important;
}

.border-success {
  border-color: rgba(5, 150, 105, 0.25) !important;
}

.border-danger {
  border-color: rgba(220, 38, 38, 0.25) !important;
}

.border-primary {
  border-color: rgba(79, 70, 229, 0.25) !important;
}

@media (max-width: 991.98px) {
  .navbar-app .navbar-collapse {
    padding: 0.75rem 0 0.25rem;
  }

  .navbar-app .nav-link {
    padding: 0.55rem 0.5rem !important;
  }
}

@media (max-width: 576px) {
  main.app-main {
    padding-top: 1.25rem;
  }

  .hero-section {
    padding-top: 2rem;
  }

  .table-responsive {
    font-size: 0.875rem;
  }

  .calendar-cell {
    min-height: 70px;
    padding: 0.25rem;
  }

  .calendar-event {
    font-size: 0.58rem;
  }
}