/* Pantheon Pages — portal.
 *
 * Hand-written CSS on purpose: the portal has no build step, and the app origin runs
 * a strict CSP (`default-src 'self'; style-src 'self'`) with no 'unsafe-inline'. That
 * means NO external fonts, NO CDN, NO <style> blocks and NO style="" attributes.
 * Everything here is self-hosted and the type is a tuned system stack.
 *
 * To adopt a real typeface later: drop a .woff2 into portal/, add it to portal_files
 * in terraform/s3.tf, declare an @font-face below, and point --display at it. The CSP
 * already allows font-src 'self'.
 */

:root {
  color-scheme: light dark;

  /* Warm neutrals — paper, not grey. Cool greys make a tool feel clinical. */
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f4f1ec;
  --text: #1c1917;
  --text-2: #57534e;
  --muted: #8a827a;
  --border: #e8e2d9;
  --border-strong: #d6cec2;

  /* Deep green reads "live" and leaves red free for danger, amber for attention. */
  --accent: #1a6b52;
  --accent-hover: #145340;
  --accent-soft: #e4f0eb;
  --accent-contrast: #ffffff;

  /* Amber is reserved for things that need a second look: public pages, warnings. */
  --warn: #90600f;
  --warn-soft: #fbf1de;
  --bad: #ab372b;
  --bad-soft: #fbe9e6;

  --shadow-sm: 0 1px 2px rgba(60, 46, 30, .06), 0 1px 3px rgba(60, 46, 30, .04);
  --shadow-md: 0 2px 4px rgba(60, 46, 30, .05), 0 6px 16px rgba(60, 46, 30, .07);
  --shadow-lg: 0 8px 24px rgba(60, 46, 30, .1), 0 24px 48px rgba(60, 46, 30, .12);

  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --display: var(--sans);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1714;
    --surface: #232019;
    --surface-2: #2c2821;
    --text: #f2eee7;
    --text-2: #c6bdb0;
    --muted: #968c7e;
    --border: #342f27;
    --border-strong: #473f35;

    --accent: #5ec39c;
    --accent-hover: #7ad3b1;
    --accent-soft: #16302a;
    --accent-contrast: #0e1f19;

    --warn: #d9a44a;
    --warn-soft: #2e2314;
    --bad: #ec8175;
    --bad-soft: #351c19;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, .4), 0 24px 48px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ONE width for every tab.
 *
 * This used to widen to 1180px on the admin tab and snap back to 900px elsewhere, which
 * moved the header, the tabs and every panel edge sideways on each tab switch — the
 * whole app appeared to resize when only the content had changed. The wide table it was
 * meant to serve already scrolls inside .table-scroll, so it never needed the extra
 * room. Anything wider than the container scrolls in its own box, not by stretching the
 * page. */
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 24px 96px; }

/* ---- header ---- */

header {
  display: flex; align-items: center; gap: 16px;
  padding: 28px 0 24px;
  margin-bottom: 8px;
}
.brand { display: flex; align-items: center; gap: 12px; font-family: var(--display); font-weight: 650; font-size: 16px; letter-spacing: -0.011em; }
.brand small { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); letter-spacing: 0; margin-top: 1px; }
.brand-mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent); color: var(--accent-contrast);
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.02em;
  box-shadow: var(--shadow-sm);
}
.spacer { flex: 1; }
.whoami { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.whoami .email { color: var(--text-2); font-weight: 500; }

/* ---- tabs ---- */

.tabs { display: flex; gap: 2px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--muted);
  padding: 9px 14px; border-radius: var(--r-sm) var(--r-sm) 0 0;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .12s ease, border-color .12s ease;
}
.tab:hover { color: var(--text-2); background: var(--surface-2); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---- panels ---- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.panel h2 { font-family: var(--display); font-size: 17px; font-weight: 650; letter-spacing: -0.011em; margin: 0 0 4px; }
.panel .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 18px; max-width: 68ch; }

/* ---- dropzone ---- */

.dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .14s ease, background .14s ease, transform .14s ease;
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.005); }
.dropzone .big { font-family: var(--display); font-size: 15.5px; font-weight: 600; margin-bottom: 3px; }
.dropzone div:not(.big) { color: var(--muted); font-size: 13px; }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.staged { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.staged input[type=text] { flex: 1; min-width: 220px; }
.file-pill {
  display: inline-flex; align-items: baseline; gap: 8px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 6px 14px;
  font-size: 13px; font-weight: 600;
}
.file-pill small { color: var(--muted); font-weight: 400; }

.published {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 16px; padding: 14px 16px;
  background: var(--accent-soft); border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  font-size: 13.5px;
}
.published .url { font-family: var(--mono); font-size: 12.5px; word-break: break-all; flex: 1; min-width: 200px; }

/* ---- page cards ---- */

.page-card {
  display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap;
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.page-card:first-of-type { border-top: 0; }
.page-main { flex: 1; min-width: 240px; }
.page-title {
  font-family: var(--display); font-size: 15px; font-weight: 600; letter-spacing: -0.008em;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.page-url { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; margin-top: 3px; }
.page-meta { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.page-audience {
  font-size: 12.5px; color: var(--text-2); margin-top: 6px;
  display: flex; align-items: center; gap: 6px;
}
.page-audience svg { flex: none; opacity: .65; }
.page-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }

/* ---- status + access badges ----
 * Access is a correctness surface, not decoration: "only you" and "anyone with the
 * link" must be impossible to confuse at a glance. Public is the only one that gets
 * a loud colour, because it is the only one with consequences outside the company.
 */

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; letter-spacing: .02em;
  padding: 2.5px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip svg { flex: none; }
.chip.live { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.chip.pending { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.chip.rejected, .chip.deleted, .chip.expired { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }

.chip.public {
  background: var(--warn); color: #fff; border-color: transparent;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--warn) 40%, transparent);
}
@media (prefers-color-scheme: dark) { .chip.public { color: #241a06; } }
.chip.open { background: var(--surface-2); color: var(--text-2); border-color: var(--border-strong); }
.chip.org, .chip.shared { background: var(--surface-2); color: var(--text-2); }

/* ---- empty + notices ---- */

.empty {
  text-align: center; padding: 44px 24px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
}
.empty .empty-title { font-family: var(--display); font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty p { margin: 0; font-size: 13.5px; max-width: 46ch; margin-inline: auto; }
.empty-inline { color: var(--muted); font-size: 12.5px; }

.error-note { color: var(--bad); font-size: 12.5px; margin-top: 6px; }
.warn-note {
  color: var(--warn); font-size: 12.5px; margin-top: 8px; max-width: 68ch;
  background: var(--warn-soft); border-radius: var(--r-sm);
  border-left: 2px solid var(--warn); padding: 8px 11px;
}
.setup-note {
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--text-2); border-radius: var(--r-md); padding: 18px 20px; font-size: 14px;
}
.setup-note code { font-family: var(--mono); font-size: 12.5px; background: var(--surface); padding: 1px 5px; border-radius: 4px; }

.dev-banner {
  background: var(--warn-soft); color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--r-sm); padding: 8px 14px; margin-top: 16px;
  font-size: 12.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.dev-banner select { font-size: 12.5px; padding: 3px 8px; }

.loading { text-align: center; padding: 64px 20px; color: var(--muted); font-size: 14px; }

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

input[type=text], input[type=search], select {
  font: inherit; font-size: 14px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 8px 11px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:hover, select:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible, button:focus-visible, .tab:focus-visible, .dropzone:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
button:focus-visible, .tab:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }

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

button {
  font: inherit; font-size: 13px; font-weight: 550;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: var(--r-sm); padding: 7px 13px; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
button:hover { background: var(--surface-2); border-color: var(--muted); }
button:active { transform: translateY(.5px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
button.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
button.ghost { border-color: transparent; background: none; padding: 5px 9px; font-size: 12.5px; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); border-color: var(--border); }
button.ghost.danger { color: var(--bad); }

.more-row { display: flex; justify-content: center; margin-top: 18px; }

/* ---- dialogs ---- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  padding: 26px;
  max-width: 520px; width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(28, 25, 23, .42); backdrop-filter: blur(2px); }
dialog h3 { font-family: var(--display); font-size: 17px; font-weight: 650; letter-spacing: -0.011em; margin: 0 0 5px; }
dialog .sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; word-break: break-all; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ---- share dialog ---- */

.field-label {
  display: block; margin: 18px 0 8px;
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.field-label:first-of-type { margin-top: 4px; }

.mode-list { display: flex; flex-direction: column; gap: 7px; }
.mode-opt {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 11px 13px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.mode-opt:hover { background: var(--surface-2); }
.mode-opt input { margin: 2px 0 0; accent-color: var(--accent); }
.mode-opt .mode-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mode-opt .mode-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.mode-opt em { font-style: normal; color: var(--muted); font-size: 12.5px; }
.mode-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.mode-opt.on .mode-name { color: var(--accent); }

/* Public is the one choice with consequences outside the company. It looks different
   selected, so nobody lands on it without noticing. */
.mode-opt.public.on { border-color: var(--warn); background: var(--warn-soft); }
.mode-opt.public.on .mode-name { color: var(--warn); }
.mode-opt.public input { accent-color: var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 26px; align-items: center; }
.chip-grant {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 5px 3px 11px;
  font-size: 12.5px; color: var(--text-2);
}
.chip-grant button {
  border: 0; background: none; padding: 0; width: 18px; height: 18px;
  display: grid; place-items: center; border-radius: 999px;
  color: var(--muted); font-size: 15px; line-height: 1;
}
.chip-grant button:hover { color: var(--bad); background: var(--bad-soft); }

.grant-add { display: flex; gap: 8px; margin-top: 10px; }
.grant-add input { flex: 1; }
.hint { color: var(--muted); font-size: 12px; margin: 9px 0 0; }
.hint code { font-family: var(--mono); font-size: 11.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.hint.warn { color: var(--warn); }

/* ---- analytics ---- */

.stat-row { display: flex; gap: 10px; margin: 18px 0; }
.stat { flex: 1; background: var(--surface-2); border-radius: var(--r-md); padding: 14px; text-align: center; }
.stat .n { font-family: var(--display); font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
.stat .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 3px; }
.viewer-list { max-height: 260px; overflow-y: auto; border-top: 1px solid var(--border); }
.viewer-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 13px; }
.viewer-list .when { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.viewer-list .empty { border: 0; background: none; padding: 26px; }

/* ---- admin table ---- */

.admin-tools { margin-bottom: 14px; }
.admin-tools input { width: 100%; max-width: 340px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 720px; }
th {
  text-align: left; padding: 10px 14px; white-space: nowrap;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.title-cell, .owner-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-cell { white-space: nowrap; }
td.page-actions { gap: 4px; }

/* ---- people & roles ----
 * Roles are a permission surface, so the control has to read as a state rather than as
 * a button: you should be able to tell who can publish by scanning the column, without
 * clicking anything.
 */

.role-toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.role-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
  padding: 4px 11px 4px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  cursor: pointer; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.role-toggle .box {
  width: 13px; height: 13px; flex: none; border-radius: 4px;
  border: 1.5px solid var(--border-strong); background: var(--surface);
  display: grid; place-items: center; color: transparent;
}
.role-toggle:hover { border-color: var(--muted); color: var(--text-2); }
.role-toggle.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.role-toggle.on .box { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.role-toggle[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
/* Admin implies publisher, so its toggle shows as satisfied but not independently set. */
.role-toggle.implied { background: var(--surface-2); color: var(--text-2); }
.role-toggle.implied .box { background: var(--border-strong); border-color: var(--border-strong); color: var(--surface); }

.you-tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 7px;
  margin-left: 7px; vertical-align: 1px;
}

.people-search { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.people-search input { flex: 1; min-width: 240px; }
.lookup-result {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 12px; padding: 13px 15px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2);
  font-size: 13.5px;
}
.lookup-result .who { flex: 1; min-width: 180px; }
.lookup-result .who small { display: block; color: var(--muted); font-size: 12px; }

/* ---- toasts ---- */

#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; align-items: center; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in .18s cubic-bezier(.2, .8, .3, 1);
}
.toast.err { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

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

@media (max-width: 620px) {
  .wrap { padding-inline: 16px; }
  header { flex-wrap: wrap; }
  .page-card { flex-direction: column; }
  .stat-row { flex-direction: column; }
}

/* ---- version history ---- */

.rev-list { max-height: 300px; overflow-y: auto; border-top: 1px solid var(--border); margin-top: 4px; }
.rev-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--border);
}
.rev-row.current { background: var(--accent-soft); border-radius: var(--r-sm); padding-inline: 10px; }
.rev-head { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.rev-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.chip-grant small { color: var(--muted); font-size: 11.5px; }
