:root {
  --bg: #f2efe9;
  --bg-accent: #e6e1d6;
  --surface: #fffdfa;
  --text: #23211d;
  --muted: #6f6a60;
  --line: #e0dbd1;
  --accent: #5a6b53;
  --accent-soft: #eef1ea;
  --danger: #8c3b2e;
  --danger-soft: #f8ece9;
  --shadow: 0 1px 2px rgba(35, 33, 29, .05), 0 12px 32px -12px rgba(35, 33, 29, .18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --bg-accent: #1e1d1a;
    --surface: #1f1e1b;
    --text: #eae7e0;
    --muted: #9d968a;
    --line: #322f2a;
    --accent: #9db393;
    --accent-soft: #23281f;
    --danger: #e09c90;
    --danger-soft: #2a1d19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

/* The UA stylesheet hides [hidden] with a bare `display: none`, which loses to
   any id/class rule that sets display — leaving empty avatars and the wrong
   panel on screen. Restate it with priority. */
[hidden] { display: none !important; }

/* The gradient lives on body; without a matching ground on html, a viewport
   taller than the content shows the browser's default white below the fold. */
html { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-accent), var(--bg));
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 40px 32px 32px;
  text-align: center;
}

.mark {
  width: 52px; height: 52px;
  margin: 0 auto 20px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-weight: 600; font-size: 17px; letter-spacing: .06em;
}

h1 { margin: 0 0 4px; font-size: 21px; font-weight: 620; letter-spacing: -.01em; }
.sub { margin: 0 0 26px; color: var(--muted); font-size: 13.5px; }

/* Microsoft's brand guidance: white button, 1px grey border, their logo at left. */
.ms-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; padding: 13px 18px;
  background: #fff; color: #1b1b1b;
  border: 1px solid #8c8c8c; border-radius: 10px;
  font-size: 15px; font-weight: 600; text-decoration: none;
  transition: box-shadow .15s ease, transform .15s ease;
}
.ms-btn:hover { box-shadow: 0 4px 14px -4px rgba(0,0,0,.28); }
.ms-btn:active { transform: translateY(1px); }
.ms-btn svg { width: 19px; height: 19px; flex: none; }

.foot { margin: 20px 0 0; font-size: 12.5px; color: var(--muted); }

.banner {
  text-align: left;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
  margin-bottom: 20px;
}
.banner.info {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}

.avatar-wrap { margin-bottom: 16px; }
#avatar, .avatar-fallback {
  width: 76px; height: 76px; border-radius: 50%;
  margin: 0 auto; display: block;
  border: 1px solid var(--line);
}
.avatar-fallback {
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-size: 26px; font-weight: 600; letter-spacing: .02em;
}

.ok-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  border-radius: 999px;
  padding: 5px 13px 5px 10px;
  font-size: 12.5px; font-weight: 550;
  margin-bottom: 26px;
}
.ok-pill svg { width: 15px; height: 15px; fill: currentColor; }

.facts {
  display: grid; grid-template-columns: auto 1fr;
  gap: 9px 18px;
  margin: 0 0 22px;
  text-align: left;
  font-size: 13.5px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.facts dd.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.claims { text-align: left; margin-bottom: 22px; }
.claims summary {
  cursor: pointer; font-size: 13px; color: var(--muted);
  padding: 8px 0; list-style-position: inside;
}
.claims summary:hover { color: var(--text); }
.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 10px; }
pre {
  background: var(--bg-accent);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  font-size: 11.5px;
  line-height: 1.5;
  margin: 0;
  max-height: 300px;
}

.actions { display: flex; flex-direction: column; gap: 9px; }
.btn {
  display: block; padding: 11px 18px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-accent); color: var(--text);
  font-size: 14px; font-weight: 550; text-decoration: none;
  transition: border-color .15s ease;
}
.btn:hover { border-color: var(--muted); }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); font-size: 12.5px; padding: 6px; }
.btn.ghost:hover { color: var(--text); }

/* ── App shell (signed in, mapped) ─────────────────────────────────────── */

.wide { max-width: 1080px; width: 100%; margin: 0 auto; padding: 28px 20px 60px; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding-bottom: 18px; margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 19px; margin: 0; }
.topbar .who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar .who img, .topbar .who .ini {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line);
}
.topbar .who .ini {
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.who-name { font-weight: 550; }
.who-sub { color: var(--muted); font-size: 12px; }
.linkbtn {
  color: var(--muted); text-decoration: none; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px;
}
.linkbtn:hover { color: var(--text); border-color: var(--muted); }
.linkbtn.active { color: var(--accent); border-color: var(--accent); }

.tabs { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.tab {
  padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
  border: 1px solid transparent; background: none; color: var(--muted); font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }

.notice {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px; text-align: center; color: var(--muted); font-size: 14px;
}
.notice strong { color: var(--text); }

/* PR cards */
.pr {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  margin-bottom: 12px; overflow: hidden;
}
.pr-head {
  display: grid; grid-template-columns: 1fr auto; gap: 14px;
  padding: 16px 18px; cursor: pointer; align-items: center;
}
.pr-head:hover { background: var(--bg-accent); }
.pr-no { font-weight: 600; font-size: 15px; }
.pr-meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.pr-right { display: flex; align-items: center; gap: 14px; }
.pr-total { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }
.pr-count { color: var(--muted); font-size: 12px; }

.btn-approve {
  padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--surface);
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
  white-space: nowrap;
}
.btn-approve:hover { filter: brightness(1.08); }
.btn-approve:disabled { opacity: .5; cursor: default; filter: none; }
.btn-approve.confirm { background: var(--danger); }

.pr-body { border-top: 1px solid var(--line); padding: 4px 18px 14px; }
table.items { width: 100%; border-collapse: collapse; font-size: 13px; }
table.items th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; padding: 10px 8px 8px; border-bottom: 1px solid var(--line);
}
table.items td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.items tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dim { color: var(--muted); }
.scroll-x { overflow-x: auto; }

/* Admin tables */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
table.grid th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 500; padding: 11px 12px; border-bottom: 1px solid var(--line);
}
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.grid tr:last-child td { border-bottom: none; }
.card-wrap { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 550; border: 1px solid transparent;
}
.pill.ok   { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.pill.warn { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.pill.mute { background: var(--bg-accent); color: var(--muted); border-color: var(--line); }

input[type="text"], select {
  font: inherit; font-size: 13px; padding: 6px 9px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--bg-accent); color: var(--text); max-width: 220px;
}
.btn-sm {
  padding: 6px 12px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--bg-accent); color: var(--text);
  font-size: 12.5px; font-weight: 550; cursor: pointer; font-family: inherit;
}
.btn-sm:hover { border-color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--text); color: var(--surface);
  padding: 11px 20px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }

/* ── Phones ────────────────────────────────────────────────────────────── */

/* .card-wrap sets `overflow: hidden` and is declared after .scroll-x, so on an
   element carrying both the hidden wins and the inner table escapes instead of
   scrolling. Restate it for the combination. */
.card-wrap.scroll-x { overflow-x: auto; overflow-y: visible; }

/* Long values (item names, emails, PR meta) must be able to break, or their
   min-content width props the whole page open. */
.pr-meta, .who-name, .who-sub, table.grid td { overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .wide { padding: 16px 14px 48px; }

  /* The topbar was the real cause of the page-wide horizontal scroll: a
     non-wrapping flex row of title + name + two buttons has a min-content width
     well over 390px. */
  .topbar { flex-wrap: wrap; gap: 10px; padding-bottom: 14px; margin-bottom: 18px; }
  .topbar h1 { width: 100%; font-size: 17px; }
  .topbar .who { width: 100%; margin-left: 0; flex-wrap: wrap; row-gap: 10px; }
  .topbar .who > span:nth-child(2) { flex: 1 1 130px; min-width: 0; }
  .linkbtn { flex: 0 0 auto; }

  .tabs { gap: 4px; }
  .tab { padding: 7px 11px; font-size: 12.5px; }

  /* PR cards: stack the header so the total and the Approve button get a full
     row instead of being squeezed off the right edge. */
  .pr-head { grid-template-columns: 1fr; gap: 12px; padding: 14px; }
  .pr-right { justify-content: space-between; width: 100%; }
  .pr-body { padding: 4px 14px 12px; }
  .btn-approve { padding: 10px 18px; }

  /* Admin grids become stacked cards. Horizontally scrolling an editable form
     on a phone is unusable, and the mapping table is the one people actually
     have to type into. */
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid thead { display: none; }
  table.grid tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.grid tr:last-child { border-bottom: none; }
  table.grid td {
    border: none; padding: 5px 0; text-align: left;
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
  }
  table.grid td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  }
  table.grid td[data-label=""]::before { content: none; }
  table.grid td[data-label=""] { justify-content: stretch; padding-top: 10px; }
  table.grid td[data-label=""] .btn-sm { width: 100%; padding: 10px; }
  table.grid .num { text-align: left; }

  input[type="text"], select { max-width: 60%; }
  .toast { left: 14px; right: 14px; transform: none; text-align: center; }
}

/* First cell of a stacked admin row reads as the card's title, not a labelled field. */
@media (max-width: 760px) {
  table.grid td.rowtitle { display: block; padding: 0 0 8px; font-weight: 550; }
  table.grid td.rowtitle::before { content: none; }
}
