/* kraal app chrome. Tokens live in tokens.css; this file only applies them.
 * High contrast, large tap targets, zero-latency feedback (BUILD_PRINCIPLES §1).
 */

/* One vendored family, every weight (D-WS-7). Provenance: static/fonts/README.md. */
@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-latin-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--m-background);
  color: var(--m-on-background);
  font-family: var(--m-font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--m-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Shell ------------------------------------------------------------- */

/* One header, one height (D-TS-13). It is a row of the page, not a floating bar: an edge rather
   than a shadow, and the height comes from the token the shell's arithmetic reads. */
.site-header {
  display: flex;
  align-items: center;
  gap: var(--m-space-sm);
  height: var(--m-header-height);
  padding: 0 var(--m-space-md);
  background: var(--m-surface-container-lowest);
  border-bottom: var(--m-edge);
}

.site-header .brand {
  display: inline-flex;
  align-items: center;
  min-height: var(--m-tap-min);
  min-width: 0;
  font-family: var(--m-font-display);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--m-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-header__tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--m-space-xs);
  margin-left: auto;
}

/* --- The one nav: a <details> sheet (D-UI-1) --------------------------- */

/* Every signed-in page wears this. It replaced a row of links that wrapped onto four lines on a
 * 390 px phone — ~200 px of chrome before the page's own content. A `<details>` wraps onto nothing,
 * needs no client and traps no focus. */
.nav-sheet { position: relative; }

.nav-sheet > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--m-tap-min);
  min-height: var(--m-tap-min);
  border-radius: var(--m-radius-full);
  background: var(--m-surface-container);
  font-size: 1.25rem;
  line-height: 1;
  list-style: none;
  cursor: pointer;
}

.nav-sheet > summary::-webkit-details-marker { display: none; }

.nav-sheet[open] > summary { background: var(--m-primary-fixed); }

.nav-sheet__list {
  position: absolute;
  top: calc(100% + var(--m-space-xs));
  right: 0;
  z-index: 600;
  min-width: 180px;
  margin: 0;
  padding: var(--m-space-xs);
  border-radius: var(--m-radius-lg);
  background: var(--m-surface-container-lowest);
  box-shadow: var(--m-shadow-float);
  list-style: none;
}

.nav-sheet__list a,
.nav-sheet__signout {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: var(--m-tap-min);
  padding: 0 var(--m-space-sm);
  border: 0;
  border-radius: var(--m-radius-md);
  background: none;
  color: var(--m-on-surface);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.nav-sheet__list a:hover,
.nav-sheet__signout:hover {
  background: var(--m-surface-container);
  text-decoration: none;
}

.nav-sheet__list a[aria-current="page"] {
  background: var(--m-primary-fixed);
  color: var(--m-primary);
}

/* --- The onboarding reminder pill (D-ONB-8) --------------------------- */

.pill-sheet {
  position: relative;
}

.pill-sheet > summary {
  list-style: none;
  cursor: pointer;
}

.pill-sheet > summary::-webkit-details-marker {
  display: none;
}

.pill-nag {
  display: inline-block;
  background: var(--m-secondary-container);
  color: var(--m-on-secondary-container);
  border-radius: var(--m-radius-full);
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill-sheet__list {
  position: absolute;
  right: 0;
  top: calc(100% + var(--m-space-sm));
  min-width: 14rem;
  margin: 0;
  padding: var(--m-space-sm) 0;
  list-style: none;
  background: var(--m-surface-container-lowest);
  border-radius: var(--m-radius-md, 12px);
  box-shadow: var(--m-shadow-ambient);
  z-index: 120;
}

.pill-sheet__list a {
  display: block;
  padding: var(--m-space-sm) var(--m-space-md);
  color: var(--m-on-surface);
}

.pill-sheet__list a:hover {
  background: var(--m-surface-container);
  text-decoration: none;
}

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--m-space-lg);
}

.app-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--m-space-lg);
  color: var(--m-on-surface-variant);
  font-size: 0.875rem;
}

/* --- Type -------------------------------------------------------------- */

h1 { font-family: var(--m-font-display); font-size: 1.75rem; letter-spacing: -0.02em; margin: 0 0 var(--m-space-md); }
h2 { font-size: 1.25rem; margin: var(--m-space-lg) 0 var(--m-space-sm); }
h3 { font-size: 1rem; margin: var(--m-space-md) 0 var(--m-space-xs); }
p  { margin: 0 0 var(--m-space-md); }
.muted { color: var(--m-on-surface-variant); }
.small { font-size: 0.875rem; }

/* --- The step chips ---------------------------------------------------- */

/* The strip itself is .workspace__strip in workspace.css: it is a row of the rail, not a frozen
 * bar, so it has no offset to get wrong (D-WS-3, F14). Only the chip is a global component. */
/* The set-up step rail (D-TS-9). Three segments that divide the width evenly, so nothing can be
   clipped at 320 px; the open one and the finished ones are marked, and the mark is a bar rather
   than a fill so the label stays readable. */
.steps {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: var(--m-space-xs);
  padding: 0 var(--m-space-md);
  border-bottom: var(--m-edge);
}

.steps__step {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-bottom: 4px solid var(--m-outline-variant);
  color: var(--m-on-surface-variant);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

.steps__step[data-done="true"] {
  border-bottom-color: var(--m-primary);
}

.steps__step[aria-current="step"] {
  border-bottom-color: var(--m-primary);
  color: var(--m-primary);
  font-weight: 700;
}

/* An author `display` rule beats the browser's `[hidden] { display: none }`, which is how
 * "Undo last corner" sat on a page with nothing to undo (F17), and how the tab panels and then
 * the action rows would have done the same. The client toggles `hidden`; this makes it mean it,
 * once, for every element in the app. Nothing here is allowed to opt out with !important. */
[hidden] { display: none !important; }

/* The state line says what the map is doing, and nothing until it is doing something (D-TS-12). */
.map-mode:empty { display: none; }

.map-mode {
  margin: 0 0 var(--m-space-sm);
  padding: var(--m-space-sm) var(--m-space-md);
  background: var(--m-surface-container-low);
  border-left: 3px solid var(--m-secondary-container);
  border-radius: var(--m-radius-sm, 8px);
  font-weight: 600;
}

.rail {
  display: flex;
  flex-wrap: wrap;
  gap: var(--m-space-sm);
  margin: 0 0 var(--m-space-lg);
  padding: 0;
  list-style: none;
}

.rail li {
  background: var(--m-surface-container-lowest);
  border-radius: var(--m-radius-full);
  box-shadow: var(--m-shadow-card);
  padding: var(--m-space-xs) var(--m-space-md);
  font-size: 0.8125rem;
  font-weight: 600;
}

.script {
  background: var(--m-surface-container-low);
  border-left: 3px solid var(--m-secondary-container);
  border-radius: var(--m-radius-sm, 8px);
  padding: var(--m-space-sm) var(--m-space-md);
  font-size: 0.9375rem;
}

.camp-picker {
  display: grid;
  gap: var(--m-space-xs);
  margin: 0 0 var(--m-space-md);
  padding: 0;
  list-style: none;
}

.camp-picker a {
  display: block;
  padding: var(--m-space-sm) var(--m-space-md);
  background: var(--m-surface-container-low);
  border-radius: var(--m-radius-sm, 8px);
  font-weight: 600;
}

/* --- Surfaces ---------------------------------------------------------- */

/* A card is a surface that *floats* over something — the name card over the map, the sign-in card
   on bare ground. Inside a rail there is nothing to float over, so the rail groups with space and
   dividers instead (D-TS-11). An edge, not a shadow: a 2% shadow is invisible in midday glare. */
.card {
  background: var(--m-surface-container-lowest);
  border: var(--m-edge);
  border-radius: var(--m-radius-2xl);
  padding: var(--m-space-lg);
  margin-bottom: var(--m-space-lg);
}

/* --- Buttons ----------------------------------------------------------- */

/* Rank means something (D-TS-12). A plain `.btn` is a bordered control; the filled shape is
   `.btn--primary` and there is exactly one of those per surface. Until this split, `.btn` computed
   identically to `.btn--primary`, so "primary" was a label with no meaning. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--m-space-sm);
  min-height: var(--m-tap-min);
  padding: var(--m-space-sm) var(--m-space-lg);
  border: 1px solid var(--m-outline);
  border-radius: var(--m-radius-full);
  background: transparent;
  color: var(--m-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: var(--m-primary-fixed); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { border: 0; background: var(--m-primary); color: var(--m-on-primary); }
.btn--primary:hover { background: var(--m-primary-dim); }
.btn--secondary { border: 0; background: var(--m-secondary-container); color: var(--m-on-secondary-container); }
.btn--ghost { border: 0; background: transparent; color: var(--m-on-surface-variant); }
.btn--danger { border: 0; background: var(--m-error); color: var(--m-on-error); }
.btn--small { min-height: var(--m-tap-min); padding: var(--m-space-xs) var(--m-space-md); font-size: 0.875rem; }

/* --- Tables ------------------------------------------------------------ */

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--m-surface-container-lowest);
  border-radius: var(--m-radius-xl);
  overflow: hidden;
}

.table th,
.table td {
  text-align: left;
  padding: var(--m-space-sm) var(--m-space-md);
  border-bottom: 1px solid var(--m-surface-container);
  vertical-align: middle;
}

.table th {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--m-on-surface-variant);
  background: var(--m-surface-container-low);
}

.table tr:last-child td { border-bottom: 0; }

/* Six columns cannot fit a phone: the camps table is 445px at its narrowest, which grew the
 * layout viewport to 461px and cut the *Move here* button — the daily act — off the right
 * edge. Under 640px a row becomes a card: the header row goes, and each cell names itself. */
@media (max-width: 640px) {
  .table--stack,
  .table--stack tbody,
  .table--stack tr,
  .table--stack td { display: block; width: auto; }

  .table--stack thead { display: none; }

  .table--stack tr {
    padding: var(--m-space-sm) var(--m-space-md);
    border-bottom: 1px solid var(--m-surface-container);
  }

  .table--stack tr:last-child { border-bottom: 0; }

  .table--stack td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--m-space-md);
    padding: var(--m-space-xs) 0;
    border-bottom: 0;
  }

  .table--stack td[data-label]::before {
    content: attr(data-label);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--m-on-surface-variant);
    flex: 0 0 auto;
  }

  .table--stack td > form { margin-left: auto; }
  .table--stack td .btn { white-space: nowrap; }
}

/* --- Badges ------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--m-space-xs);
  padding: 0.125rem var(--m-space-sm);
  border-radius: var(--m-radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--m-surface-container);
  color: var(--m-on-surface-variant);
  white-space: nowrap;
}

.badge--grazing { background: var(--m-primary-fixed); color: var(--m-on-primary-fixed); }
.badge--resting { background: var(--m-warn-container); color: var(--m-warn); }
.badge--ready   { background: var(--m-primary-fixed); color: var(--m-on-primary-fixed); }
.badge--never   { background: var(--m-surface-container-high); color: var(--m-on-surface-variant); }

/* --- Forms ------------------------------------------------------------- */

/* A field inside a `.row` takes the room the buttons leave, instead of collapsing to the
 * browser's 20-character default (which is what made a name box 177px wide next to Save). */
/* The one field pattern (D-TS-10): label (+ Optional on the right) → hint → field → error, in that
   order. The hint is read before typing and cannot be hidden by the keyboard, which is why it sits
   above the control rather than under it. */
.field { margin: 0 0 var(--m-space-lg); min-width: 0; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--m-space-sm);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.5;
}

.field__optional { font-weight: 400; color: var(--m-on-surface-variant); }

.field .hint {
  margin: var(--m-space-xs) 0;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--m-on-surface-variant);
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--m-outline);
  border-radius: var(--m-radius-lg);
  background: var(--m-surface-container-lowest);
  color: var(--m-on-surface);
  font: inherit;
  font-size: 1rem;
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--m-primary);
  outline-offset: 1px;
}

/* A count is short: a full-width box for two digits is a box that looks like it wants a paragraph. */
.field input[inputmode="numeric"] { max-width: 9rem; }

.form-error {
  padding: var(--m-space-sm) var(--m-space-md);
  border-radius: var(--m-radius-lg);
  background: var(--m-error-container);
  color: var(--m-on-error-container);
  margin-bottom: var(--m-space-md);
}

/* A confirmation is not a fault: "Herd saved" was printed in the error colour
   because every message used `.form-error` (F18). */
.form-note {
  padding: var(--m-space-sm) var(--m-space-md);
  border-radius: var(--m-radius-lg);
  background: var(--m-primary-container);
  color: var(--m-on-primary-container);
  margin-bottom: var(--m-space-md);
}

/* --- Layout helpers ---------------------------------------------------- */

.row { display: flex; gap: var(--m-space-md); align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.stack > * + * { margin-top: var(--m-space-md); }
.grid { display: grid; gap: var(--m-space-md); }
.grid--two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

@media (max-width: 640px) {
  .app-main { padding: var(--m-space-md); }
  h1 { font-size: 1.5rem; }
  .table th, .table td { padding: var(--m-space-sm); }
}

/* --- The confirmation disclosure (D-UI-4) ------------------------------ */

/* A destructive act asks before it writes, and asks in place: the summary IS the danger button, so
   nothing new appears on the page until it is pressed. No dialog, no focus trap, works with no JS,
   and the sentence that explains what is kept sits beside the button that does it. */
/* Inside a table cell the body has nowhere to grow, so it floats like the nav sheet instead of
   pushing the row open: the same pattern, anchored to the control that asked (D-UI-4). */
.row-confirm {
  position: relative;
  display: inline-block;
}

.row-confirm > summary {
  list-style: none;
  cursor: pointer;
}

.row-confirm > summary::-webkit-details-marker { display: none; }

.row-confirm__body {
  position: absolute;
  top: calc(100% + var(--m-space-xs));
  right: 0;
  z-index: 700;
  display: grid;
  gap: var(--m-space-xs);
  width: max-content;
  max-width: 260px;
  padding: var(--m-space-sm);
  border-radius: var(--m-radius-lg);
  background: var(--m-surface-container-lowest);
  box-shadow: var(--m-shadow-float);
  text-align: left;
}

.row-confirm__body .hint { margin: 0; }
