/* Shared components — mirror SharedComponents.swift. */

/* Reset for button-based components (kept off bare `button` so legacy buttons are unaffected) */
.ui-btn, .seg-item, .ui-chip, .sheet-close, .ui-card-tap, .profile-btn, .ui-btn-link { background: none; border: 0; padding: 0; }

/* Card */
.ui-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex; flex-direction: column; gap: var(--space-md);
  min-width: 0;
}
.ui-card-tap { cursor: pointer; transition: border-color .15s, transform .1s; text-align: left; width: 100%; color: inherit; }
.ui-card-tap:hover { border-color: var(--border-strong); }
.ui-card-tap:active { transform: scale(0.99); }

/* Buttons: tactile accent (pill), secondary, destructive */
.ui-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 16px; font-weight: 700; line-height: 1.2;
  padding: 14px 20px; border-radius: var(--radius-pill);
  color: var(--on-accent);
  background: var(--grad-accent-button);
  box-shadow: 0 4px 10px rgba(52, 219, 135, 0.35);
  transition: transform .15s cubic-bezier(.3,1.6,.6,1), box-shadow .15s, opacity .15s;
  width: 100%;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.ui-btn:active:not(:disabled) { transform: scale(0.97); opacity: .9; box-shadow: 0 1px 2px rgba(52, 219, 135, 0.35); }
.ui-btn:disabled { opacity: .45; cursor: not-allowed; }
.ui-btn svg { width: 20px; height: 20px; flex: none; }
.ui-btn-compact { font-size: 14px; padding: 10px 18px; width: auto; }
.ui-btn-secondary {
  color: var(--text-primary); font-weight: 600; font-size: 15px; padding: 12px 18px;
  background: var(--surface-raised); border: 1px solid var(--border-strong);
  box-shadow: none; width: auto;
}
.ui-btn-secondary:active:not(:disabled) { box-shadow: none; }
.ui-btn-destructive {
  background: var(--red); box-shadow: 0 4px 10px rgba(250, 92, 107, 0.35);
}
.ui-btn-destructive:active:not(:disabled) { box-shadow: 0 1px 2px rgba(250, 92, 107, 0.35); }
.ui-btn-link { color: var(--text-secondary); font-size: 13px; font-weight: 600; }
.ui-btn.ui-btn-link { background: none; box-shadow: none; width: auto; padding: 8px 12px; }
.ui-btn-link svg { width: 22px; height: 22px; }
.ui-btn-link:hover { color: var(--text-primary); }
.ui-btn-block { width: 100%; }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.input {
  width: 100%; font-size: 16px; padding: 12px 14px;
  background: var(--surface-raised); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.input::placeholder { color: var(--text-tertiary); }
.input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(52, 219, 135, 0.18); }
textarea.input { resize: vertical; min-height: 84px; }

/* Segmented control */
.seg {
  display: flex; padding: 3px; gap: 2px;
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.seg-item {
  flex: 1; text-align: center; font-size: 14px; font-weight: 600;
  padding: 8px 10px; border-radius: 8px; color: var(--text-secondary);
  transition: background .15s, color .15s;
}
.seg-item[aria-pressed="true"], .seg-item[aria-selected="true"] {
  background: rgba(255, 255, 255, 0.14); color: var(--text-primary);
}

/* Chips */
.ui-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.08); color: var(--text-secondary);
  border: 1px solid transparent;
}
.ui-chip-green { background: var(--green-tint); color: var(--green); border-color: rgba(52,219,135,.35); }
.ui-chip-amber { background: var(--amber-tint); color: var(--amber); border-color: rgba(255,184,61,.35); }
.ui-chip-red { background: var(--red-tint); color: var(--red); border-color: rgba(250,92,107,.35); }
.ui-chip-blue { background: rgba(92,158,255,.12); color: var(--blue); border-color: rgba(92,158,255,.35); }
.ui-chip-gold { background: rgba(255,211,77,.12); color: var(--gold); border-color: rgba(255,211,77,.35); }
button.ui-chip[aria-pressed="true"] { background: var(--green-tint); color: var(--green); border-color: rgba(52,219,135,.35); }

/* SG values + breakdown */
.sg-pos { color: var(--green); } .sg-neg { color: var(--red); } .sg-flat { color: var(--text-secondary); }
.sg-value { font-variant-numeric: tabular-nums; }
.sg-breakdown { display: flex; align-items: center; }
.sg-cell { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.sg-cell .sg-value { font-size: 15px; font-weight: 700; }
.sg-cell.emph .sg-value { font-size: 17px; font-weight: 800; }
.sg-divider { width: 1px; height: 40px; background: var(--border); flex: none; }
.hc-equiv {
  font-size: 9px; font-weight: 500; color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: var(--radius-pill);
}

/* Stat tile */
.stat-tile {
  position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0;
  padding: var(--space-md); border-radius: var(--radius-md);
  background: var(--surface-card); border: 1px solid var(--border);
}
.stat-tile .st-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-tile .st-line { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.stat-tile.rating-good { background: var(--green-tint); border-color: rgba(52,219,135,.40); }
.stat-tile.rating-ok { background: var(--amber-tint); border-color: rgba(255,184,61,.40); }
.stat-tile.rating-poor { background: var(--red-tint); border-color: rgba(250,92,107,.40); }
.stat-tile.rating-good .st-value { color: var(--green); }
.stat-tile.rating-ok .st-value { color: var(--amber); }
.stat-tile.rating-poor .st-value { color: var(--red); }
.stat-tile[class*="rating-"]:not(.rating-neutral)::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 2px;
  background: currentColor;
}
.stat-tile.rating-good::before { color: var(--green); }
.stat-tile.rating-ok::before { color: var(--amber); }
.stat-tile.rating-poor::before { color: var(--red); }

/* Expected range + trend badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px; align-self: flex-start;
  padding: 2px 6px; border-radius: var(--radius-pill);
  font-size: 10px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.badge svg { width: 10px; height: 10px; flex: none; }
.badge-good { color: var(--green); background: rgba(52,219,135,.12); }
.badge-ok { color: var(--amber); background: rgba(255,184,61,.12); }
.badge-poor { color: var(--red); background: rgba(250,92,107,.12); }
.badge-neutral { color: var(--text-primary); background: rgba(255,255,255,.12); }
.trend { font-size: 11px; font-weight: 600; padding: 2px 5px; gap: 2px; }
.trend-up { color: var(--green); background: rgba(52,219,135,.14); }
.trend-down { color: var(--red); background: rgba(250,92,107,.14); }
.trend-flat { color: var(--text-secondary); background: rgba(255,255,255,.10); }

/* Hero banner (logo + wordmark) */
.hero-banner { display: flex; align-items: center; gap: 14px; padding: 4px 0; }
.hero-logo {
  width: 60px; height: 60px; border-radius: var(--radius-md); flex: none; object-fit: cover;
  box-shadow: 0 0 10px rgba(52, 219, 135, 0.35), 0 3px 5px rgba(0, 0, 0, 0.45);
}
.wordmark { font-size: 22px; font-weight: 800; letter-spacing: -0.4px; line-height: 1.15; }
.wordmark .ai { color: var(--gold); }
.hero-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 5px; }
.hero-tag {
  margin-left: auto; padding: 5px 10px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase;
  color: var(--green); background: var(--green-tint); border: 1px solid rgba(52,219,135,.35);
}

/* Avatar */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; background: var(--grad-brand); border: 1px solid var(--border);
  font-weight: 800; color: var(--text-primary); text-transform: uppercase;
}

/* Loading / error / empty */
.ui-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.18); border-top-color: var(--green);
  animation: ui-spin .8s linear infinite; display: inline-block;
}
.ui-spinner-sm { width: 16px; height: 16px; }
.loading { display: flex; justify-content: center; padding: var(--space-xl); }
.loading-error { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: var(--space-lg); text-align: center; color: var(--text-secondary); }
.loading-error svg { width: 34px; height: 34px; color: var(--amber); }
.ui-empty { display: flex; align-items: center; gap: var(--space-md); color: var(--text-secondary); font-size: 15px; }
.ui-empty svg { width: 20px; height: 20px; color: var(--text-tertiary); flex: none; }
.form-error { color: var(--red); font-size: 13px; text-align: center; }

/* Toast */
.ui-toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); display: flex; justify-content: center; z-index: 2000; pointer-events: none; }
.ui-toast {
  background: var(--surface-raised); border: 1px solid var(--border-strong);
  padding: 10px 16px; border-radius: var(--radius-pill); font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); animation: ui-fade .2s ease;
}
.ui-toast.err { border-color: rgba(250,92,107,.5); color: var(--red); }
@media (min-width: 768px) { .ui-toast-host { bottom: 24px; } }

/* Sheet: bottom sheet on phones, centered dialog on desktop */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 1500; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
  animation: ui-fade .18s ease;
}
.sheet {
  width: 100%; max-height: 90vh; display: flex; flex-direction: column;
  background: var(--surface-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding-bottom: var(--safe-bottom);
}
.sheet-grab { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-md) var(--space-lg); }
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-close { color: var(--text-secondary); font-size: 22px; line-height: 1; padding: 4px 8px; }
.sheet-body { padding: 0 var(--space-lg) var(--space-lg); overflow-y: auto; }
@media (min-width: 768px) {
  .sheet-backdrop { align-items: center; }
  .sheet { width: min(520px, calc(100vw - 48px)); border-radius: var(--radius-lg); padding-bottom: 0; }
  .sheet-grab { display: none; }
}

/* SG trend chart */
.sg-chart { position: relative; }
.sg-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.sg-chart .axis-label { font-size: 10px; fill: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.sg-chart .zero-line { stroke: rgba(255,255,255,.35); stroke-dasharray: 4 4; }
.sg-chart .grid-line { stroke: var(--border); }
.sg-chart .hover-line { stroke: var(--border-strong); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px;
  background: var(--surface-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
}
.chart-tip .tip-date { color: var(--text-secondary); margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; justify-content: space-between; gap: 12px; }
