/**
 * Arbor (K5) — Sponsor Dashboard Styles
 *
 * Colour and type come from ../shared/brand.css (Brandbook §3/§4). No hex
 * literals live in this file — the previous palette (#1F6F6B / #155551 /
 * #E2F0EF / #152226 / #5C6B72 / #c8d3d8 / #B23A2E) was the archived
 * CohortTrials teal and shared no colour with the Arbor brandbook.
 *
 * Contrast corrections made here:
 *   - disclaimer banner was #9A6B00 on #FBF0D6 (4.14:1) -> --flint-text on
 *     --flint-surface (6.05:1)
 *   - .topbar-subtitle / .topbar-user were white at 75%/90% opacity on the
 *     header (4.11:1) -> full-opacity --mist
 *   - .chip-green/.chip-active were #1E7F4F on #E3F3EA (4.35:1) -> --ok on --ok-bg
 *   - input borders were #c8d3d8 on white (1.53:1, below the 3:1 required of a
 *     non-text UI boundary) -> --border-input
 *   - `.field input:focus { outline: none }` plus a 12%-opacity box-shadow is
 *     not a perceivable focus indicator; removed so brand.css :focus-visible
 *     applies.
 */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--chalk);
  color: var(--bark);
  line-height: 1.5;
  min-height: 100vh;
}

/* Programmatic focus on a view container should not paint a ring. */
main:focus, main:focus-visible { outline: none; }

/* ---- Brand mark ---- */
.brand-mark-branch { fill: none; stroke: var(--mist); stroke-linecap: round; }
.brand-mark-leaf { fill: var(--paper); }
.brand-mark-leaf-soft { fill: var(--lichen); }

/* ---- Native dialog ---- */
dialog {
  border: none; border-radius: 12px;
  padding: 24px; max-width: 480px; width: calc(100% - 32px);
  background: var(--paper); color: var(--bark);
  font-family: var(--font-body);
  box-shadow: 0 12px 32px rgba(42, 42, 42, 0.28);
}
dialog::backdrop { background: rgba(42, 42, 42, 0.45); }
dialog h2 { margin-bottom: 12px; font-size: var(--fs-h3); }
dialog p { margin-bottom: 4px; white-space: pre-line; }
dialog .dialog-actions {
  display: flex; gap: 12px; justify-content: flex-end; margin-top: 16px;
}
dialog .dialog-actions button {
  min-height: 44px; padding: 0 20px; border-radius: var(--radius);
  border: 1px solid var(--grove); background: var(--grove); color: var(--paper);
  font-family: inherit; font-weight: 600; cursor: pointer; font-size: 0.95rem;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--grove);
  color: var(--paper);
  padding: 0 24px;
  min-height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-title {
  font-family: var(--font-heading);
  font-size: 1.125rem; font-weight: 600; letter-spacing: -0.01em;
}
.topbar-subtitle { font-size: 0.8rem; color: var(--mist); margin-left: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: 0.85rem; color: var(--mist); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 20px;
  min-height: 40px;
  transition: background 0.15s, border-color 0.15s;
}
.btn:disabled { cursor: progress; opacity: 0.65; }
.btn-primary { background: var(--grove); color: var(--paper); }
.btn-primary:hover:not(:disabled) { background: var(--canopy); }
.btn-outline { background: transparent; color: var(--mist); border: 1.5px solid var(--mist); }
.btn-outline:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
.btn-outline-dark {
  background: var(--paper); color: var(--grove); border: 1.5px solid var(--border-input);
}
.btn-outline-dark:hover:not(:disabled) { background: var(--mist); border-color: var(--canopy); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; min-height: 34px; }
.btn-full { width: 100%; }

.btn.is-busy::before {
  content: '';
  width: 0.85em; height: 0.85em; margin-right: 0.5em;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%;
  animation: arbor-spin 0.7s linear infinite;
}
@keyframes arbor-spin { to { transform: rotate(360deg); } }

.link-btn {
  background: none; border: none; padding: 4px 0;
  font-family: var(--font-body); font-size: 0.85rem; font-weight: 600;
  color: var(--grove); text-decoration: underline; cursor: pointer;
}
.link-btn:hover { color: var(--canopy); }

/* ---- Login / MFA ---- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 56px);
  padding: 24px;
}
.login-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-card);
}
.login-card h1 { font-size: var(--fs-h2); margin-bottom: 4px; }
.login-subtitle { color: var(--stone); margin-bottom: 24px; font-size: 0.9rem; }
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 0.85rem; font-weight: 600;
  color: var(--slate-fern); margin-bottom: 6px;
}
.field-hint { font-size: 0.75rem; color: var(--stone); margin-top: 6px; }
.field input, .select, .textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border-input);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--bark);
  background: var(--paper);
  transition: border-color 0.15s;
}
.field input:hover, .select:hover, .textarea:hover { border-color: var(--canopy); }
.error-msg { color: var(--danger); font-size: 0.85rem; min-height: 20px; margin-bottom: 8px; }

.mfa-alt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ---- Dashboard Layout ---- */
.dashboard { max-width: 1200px; margin: 0 auto; padding: 24px; }
.dashboard-title { font-size: var(--fs-h2); margin-bottom: 16px; }

.protocol-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-weight: 600;
  color: var(--slate-fern);
}
.protocol-bar .select { width: auto; min-width: 280px; }

.loading-indicator { font-size: 0.8rem; font-weight: 600; color: var(--stone); }
.loading-indicator.is-active::before {
  content: '';
  display: inline-block;
  width: 0.8em; height: 0.8em; margin-right: 0.45em;
  vertical-align: -0.05em;
  border: 2px solid var(--canopy); border-top-color: transparent;
  border-radius: 50%;
  animation: arbor-spin 0.7s linear infinite;
}

.disclaimer-banner {
  background: var(--flint-surface);
  color: var(--flint-text);
  border: 1px solid var(--flint);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
}

.load-error {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid var(--danger); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 20px;
  font-size: 0.88rem; font-weight: 600;
}
.load-error .btn { margin-left: auto; }

.panel-empty { font-size: 0.85rem; color: var(--stone); }

/* ---- KPI Tiles ---- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow-card);
  text-align: center;
}
.kpi-value {
  font-family: var(--font-heading);
  font-size: 2rem; font-weight: 600; color: var(--grove); line-height: 1.1;
}
.kpi-label {
  font-size: 0.8rem; color: var(--stone); margin-top: 6px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.kpi-sub { font-size: 0.75rem; color: var(--stone); margin-top: 4px; }
.kpi-card.better .kpi-value { color: var(--ok); }
.kpi-card.worse .kpi-value { color: var(--danger); }
.kpi-row[aria-busy="true"] .kpi-value { color: var(--stone); }

/* ---- Panels ---- */
.panel {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}
.panel[aria-busy="true"] { opacity: 0.65; }
.panel h2 { font-size: var(--fs-h3); margin-bottom: 16px; }
.panel-sub { font-size: 0.85rem; color: var(--stone); margin: -10px 0 16px; }

/* ---- Criteria submission ---- */
.textarea {
  resize: vertical; min-height: 120px; margin-bottom: 12px;
  font-size: 0.9rem;
}
.criteria-submit-result {
  margin-top: 14px; padding: 12px 14px; border-radius: 8px;
  background: var(--mist); font-size: 0.85rem; color: var(--bark);
}
.criteria-submit-result.error {
  background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger);
}
.criteria-submit-result ul { margin: 6px 0 0 20px; }
.criteria-submit-result p { margin-top: 8px; }

/* ---- Funnel Chart ---- */
.funnel-chart { display: flex; flex-direction: column; gap: 12px; }
.funnel-row { display: flex; align-items: center; gap: 12px; }
.funnel-label {
  width: 120px; font-size: 0.85rem; font-weight: 600;
  color: var(--slate-fern); text-align: right;
}
.funnel-bar-wrap {
  flex: 1; background: var(--mist); border-radius: 6px; height: 36px;
  position: relative; overflow: hidden;
}
.funnel-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--canopy), var(--grove));
  border-radius: 6px;
  transition: width 0.6s ease;
  min-width: 2px;
}
.funnel-count {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--bark);
}
.funnel-pct { width: 60px; font-size: 0.85rem; font-weight: 700; color: var(--grove); }
.funnel-drop { font-size: 0.75rem; color: var(--danger); margin-left: 8px; }

/* ---- Site Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--stone);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--mist); }
tbody tr:hover { background: var(--chalk); }

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}
.chip-active { background: var(--ok-bg); color: var(--ok); }
.chip-screening { background: var(--flint-surface); color: var(--flint-text); }
.chip-pending { background: var(--mist); color: var(--stone-on-mist); }
.chip-bottleneck { background: var(--danger-bg); color: var(--danger); }

/* ---- Insights ---- */
.insights-list { display: flex; flex-direction: column; gap: 10px; }
.insight-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--chalk);
  border: 1px solid var(--border);
  border-radius: 8px;
  border-left: 4px solid var(--danger);
}
.insight-pct {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--danger);
  min-width: 56px;
  text-align: center;
}
.insight-text { font-size: 0.85rem; color: var(--bark); flex: 1; }
.insight-type {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--danger-bg);
  color: var(--danger);
}

/* ---- Export ---- */
.export-panel { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.export-status { font-size: 0.85rem; color: var(--stone); margin-left: 8px; }

/* ---- Portfolio badge (Brandbook §7) ---- */
.portfolio-badge { padding: 8px 0 24px; text-align: center; }
.portfolio-badge p {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--stone-on-mist);
  margin: 0;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .dashboard { padding: 16px; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .funnel-label { width: 80px; font-size: 0.75rem; }
  .protocol-bar { flex-wrap: wrap; }
  .protocol-bar .select { min-width: 200px; }
  .export-panel { flex-wrap: wrap; }
}

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