/* ─ External Meridian Portal — minimal, neutral, no internal nav ─────────
   Intentionally light + restrained. This is a customer/partner-facing
   surface, not the internal Meridian dashboard. No nav rail, no analytics,
   no team navigation — just the magic-link sign-in and a per-persona
   landing shell. Phase 1+ swap richer per-persona content into the
   `#persona-content` slot in dashboard.html. */

:root {
  --bg:           #f7f9f6;
  --surface:     #ffffff;
  --border:      #e4eae0;
  --text:        #1a1f1c;
  --text-muted:  #5a665d;
  --accent:      #0a6e3a;       /* DRE green */
  --accent-ink:  #ffffff;
  --error:       #b3261e;
  --success:     #1a7a3d;
  --info:        #21506b;

  --radius:        10px;
  --radius-sm:     6px;
  --shadow-sm:     0 1px 2px rgba(20, 30, 25, 0.05);
  --shadow-md:     0 6px 24px rgba(20, 30, 25, 0.08);

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over elements that set an
   explicit `display` (e.g. .portal-status uses display:flex). Without this,
   `el.hidden = true` is silently ignored on those elements. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Portal sign-in (portal.html) ────────────────────────────────────── */
.portal-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.portal-shell {
  width: 100%;
  max-width: 460px;
}

.brand-mark {
  text-align: center;
  margin-bottom: 28px;
}
.brand-mark h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.brand-mark .brand-tagline {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.portal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-md);
}
.portal-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
}
.lede {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  background: #fdfdfd;
  color: var(--text);
}
input[type="email"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

button {
  margin-top: 14px;
  width: 100%;
  padding: 11px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease;
}
button:hover:not(:disabled) { background: #0c8043; }
button:disabled { opacity: 0.5; cursor: progress; }

.status {
  margin-top: 18px;
  font-size: 14px;
  min-height: 1.5em;
}
.status[data-kind="error"]   { color: var(--error); }
.status[data-kind="success"] { color: var(--success); }
.status[data-kind="info"]    { color: var(--info); }

.portal-footer {
  margin-top: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ── Dashboard (dashboard.html) ──────────────────────────────────────── */
.dashboard-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand-mark--compact {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.brand-name {
  font-weight: 600;
  color: var(--accent);
  font-size: 15px;
}
.brand-subname {
  font-size: 12px;
  color: var(--text-muted);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-greeting {
  color: var(--text-muted);
  font-size: 14px;
}
.dashboard-topbar button {
  margin-top: 0;
  width: auto;
  padding: 7px 14px;
  font-size: 13px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.dashboard-topbar button:hover:not(:disabled) {
  background: #f3f5f1;
  color: var(--text);
}

.dashboard-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 28px 64px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-sm);
}
.panel h1 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
}
.persona-note {
  margin-top: 18px;
  padding: 14px 16px;
  background: #f3f7ef;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
}
.persona-note span {
  font-weight: 600;
  color: var(--accent);
}

/* ══ Phase 1 — client portal dashboard ════════════════════════════════════ */
:root {
  --accent-soft:  #eef5ee;     /* tinted green surface */
  --warn:         #b5760a;
  --space-stack:  20px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* ── Topbar project switcher ──────────────────────────────────────────── */
.topbar-select select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: #fdfdfd;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px;
  max-width: 240px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%235a665d' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.topbar-select select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* ── Loading / empty / status ─────────────────────────────────────────── */
.portal-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 220px;
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
}
.panel-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
  padding: 28px 4px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  flex: none;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state[data-kind="error"] {
  color: var(--error);
  border-color: #e7c9c7;
  background: #fdf6f5;
}
.empty-state p { margin: 0; font-size: 14px; }

/* ── Project header ───────────────────────────────────────────────────── */
.project-view { animation: rise 240ms var(--ease, ease) both; }
.project-header { margin-bottom: 22px; }
.project-eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.project-header h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 34px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.project-sub {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 15px;
}

/* ── Tabs (ARIA tablist) ──────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
}
.tab {
  margin: 0;
  width: auto;
  padding: 12px 16px;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}
.tab:hover:not([aria-selected="true"]) { color: var(--text); }
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

.tabpanel { animation: rise 220ms var(--ease, ease) both; }
.tabpanel:focus-visible { outline: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Overview stat grid (bento) ───────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.stat-value {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

/* ── Production KPIs ──────────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi-card {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.kpi-card[data-tone="good"] { border-left-color: var(--success); }
.kpi-card[data-tone="ok"]   { border-left-color: var(--accent); }
.kpi-card[data-tone="warn"] { border-left-color: var(--warn); }
.kpi-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.kpi-value {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-card[data-tone="good"] .kpi-value { color: var(--success); }
.kpi-card[data-tone="warn"] .kpi-value { color: var(--warn); }
.kpi-sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Charts ───────────────────────────────────────────────────────────── */
.chart-card {
  padding: 20px 22px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.chart-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
}
.chart-box {
  position: relative;
  height: 320px;
}

/* ── Documents ────────────────────────────────────────────────────────── */
.doc-group { margin-bottom: 26px; }
.doc-group-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.doc-row:hover {
  border-color: #cdd9c8;
  box-shadow: var(--shadow-sm);
}
.doc-type {
  flex: none;
  min-width: 44px;
  padding: 4px 8px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
}
.doc-name {
  flex: 1 1 auto;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-status {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
}
.doc-download {
  margin: 0;
  width: auto;
  flex: none;
  padding: 7px 14px;
  font-size: 13px;
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .dashboard-topbar { flex-wrap: wrap; gap: 10px; padding: 12px 18px; }
  .dashboard-shell { padding: 20px 18px 56px; }
  .topbar-select select { max-width: 160px; }
  .chart-box { height: 260px; }
  .doc-name { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  .project-view, .tabpanel { animation: none; }
  .spinner { animation-duration: 1400ms; }
  .tab, .doc-row { transition: none; }
}
