/* ============================================================
   Budget Tracker - Design System
   SRS Section 40: colours, typography, radii, breakpoints
   Layered on top of Bootstrap 5.
   ============================================================ */

:root {
  --bt-primary:      #2563EB;
  --bt-primary-dark: #1D4ED8;
  --bt-primary-soft: rgba(37, 99, 235, .10);
  --bt-success:      #22C55E;
  --bt-success-soft: rgba(34, 197, 94, .12);
  --bt-warning:      #F59E0B;
  --bt-warning-soft: rgba(245, 158, 11, .12);
  --bt-orange:       #F97316;
  --bt-danger:       #EF4444;
  --bt-danger-soft:  rgba(239, 68, 68, .12);
  --bt-info:         #0EA5E9;

  --bt-bg:        #F8FAFC;
  --bt-surface:   #FFFFFF;
  --bt-surface-2: #F1F5F9;
  --bt-border:    #E2E8F0;
  --bt-text:      #1E293B;
  --bt-muted:     #64748B;
  --bt-faint:     #94A3B8;

  --bt-radius-btn:   12px;
  --bt-radius-card:  18px;
  --bt-radius-input: 12px;
  --bt-radius-modal: 20px;

  --bt-shadow-card:  0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .05);
  --bt-shadow-hover: 0 4px 8px rgba(15, 23, 42, .06), 0 12px 28px rgba(15, 23, 42, .09);
  --bt-shadow-modal: 0 24px 48px rgba(15, 23, 42, .18);
  --bt-shadow-drop:  0 8px 24px rgba(15, 23, 42, .12);

  --bt-sidebar-w: 260px;
  --bt-topbar-h:  64px;
}

[data-theme="dark"] {
  --bt-bg:        #0F172A;
  --bt-surface:   #1E293B;
  --bt-surface-2: #273449;
  --bt-border:    #334155;
  --bt-text:      #E2E8F0;
  --bt-muted:     #94A3B8;
  --bt-faint:     #64748B;
  --bt-primary-soft: rgba(37, 99, 235, .18);
  --bt-shadow-card:  0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  --bt-shadow-hover: 0 12px 28px rgba(0, 0, 0, .4);
  --bt-shadow-modal: 0 24px 48px rgba(0, 0, 0, .5);
}

/* ---------- Base ---------- */
* { -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Inter', system-ui, -apple-system, Arial, sans-serif;
  background: var(--bt-bg);
  color: var(--bt-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

h1 { font-size: 36px; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
h3 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
h4 { font-size: 20px; font-weight: 650; }
h5 { font-size: 17px; font-weight: 600; }
small, .small { font-size: 14px; }
.text-muted { color: var(--bt-muted) !important; }
.text-faint  { color: var(--bt-faint) !important; }
a { color: var(--bt-primary); text-decoration: none; }
a:hover { color: var(--bt-primary-dark); }

.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Focus visibility (WCAG 2.1 AA) ---------- */
:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .45);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Layout ---------- */
.bt-shell { min-height: 100vh; }

.bt-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--bt-sidebar-w);
  background: var(--bt-surface);
  border-right: 1px solid var(--bt-border);
  padding: 20px 14px;
  overflow-y: auto;
  z-index: 1040;
  transition: transform .25s ease;
}

.bt-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 750; font-size: 19px; letter-spacing: -.02em;
  color: var(--bt-text); padding: 4px 8px 18px;
}
.bt-brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--bt-primary), #7C3AED);
  color: #fff; display: grid; place-items: center; font-size: 15px;
  flex-shrink: 0;
}

.bt-nav-label {
  font-size: 11px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--bt-faint);
  padding: 16px 10px 6px;
}

.bt-nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: var(--bt-radius-btn);
  color: var(--bt-muted); font-weight: 500; font-size: 15px;
  min-height: 44px;
  transition: background .15s ease, color .15s ease;
}
.bt-nav-link i { width: 20px; text-align: center; font-size: 15px; }
.bt-nav-link:hover { background: var(--bt-surface-2); color: var(--bt-text); }
.bt-nav-link.active { background: var(--bt-primary-soft); color: var(--bt-primary); font-weight: 600; }
.bt-nav-link .badge { margin-left: auto; }

.bt-main {
  margin-left: var(--bt-sidebar-w);
  min-height: 100vh;
  padding-bottom: 40px;
}

.bt-topbar {
  position: sticky; top: 0; z-index: 1020;
  height: var(--bt-topbar-h);
  background: color-mix(in srgb, var(--bt-surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--bt-border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
}

.bt-content { padding: 24px 20px 0; max-width: 1560px; }

/* ---------- Cards ---------- */
.bt-card {
  background: var(--bt-surface);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-card);
  box-shadow: var(--bt-shadow-card);
  padding: 20px;
  transition: box-shadow .2s ease, transform .2s ease;
}
.bt-card-hover:hover { box-shadow: var(--bt-shadow-hover); transform: translateY(-2px); }
.bt-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.bt-card-title { font-size: 16px; font-weight: 650; margin: 0; }

/* ---------- Stat cards ---------- */
.bt-stat-label {
  font-size: 12px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--bt-muted); margin-bottom: 6px;
}
.bt-stat-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.bt-stat-sub { font-size: 13px; color: var(--bt-muted); margin-top: 4px; }

.bt-icon-box {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 16px; flex-shrink: 0;
}

/* ---------- Hero / net worth ---------- */
.bt-hero {
  background: linear-gradient(135deg, #1D4ED8 0%, #2563EB 45%, #7C3AED 100%);
  color: #fff; border: none;
}
.bt-hero .bt-stat-label { color: rgba(255, 255, 255, .72); }
.bt-hero .bt-stat-sub   { color: rgba(255, 255, 255, .78); }
.bt-hero-divider { border-color: rgba(255, 255, 255, .22); }

/* ---------- Buttons ---------- */
.btn { border-radius: var(--bt-radius-btn); font-weight: 550; font-size: 15px; padding: 9px 16px; min-height: 42px; }
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--bt-primary); border-color: var(--bt-primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--bt-primary-dark); border-color: var(--bt-primary-dark); }
.btn-outline-secondary { color: var(--bt-muted); border-color: var(--bt-border); background: var(--bt-surface); }
.btn-outline-secondary:hover { background: var(--bt-surface-2); color: var(--bt-text); border-color: var(--bt-border); }
.btn-soft { background: var(--bt-surface-2); border: 1px solid var(--bt-border); color: var(--bt-text); }
.btn-soft:hover { background: var(--bt-border); color: var(--bt-text); }
.btn-icon { width: 42px; height: 42px; padding: 0; display: inline-grid; place-items: center; }
.btn-sm { min-height: 34px; padding: 5px 11px; font-size: 13.5px; border-radius: 9px; }

/* ---------- Forms ---------- */
.form-label { font-size: 13.5px; font-weight: 600; color: var(--bt-text); margin-bottom: 6px; }
.form-control, .form-select {
  border-radius: var(--bt-radius-input);
  border: 1px solid var(--bt-border);
  background: var(--bt-surface);
  color: var(--bt-text);
  padding: 10px 13px;
  min-height: 44px;
  font-size: 15px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--bt-primary);
  box-shadow: 0 0 0 3px var(--bt-primary-soft);
  background: var(--bt-surface);
  color: var(--bt-text);
}
.form-control::placeholder { color: var(--bt-faint); }
.form-control:disabled, .form-control[readonly] { background: var(--bt-surface-2); }
textarea.form-control { min-height: 88px; }
.form-check-input { width: 18px; height: 18px; margin-top: .18em; }
.form-check-input:checked { background-color: var(--bt-primary); border-color: var(--bt-primary); }
.input-group-text {
  background: var(--bt-surface-2); border-color: var(--bt-border);
  color: var(--bt-muted); border-radius: var(--bt-radius-input);
}
.invalid-feedback.d-block { font-size: 13px; }

/* ---------- Tables ---------- */
.bt-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.bt-table th {
  font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  color: var(--bt-muted); padding: 10px 14px; border-bottom: 1px solid var(--bt-border);
  white-space: nowrap; text-align: left;
}
.bt-table td {
  padding: 13px 14px; border-bottom: 1px solid var(--bt-border);
  font-size: 14.5px; vertical-align: middle;
}
.bt-table tbody tr:last-child td { border-bottom: none; }
.bt-table tbody tr:hover { background: var(--bt-surface-2); }
.bt-table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }

/* ---------- Badges & pills ---------- */
.bt-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.bt-pill-success { background: var(--bt-success-soft); color: #15803D; }
.bt-pill-danger  { background: var(--bt-danger-soft);  color: #B91C1C; }
.bt-pill-warning { background: var(--bt-warning-soft); color: #B45309; }
.bt-pill-primary { background: var(--bt-primary-soft); color: var(--bt-primary); }
.bt-pill-muted   { background: var(--bt-surface-2);    color: var(--bt-muted); }
[data-theme="dark"] .bt-pill-success { color: #4ADE80; }
[data-theme="dark"] .bt-pill-danger  { color: #FCA5A5; }
[data-theme="dark"] .bt-pill-warning { color: #FCD34D; }

.amount-in  { color: #15803D; font-weight: 600; }
.amount-out { color: #B91C1C; font-weight: 600; }
[data-theme="dark"] .amount-in  { color: #4ADE80; }
[data-theme="dark"] .amount-out { color: #FCA5A5; }

/* ---------- Progress ---------- */
.bt-progress {
  height: 9px; background: var(--bt-surface-2);
  border-radius: 999px; overflow: hidden;
}
.bt-progress-bar {
  height: 100%; border-radius: 999px;
  transition: width .7s cubic-bezier(.4, 0, .2, 1);
  background: var(--bt-primary);
}
.bar-success { background: var(--bt-success); }
.bar-warning { background: var(--bt-warning); }
.bar-orange  { background: var(--bt-orange); }
.bar-danger  { background: var(--bt-danger); }
.bar-primary { background: var(--bt-primary); }

/* ---------- Transaction rows ---------- */
.bt-tx-row {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 4px; border-bottom: 1px solid var(--bt-border);
}
.bt-tx-row:last-child { border-bottom: none; }
.bt-tx-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
}
.bt-tx-body { min-width: 0; flex: 1; }
.bt-tx-title {
  font-weight: 600; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bt-tx-meta { font-size: 12.5px; color: var(--bt-muted); }

/* ---------- Insights ---------- */
.bt-insight {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 14px; border-radius: 14px;
  background: var(--bt-surface-2); font-size: 14px; margin-bottom: 9px;
}
.bt-insight i { margin-top: 2px; }
.bt-insight-success { background: var(--bt-success-soft); }
.bt-insight-warning { background: var(--bt-warning-soft); }
.bt-insight-danger  { background: var(--bt-danger-soft); }
.bt-insight-info    { background: var(--bt-primary-soft); }

/* ---------- Empty states ---------- */
.bt-empty { text-align: center; padding: 44px 20px; color: var(--bt-muted); }
.bt-empty-icon {
  width: 64px; height: 64px; margin: 0 auto 14px;
  border-radius: 20px; display: grid; place-items: center;
  background: var(--bt-surface-2); font-size: 24px; color: var(--bt-faint);
}

/* ---------- Modals ---------- */
.modal-content {
  border-radius: var(--bt-radius-modal);
  border: 1px solid var(--bt-border);
  background: var(--bt-surface);
  box-shadow: var(--bt-shadow-modal);
}
.modal-header, .modal-footer { border-color: var(--bt-border); padding: 18px 22px; }
.modal-body { padding: 6px 22px 18px; }
.modal-title { font-size: 18px; font-weight: 650; }

/* ---------- Dropdowns ---------- */
.dropdown-menu {
  border-radius: 14px; border: 1px solid var(--bt-border);
  box-shadow: var(--bt-shadow-drop); background: var(--bt-surface);
  padding: 6px;
}
.dropdown-item { border-radius: 9px; padding: 9px 12px; font-size: 14.5px; color: var(--bt-text); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--bt-surface-2); color: var(--bt-text); }
.dropdown-divider { border-color: var(--bt-border); }

/* ---------- Search ---------- */
.bt-search { position: relative; flex: 1; max-width: 440px; }
.bt-search input { padding-left: 40px; background: var(--bt-surface-2); border-color: transparent; }
.bt-search i {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--bt-faint); font-size: 14px; pointer-events: none;
}
.bt-search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bt-surface); border: 1px solid var(--bt-border);
  border-radius: 14px; box-shadow: var(--bt-shadow-drop);
  max-height: 380px; overflow-y: auto; z-index: 1050; display: none;
}
.bt-search-results.show { display: block; }
.bt-search-item { display: block; padding: 11px 14px; border-bottom: 1px solid var(--bt-border); color: var(--bt-text); }
.bt-search-item:last-child { border-bottom: none; }
.bt-search-item:hover { background: var(--bt-surface-2); }

/* ---------- Avatar ---------- */
.bt-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bt-primary); color: #fff;
  display: grid; place-items: center;
  font-weight: 650; font-size: 14px; flex-shrink: 0;
}

/* ---------- Calendar ---------- */
.bt-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.bt-cal-dow {
  text-align: center; font-size: 11.5px; font-weight: 700;
  color: var(--bt-muted); text-transform: uppercase; padding: 6px 0;
}
.bt-cal-day {
  min-height: 96px; border: 1px solid var(--bt-border);
  border-radius: 12px; padding: 7px; background: var(--bt-surface);
  font-size: 12px; overflow: hidden;
}
.bt-cal-day.empty { background: transparent; border-color: transparent; }
.bt-cal-day.today { border-color: var(--bt-primary); box-shadow: 0 0 0 1px var(--bt-primary); }
.bt-cal-num { font-weight: 650; font-size: 13px; margin-bottom: 4px; }
.bt-cal-ev {
  font-size: 10.5px; padding: 2px 5px; border-radius: 6px;
  margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Bottom navigation (mobile) ---------- */
.bt-bottomnav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1045;
  background: var(--bt-surface);
  border-top: 1px solid var(--bt-border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  grid-template-columns: repeat(5, 1fr);
}
.bt-bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px; color: var(--bt-muted);
  font-size: 10.5px; font-weight: 550; min-height: 48px;
  border-radius: 10px;
}
.bt-bottomnav a i { font-size: 17px; }
.bt-bottomnav a.active { color: var(--bt-primary); }

.bt-fab {
  position: fixed; right: 18px; bottom: 78px; z-index: 1046;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--bt-primary); color: #fff; border: none;
  box-shadow: 0 8px 22px rgba(37, 99, 235, .42);
  display: none; place-items: center; font-size: 20px;
}
.bt-fab:active { transform: scale(.94); }

/* ---------- Auth pages ---------- */
.bt-auth {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1000px 480px at 12% -8%, rgba(37, 99, 235, .13), transparent 60%),
    radial-gradient(880px 420px at 100% 0%, rgba(124, 58, 237, .11), transparent 55%),
    var(--bt-bg);
}
.bt-auth-card { width: 100%; max-width: 480px; }
.bt-auth-wide { max-width: 680px; }

/* ---------- Toast ---------- */
.bt-toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 1090; max-width: 380px; }
.bt-toast {
  display: flex; align-items: flex-start; gap: 11px;
  background: var(--bt-surface); border: 1px solid var(--bt-border);
  border-left: 4px solid var(--bt-primary);
  border-radius: 14px; box-shadow: var(--bt-shadow-drop);
  padding: 13px 15px; margin-bottom: 10px; font-size: 14.5px;
  animation: bt-slide-in .28s cubic-bezier(.16, 1, .3, 1);
}
.bt-toast.success { border-left-color: var(--bt-success); }
.bt-toast.error   { border-left-color: var(--bt-danger); }
.bt-toast.warning { border-left-color: var(--bt-warning); }
@keyframes bt-slide-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

/* ---------- Skeleton loaders ---------- */
.bt-skeleton {
  background: linear-gradient(90deg, var(--bt-surface-2) 25%, var(--bt-border) 37%, var(--bt-surface-2) 63%);
  background-size: 400% 100%;
  animation: bt-shimmer 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes bt-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Segmented control ---------- */
.bt-seg { display: inline-flex; background: var(--bt-surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.bt-seg a {
  padding: 7px 14px; border-radius: 9px; font-size: 14px; font-weight: 550;
  color: var(--bt-muted); min-height: 36px; display: inline-flex; align-items: center;
}
.bt-seg a.active { background: var(--bt-surface); color: var(--bt-text); box-shadow: var(--bt-shadow-card); }

/* ---------- Chart wrapper ---------- */
.bt-chart { position: relative; width: 100%; }
.bt-chart canvas { max-width: 100%; }

/* ---------- Responsive: SRS section 40 breakpoints ---------- */
@media (max-width: 1199.98px) {
  .bt-sidebar { transform: translateX(-100%); box-shadow: var(--bt-shadow-modal); }
  .bt-sidebar.open { transform: none; }
  .bt-main { margin-left: 0; }
  .bt-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
    z-index: 1035; display: none;
  }
  .bt-backdrop.show { display: block; }
}

@media (max-width: 991.98px) {
  h1 { font-size: 28px; }
  h2 { font-size: 24px; }
  .bt-content { padding: 18px 15px 0; }
  .bt-stat-value { font-size: 24px; }
}

@media (max-width: 767.98px) {
  .bt-bottomnav { display: grid; }
  .bt-fab { display: grid; }
  .bt-main { padding-bottom: 96px; }
  .bt-content { padding: 15px 13px 0; }
  .bt-card { padding: 16px; border-radius: 16px; }
  .bt-table-wrap { margin: 0 -16px; padding: 0 16px; }
  .bt-stat-value { font-size: 22px; }
  h1 { font-size: 24px; }
  .bt-cal-day { min-height: 62px; padding: 4px; }
  .bt-cal { gap: 4px; }
  .modal-body, .modal-header, .modal-footer { padding-left: 16px; padding-right: 16px; }
  .bt-toast-wrap { left: 12px; right: 12px; max-width: none; }
}

@media (max-width: 575.98px) {
  body { font-size: 15px; }
  .bt-stat-value { font-size: 20px; }
  .bt-topbar { padding: 0 13px; }
  .bt-cal-num { font-size: 11px; }
}

/* ---------- Print ---------- */
@media print {
  .bt-sidebar, .bt-topbar, .bt-bottomnav, .bt-fab, .no-print { display: none !important; }
  .bt-main { margin-left: 0; }
  .bt-card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  body { background: #fff; font-size: 12pt; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
