/* ============================================================
   Krewsend — app styles, built on the Krew design system
   (krew-tokens.css). Warm paper. Heavy ink. One spark.
   ============================================================ */

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

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--fg-1);
  font-family: var(--font-sans);
  font-size: var(--fs-15);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

/* paper grain overlay, straight from the landing page */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='3'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.1  0 0 0 0 0.1  0 0 0 1 0'/></filter><rect width='240' height='240' filter='url(%23n)'/></svg>");
}

main { max-width: 1080px; margin: var(--s-8) auto; padding: 0 var(--s-6); position: relative; z-index: 2; }

h1 { font-size: var(--fs-30); font-weight: 900; letter-spacing: var(--tracking-tight); line-height: var(--lh-tight); }
h2 { font-size: var(--fs-18); font-weight: 800; letter-spacing: var(--tracking-tight); margin-top: var(--s-10); }

/* ---------- top nav ---------- */
.topnav {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: var(--s-8);
  padding: var(--s-4) var(--s-8);
  background: color-mix(in oklch, var(--bg-page) 82%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-hair);
}
.topnav .brand {
  display: inline-flex; align-items: baseline; gap: 2px;
  text-decoration: none; color: var(--fg-1);
}
.topnav .brand img { height: 22px; display: block; }
.topnav .brand .hand-suffix {
  font-family: var(--font-hand);
  font-size: var(--fs-20);
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.topnav a:not(.brand) {
  text-decoration: none;
  color: var(--fg-3);
  font-size: var(--fs-12);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  transition: color var(--dur-1) var(--ease-out);
}
.topnav a:not(.brand):hover { color: var(--fg-1); }
.topnav .logout { margin-left: auto; }
.topnav .logout button {
  background: transparent;
  color: var(--fg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-2);
  padding: var(--s-2) var(--s-4);
  font-size: var(--fs-12);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
}
.topnav .logout button:hover { color: var(--fg-1); border-color: var(--border-strong); }

/* ---------- cards & forms ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
  padding: var(--s-6);
  margin: var(--s-6) 0;
  display: flex; flex-direction: column; gap: var(--s-3);
  max-width: 480px;
}
.card h2 { margin: 0 0 var(--s-2); }

label {
  font-size: var(--fs-12);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--fg-3);
}

input, select {
  font: inherit;
  color: var(--fg-1);
  background: var(--bg-raised);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-2);
  transition: border-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

button, a.button {
  font: inherit;
  font-weight: 800;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--krew-spark-ink);
  border-radius: var(--r-2);
  padding: var(--s-2) var(--s-5);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background var(--dur-1) var(--ease-out),
              transform var(--dur-1) var(--ease-spark),
              box-shadow var(--dur-1) var(--ease-spark);
}
button:hover, a.button:hover { background: var(--accent-hover); color: #fff; }
button:active, a.button:active { transform: translate(1px, 1px); box-shadow: none; }

/* ---------- auth / gate ---------- */
.auth { max-width: 400px; margin: 12vh auto; }
.auth h1 { text-align: center; margin-bottom: var(--s-6); }
h1.brand-lockup {
  display: flex; align-items: baseline; justify-content: center; gap: 3px;
}
h1.brand-lockup img { height: 34px; }
h1.brand-lockup .hand-suffix {
  font-family: var(--font-hand);
  font-size: var(--fs-30);
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.auth .card {
  box-shadow: var(--shadow-ink);   /* the stamp */
  border: 1px solid var(--border-ink);
}

/* ---------- text utilities ---------- */
a { color: var(--accent); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
.error { color: var(--danger); font-weight: 600; }
.muted { color: var(--fg-4); }
code { font-family: var(--font-mono); font-size: 0.92em; background: var(--bg-sunken); padding: 1px 6px; border-radius: var(--r-1); }
::selection { background: var(--accent-soft); color: var(--krew-slate-deep); }

/* ---------- tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-3);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
th {
  font-size: var(--fs-12);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--fg-3);
}
th, td { text-align: left; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border-hair); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--krew-grain-pale); }

/* ---------- viewer (direct pdf.js page rendering) ---------- */
.doc-topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-6);
  padding: var(--s-3) var(--s-6);
  background: color-mix(in oklch, var(--bg-page) 86%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-hair);
}
.doc-topbar .brand { display: inline-flex; align-items: baseline; gap: 2px; }
.doc-topbar .brand img { height: 20px; display: block; }
.doc-topbar .brand .hand-suffix {
  font-family: var(--font-hand); font-size: var(--fs-18);
  font-weight: 600; color: var(--accent); line-height: 1;
}
.doc-tools { display: flex; align-items: center; gap: var(--s-5); }
#doc-progress { font-family: var(--font-mono); font-size: var(--fs-13); min-width: 3.5em; text-align: center; }

.zoom-pill {
  display: inline-flex; align-items: center; gap: 2px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-pill);
  background: var(--bg-surface);
  padding: 2px;
}
.zoom-pill button {
  background: transparent; color: var(--fg-2); border: none;
  width: 28px; height: 24px; padding: 0; line-height: 1;
  border-radius: var(--r-pill); font-weight: 800;
}
.zoom-pill button:hover { background: var(--krew-grain-pale); color: var(--fg-1); }
#zoom-level { font-family: var(--font-mono); font-size: var(--fs-12); min-width: 3.2em; text-align: center; color: var(--fg-3); }

/* the document viewer uses the whole window, not the 1080px column —
   zooming grows the page into real estate instead of cropping in a box */
main.viewer { max-width: none; margin: var(--s-6) 0; padding: 0 var(--s-6); }
.pdf-scroll { overflow-x: auto; width: 100%; }
#pdf-pages {
  --krew-doc-aspect: 612 / 792;        /* portrait default; JS sets per doc */
  display: flex;
  flex-direction: column;
  align-items: center;                  /* zoomed-out pages stay centered */
  gap: var(--s-6);
  margin: var(--s-6) 0;
  width: max-content;
  min-width: 100%;
}
.pdf-slot {
  position: relative;                   /* hosts the link-annotation layer */
  aspect-ratio: var(--krew-doc-aspect);
  background: rgba(28, 26, 24, 0.85);  /* no white flash while pages load */
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(28, 26, 24, 0.18), 0 12px 28px rgba(28, 26, 24, 0.12);
}
.pdf-slot canvas { display: block; width: 100%; height: 100%; }
/* capture deterrence: no selection, no print, blur when unfocused */
#pdf-pages { user-select: none; -webkit-user-select: none; }
body.capture-shield #pdf-pages { filter: blur(16px); transition: filter 120ms var(--ease-out); }
@media print {
  .pdf-scroll, #pdf-pages { display: none !important; }
  main.viewer::after {
    content: "Printing is disabled for this document.";
    display: block; padding: 2rem; font-weight: 700;
  }
}

.pdf-annots { position: absolute; inset: 0; }
.pdf-annots a { position: absolute; display: block; border-radius: 2px; }
.pdf-annots a:hover { background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent-ring); }
.viewer-bar { display: flex; align-items: center; justify-content: flex-end; gap: var(--s-4); }

/* ---------- room folders ---------- */
.folder-block { margin: var(--s-4) 0 var(--s-4) var(--s-6); padding-left: var(--s-4); border-left: 2px solid var(--border-soft); }
.folder-head { display: flex; align-items: center; gap: var(--s-4); }
.folder-head h3 { font-size: var(--fs-15); font-weight: 800; margin: var(--s-2) 0; }
.folder-head form button { padding: 2px var(--s-2); font-size: var(--fs-12); }
.inline-form { display: inline-flex; align-items: center; gap: var(--s-2); }
.inline-form select { font-size: var(--fs-13); padding: 2px var(--s-2); }
.inline-form button { padding: 2px var(--s-3); font-size: var(--fs-12); }
table.room-docs { margin: var(--s-2) 0; }
.room-forms { display: flex; gap: var(--s-6); flex-wrap: wrap; align-items: flex-start; margin-top: var(--s-8); }

.room-tree { list-style: none; padding-left: 0; }
.room-tree .room-tree { padding-left: var(--s-6); border-left: 2px solid var(--border-soft); margin-left: var(--s-2); }
.room-tree li { padding: var(--s-2) 0; }
.room-tree .folder-name { font-weight: 800; }
.room-tree a.dl { font-size: var(--fs-12); color: var(--fg-4); }

/* ---------- dashboard ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-4);
  margin: var(--s-6) 0;
}
.stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
  padding: var(--s-4) var(--s-5);
  position: relative;
}
.stat::after {
  content: "";
  position: absolute; top: var(--s-4); right: var(--s-4);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.stat-n { font-size: var(--fs-36); font-weight: 900; letter-spacing: var(--tracking-tight); line-height: var(--lh-tight); }
.stat-label {
  font-size: var(--fs-12);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--fg-3);
  margin-top: var(--s-1);
}

.activity { list-style: none; padding: 0; }
.activity li { padding: var(--s-3) 0; border-bottom: 1px solid var(--border-hair); }
.event-type {
  font-size: var(--fs-12);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  padding: 2px var(--s-2);
  border-radius: var(--r-1);
  background: var(--bg-sunken);
}
.event-type.visit { background: var(--accent-soft); color: var(--krew-spark-ink); }
.event-type.view { background: rgba(63, 110, 74, 0.14); color: var(--krew-safe); }
.event-type.download { background: rgba(196, 167, 122, 0.25); color: var(--krew-reel); }
.ts { font-size: var(--fs-13); }

.slug-row { display: flex; align-items: center; gap: var(--s-2); }
.slug-row input { flex: 1; }

/* ---------- NDA ---------- */
.nda-card { max-width: 680px; }
main.auth:has(.nda-card) { max-width: 720px; }
.nda-body {
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-2);
  padding: var(--s-4);
  font-size: var(--fs-14);
}
label.consent { display: flex; align-items: center; gap: var(--s-2); text-transform: none; letter-spacing: 0; font-size: var(--fs-14); font-weight: 500; color: var(--fg-2); }
.nda-form { max-width: 680px; }
.nda-form textarea { font: inherit; font-size: var(--fs-14); padding: var(--s-3); border: 1px solid var(--border-soft); border-radius: var(--r-2); width: 100%; }
.nda-form details { margin-top: var(--s-2); }
.nda-form summary { cursor: pointer; color: var(--fg-3); font-size: var(--fs-13); }

/* ---------- link management ---------- */
.manage { max-width: 560px; }
.manage-row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.inline-label { flex: none; }
.manage-row input { flex: 1; }
button.secondary {
  background: transparent;
  color: var(--fg-2);
  border: 1px solid var(--border-soft);
}
button.secondary:hover { background: var(--krew-grain-pale); color: var(--fg-1); }
button.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
button.danger-btn:hover { background: var(--danger); color: #fff; }

/* ---------- page engagement bars ---------- */
.page-doc h3 { font-size: var(--fs-14); font-weight: 700; margin: var(--s-4) 0 var(--s-2); }
.page-bars { display: flex; flex-direction: column; gap: var(--s-1); }
.page-bar-row { display: grid; grid-template-columns: 44px 1fr 200px; align-items: center; gap: var(--s-3); }
.page-num { font-family: var(--font-mono); font-size: var(--fs-12); color: var(--fg-3); text-align: right; }
.page-bar-track { background: var(--bg-sunken); border-radius: var(--r-1); height: 14px; }
.page-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-1);
  box-shadow: inset 0 0 0 1px var(--krew-spark-ink);
}
.page-count { font-size: var(--fs-12); white-space: nowrap; }
.funnel-note { margin-top: calc(-1 * var(--s-2)); }
.page-bar-track.mini { display: inline-block; width: 120px; height: 8px; vertical-align: middle; }
.visit-progress { white-space: nowrap; font-size: var(--fs-13); }

/* ---------- activity timeseries ---------- */
.ts-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); }
.bin-picker { display: inline-flex; gap: 2px; border: 1px solid var(--border-soft); border-radius: var(--r-2); padding: 2px; background: var(--bg-surface); }
.bin-picker a {
  text-decoration: none;
  color: var(--fg-3);
  font-size: var(--fs-12);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  padding: 3px var(--s-3);
  border-radius: var(--r-1);
}
.bin-picker a.active { background: var(--krew-ink); color: var(--krew-grain); }
.bin-picker a:not(.active):hover { color: var(--fg-1); }

svg.ts-chart {
  display: block;
  width: 100%;
  height: 170px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
  margin-top: var(--s-3);
}
.ts-label { font-size: 11px; fill: var(--fg-4); font-family: var(--font-mono); }

/* hover: highlight the column; details land in the header readout */
.ts-chart g:hover rect.hit { fill: var(--accent-soft); }
#ts-readout {
  flex: 1;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  color: var(--fg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 1em;
}

/* the in-progress bucket breathes gently */
.ts-chart g.live rect:not(.hit) { animation: ts-breathe 2.4s var(--ease-in-out) infinite; }
@keyframes ts-breathe { 50% { opacity: 0.6; } }

/* "Live" eyebrow pill — the landing page's flagship pill, repurposed */
.live-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 3px 12px 3px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-pill);
  background: var(--bg-surface);
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-3);
  white-space: nowrap;
}
.live-pill::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  animation: ts-breathe 2.4s var(--ease-in-out) infinite;
}

.ts-legend { display: flex; gap: var(--s-5); margin-top: var(--s-2); }
.ts-legend .chip { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--fg-3); font-weight: 700; text-transform: uppercase; letter-spacing: var(--tracking-wide); }
.ts-legend .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.ts-legend .swatch.views { background: var(--krew-spark); }
.ts-legend .swatch.visits { background: var(--krew-leader); }
.ts-legend .swatch.downloads { background: var(--krew-reel); }
