/* Net Worth Tracker — app styles layered on Bootstrap 5.3
   Bootstrap handles light/dark via [data-bs-theme]; we add finance-specific tokens
   and an intentionally designed dark palette (plan section 4). */

:root,
[data-bs-theme="light"] {
  --nw-pos: #1a7f37;
  --nw-pos-bg: rgba(26, 127, 55, 0.10);
  --nw-neg: #b42318;
  --nw-neg-bg: rgba(180, 35, 24, 0.10);
  --nw-accent: #1f6feb;
  --nw-muted: #656d76;

  --nw-page-bg: #f6f7f9;
  --nw-card-bg: #ffffff;
  --nw-card-border: rgba(0, 0, 0, 0.09);
  --nw-nav-bg: #ffffff;
  --nw-glass-bg: rgba(255, 255, 255, 0.68);
  --nw-glass-border: rgba(255, 255, 255, 0.5);
  --nw-accent-bg: rgba(31, 111, 235, 0.12);
}

[data-bs-theme="dark"] {
  --nw-pos: #3fb950;
  --nw-pos-bg: rgba(63, 185, 80, 0.15);
  --nw-neg: #f85149;
  --nw-neg-bg: rgba(248, 81, 73, 0.15);
  --nw-accent: #58a6ff;
  --nw-muted: #9198a1;

  --nw-page-bg: #0d1117;   /* very dark charcoal, not pure black */
  --nw-card-bg: #161b22;   /* slightly lifted */
  --nw-card-border: rgba(255, 255, 255, 0.10);
  --nw-nav-bg: #12161d;
  --nw-glass-bg: rgba(22, 27, 34, 0.62);
  --nw-glass-border: rgba(255, 255, 255, 0.12);
  --nw-accent-bg: rgba(88, 166, 255, 0.16);

  /* Nudge Bootstrap's own tokens so built-in components match */
  --bs-body-bg: #0d1117;
  --bs-body-color: #e6edf3;
  --bs-tertiary-bg: #161b22;
  --bs-border-color: rgba(255, 255, 255, 0.12);
  --bs-secondary-color: #9198a1;
}

body {
  background: var(--nw-page-bg);
  -webkit-font-smoothing: antialiased;
  /* On a short page (nothing to scroll — e.g. History with few rows),
     iOS Safari keeps its own toolbar chrome fully expanded instead of
     auto-hiding it, which shifts how much viewport is actually visible;
     a fixed bottom element can then look like it "floats" at a different
     height than on a taller, scrollable page. 100dvh tracks the *current*
     visible viewport instead of assuming a fixed chrome size, so the page
     — and anything fixed to its viewport — stays put regardless of
     content length. Falls back to plain vh where dvh isn't supported. */
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---- Mobile bottom nav (thumb-reachable core actions) ----
   Floating glass pill, not a bar fixed to the screen edge — frosted
   (backdrop-filter) so page content softly shows through, like the iOS
   tab-bar / Dynamic Island "liquid glass" language. Falls back to a
   near-opaque tint where backdrop-filter isn't supported. */
.nw-bottom-nav {
  position: fixed;
  left: 10px; right: 10px;
  bottom: 10px; /* plain browser tab: no safe area, so this is the whole gap */
  z-index: 1040;
  display: flex;
  gap: 2px;
  border-radius: 22px;
  background: var(--nw-glass-bg);
  border: 1px solid var(--nw-glass-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16), 0 1px 2px rgba(0, 0, 0, 0.08);
  padding: 5px;
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}
/* Installed on the home screen (standalone), the home-indicator safe area
   IS the gap — stacking our own 10px on top of it read as too generous.
   A plain browser tab has no safe area to speak of, so it keeps the flat
   10px above. display-mode:standalone is how a page tells the two apart. */
@media (display-mode: standalone) {
  .nw-bottom-nav { bottom: env(safe-area-inset-bottom, 10px); }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  [data-bs-theme="light"] .nw-bottom-nav { background: rgba(255, 255, 255, 0.96); }
  [data-bs-theme="dark"] .nw-bottom-nav { background: rgba(18, 22, 29, 0.96); }
}
.nw-bottom-nav a {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 7px 2px;
  border-radius: 16px;
  font-size: 0.62rem;
  color: var(--nw-muted);
  text-decoration: none;
  line-height: 1.15;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nw-bottom-nav a.active { color: var(--nw-accent); font-weight: 600; background: var(--nw-accent-bg); }
.nw-bottom-nav .icon { display: flex; line-height: 1; }
.nw-bottom-nav .icon svg { display: block; }
@media (max-width: 991.98px) {
  body:has(.nw-bottom-nav) { padding-bottom: calc(70px + env(safe-area-inset-bottom, 0)); }
}

/* ---- Buttons ----
   Bootstrap's outline-secondary is too dim on our card backgrounds; give the
   neutral / semantic outline buttons enough contrast to read as buttons. */
.btn-outline-secondary {
  --bs-btn-color: #5b636b;
  --bs-btn-border-color: #b9c0c7;
  --bs-btn-hover-bg: #5b636b;
  --bs-btn-hover-border-color: #5b636b;
}
[data-bs-theme="dark"] .btn-outline-secondary {
  --bs-btn-color: #b8c0c9;
  --bs-btn-border-color: #495159;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #495159;
  --bs-btn-hover-border-color: #5b646d;
}
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: #6cb0ff; --bs-btn-border-color: #2f5f96; }
[data-bs-theme="dark"] .btn-outline-warning { --bs-btn-color: #e3b341; --bs-btn-border-color: #6b5320; }
[data-bs-theme="dark"] .btn-outline-success { --bs-btn-color: #4ac26b; --bs-btn-border-color: #2c5c39; }
[data-bs-theme="dark"] .btn-outline-danger  { --bs-btn-color: #f0817a; --bs-btn-border-color: #6e2f2c; }

/* Theme toggle icon: driven purely by [data-bs-theme], which is already set
   pre-paint, so there's no flash of the wrong icon while JS loads. */
[data-theme-icon="moon"] { display: none; }
[data-bs-theme="dark"] [data-theme-icon="sun"] { display: none; }
[data-bs-theme="dark"] [data-theme-icon="moon"] { display: inline-block; }

/* Table row action clusters: keep them tight and aligned */
td .btn.btn-sm + .btn.btn-sm,
td .btn.btn-sm + form,
td form + .btn.btn-sm,
td form + form { margin-left: 0.25rem; }

/* ---- Layout ---- */
.nw-nav {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: var(--nw-nav-bg) !important;
  /* Installed on an iPhone home screen, the status bar (time/battery/
     signal) overlays the page instead of pushing it down (apple-mobile-
     web-app-status-bar-style is "black-translucent" for that immersive,
     edge-to-edge look) — stack the inset ON TOP OF Bootstrap's own navbar
     padding (--bs-navbar-padding-y) rather than replacing it, so browsers
     without a safe area (env() = 0 there) keep the normal top padding. */
  padding-top: calc(var(--bs-navbar-padding-y, 0.5rem) + env(safe-area-inset-top, 0));
}

.nw-container {
  max-width: 1080px;
}

/* ---- Cards ---- */
.nw-card {
  border: 1px solid var(--nw-card-border);
  border-radius: 14px;
  background: var(--nw-card-bg);
}
.nw-card .card-body { padding: 1.1rem 1.25rem; }

[data-bs-theme="light"] .nw-card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.03);
}

.nw-kpi-label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--nw-muted);
  margin-bottom: 0.25rem;
}

/* Section divider heading — <h2 class="nw-section">…</h2> between the
   distinct areas of a page so they don't blend into one another. */
.nw-section {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--nw-muted);
  margin: 1.75rem 0 0.6rem;
}
.nw-section:first-child { margin-top: 0; }
.nw-kpi-value {
  font-size: 1.55rem;
  font-weight: 650;
  line-height: 1.1;
}

.nw-sparkline {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 28px !important;
  width: 100% !important;
  opacity: 0.55;
  pointer-events: none;
}

.nw-hero-value {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 720;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* ---- Change indicators ---- */
.change-pos { color: var(--nw-pos); }
.change-neg { color: var(--nw-neg); }
.change-neutral { color: var(--nw-muted); }

.nw-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.nw-pill.change-pos { background: var(--nw-pos-bg); }
.nw-pill.change-neg { background: var(--nw-neg-bg); }

/* ---- Numeric tables ---- */
.nw-num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* ---- Auth screens ---- */
.nw-auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top, 0));
}
.nw-auth-card {
  width: 100%;
  max-width: 400px;
}

/* ---- Pull-to-refresh indicator (app.js drives transform/opacity) ---- */
.nw-pull-indicator {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  padding-top: 10px;
  opacity: 0;
  pointer-events: none;
  z-index: 1060; /* above the sticky nav (1030) and bottom nav (1040) */
  transition: opacity 0.1s ease;
}
.nw-pull-spinner {
  display: block;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--nw-card-border);
  border-top-color: var(--nw-accent);
  background: var(--nw-card-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.nw-pull-indicator.nw-pull-ready .nw-pull-spinner { border-top-color: var(--nw-pos); }
.nw-pull-indicator.nw-pull-loading .nw-pull-spinner { animation: nw-pull-spin 0.6s linear infinite; }
@keyframes nw-pull-spin { to { transform: rotate(360deg); } }

/* ---- Utility ---- */
.nw-muted { color: var(--nw-muted); }
.nw-mono { font-family: var(--bs-font-monospace); }

@media (max-width: 575.98px) {
  .nw-kpi-value { font-size: 1.3rem; }
}
