/* ============================================================
   HEALTH ANALYTICS ENGINE — styles
   Follows the existing design-system variables from style.css
   ============================================================ */

/* ── Section wrapper ──────────────────────────────────────── */
.ha-section {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.ha-section-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ha-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: .01em;
}
.ha-section-subtitle {
  font-size: 11px;
  color: var(--ink-2);
}
.ha-section-subtitle em {
  color: var(--amber);
  font-style: normal;
  font-weight: 600;
}

/* ── Score card row ───────────────────────────────────────── */
.ha-score-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
@media (max-width: 780px) {
  .ha-score-row {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (max-width: 480px) {
  .ha-score-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Score card ───────────────────────────────────────────── */
.ha-score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease), transform 120ms var(--ease);
  user-select: none;
  text-align: center;
}
.ha-score-card:hover {
  border-color: var(--brand);
  box-shadow: var(--sh-sm);
  transform: translateY(-2px);
}
.ha-score-card--active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(124,58,237,.12), var(--sh-sm);
}
.ha-gauge-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}
.ha-gauge-outer {
  position: relative;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  border: 5px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Scale wrapper — animates from 0 → target on load */
.ha-gauge-scale {
  position: absolute;
  inset: 0;
  transform: scale(0);
  transform-origin: center;
  transition: transform 0.7s cubic-bezier(0.25, 0.8, 0.4, 1);
}

/* Colored blob — morphs border-radius for liquid feel */
.ha-gauge-blob {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}
.ha-gauge-blob--slosh {
  animation: ha-slosh 4s ease-in-out infinite;
}
@keyframes ha-slosh {
  0%   { border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%; }
  18%  { border-radius: 60% 40% 55% 45% / 44% 56% 40% 60%; }
  36%  { border-radius: 44% 56% 46% 54% / 58% 42% 58% 42%; }
  54%  { border-radius: 56% 44% 42% 58% / 40% 60% 44% 56%; }
  72%  { border-radius: 42% 58% 60% 40% / 60% 40% 56% 44%; }
  90%  { border-radius: 58% 42% 48% 52% / 46% 54% 42% 58%; }
  100% { border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%; }
}

.ha-gauge-pct {
  position: relative;
  z-index: 1;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.03em;
  text-shadow: 0 1px 5px rgba(0,0,0,.45);
}
.ha-card-name {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-2);
  line-height: 1.3;
}
.ha-card-desc {
  font-size: 9.5px;
  line-height: 1.45;
  color: var(--ink-2);
  opacity: .7;
  margin-top: 2px;
}
.ha-card-raw {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
}
.ha-card-status {
  align-self: center;
}

/* ── Top overview ─────────────────────────────────────────── */
.ha-overview {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr);
  gap: 14px;
}
@media (max-width: 920px) {
  .ha-overview {
    grid-template-columns: 1fr;
  }
}
.ha-overview-hero,
.ha-overview-side,
.ha-insight-card,
.ha-raw-panel {
  background: linear-gradient(180deg, rgba(13,18,36,.92), rgba(8,12,24,.98));
  border: 1px solid rgba(124,58,237,.18);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(4,7,16,.24);
}
.ha-overview-hero {
  padding: 22px 22px 18px;
}
.ha-top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
@media (max-width: 720px) {
  .ha-top-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}
.ha-top-actions span {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148,163,184,.18);
  background: rgba(255,255,255,.03);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
}
.ha-top-checkin {
  border: none;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 12px;
  font-weight: 800;
  color: white;
  background: linear-gradient(90deg, #ff5b61, #ff7b63);
  box-shadow: 0 10px 24px rgba(255,91,97,.26);
  cursor: pointer;
}
.ha-master-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin-top: 10px;
}
@media (max-width: 720px) {
  .ha-master-row {
    grid-template-columns: 1fr;
  }
}
.ha-master-score {
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--ha-master) 55%, transparent);
  background: color-mix(in srgb, var(--ha-master) 10%, rgba(255,255,255,.03));
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ha-master-score span {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #94a3b8;
}
.ha-master-score strong {
  font-size: 46px;
  line-height: .95;
  color: #f8fafc;
}
.ha-master-score small {
  font-size: 13px;
  font-weight: 700;
  color: var(--ha-master);
}
.ha-master-copy h3 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.05;
  color: #f8fafc;
}
.ha-master-copy p {
  margin: 0;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.6;
}
.ha-master-limiter {
  margin-top: 12px;
  color: #fbbf24;
  font-size: 12px;
  font-weight: 700;
}
.ha-overview-kicker,
.ha-insight-kicker {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #94a3b8;
}
.ha-overview-hero h3,
.ha-insight-card h4 {
  margin: 10px 0 8px;
  font-size: 26px;
  line-height: 1.08;
  color: #f8fafc;
}
.ha-overview-hero p,
.ha-insight-card p {
  margin: 0;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.6;
}
.ha-method-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.ha-method-row span {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  color: #cbd5e1;
  background: rgba(148,163,184,.10);
  border: 1px solid rgba(148,163,184,.16);
}
.ha-overview-side {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.ha-mini-metric {
  padding: 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(148,163,184,.12);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ha-mini-metric span {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #94a3b8;
}
.ha-mini-metric strong {
  font-size: 24px;
  line-height: 1;
  color: #f8fafc;
}
.ha-mini-metric small {
  color: #cbd5e1;
  font-size: 11px;
  line-height: 1.4;
}
.ha-driver-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ha-driver-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}
.ha-driver-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ha-driver-list span {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(245,158,11,.10);
  border: 1px solid rgba(245,158,11,.24);
  color: #fbbf24;
  font-size: 11px;
  font-weight: 700;
}
.ha-insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 920px) {
  .ha-insight-grid {
    grid-template-columns: 1fr;
  }
}
.ha-insight-card {
  padding: 18px;
}

/* ── Raw signal context ───────────────────────────────────── */
.ha-raw-panel {
  padding: 16px 18px;
}
.ha-raw-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
@media (max-width: 720px) {
  .ha-raw-head {
    flex-direction: column;
  }
}
.ha-raw-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ha-raw-meta span {
  font-size: 11px;
  color: #94a3b8;
}
.ha-raw-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 900px) {
  .ha-raw-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 520px) {
  .ha-raw-grid {
    grid-template-columns: 1fr;
  }
}
.ha-raw-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(148,163,184,.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ha-raw-item span {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #94a3b8;
}
.ha-raw-item strong {
  color: #f8fafc;
  font-size: 18px;
  line-height: 1.15;
}

/* ── Pills (status badges) ────────────────────────────────── */
.ha-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.ha-green  { background: #dcfce7; color: #166534; }
.ha-blue   { background: #dbeafe; color: #1e40af; }
.ha-amber  { background: #fef3c7; color: #92400e; }
.ha-red    { background: #fee2e2; color: #991b1b; }
.ha-red-dark { background: #fca5a5; color: #7f1d1d; }
.ha-gray   { background: var(--surface-2); color: var(--ink-2); }

.ha-reduce   { background: #fee2e2; color: #991b1b; }
.ha-maintain { background: #fef3c7; color: #92400e; }
.ha-progress { background: #dcfce7; color: #166534; }
.ha-rest     { background: #e0e7ff; color: #3730a3; }

/* ── Detail panel ─────────────────────────────────────────── */
.ha-detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: cardIn 0.2s var(--ease);
}
.ha-detail-panel.hidden { display: none; }

.ha-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.ha-detail-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.ha-detail-summary {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 4px;
  line-height: 1.55;
}
.ha-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: background 120ms;
}
.ha-close-btn:hover { background: var(--surface-2); }

.ha-recommendation {
  align-self: flex-start;
}

/* ── Factor table ─────────────────────────────────────────── */
.ha-factor-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.ha-factor-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 2px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.ha-factor-row:last-child { border-bottom: none; }
.ha-factor-row:nth-child(even) { background: var(--surface-2); }

.ha-factor-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.ha-factor--positive .ha-factor-indicator { background: #22c55e; }
.ha-factor--neutral  .ha-factor-indicator { background: #94a3b8; }
.ha-factor--negative .ha-factor-indicator { background: #ef4444; }

.ha-factor-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  grid-column: 2;
  grid-row: 1;
}
.ha-factor-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  text-align: right;
  grid-column: 3;
  grid-row: 1;
  white-space: nowrap;
}
.ha-factor-explanation {
  font-size: 11px;
  color: var(--ink-2);
  grid-column: 2 / 4;
  grid-row: 2;
  line-height: 1.45;
}

/* ── Reference / data-source ──────────────────────────────── */
.ha-reference {
  font-size: 10px;
  color: var(--faint);
  border-top: 1px solid var(--border);
  padding-top: 10px;
  line-height: 1.4;
}
.ha-data-source {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-2);
}
.ha-btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color 120ms, color 120ms;
}
.ha-btn-ghost:hover { border-color: var(--brand); color: var(--brand); }

/* ── Import panel ─────────────────────────────────────────── */
.ha-import-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ha-import-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.ha-import-hint {
  font-size: 11px;
  color: var(--ink-2);
  line-height: 1.5;
}
.ha-import-textarea {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  resize: vertical;
  min-height: 80px;
  color: var(--ink);
  width: 100%;
  box-sizing: border-box;
}
.ha-import-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Empty / loading state ────────────────────────────────── */
.ha-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--ink-2);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.ha-empty-icon {
  font-size: 28px;
  opacity: .4;
}
