/* public/css/app.css
 *
 * The component layer for every page that is not the landing page: the five
 * member-portal pages and the policy pages.
 *
 * ── What this replaced ────────────────────────────────────────────────────
 * Each portal page carried its own eight-line <style> block, and all five said
 * roughly the same thing:
 *
 *   body { font-family: Georgia, serif; margin: 0; background: #faf7f2; }
 *   nav  { display: flex; gap: 1.5rem; padding: 1rem 2rem; border-bottom: 1px solid #ddd; }
 *
 * Georgia on #faf7f2, with no relationship to the landing page a subscriber
 * had just paid through. That gap is the problem this file exists to close:
 * the portal is what somebody sees AFTER giving you money, and it looked like
 * an internal admin tool. The landing page promised an illuminated book of
 * hours; the product behind it looked like a database viewer.
 *
 * Depends on tokens.css. Load that first.
 */

@import url('./tokens.css');

/* ── Reset ─────────────────────────────────────────────────────────────── */

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

html {
  /* Anchored headings clear the sticky masthead instead of hiding under it. */
  scroll-padding-top: var(--space-8);
}

body {
  background: var(--parchment);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 19px;
  line-height: 1.65;
  /* Column flex with a growing main is what pins the footer to the bottom of a
   * short page. Without it, a page with one panel on it leaves the footer
   * floating mid-screen with a band of empty parchment underneath -- which
   * reads as a broken page rather than a short one.
   * dvh, not vh: on mobile Safari 100vh is taller than the visible viewport,
   * so the footer would sit just below the fold on every page. */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Removes the 300ms double-tap delay without disabling pinch zoom. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(152, 32, 31, 0.12);
}

/* The growing middle. Any direct child of body that is the main content. */
body > main,
body > .signin-wrap {
  flex: 1 0 auto;
}

body > .site-footer {
  flex-shrink: 0;
}

::selection {
  background: rgba(152, 32, 31, 0.15);
}

/* The same paper grain the landing page carries. Fixed and non-interactive, so
 * it costs one composited layer and nothing else. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 300;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Skip link ─────────────────────────────────────────────────────────── */

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: var(--space-4);
  z-index: 400;
  background: var(--rubric);
  color: var(--panel);
  padding: var(--space-3) var(--space-5);
  text-decoration: none;
  /* Moved off-screen rather than display:none, so it stays focusable. */
  transform: translateY(-200%);
  transition: transform var(--dur) var(--ease);
}

.skip-link:focus {
  transform: none;
}

/* ── Typography ────────────────────────────────────────────────────────── */

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  /* Stops a one-word last line on a two-line heading. */
  text-wrap: balance;
}

h1 {
  font-size: clamp(1.9rem, 5vw, 2.6rem);
  font-weight: 500;
}

h2 {
  font-size: clamp(1.4rem, 3.5vw, 1.8rem);
}

h3 {
  font-size: 1.2rem;
}

p {
  text-wrap: pretty;
}

a {
  color: var(--rubric);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* The red small-caps label the whole site uses to introduce a section. In
 * manuscripts the rubric is the instruction written in red; here it is the
 * quiet line above a heading that says what kind of thing follows. */
.rubric {
  display: block;
  font-family: var(--font-text);
  font-variant: small-caps;
  text-transform: lowercase;
  letter-spacing: 0.28em;
  font-size: 0.82rem;
  color: var(--rubric);
}

.muted {
  color: var(--ink-faded);
}

.gilt-rule {
  width: 220px;
  margin: var(--space-7) auto;
  border: none;
  border-top: 1px solid var(--gilt);
  position: relative;
}

.gilt-rule::after {
  content: '✠';
  position: absolute;
  top: -0.72em;
  left: 50%;
  transform: translateX(-50%);
  background: var(--parchment);
  padding: 0 14px;
  color: var(--gilt);
  font-size: 0.95rem;
}

/* ── Masthead and navigation ───────────────────────────────────────────── */

.masthead {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--parchment);
  border-bottom: 1px solid var(--rule);
  padding: var(--space-3) 5vw;
  /* Notched phones: keep the bar clear of the display cutout in landscape. */
  padding-left: max(5vw, env(safe-area-inset-left));
  padding-right: max(5vw, env(safe-area-inset-right));
}

.masthead-inner {
  max-width: var(--measure-wide);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.nav-mark {
  font-family: var(--font-display);
  font-variant: small-caps;
  text-transform: lowercase;
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.nav-mark .cross {
  color: var(--rubric);
  margin-right: var(--space-2);
}

.portal-nav {
  display: flex;
  gap: var(--space-2);
  list-style: none;
  flex-wrap: wrap;
  align-items: center;
}

.portal-nav a {
  display: block;
  font-variant: small-caps;
  text-transform: lowercase;
  letter-spacing: 0.16em;
  font-size: 0.85rem;
  color: var(--ink-faded);
  text-decoration: none;
  /* 44px min touch target, met by padding rather than by a fixed height so the
   * label can wrap on a narrow phone without being clipped. */
  padding: var(--space-3) var(--space-3);
  border-bottom: 2px solid transparent;
  transition:
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.portal-nav a:hover {
  color: var(--rubric);
}

/* Current page. Marked with aria-current="page" in the markup, so the styling
 * hangs off the thing screen readers already announce rather than a class that
 * only sighted users benefit from. */
.portal-nav a[aria-current='page'] {
  color: var(--rubric);
  border-bottom-color: var(--rubric);
}

/* ── Layout ────────────────────────────────────────────────────────────── */

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--space-8) 6vw var(--space-9);
  padding-bottom: max(var(--space-9), env(safe-area-inset-bottom));
}

.page-head {
  margin-bottom: var(--space-7);
}

.page-head .rubric {
  margin-bottom: var(--space-3);
}

.page-head p {
  margin-top: var(--space-3);
  color: var(--ink-faded);
}

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

/* ── Panel ─────────────────────────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  padding: clamp(var(--space-5), 4vw, var(--space-7));
}

/* The double-rule treatment the landing page uses on its plates and letter.
 * Reserved for the one panel on a page that matters most. */
.panel-illuminated {
  position: relative;
}

.panel-illuminated::before {
  content: '';
  position: absolute;
  inset: var(--space-2);
  border: 1px solid rgba(167, 124, 44, 0.45);
  pointer-events: none;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

/* ── Definition rows ───────────────────────────────────────────────────── */

.rows {
  display: grid;
  gap: 0;
}

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--rule-soft);
}

.row:last-child {
  border-bottom: none;
}

.row-label {
  font-variant: small-caps;
  text-transform: lowercase;
  letter-spacing: 0.16em;
  font-size: 0.82rem;
  color: var(--ink-faded);
  flex-shrink: 0;
}

.row-value {
  text-align: right;
  /* Long values (an email, a plan name) wrap instead of forcing the row wide. */
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ── Status pill ───────────────────────────────────────────────────────── */

/* Never colour alone: every pill carries a text label, and the dot is a second
 * non-colour cue for anyone who cannot separate the hues. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-variant: small-caps;
  text-transform: lowercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  padding: var(--space-1) var(--space-3);
  border: 1px solid currentColor;
  white-space: nowrap;
}

.pill::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.pill-good {
  color: var(--state-good);
  background: var(--state-good-bg);
}

.pill-warn {
  color: var(--state-warn);
  background: var(--state-warn-bg);
}

.pill-bad {
  color: var(--state-bad);
  background: var(--state-bad-bg);
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-text);
  font-size: 0.95rem;
  font-variant: small-caps;
  text-transform: lowercase;
  letter-spacing: 0.2em;
  /* 14px vertical + 19px line-height clears the 44px minimum target. */
  padding: 14px var(--space-6);
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 0;
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    letter-spacing var(--dur-slow) var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn-rubric {
  background: var(--rubric);
  color: var(--panel);
  border-color: var(--rubric);
}

.btn-rubric:hover {
  background: #7d1a19;
  letter-spacing: 0.24em;
}

.btn-quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule);
}

.btn-quiet:hover {
  border-color: var(--ink);
  letter-spacing: 0.24em;
}

/* Destructive actions are visually separated from ordinary ones rather than
 * merely tinted, so "remove" never sits shoulder to shoulder with "save". */
.btn-danger {
  background: transparent;
  color: var(--rubric);
  border-color: rgba(152, 32, 31, 0.4);
}

.btn-danger:hover {
  background: var(--state-bad-bg);
  border-color: var(--rubric);
}

.btn-small {
  font-size: 0.82rem;
  padding: var(--space-2) var(--space-4);
  min-height: 40px;
}

/* Disabled carries three cues: opacity, cursor, and the disabled attribute
 * itself for assistive tech. Never opacity alone. */
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Forms ─────────────────────────────────────────────────────────────── */

fieldset {
  border: none;
}

legend {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  margin-bottom: var(--space-4);
}

.field + .field,
.field + .field-row,
.field-row + .field {
  margin-top: var(--space-5);
}

.field label,
.field-label {
  display: block;
  font-variant: small-caps;
  text-transform: lowercase;
  letter-spacing: 0.2em;
  font-size: 0.82rem;
  color: var(--rubric);
  margin-bottom: var(--space-2);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--font-text);
  /* 16px minimum: anything smaller makes iOS Safari zoom on focus. */
  font-size: 1.05rem;
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  border-radius: 0;
  transition: border-color var(--dur) var(--ease);
}

/* Textareas do not inherit the text font, and arrive monospace otherwise.
 * Vertical resize only: horizontal dragging breaks the panel width. */
.field textarea {
  resize: vertical;
  line-height: 1.5;
}

/* Native selects need both colours declared explicitly or Windows dark mode
 * renders white-on-white. */
.field select {
  background-color: var(--panel);
  color: var(--ink);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--rubric);
}

/* Helper text is persistent, unlike a placeholder, which disappears exactly
 * when the user starts typing and needs it most. */
.field-help {
  margin-top: var(--space-2);
  font-size: 0.85rem;
  color: var(--ink-faded);
  font-style: italic;
}

.field-row {
  display: flex;
  gap: var(--space-4);
}

.field-row .field {
  flex: 1;
  /* Lets a flex child shrink below its content width instead of overflowing. */
  min-width: 0;
  margin-top: 0;
}

@media (max-width: 520px) {
  .field-row {
    flex-direction: column;
    gap: var(--space-5);
  }
}

/* ── Focus ─────────────────────────────────────────────────────────────── */

/* One rule for everything focusable. :focus-visible rather than :focus, so a
 * mouse click does not leave a ring behind but a Tab key does. */
:focus-visible {
  outline: 2px solid var(--rubric);
  outline-offset: 3px;
}

/* ── Messages ──────────────────────────────────────────────────────────── */

/* Paired with aria-live in the markup so an async result is announced, and
 * carrying an icon glyph so the meaning does not rest on colour. */
.message {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid;
  font-size: 0.95rem;
}

.message:empty {
  display: none;
}

.message::before {
  font-weight: 600;
  flex-shrink: 0;
}

.message-good {
  color: var(--state-good);
  background: var(--state-good-bg);
  border-color: var(--state-good);
}

.message-good::before {
  content: '✓';
}

.message-bad {
  color: var(--state-bad);
  background: var(--state-bad-bg);
  border-color: var(--state-bad);
}

.message-bad::before {
  content: '!';
}

/* ── Empty states ──────────────────────────────────────────────────────── */

/* An empty list is a moment to say something, not a blank area. Every empty
 * state here names what will appear and how to make it appear. */
.empty {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  border: 1px dashed var(--rule);
}

.empty .cross {
  display: block;
  color: var(--gilt);
  font-size: 1.6rem;
  margin-bottom: var(--space-4);
}

.empty p {
  color: var(--ink-faded);
  max-width: 32rem;
  margin: 0 auto;
}

.empty .btn {
  margin-top: var(--space-5);
}

/* ── Lists ─────────────────────────────────────────────────────────────── */

.list {
  list-style: none;
}

.list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--rule-soft);
}

.list li:last-child {
  border-bottom: none;
}

.list-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
}

.list-meta {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-faded);
  margin-top: 2px;
}

/* Timestamps and counts line up column to column instead of jittering. */
.tabular {
  font-variant-numeric: tabular-nums;
}

/* ── Footer ────────────────────────────────────────────────────────────── */

.site-footer {
  background: var(--ink);
  color: rgba(246, 239, 225, 0.6);
  text-align: center;
  padding: var(--space-7) var(--space-5);
  padding-bottom: max(var(--space-7), env(safe-area-inset-bottom));
  font-size: 0.9rem;
}

.site-footer .cross {
  color: var(--gilt);
  font-size: 1.3rem;
  display: block;
  margin-bottom: var(--space-4);
}

.site-footer a {
  color: rgba(167, 124, 44, 0.85);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--gilt);
  text-decoration: underline;
}

.site-footer .flinks {
  display: flex;
  gap: var(--space-5);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--space-4);
}

/* ── Loading ───────────────────────────────────────────────────────────── */

/* A skeleton rather than a spinner: it reserves the space the real content will
 * occupy, so the page does not jump when the fetch resolves. */
.skeleton {
  background: linear-gradient(90deg, var(--recess) 25%, var(--panel) 50%, var(--recess) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  color: transparent;
  user-select: none;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
