/* mdfi portal components. Built only from tokens (tokens.css, synced from design/tokens.css).
   Reference: design/index.html. Class prefix m-, BEM-style modifiers. */

@font-face { font-family: "mdfi Serif"; font-style: normal; font-weight: 400; font-display: swap; src: url("/static/fonts/mdfi-serif-regular.woff2") format("woff2"); }
@font-face { font-family: "mdfi Serif"; font-style: italic; font-weight: 400; font-display: swap; src: url("/static/fonts/mdfi-serif-italic.woff2") format("woff2"); }
@font-face { font-family: "mdfi Serif"; font-style: normal; font-weight: 700; font-display: swap; src: url("/static/fonts/mdfi-serif-bold.woff2") format("woff2"); }

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

/* Visually hidden, still read by screen readers (hidden would remove it from both). */
.m-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: var(--text-body);
  line-height: var(--leading-prose);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); text-underline-offset: 0.18em; }
a:hover { color: var(--ink); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }

/* ---------- layout ---------- */

.m-shell { min-height: 100vh; display: flex; flex-direction: column; }

.m-main {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: var(--content-max);
  padding: var(--space-6) var(--space-4) var(--space-8);
}

.m-page-head { margin-bottom: var(--space-6); }
.m-page-head .m-lede { margin-top: var(--space-2); }

.m-stack > * + * { margin-top: var(--space-5); }
.m-stack--tight > * + * { margin-top: var(--space-3); }

.m-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.m-row--between { justify-content: space-between; }

.m-panel {
  background: var(--ground-rise);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}
.m-panel > :first-child { margin-top: 0; }
.m-panel > :last-child { margin-bottom: 0; }

.m-narrow { max-width: 28rem; margin: 0 auto; padding: var(--space-8) var(--space-4); }

.m-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }

/* ---------- navigation ---------- */

.m-nav {
  background: var(--ground-sunk);
  border-bottom: 1px solid var(--rule);
  padding: var(--space-2) var(--space-4);
}

.m-nav__bar { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap); }

.m-wordmark {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.m-wordmark span { color: var(--accent); }

.m-nav__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.m-nav__list { list-style: none; margin: var(--space-2) 0 0; padding: 0; }
.m-nav__list[hidden] { display: none; }

.m-nav__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border-left: 2px solid transparent;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: var(--text-sm);
}
.m-nav__item svg { width: 1.25rem; height: 1.25rem; flex: none; }
.m-nav__item:hover { color: var(--ink); background: var(--ground); }
.m-nav__item--active { color: var(--ink); border-left-color: var(--accent); background: var(--ground); }

.m-nav__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-3);
  border-top: 1px solid var(--rule);
  font-size: var(--text-sm);
}
.m-nav__user-text { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.m-nav__user-text strong { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 400; color: var(--ink); }

@media (min-width: 56.25em) {
  .m-shell { flex-direction: row; }
  .m-nav {
    position: sticky;
    top: 0;
    width: 15rem;
    flex: none;
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-bottom: 0;
    border-right: 1px solid var(--rule);
    padding: var(--space-5) var(--space-3);
  }
  .m-nav__bar { padding: 0 var(--space-3) var(--space-4); }
  .m-nav__toggle { display: none; }
  .m-nav__list, .m-nav__list[hidden] { display: block; flex: 1; }
  .m-nav__body { display: flex; flex-direction: column; flex: 1; }
  .m-main { padding: var(--space-7) var(--space-7) var(--space-8); }
}

/* ---------- text ---------- */

.m-h1, .m-h2, .m-h3 { font-family: var(--font-serif); color: var(--ink); margin: 0; line-height: var(--leading-tight); }
.m-h1 { font-size: var(--text-2xl); font-weight: 400; letter-spacing: -0.01em; }
.m-h2 { font-size: var(--text-xl); font-weight: 400; }
.m-h3 { font-size: var(--text-lg); font-weight: 700; }
.m-lede { color: var(--ink-soft); max-width: var(--measure); margin: 0; }
.m-soft { color: var(--ink-soft); }
.m-small { font-size: var(--text-sm); }
.m-mono { font-family: var(--font-mono); font-size: var(--text-sm); line-height: var(--leading-mono); }
.m-prose { max-width: var(--measure); }

/* ---------- buttons ---------- */

.m-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--text-sm);
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-quick) var(--ease-out), border-color var(--dur-quick) var(--ease-out), color var(--dur-quick) var(--ease-out);
}
.m-button:disabled, .m-button[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.m-button--primary { background: var(--accent-ink); color: var(--on-accent); }
.m-button--primary:hover:not(:disabled), .m-button--primary.is-hover { background: var(--ink); color: var(--ground-rise); }

.m-button--secondary { background: transparent; border-color: var(--rule-strong); color: var(--ink); }
.m-button--secondary:hover:not(:disabled), .m-button--secondary.is-hover { border-color: var(--ink); color: var(--ink); }

.m-button--quiet { background: transparent; color: var(--accent-ink); padding: 0 var(--space-2); }
.m-button--quiet:hover:not(:disabled), .m-button--quiet.is-hover { color: var(--ink); }

.m-button--danger { background: transparent; border-color: var(--egress); color: var(--egress); }
.m-button--danger:hover:not(:disabled), .m-button--danger.is-hover { background: var(--egress); color: var(--ground-rise); }

.m-button--block { width: 100%; }

/* ---------- forms ---------- */

.m-field { display: block; }
.m-field + .m-field { margin-top: var(--space-4); }
.m-grid > .m-field + .m-field, .m-row > .m-field + .m-field { margin-top: 0; }
.m-label { display: block; margin-bottom: var(--space-1); font-size: var(--text-sm); color: var(--ink); }

.m-input, .m-textarea, .m-select {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  background: var(--ground-sunk);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-body);
}
.m-textarea { font-family: var(--font-mono); font-size: var(--text-sm); line-height: var(--leading-mono); min-height: 16rem; }
.m-input:focus, .m-textarea:focus, .m-select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.m-input[aria-invalid="true"], .m-textarea[aria-invalid="true"] { border-color: var(--egress); }

.m-check { display: flex; align-items: center; gap: var(--space-2); min-height: var(--tap); font-size: var(--text-sm); }
.m-check input { width: 1.125rem; height: 1.125rem; accent-color: var(--accent-ink); }

.m-field__hint { margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--ink-soft); }
.m-field__error { margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--egress); }

/* ---------- feedback ---------- */

.m-message {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--ground-rise);
  font-size: var(--text-sm);
}
.m-message p { margin: 0; }
.m-message--success { border-left-color: var(--contained); }
.m-message--success strong { color: var(--contained); }
.m-message--problem { border-left-color: var(--egress); }
.m-message--problem strong { color: var(--egress); }
.m-message__close { background: none; border: 0; color: var(--ink-soft); cursor: pointer; font: inherit; min-width: var(--tap); min-height: var(--tap); margin: calc(-1 * var(--space-3)) calc(-1 * var(--space-3)) 0 0; }

.m-empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--ink-soft); }

/* ---------- data ---------- */

.m-table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius-md); background: var(--ground-rise); }
.m-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.m-table th, .m-table td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--rule); overflow-wrap: break-word; vertical-align: top; }
.m-table th { font-weight: 400; color: var(--ink-soft); background: var(--ground-sunk); }
.m-table tr:last-child td { border-bottom: 0; }
.m-table th.m-num { font-family: inherit; }
.m-num { text-align: right !important; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }

.m-figure { font-family: var(--font-mono); font-size: var(--text-2xl); line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.m-figure small { font-size: var(--text-sm); color: var(--ink-soft); }

.m-meter { height: 0.375rem; margin-top: var(--space-3); background: var(--ground-sunk); border-radius: var(--radius-sm); overflow: hidden; }
.m-meter__fill { height: 100%; width: var(--fill, 0%); background: var(--accent); animation: m-fill var(--dur-reveal) var(--ease-out); }
@keyframes m-fill { from { width: 0; } }
.m-meter--near .m-meter__fill { background: var(--egress); }

.m-score {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--ink-soft);
}
.m-score--ok { border-color: var(--contained); color: var(--contained); }
.m-score--low { border-color: var(--egress); color: var(--egress); }

.m-tile {
  position: relative;
  aspect-ratio: 3 / 4;
  padding: var(--space-2);
  background: var(--ground-rise);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-faint);
  transition: transform var(--dur-move) var(--ease-out), border-color var(--dur-quick) var(--ease-out);
}
.m-tile--working { border-color: var(--accent); color: var(--accent-ink); }
.m-tile--ready { border-color: var(--contained); color: var(--contained); }
.m-tile--low { border-color: var(--egress); color: var(--egress); transform: translateY(-0.5rem); box-shadow: var(--lift); }
.m-tile--off { border-style: dashed; }

.m-table-label { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--accent-ink); }

.m-code {
  position: relative;
  margin: 0;
  padding: var(--space-4);
  padding-right: calc(var(--space-4) + 4.5rem);
  background: var(--ground-sunk);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
}
.m-code--scroll { white-space: pre; overflow-wrap: normal; overflow-x: auto; }

.m-copy {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  background: var(--ground-rise);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font: inherit;
  font-family: var(--font-serif);
  font-size: var(--text-xs);
  cursor: pointer;
}
.m-copy:hover { color: var(--ink); border-color: var(--rule-strong); }

.m-key {
  display: block;
  padding: var(--space-3) var(--space-4);
  background: var(--ground-sunk);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
  user-select: all;
}

@media (max-width: 35.99em) {
  .m-panel { padding: var(--space-4); }
  .m-code { padding: calc(var(--space-3) + var(--tap)) var(--space-3) var(--space-3); }
}

/* ---------- plans ---------- */

.m-plan { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); background: var(--ground-rise); border: 1px solid var(--rule); border-radius: var(--radius-md); }
.m-plan__price { font-family: var(--font-mono); font-size: var(--text-xl); color: var(--ink); }
.m-plan__price small { font-family: var(--font-serif); font-size: var(--text-sm); color: var(--ink-soft); }
.m-plan ul { margin: 0; padding-left: var(--space-5); color: var(--ink-soft); font-size: var(--text-sm); }
.m-plan .m-button { margin-top: auto; }
.m-plan--current { border-color: var(--contained); }
.m-plan__badge { align-self: flex-start; font-size: var(--text-xs); color: var(--contained); border: 1px solid var(--contained); border-radius: var(--radius-sm); padding: 0 var(--space-2); }

/* ---------- savings ---------- */

.m-savings { background: var(--ground-rise); border: 1px solid var(--rule); border-radius: var(--radius-md); }
.m-savings__row { display: grid; grid-template-columns: 7rem 1fr auto; gap: var(--space-3); align-items: baseline; padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--rule); font-size: var(--text-sm); }
.m-savings__row:last-child { border-bottom: 0; }
.m-savings__provider { color: var(--ink); }
.m-savings__value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.m-savings__row--saving .m-savings__value { color: var(--contained); font-size: var(--text-lg); }
.m-savings__row--notyet { color: var(--ink-soft); }
.m-savings__row--unmeasured { color: var(--ink-faint); }
.m-savings__row--unmeasured .m-savings__provider { color: var(--ink-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
