/* Base reset + shared component styles. Ported from the finance dashboard's base.css — same
   reset, brand-bar, .card/.btn/.badge/.field idiom. Everything here reads from tokens.css
   variables — no hardcoded colors, spacing, or font sizes. Two additions at the bottom
   (.stat-grid and .link-card-grid) generalize patterns the finance dashboard had only as
   page-specific one-offs (hero-score-stat-*, quick-link-card) into reusable components, since
   this app expects most module pages to need a small stat row and a card grid of links. */

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

[hidden] {
  display: none !important;
}

/* App-wide brand mark — top-left on every page. Height is fixed and known
   (--brand-bar-height) so pages that need to compensate for it can do the math instead of
   guessing. */
:root {
  --brand-bar-height: 5.5rem;
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--brand-bar-height);
  padding: 0 var(--space-4);
}

.brand-bar-identity {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
}

.brand-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-bar img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

.brand-bar span {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .brand-bar span {
    display: none;
  }

  .brand-bar img {
    width: 44px;
    height: 44px;
  }
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0 0 var(--space-3) 0;
}

h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-accent);
}

h2 {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}

h3 {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-medium);
}

.text-muted {
  color: var(--color-text-muted);
}

a {
  color: var(--color-accent);
}

/* ---- Layout ---- */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-8);
}

@media (min-width: 900px) {
  .page {
    max-width: 1040px;
  }
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

@media (min-width: 900px) {
  .entity-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    align-items: start;
  }
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.section-header {
  margin-bottom: var(--space-4);
}

/* ---- Buttons ---- */

.btn {
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

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

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  border-color: var(--color-accent);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
}

.btn-ghost:hover {
  color: var(--color-text);
}

.btn-ghost-action {
  padding: var(--space-2) var(--space-4);
}

.btn-accent {
  background: var(--color-surface);
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.btn-accent:hover {
  background: var(--color-accent-muted);
  border-color: var(--color-accent-hover);
}

.btn-ghost-accent {
  background: transparent;
  color: var(--color-accent);
  padding: var(--space-1) var(--space-2);
}

.btn-ghost-accent:hover {
  color: var(--color-accent-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Form controls ---- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field label {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* Currency-field's health-dashboard counterpart — any numeric field that needs a fixed prefix
   (a unit, not just $), e.g. "lbs", "mg", "mL". Same shape, generic prefix content via a data
   attribute instead of a hardcoded "$". */
.unit-field {
  position: relative;
  display: block;
  width: 100%;
}

.unit-field::before {
  content: attr(data-unit);
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  pointer-events: none;
}

.unit-field input {
  padding-right: calc(var(--space-2) + 2.2em);
  width: 100%;
}

/* Editable-in-place value: looks like plain text until focused/hovered. Every module's
   direct-edit fields (per CLAUDE.md's "values are directly editable in place" rule) use this. */
.editable-value {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  background: transparent;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  width: 100%;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.editable-value:hover {
  border-color: var(--color-border);
  background: var(--color-surface);
}

.editable-value:focus {
  border-color: var(--color-accent);
  background: var(--color-surface);
  outline: none;
}

.editable-value.is-saving {
  opacity: 0.6;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  padding: 2px var(--space-2);
  border-radius: 999px;
}

.badge-accent {
  background: var(--color-accent-muted);
  color: var(--color-accent);
}

.badge-success {
  background: var(--color-success-muted);
  color: var(--color-success);
}

.badge-warning {
  background: var(--color-warning-muted);
  color: var(--color-warning);
}

.badge-danger {
  background: var(--color-danger-muted);
  color: var(--color-danger);
}

.form-error {
  min-height: 1.2em;
  color: var(--color-danger);
  margin: 0;
}

.form-success {
  color: var(--color-success);
}

/* ---- Utility ---- */

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

/* Reserved for the single biggest figure on a page, never applied blanket. */
.hero-numeral {
  font-family: var(--font-sans);
  font-weight: var(--font-weight-black);
  font-size: var(--text-hero);
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.app-footer {
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
  text-align: center;
}

.app-footer p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Scroll-triggered reveal (public/js/components/scroll-reveal.js). */
.reveal-on-scroll {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 300ms ease, transform 300ms ease;
}

.reveal-on-scroll.is-revealed {
  opacity: 1;
  transform: translateY(0);
}

.charts-grid .reveal-on-scroll:nth-child(2) { transition-delay: 60ms; }
.charts-grid .reveal-on-scroll:nth-child(3) { transition-delay: 120ms; }
.charts-grid .reveal-on-scroll:nth-child(4) { transition-delay: 180ms; }

@media (prefers-reduced-motion: reduce) {
  .reveal-on-scroll {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ---- Stat card (generalized from the finance dashboard's hero-score-stat-* one-offs) ----
   A label/value pair — label small, muted, uppercase; value large and bold — repeated in a row
   or grid. Used for the small metric rows atop module pages (e.g. Summary's "This week" strip)
   even before there's real data behind them. */

.stat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* ---- Metric card (Monitoring's stat-card-with-sparkline grid) ---- */

.metric-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.metric-card .editable-value {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
}

.sparkline {
  width: 100%;
  height: 36px;
  display: block;
}

.goal-chart {
  width: 100%;
  height: auto;
  display: block;
}

/* ---- Goal progress bar ---- */

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

.goal-progress-fill {
  height: 100%;
  background: var(--color-body);
  border-radius: 999px;
  transition: width var(--transition-normal);
}

/* ---- Suggestion nudge ---- */

.nudge-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  background: var(--color-body-muted);
  border: 1px solid var(--color-body);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}

/* ---- Link card grid (generalized from the finance dashboard's quick-links-grid) ----
   A grid of cards that are themselves links — used on Summary to hub out to every module, and
   anywhere else a page needs to point at a handful of related destinations. */

.link-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.link-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}

.link-card:hover {
  border-color: var(--color-accent);
  transform: translateY(-2px);
}

.link-card strong {
  color: var(--color-accent);
}

/* ---- Empty state ---- */
/* Same idiom the finance dashboard used ad hoc (a muted, small paragraph inside an otherwise
   empty section) — named here so every module page uses one consistent class instead of
   re-deriving the same three utility classes each time. */
.empty-state {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

@media (max-width: 600px) {
  .page {
    padding: var(--space-4) var(--space-3) var(--space-7);
  }

  .card {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }

  .stat-grid {
    gap: var(--space-4);
  }
}
