/* ============================================================
   Account area — login / reset / the signed-in app shell.
   Builds on tokens.css + base.css.
   ============================================================ */

/* ---- shared form controls (theme-aware — used on light cards AND the
       dark modal, so everything reads from --text / --bg, never --ink) ---- */
.field { display: grid; gap: 0.35rem; margin-bottom: 1rem; }
.field label {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.field input {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.field input:focus {
  outline: 2px solid color-mix(in srgb, var(--airmail-blue) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--airmail-blue);
}
.field .hint { margin-top: 0.15rem; color: var(--text-faint); }

.form-msg {
  font-size: 0.86rem;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  margin: 0.25rem 0 1rem;
}
.form-msg.is-error { color: var(--postal-red-dark); background: var(--postal-red-tint); border: 1px solid color-mix(in srgb, var(--postal-red) 30%, transparent); }
.form-msg.is-ok    { color: var(--good); background: var(--good-tint); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }
.form-msg.hidden { display: none; }

/* ============================================================
   Auth pages (login.html, reset.html)
   ============================================================ */
.auth-shell {
  min-height: calc(100vh - 4rem);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(2rem, 8vh, 6rem) 1.25rem 4rem;
}
.auth-card {
  width: 100%;
  max-width: 26rem;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.75rem 1.6rem 1.5rem;
  position: relative;
}
.auth-theme-toggle {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  width: 2.1rem;
  height: 2.1rem;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 1.1rem;
}
.auth-brand svg { width: 1.9em; height: 1.9em; color: var(--postal-red); fill: currentColor; transform: rotate(-6deg); }
.auth-brand .pg-neg { fill: var(--bg-raised); stroke: var(--bg-raised); }
.auth-card h1 { font-size: 1.4rem; margin: 0 0 0.3rem; color: var(--text); }
.auth-card > p.sub { color: var(--text-dim); font-size: 0.92rem; margin: 0 0 1.3rem; }
.auth-card form { margin: 0; }
.auth-card .btn-primary { width: 100%; margin-top: 0.3rem; }

.auth-alt {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  justify-content: space-between;
}
.auth-alt button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--airmail-blue);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.auth-alt button:hover { color: var(--postal-red-dark); }

/* ============================================================
   Signed-in shell (app.html)
   ============================================================ */
.app-main { padding: 2rem 0 5rem; }
.app-head {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-head h1 { font-size: var(--step-3); margin: 0 0 0.2rem; }
.app-head p { color: var(--text-dim); margin: 0; font-family: var(--font-mono); font-size: 0.85rem; }
.app-head .btn { flex: none; white-space: nowrap; }

.app-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (min-width: 820px) { .app-grid { grid-template-columns: 12rem minmax(0, 1fr); gap: 2rem; } }

.app-nav {
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  gap: 0.3rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}
.app-nav a {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.app-nav a:hover { color: var(--text); }
.app-nav a.is-active { color: var(--text); background: var(--postal-red-tint); border-left-color: var(--postal-red); }
.app-nav a[aria-disabled="true"] { color: var(--text-faint); cursor: not-allowed; }
.app-nav a .soon {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  padding: 0.05rem 0.25rem;
  color: var(--text-faint);
}
@media (min-width: 820px) {
  .app-nav { flex-direction: column; overflow: visible; border-bottom: 0; padding-bottom: 0; position: sticky; top: 5.5rem; }
}

.app-view { display: none; }
.app-view.is-active { display: block; animation: app-fade 0.2s ease; }
@keyframes app-fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.1rem;
  position: relative;
}
.card h2 { font-size: 1.15rem; margin: 0 0 0.2rem; color: var(--text); }
.card > p.card-sub { color: var(--text-dim); font-size: 0.9rem; margin: 0 0 1rem; }
.card form { margin: 0; }
.card .btn { margin-top: 0.2rem; }

.card.is-danger { border: 1.5px solid color-mix(in srgb, var(--postal-red) 45%, transparent); }
.card.is-danger h2 { color: var(--postal-red); }
.btn-danger {
  background: transparent;
  border: 2px solid var(--postal-red);
  color: var(--postal-red);
}
.btn-danger:hover { background: var(--postal-red); color: var(--bg-raised); }

.kv { font-family: var(--font-mono); font-size: 0.9rem; color: var(--text); }
.kv span { color: var(--text-dim); }

/* delete-account confirm modal */
.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 14, 17, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}
.modal-scrim.hidden { display: none; }
.modal {
  background: var(--bg-raised);
  color: var(--text);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  max-width: 27rem;
  width: 100%;
}
.modal h3 { font-size: 1.1rem; margin: 0 0 0.4rem; color: var(--text); }
.modal p { color: var(--text-dim); font-size: 0.92rem; }
.modal-actions { display: flex; gap: 0.7rem; justify-content: flex-end; margin-top: 1rem; }

/* ---- handwriting profiles (app.html) --------------------------------- */
.hw-view-head {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.hw-view-head h2 { font-size: 1.15rem; margin: 0 0 0.2rem; color: var(--text); }
.hw-view-head .btn { flex: none; white-space: nowrap; }

.hw-profile-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 620px) {
  .hw-profile-list { grid-template-columns: repeat(2, 1fr); }
}

.hw-profile {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.hw-profile.is-default { border-color: color-mix(in srgb, var(--postal-red) 55%, transparent); }

.hw-profile-preview {
  background: var(--paper);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  min-height: 3.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.hw-profile-preview svg { max-width: 100%; height: auto; }
.hw-profile-preview .is-muted { color: var(--text-dim); font-size: 0.82rem; }

.hw-profile-body { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.hw-profile-name {
  flex: 1 1 8rem;
  min-width: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.4rem;
}
.hw-profile-name:hover { border-color: var(--border); }
.hw-profile-name:focus { outline: none; border-color: var(--border-strong); background: var(--bg-raised); }

.hw-profile-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  /* colour via the shared --danger-text rule (theme-aware) */
  border: 1px solid color-mix(in srgb, var(--postal-red) 45%, transparent);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}

.hw-profile-actions {
  display: flex;
  gap: 1rem;
  border-top: 1px dashed var(--border);
  padding-top: 0.6rem;
  margin-top: auto;
}
.hw-profile-actions .link-btn { font-size: 0.85rem; }
.hw-profile-actions .link-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
/* .link-btn.hw-danger colour is set with the shared --danger-text rule below */

/* ---- orders (app.html) ------------------------------------------------ */
.ord-view-head {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.ord-view-head h2 { font-size: 1.15rem; margin: 0 0 0.2rem; color: var(--text); }
.ord-view-head .btn { flex: none; white-space: nowrap; }

.ord-list { display: flex; flex-direction: column; gap: 0.9rem; }

.ord-card {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 0.9rem 1rem;
}
.ord-card-row { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.ord-status {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}
/* Status colors are checked against --bg-raised in both themes (WCAG AA,
   4.5:1) — plain var(--good)/var(--postal-red) text falls just short at
   this font-size in one theme each, so both get a small same-direction
   nudge. --good only needs a hair more ink in every theme; --postal-red
   needs lightening, but only in dark mode (it already clears 5:1 in
   light), hence the guarded override below. */
.ord-status-mailed, .ord-status-stamped {
  color: color-mix(in srgb, var(--good) 95%, var(--ink));
  border-color: color-mix(in srgb, var(--good) 45%, transparent);
}
.ord-status-paid, .ord-status-ready_to_print, .ord-status-printing, .ord-status-plotting {
  color: var(--airmail-blue-bright); border-color: color-mix(in srgb, var(--airmail-blue-bright) 45%, transparent);
}
.ord-status-canceled {
  color: var(--postal-red); border-color: color-mix(in srgb, var(--postal-red) 45%, transparent);
}
/* Small red text (status pill, danger link, saved-card badge) on
   --bg-raised: plain --postal-red clears 5:1 in light but only ~3.5:1 in
   dark. Lighten it toward --on-dark for dark only. Checked with
   composited-pixel luminance math. */
.ord-status-canceled,
.pm-badge,
.hw-profile-badge,
.link-btn.hw-danger,
.link-btn.pm-danger,
.link-btn.adm-danger { --danger-text: var(--postal-red); color: var(--danger-text); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ord-status-canceled,
  :root:not([data-theme="light"]) .pm-badge,
  :root:not([data-theme="light"]) .hw-profile-badge,
  :root:not([data-theme="light"]) .link-btn.hw-danger,
  :root:not([data-theme="light"]) .link-btn.pm-danger,
  :root:not([data-theme="light"]) .link-btn.adm-danger { --danger-text: color-mix(in srgb, var(--postal-red) 75%, var(--on-dark)); }
}
:root[data-theme="dark"] .ord-status-canceled,
:root[data-theme="dark"] .pm-badge,
:root[data-theme="dark"] .hw-profile-badge,
:root[data-theme="dark"] .link-btn.hw-danger,
:root[data-theme="dark"] .link-btn.pm-danger,
:root[data-theme="dark"] .link-btn.adm-danger { --danger-text: color-mix(in srgb, var(--postal-red) 75%, var(--on-dark)); }
.ord-date { color: var(--text-dim); font-size: 0.85rem; }
.ord-price { font-family: var(--font-mono); font-size: 0.85rem; color: var(--text); }
.ord-card-row .link-btn { margin-left: auto; font-size: 0.85rem; }
.ord-note { margin: 0.5rem 0 0; color: var(--text-dim); font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.ord-note .is-muted { font-style: italic; }

.ord-files { margin-top: 0.7rem; padding-top: 0.7rem; border-top: 1px dashed var(--border); }
.ord-file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.ord-file-list li { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; font-size: 0.88rem; }
.ord-file-list a { color: var(--airmail-blue-bright); }
.ord-file-list a:hover { color: var(--postal-red-dark); }

/* ---- payment methods (app.html) ------------------------------------- */
.pm-list { display: flex; flex-direction: column; gap: 0.7rem; }
.pm-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 0.85rem 1rem;
}
.pm-card.is-default { border-color: color-mix(in srgb, var(--postal-red) 45%, transparent); }
.pm-brand { font-weight: 600; }
.pm-num { font-family: var(--font-mono); color: var(--text); }
.pm-exp { font-family: var(--font-mono); color: var(--text-dim); font-size: 0.85rem; }
.pm-badge {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  /* colour via the shared --danger-text rule (theme-aware) */
  border: 1px solid color-mix(in srgb, var(--postal-red) 45%, transparent);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.pm-card .link-btn { font-size: 0.85rem; }
.pm-card [data-act="default"] { margin-left: auto; }
.pm-card [data-act="default"] + .pm-danger { margin-left: 0; }
.pm-card .pm-badge + .pm-danger,
.pm-card .pm-num + .pm-danger { margin-left: auto; }
/* .link-btn.pm-danger + .pm-badge colours come from the shared --danger-text rule */

/* ---- operator console (app.html) ------------------------------------ */
.adm-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 1rem;
}
.adm-filter button {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--text-dim);
  cursor: pointer;
}
.adm-filter button:hover { color: var(--text); }
.adm-filter button.is-active {
  background: var(--postal-red-tint);
  border-color: color-mix(in srgb, var(--postal-red) 45%, transparent);
  color: var(--text);
}

.adm-list { display: flex; flex-direction: column; gap: 0.8rem; }
.adm-card {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 0.85rem 1rem;
}
.adm-row { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.adm-to { font-weight: 500; }
.adm-date { color: var(--text-dim); font-size: 0.85rem; }
.adm-row .link-btn { margin-left: auto; font-size: 0.85rem; }

.adm-detail { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px dashed var(--border); }
.adm-detail.hidden { display: none; }
.adm-detail-grid { display: grid; grid-template-columns: 1fr; gap: 1.2rem; }
@media (min-width: 620px) { .adm-detail-grid { grid-template-columns: 1fr 1fr; } }
.adm-detail h4 {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0.9rem 0 0.25rem;
}
.adm-detail h4:first-child { margin-top: 0; }
.adm-detail p { margin: 0; font-size: 0.9rem; }
.adm-addr, .adm-note { white-space: pre-wrap; overflow-wrap: anywhere; }
.adm-note { color: var(--text-dim); }

.adm-files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.adm-files li { display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.85rem; font-family: var(--font-mono); }
.adm-files a { color: var(--airmail-blue-bright); }
.adm-files .is-muted { color: var(--text-faint); }

.adm-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.1rem; }
/* .link-btn.adm-danger colour comes from the shared --danger-text rule */

.adm-log { margin-top: 0.9rem; font-size: 0.85rem; }
.adm-log summary { cursor: pointer; color: var(--text-dim); }
.adm-log ul { margin: 0.5rem 0 0; padding-left: 1.1rem; color: var(--text-dim); }
.adm-log li { margin: 0.15rem 0; }
.adm-log code {
  font-size: 0.82em;
  background: none;
  padding: 0;
  color: var(--text);
}

/* ---- OAuth (login.html) --------------------------------------------- */
.oauth-row { display: grid; gap: 0.55rem; margin-bottom: 1.1rem; }
.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.65rem 0.9rem;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-oauth:hover { border-color: var(--airmail-blue); }
.btn-oauth:disabled { opacity: 0.55; cursor: default; }
.btn-oauth svg { flex: none; }
.oauth-sep {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.oauth-sep::before, .oauth-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
