/* Spendly — reusable components (§50). */

/* ==========================================================
   Brand
   ========================================================== */

.brand { display: inline-flex; align-items: center; gap: var(--s-3); }

.brand-mark {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--gradient-brand);
  box-shadow: var(--shadow-accent);
  color: #fff;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-mark--lg { width: 60px; height: 60px; border-radius: 19px; }
.brand-mark--lg svg { width: 32px; height: 32px; }

.brand-name {
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: -0.03em;
}
.brand-tagline {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* ==========================================================
   Buttons
   ========================================================== */

.btn {
  --btn-h: 48px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--btn-h);
  padding: 0 var(--s-5);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: transform var(--t-fast) var(--ease),
              background-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              opacity var(--t-fast) var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; }
.btn svg { width: 20px; height: 20px; flex: none; }

.btn-primary {
  background: var(--gradient-cta);
  color: var(--on-accent);
  box-shadow: var(--shadow-accent);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-alt); }

.btn-soft {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.btn-soft:hover:not(:disabled) { filter: brightness(0.97); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.06); }

.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }

.btn-block { display: flex; width: 100%; }
.btn-sm { --btn-h: 38px; padding-inline: var(--s-4); font-size: var(--fs-sm); }
.btn-lg { --btn-h: 54px; font-size: var(--fs-lg); }

/* Icon-only button — keeps a 44px touch target (§38). */
.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-full);
  color: var(--text-muted);
  transition: background-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.btn-icon:hover { background: var(--surface-alt); color: var(--text); }
.btn-icon:active { transform: scale(0.92); }
.btn-icon svg { width: 22px; height: 22px; }

/* Google sign-in button — neutral chrome, per brand guidelines. */
.btn-google {
  background: #FFFFFF;
  color: #1F1F1F;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn-google:hover:not(:disabled) { background: #F5F5F7; }
:root[data-theme="dark"] .btn-google {
  background: #FFFFFF;
  color: #1F1F1F;
  border-color: transparent;
}

/* Inline spinner shown while a button is busy. */
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2.5px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 640ms linear infinite;
  color: var(--on-accent);
}
.btn-secondary.is-loading::after,
.btn-ghost.is-loading::after,
.btn-google.is-loading::after { color: var(--text-muted); }

/* ==========================================================
   Cards
   ========================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--s-4);
}
.card-flush { padding: 0; overflow: hidden; }
.card-pad { padding: var(--s-4); }

/* ==========================================================
   Form fields
   ========================================================== */

.field { display: block; }
.field + .field { margin-top: var(--s-4); }

.field-label {
  display: block;
  margin-bottom: var(--s-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 48px;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  color: var(--text);
  transition: border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.textarea { min-height: 88px; resize: vertical; line-height: 1.5; }

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--s-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2371718A' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
  background-size: 18px;
}

.field-error {
  display: block;
  margin-top: var(--s-2);
  font-size: var(--fs-sm);
  color: var(--danger);
}
.input[aria-invalid="true"] { border-color: var(--danger); }

/* Input with a leading icon */
.input-group { position: relative; }
.input-group .input { padding-left: var(--s-10); }
.input-group-icon {
  position: absolute;
  left: var(--s-4);
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-subtle);
  pointer-events: none;
}

/* ==========================================================
   Segmented control (period switch, expense/income toggle)
   ========================================================== */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  background: var(--surface-sunken);
  border-radius: var(--r-full);
}
.segmented-item {
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  transition: background-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
}
.segmented-item[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ==========================================================
   Progress bar
   ========================================================== */

.progress {
  height: 10px;
  border-radius: var(--r-full);
  background: var(--surface-sunken);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--gradient-cta);
  transition: width var(--t-slow) var(--ease);
}
.progress-fill[data-state="moderate"] { background: linear-gradient(90deg, #F5B33C, var(--warning)); }
.progress-fill[data-state="warning"]  { background: linear-gradient(90deg, #FB8C4A, #F97316); }
.progress-fill[data-state="over"]     { background: linear-gradient(90deg, #F87171, var(--danger)); }

/* ==========================================================
   Badges / pills
   ========================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 3px var(--s-2);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 650;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-accent  { background: var(--accent-soft);  color: var(--accent-text); }

/* ==========================================================
   Category icon chip
   ========================================================== */

.cat-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: var(--r-md);
  font-size: 20px;
  line-height: 1;
  background: var(--accent-soft);
}
.cat-icon-sm { width: 36px; height: 36px; border-radius: var(--r-sm); font-size: 17px; }

/* ==========================================================
   Toast (§35)
   ========================================================== */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + var(--s-4));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: min(420px, calc(100vw - var(--s-8)));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-subtle);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-base);
  pointer-events: auto;
  animation: rise-in var(--t-base) var(--ease) both;
}
.toast.is-leaving {
  animation: fade-out var(--t-fast) var(--ease) both;
}
.toast-icon { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 650; }
.toast-text { font-size: var(--fs-sm); color: var(--text-muted); }

.toast--success { border-left-color: var(--success); }
.toast--success .toast-icon { color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
.toast--error .toast-icon { color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }
.toast--warning .toast-icon { color: var(--warning); }
.toast--info    { border-left-color: var(--info); }
.toast--info .toast-icon { color: var(--info); }

/* ==========================================================
   Skeleton loaders (§33)
   ========================================================== */

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(
    90deg,
    var(--surface-sunken) 25%,
    var(--surface-alt) 50%,
    var(--surface-sunken) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton-line { height: 12px; margin-bottom: var(--s-2); }
.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-w-40 { width: 40%; }
.skeleton-w-60 { width: 60%; }
.skeleton-w-80 { width: 80%; }

/* ==========================================================
   Empty state (§32)
   ========================================================== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--s-10) var(--s-5);
  animation: rise-in var(--t-slow) var(--ease) both;
}
.empty-art {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin-bottom: var(--s-5);
  border-radius: var(--r-xl);
  background: var(--accent-soft);
  color: var(--accent);
}
.empty-art svg { width: 38px; height: 38px; }
.empty-title { font-size: var(--fs-lg); font-weight: 700; }
.empty-text {
  margin-top: var(--s-2);
  max-width: 34ch;
  font-size: var(--fs-base);
  color: var(--text-muted);
}
.empty .btn { margin-top: var(--s-6); }

/* ==========================================================
   Overlay, bottom sheet, modal
   ========================================================== */

.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  background: var(--scrim);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fade-in var(--t-base) var(--ease) both;
}
.overlay.is-leaving { animation: fade-out var(--t-fast) var(--ease) both; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  max-height: min(92dvh, 780px);
  background: var(--bg-elevated);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  animation: slide-up var(--t-slow) var(--ease) both;
}
.sheet.is-leaving { animation: slide-down var(--t-base) var(--ease) both; }

.sheet-grabber {
  width: 40px;
  height: 4px;
  margin: var(--s-3) auto var(--s-1);
  border-radius: var(--r-full);
  background: var(--border-strong);
  flex: none;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4) var(--s-2);
  flex: none;
}
.sheet-title { font-size: var(--fs-lg); font-weight: 700; }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s-2) var(--s-4) var(--s-4);
  -webkit-overflow-scrolling: touch;
}
.sheet-foot {
  flex: none;
  padding: var(--s-3) var(--s-4);
  padding-bottom: calc(var(--s-4) + var(--safe-b));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--s-5);
  pointer-events: none;
}
.modal-panel {
  width: min(400px, 100%);
  padding: var(--s-6);
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: scale-in var(--t-base) var(--ease-out-back) both;
}
.modal.is-leaving .modal-panel { animation: scale-out var(--t-fast) var(--ease) both; }
.modal-title { font-size: var(--fs-lg); font-weight: 700; }
.modal-text { margin-top: var(--s-2); color: var(--text-muted); }
.modal-actions {
  display: flex;
  gap: var(--s-3);
  margin-top: var(--s-6);
}
.modal-actions .btn { flex: 1; }

body.is-locked { overflow: hidden; }

/* ==========================================================
   Auth screens
   ========================================================== */

.auth {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: calc(var(--s-10) + var(--safe-t)) var(--s-5)
           calc(var(--s-8) + var(--safe-b));
}

/* The auth screen is topped by an SVG backdrop that bleeds under the device
   status bar (see .app-backdrop). Desktop swaps it for soft glows instead. */

.auth-inner {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  margin: auto;
}

.auth-head { text-align: center; margin-bottom: var(--s-8); }
.auth-head .brand-mark--lg { margin: 0 auto var(--s-5); }
.auth-title {
  font-size: var(--fs-3xl);
  font-weight: 800;
  letter-spacing: -0.035em;
}
.auth-sub {
  margin-top: var(--s-2);
  color: var(--text-muted);
}

.auth-card {
  padding: var(--s-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin: var(--s-5) 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-switch {
  margin-top: var(--s-5);
  text-align: center;
  font-size: var(--fs-base);
  color: var(--text-muted);
}
.auth-switch button {
  font-weight: 650;
  color: var(--accent-text);
}
.auth-switch button:hover { text-decoration: underline; }

.auth-legal {
  margin-top: var(--s-6);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-subtle);
}

/* Inline alert used for auth errors (§34). */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  padding: var(--s-3);
  margin-bottom: var(--s-4);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  background: var(--danger-soft);
  color: var(--danger);
  animation: rise-in var(--t-base) var(--ease) both;
}
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* Feature bullets on the marketing/landing view. */
.feature-list { display: grid; gap: var(--s-4); }
.feature {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
}
.feature-icon {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  flex: none;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
}
.feature-icon svg { width: 20px; height: 20px; }
.feature-title { font-weight: 650; }
.feature-text { font-size: var(--fs-sm); color: var(--text-muted); }

/* ==========================================================
   Full-page splash shown while auth state resolves (§33/§59)
   ========================================================== */

.splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  gap: var(--s-5);
  align-content: center;
  background: var(--bg);
  transition: opacity var(--t-slow) var(--ease), visibility var(--t-slow);
}
.splash[hidden] { display: grid !important; opacity: 0; visibility: hidden; }
.splash-spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.splash-text { font-size: var(--fs-sm); color: var(--text-subtle); }

/* ==========================================================
   Theme toggle used on auth pages
   ========================================================== */

.auth-theme-toggle {
  position: absolute;
  top: calc(var(--s-4) + var(--safe-t));
  right: var(--s-4);
  z-index: 2;
}

/* Trailing action inside a field (e.g. show/hide password). */
.input-action {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
}
.input-action svg { width: 20px; height: 20px; }
.input-group:has(.input-action) .input { padding-right: 48px; }

/* ==========================================================
   App backdrop — decorative SVG artwork that bleeds under the
   device status bar so the app reads as native (§38, §66).

   The page uses viewport-fit=cover, so a fixed element at top:0
   already extends into the safe area; the meta theme-color is set
   to --backdrop-1 on these screens so Android's status bar matches,
   and iOS uses black-translucent to let the artwork show through.
   ========================================================== */

.app-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 0;
  width: 100%;
  height: clamp(300px, 46vh, 460px);
  pointer-events: none;
  user-select: none;
}
.app-backdrop svg { width: 100%; height: 100%; display: block; }

/* SVG gradient stops read the theme tokens, so the artwork follows dark mode. */
.bd-stop-1 { stop-color: var(--backdrop-1); }
.bd-stop-2 { stop-color: var(--backdrop-2); }
.bd-stop-3 { stop-color: var(--backdrop-3); }

.bd-shape { fill: url(#bd-sky); }
.bd-blob { fill: #fff; }
.bd-ring { fill: none; stroke: #fff; stroke-width: 1.4; }
.bd-dot { fill: #fff; }
.bd-shine { fill: url(#bd-shine); }

/* Content above the artwork is white in both themes. */
@media (max-width: 1024px) {
  .auth-inner { margin: 0 auto; }

  .auth-head { color: var(--on-backdrop); }
  .auth-head .auth-sub { color: var(--on-backdrop-muted); }

  /* On the purple field the brand mark reads better as glass than as gradient. */
  .auth-head .brand-mark {
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: none;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }

  .auth-theme-toggle { color: var(--on-backdrop); }
  .auth-theme-toggle:hover { background: rgba(255, 255, 255, 0.16); }

  /* Lift the card so it clearly floats on the artwork. */
  .auth-card { box-shadow: var(--shadow-lg); }

  .auth-legal { color: var(--text-subtle); }
}

/* ==========================================================
   Dashboard hero — the same treatment for the app shell (§10, §60)
   ========================================================== */

.app-hero {
  position: relative;
  isolation: isolate;
  padding-top: calc(var(--safe-t) + var(--s-8));
  padding-bottom: var(--s-12);
  color: var(--on-backdrop);
  overflow: hidden;
}
.app-hero-art {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.app-hero-art svg { width: 100%; height: 100%; display: block; }

.app-hero .hero-greeting {
  font-size: var(--fs-base);
  color: var(--on-backdrop-muted);
}
.app-hero .hero-month {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-hero .btn-icon {
  color: var(--on-backdrop);
}
.app-hero .btn-icon:hover { background: rgba(255, 255, 255, 0.16); }

/* Body content overlaps the hero's lower edge — the signature fintech look. */
.app-body {
  position: relative;
  margin-top: calc(var(--s-8) * -1);
  padding-bottom: calc(var(--s-10) + var(--safe-b));
}

/* ==========================================================
   Landing page extras
   ========================================================== */

.landing-points { display: grid; gap: var(--s-2); }
.landing-point {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.landing-check {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: none;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
}
.landing-check svg { width: 12px; height: 12px; }

.landing-mobile-features { color: var(--text); }

/* The desktop brand column already carries this content. */
@media (min-width: 1025px) {
  .landing-mobile-features { display: none; }
}

/* ==========================================================
   Install instructions (§40)
   ========================================================== */

.install-steps {
  display: grid;
  gap: var(--s-3);
  counter-reset: install;
}
.install-step {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-alt);
}
.install-step-num {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-sm);
  font-weight: 700;
}
.install-step-icon { display: grid; place-items: center; color: var(--accent); flex: none; }
