/* ==========================================================================
   Healthdash — Clinical Instrument Panel
   Dark theme, data-dense, glanceable health intelligence
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Tokens --- */
:root {
  --bg-root:     #0f0f0f;
  --bg-card:     #1a1a1a;
  --bg-card-hover: #1e1e1e;
  --bg-surface:  #141414;
  --border:      #2a2a2a;
  --border-light:#222;

  --text-primary:   #f0f0f0;
  --text-secondary: #aaa;
  --text-tertiary:  #666;
  --text-dim:       #555;
  --text-faint:     #444;

  --green:   #4caf70;
  --amber:   #f0a500;
  --red:     #e05555;
  --blue:    #4a9edd;
  --cyan:    #5ec4c4;

  --green-bg:  #0d2210;
  --green-bdr: #1a3a20;
  --amber-bg:  #2a1f00;
  --amber-bdr: #3d2e00;
  --red-bg:    #2a1010;
  --red-bdr:   #3d1a1a;
  --blue-bg:   #0d1a2a;
  --blue-bdr:  #1a2e44;

  --font-body:  'DM Sans', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', 'SF Mono', 'Consolas', monospace;

  --radius:    8px;
  --radius-sm: 6px;
  --radius-lg: 12px;

  --nav-height: 56px;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-root);
  color: var(--text-secondary);
  line-height: 1.55;
  min-height: 100vh;
}

/* --- Navigation --- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: rgba(15, 15, 15, 0.82);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 0;
}

.nav-brand {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-right: 2rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-brand .brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px rgba(76, 175, 112, 0.4);
  animation: pulse-dot 3s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px rgba(76, 175, 112, 0.4); }
  50% { opacity: 0.6; box-shadow: 0 0 3px rgba(76, 175, 112, 0.2); }
}

.nav-links {
  display: flex;
  gap: 2px;
  list-style: none;
}

.nav-links a {
  display: block;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-tertiary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  letter-spacing: 0.01em;
}

.nav-links a:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.04);
}

.nav-links a.active {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
  font-weight: 500;
}

/* --- Layout --- */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.page--wide {
  max-width: 100%;
  padding-left: 2rem;
  padding-right: 2rem;
}

.page-header {
  margin-bottom: 2rem;
}

.page-title {
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* --- Section titles --- */
.section-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.divider {
  border: none;
  border-top: 0.5px solid var(--border-light);
  margin: 1.75rem 0;
}

/* ==========================================================================
   Home — Morning Snapshot
   ========================================================================== */

.snapshot-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.snapshot-grid.grid-2x2 {
  grid-template-columns: repeat(2, 1fr);
}

.gauge {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
}

.gauge:hover {
  border-color: #333;
  transform: translateY(-1px);
}

/* Subtle top accent line */
.gauge::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--gauge-accent, var(--border));
  opacity: 0.7;
  border-radius: var(--radius) var(--radius) 0 0;
}

.gauge-label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.gauge-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.02em;
}

.gauge-unit {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dim);
  margin-left: 3px;
}

.gauge-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 6px;
}

.gauge-delta {
  font-size: 11px;
  font-weight: 500;
  margin-top: 4px;
  font-family: var(--font-mono);
}

.delta-up { color: var(--green); }
.delta-down { color: var(--red); }
.delta-neutral { color: var(--text-dim); }

/* Accent variants */
.gauge--green  { --gauge-accent: var(--green); }
.gauge--amber  { --gauge-accent: var(--amber); }
.gauge--red    { --gauge-accent: var(--red); }
.gauge--blue   { --gauge-accent: var(--blue); }
.gauge--cyan   { --gauge-accent: var(--cyan); }

/* --- Status bar for quick readout --- */
.status-bar {
  display: flex;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-size: 12px;
  color: var(--text-dim);
  align-items: center;
  flex-wrap: wrap;
}

.status-bar .status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-bar .status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
}

.status-bar .status-dot--amber { background: var(--amber); }
.status-bar .status-dot--red   { background: var(--red); }

.status-label {
  color: var(--text-tertiary);
}

.status-value {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

/* --- No-data states --- */
.no-data {
  font-size: 12.5px;
  color: var(--text-dim);
  font-style: italic;
  padding: 2rem 0;
}

/* ==========================================================================
   Check-in — Ported from kahunas_prep
   ========================================================================== */

.checkin-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 1.5rem;
}

.copy-btn {
  font-size: 12px;
  font-family: var(--font-body);
  padding: 5px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 0.5px solid #444;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.copy-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Flags */
.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.flag {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.flag-warn { background: var(--amber-bg); color: var(--amber); border: 0.5px solid var(--amber-bdr); }
.flag-good { background: var(--green-bg); color: var(--green); border: 0.5px solid var(--green-bdr); }
.flag-info { background: var(--blue-bg);  color: var(--blue);  border: 0.5px solid var(--blue-bdr); }

/* Metric grids */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.metric-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  border: 0.5px solid var(--border);
}

.metric-label {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1;
}

.metric-value span {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dim);
}

.metric-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
}

.metric-delta {
  font-size: 11px;
  font-weight: 500;
  margin-top: 3px;
  font-family: var(--font-mono);
}

/* Scale rows for scores */
.scale-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.scale-label {
  font-size: 13px;
  color: #ccc;
  width: 130px;
  flex-shrink: 0;
}

.scale-track {
  flex: 1;
  height: 5px;
  background: #1e1e1e;
  border-radius: 3px;
  overflow: hidden;
}

.scale-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease-out;
}

.scale-num {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  width: 22px;
  text-align: right;
  color: var(--text-primary);
}

.scale-context {
  font-size: 11px;
  color: var(--text-dim);
  width: 220px;
  text-align: right;
  flex-shrink: 0;
}

.scale-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.6;
}

/* Narrative */
.narrative {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.75;
  border-left: 2px solid var(--blue);
}

.null-note {
  font-size: 12.5px;
  color: var(--text-dim);
  font-style: italic;
}

/* ==========================================================================
   Grafana Embed
   ========================================================================== */

.grafana-embed-wrap {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 0.5rem;
  /* Container clips the scaled iframe */
  position: relative;
}

.grafana-embed-wrap iframe {
  display: block;
  border: none;
  background: var(--bg-root);
  /* Scale trick: render at larger size, then shrink to fit.
     The iframe is 1/.75 = 133% wide/tall, then scaled to 75%,
     so it visually fills 100% of the container without scrolling. */
  --scale: 0.9;
  width: calc(100% / var(--scale));
  height: calc(100vh / var(--scale));
  transform: scale(var(--scale));
  transform-origin: 0 0;
}

/* The container needs an explicit height to match the visual size */
.grafana-embed-wrap {
  height: calc(100vh - var(--nav-height) - 110px);
  min-height: 600px;
}

/* ==========================================================================
   Correlations
   ========================================================================== */

.corr-summary {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  font-family: var(--font-mono);
}

.corr-finding {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

.corr-finding:hover {
  border-color: #333;
}

.corr-finding--exploratory {
  border-left: 2px solid var(--amber);
}

.corr-interp {
  font-size: 15px;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: 8px;
}

.corr-detail {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.corr-detail-pair {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
}

.corr-detail-pair .arrow {
  color: var(--text-faint);
  margin: 0 4px;
}

.lag-badge {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-dim);
  background: rgba(255,255,255,0.04);
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
}

.corr-detail-stats {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
}

.r-value { font-weight: 500; }
.r-pos { color: var(--green); }
.r-neg { color: var(--red); }

.corr-none {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
  font-size: 13px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
  .nav {
    padding: 0 1rem;
    overflow-x: auto;
  }

  .nav-brand { margin-right: 1rem; }
  .nav-links a { padding: 6px 10px; font-size: 12px; white-space: nowrap; }

  .page { padding: 1.5rem 1rem 3rem; }

  .snapshot-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-grid-3 {
    grid-template-columns: 1fr;
  }

  .scale-row {
    flex-wrap: wrap;
  }

  .scale-context {
    width: 100%;
    text-align: left;
    margin-top: 2px;
  }

  .grafana-embed-wrap iframe {
    height: calc(100vh - var(--nav-height) - 100px);
    min-height: 500px;
  }
}

@media (max-width: 480px) {
  .snapshot-grid {
    grid-template-columns: 1fr;
  }

  .gauge-value {
    font-size: 24px;
  }
}

/* --- Entrance animations --- */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.gauge,
.metric-card,
.corr-finding {
  animation: fade-up 0.35s ease-out both;
}

.gauge:nth-child(1) { animation-delay: 0.03s; }
.gauge:nth-child(2) { animation-delay: 0.06s; }
.gauge:nth-child(3) { animation-delay: 0.09s; }
.gauge:nth-child(4) { animation-delay: 0.12s; }
.gauge:nth-child(5) { animation-delay: 0.15s; }
.gauge:nth-child(6) { animation-delay: 0.18s; }

.corr-finding:nth-child(1) { animation-delay: 0.03s; }
.corr-finding:nth-child(2) { animation-delay: 0.06s; }
.corr-finding:nth-child(3) { animation-delay: 0.09s; }
.corr-finding:nth-child(4) { animation-delay: 0.12s; }
.corr-finding:nth-child(5) { animation-delay: 0.15s; }
.corr-finding:nth-child(6) { animation-delay: 0.18s; }
.corr-finding:nth-child(7) { animation-delay: 0.21s; }
.corr-finding:nth-child(8) { animation-delay: 0.24s; }

/* ==========================================================================
   Insights
   ========================================================================== */

.insight-card {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 18px 22px;
  border-left: 2px solid var(--cyan);
  animation: fade-up 0.35s ease-out both;
}

.insight-card--empty {
  border-left-color: var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.insight-content {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.75;
}

.insight-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 10px;
  font-family: var(--font-mono);
}

.generate-btn {
  font-size: 12px;
  font-family: var(--font-body);
  padding: 5px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  background: rgba(94, 196, 196, 0.1);
  border: 0.5px solid rgba(94, 196, 196, 0.3);
  color: var(--cyan);
  transition: background 0.15s, color 0.15s;
}

.generate-btn:hover {
  background: rgba(94, 196, 196, 0.18);
  color: #7dd4d4;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }
