/* Valkompass — one stylesheet, no framework, no build step.
 *
 * Tokens first, then layout, then components. Colours are declared twice: once
 * for light and once inside prefers-color-scheme, and never anywhere else — a
 * colour with its only definition inside a media query renders as whatever the
 * browser's initial value happens to be for the other scheme.
 *
 * No web font is shipped. font-src in the CSP is 'self' and there is nothing
 * for it to allow: the system stack renders instantly, weighs nothing, and
 * removes a request that would otherwise block first paint. */

:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --panel-edge: #e3e1db;
  --ink: #1b1c1f;
  --ink-soft: #5c5f66;
  --ink-faint: #8b8e95;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --accent-soft: #e8eff6;
  --danger: #a3342b;
  --danger-soft: #fbeceb;
  --ok: #2f6b4f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 21, 24, .06), 0 8px 24px rgba(20, 21, 24, .05);
  --measure: 62ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141518;
    --panel: #1c1e22;
    --panel-edge: #2c2f35;
    --ink: #eceef1;
    --ink-soft: #a8acb4;
    --ink-faint: #7b8089;
    --accent: #7ba7d4;
    --accent-ink: #10161d;
    --accent-soft: #202a35;
    --danger: #e79b93;
    --danger-soft: #2b1d1c;
    --ok: #86c7a4;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }
p { margin: 0 0 .75rem; max-width: var(--measure); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9em;
  background: var(--accent-soft);
  padding: .1em .35em;
  border-radius: 4px;
}

/* -------------------------------------------------------------- controls -- */
button { font: inherit; cursor: pointer; }

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .7rem 1.1rem;
  font-weight: 600;
  width: 100%;
  margin-top: .35rem;
}
.primary:disabled { opacity: .55; cursor: not-allowed; }
.primary.auto, .ghost.auto { width: auto; margin-top: 0; }

.ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  padding: .45rem .8rem;
}
.ghost:hover { color: var(--ink); }

.linkButton {
  background: none;
  border: 0;
  color: var(--accent);
  padding: .5rem 0 0;
  text-align: left;
  text-decoration: underline;
}

.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  padding: .35rem .7rem;
  font-size: .9rem;
}

label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: .85rem 0 .3rem;
  letter-spacing: .01em;
}

input[type="email"], input[type="password"], input[type="text"] {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
}
input:disabled { color: var(--ink-faint); }
input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkboxRow {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1rem;
  font-weight: 400;
  color: var(--ink);
  text-transform: none;
}
.checkboxRow input { width: auto; }

/* ----------------------------------------------------------------- brand -- */
.brand { display: flex; align-items: center; gap: .55rem; }
.brandMark {
  width: 18px; height: 18px;
  border-radius: 50%;
  /* A compass needle, in two stops. No image request for a decoration. */
  background: conic-gradient(from 210deg, var(--accent) 0 25%, var(--panel-edge) 25% 100%);
  box-shadow: inset 0 0 0 2px var(--panel);
}
.brandName { font-weight: 700; letter-spacing: -.01em; }

/* ----------------------------------------------------------------- login -- */
.authScreen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}
.authCard {
  width: 100%;
  max-width: 25rem;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}
.authCard .brand { margin-bottom: 1.25rem; }
.authForm h1 { margin-bottom: .75rem; }

.authError, .authStatus, .status {
  border-radius: var(--radius-sm);
  padding: .6rem .75rem;
  font-size: .92rem;
  margin: 0 0 .9rem;
}
.authError { background: var(--danger-soft); color: var(--danger); }
.authStatus, .status { background: var(--accent-soft); color: var(--ink); }

.fineprint { font-size: .85rem; color: var(--ink-faint); margin-top: .8rem; }

/* ----------------------------------------------------------------- shell -- */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .8rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-edge);
}
.nav { display: flex; gap: .25rem; flex: 1 1 auto; flex-wrap: wrap; }
.navItem {
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  padding: .45rem .7rem;
  font-weight: 600;
}
.navItem:hover { color: var(--ink); background: var(--accent-soft); }
.navItem[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.topbarRight { display: flex; align-items: center; gap: .6rem; }
.userChip { font-size: .88rem; color: var(--ink-soft); }

.content { flex: 1 1 auto; padding: 1.5rem 1.25rem 3rem; max-width: 56rem; width: 100%; margin: 0 auto; }
.lead { color: var(--ink-soft); }

.card, .placeholderCard {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin: 1.25rem 0;
  box-shadow: var(--shadow);
}
.formCard { max-width: 26rem; }
.card ul, .placeholderCard ul { margin: .25rem 0 .75rem; padding-left: 1.2rem; color: var(--ink-soft); }
.card li, .placeholderCard li { margin: .25rem 0; }
.meta { font-size: .85rem; color: var(--ink-faint); }

/* ------------------------------------------------------------ user list -- */
.userList { display: flex; flex-direction: column; gap: .5rem; }
.userRow {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .7rem .8rem;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.userRow .who { flex: 1 1 12rem; min-width: 0; }
.userRow .name { font-weight: 600; display: block; overflow-wrap: anywhere; }
.userRow .sub { font-size: .82rem; color: var(--ink-faint); overflow-wrap: anywhere; }
.userRow .actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.tag {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .18rem .45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.tag.muted { background: var(--panel-edge); color: var(--ink-soft); }

/* ------------------------------------------------------------- compasses -- */
.compassHistory { display: flex; flex-direction: column; gap: .5rem; margin: .75rem 0 1.5rem; }
.compassRow {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .7rem .9rem;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.compassRow .who { flex: 1 1 12rem; min-width: 0; }
.compassRow .when { font-weight: 600; display: block; }
.compassRow .summary { font-size: .82rem; color: var(--ink-faint); }
.compassEmpty { color: var(--ink-faint); font-size: .9rem; }

.compassProgress { font-size: .88rem; color: var(--ink-soft); margin: 0 0 .5rem; }

.compassQuestions { display: flex; flex-direction: column; gap: .9rem; margin: .75rem 0; }
.compassQuestion {
  padding: .85rem .95rem;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.compassQuestion .qtext { margin: 0 0 .6rem; font-weight: 500; }
.compassOptions { display: flex; gap: .5rem; flex-wrap: wrap; }
.compassOption {
  padding: .4rem .8rem;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--ink-soft);
  font-size: .86rem;
  font-weight: 600;
}
.compassOption:hover { border-color: var(--accent); color: var(--ink); }
.compassOption[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.compassOption:disabled { opacity: .6; cursor: not-allowed; }

.compassActions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.1rem; }

.compassResultSummary { display: flex; gap: .75rem; flex-wrap: wrap; margin: .5rem 0 1.25rem; }
.compassStat {
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  font-size: .82rem;
  color: var(--ink-soft);
  min-width: 6rem;
}
.compassStat strong { display: block; font-size: 1.35rem; line-height: 1.3; color: var(--ink); }

.compassChartHost { display: flex; justify-content: center; margin: .75rem 0 1.25rem; }
.compassChart { width: 100%; max-width: 22rem; height: auto; }

.partyRanking { display: flex; flex-direction: column; gap: .4rem; margin: 0 0 1.5rem; }
.partyRow {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .7rem;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: .9rem;
}
.partySwatch { width: .8rem; height: .8rem; border-radius: 50%; flex: 0 0 auto; }
.partyName { flex: 1 1 auto; font-weight: 600; }
.partyDistance { font-size: .8rem; color: var(--ink-faint); white-space: nowrap; }

/* ---------------------------------------------------------------- footer -- */
.footer {
  padding: 1rem 1.25rem 2rem;
  font-size: .8rem;
  color: var(--ink-faint);
  text-align: center;
}

/* ----------------------------------------------------------------- toast -- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  max-width: min(30rem, calc(100vw - 2rem));
  background: var(--ink);
  color: var(--bg);
  padding: .65rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: .92rem;
  z-index: 40;
}

/* ------------------------------------------------------------ watchdog --- */
/* Deliberately plain: this has to render when everything else has failed, so it
 * depends on no token, no layout class and no script beyond the one that
 * unhides it. */
.bootError {
  margin: 2rem auto;
  max-width: 40rem;
  padding: 1.25rem;
  border: 1px solid #d9534f;
  border-radius: 12px;
  background: #fff;
  color: #1b1c1f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
.bootError h1 { font-size: 1.15rem; }
.bootError pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #f4f4f4;
  padding: .75rem;
  border-radius: 8px;
  font-size: .82rem;
  margin: 0;
}

@media (max-width: 34rem) {
  .topbar { padding: .7rem .9rem; }
  .content { padding: 1.1rem .9rem 2.5rem; }
  .topbarRight { width: 100%; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
