/* ---------------------------------------------------------------------------
   v2intra shell.

   Mobile first, and meant literally: every rule below is written for a 360px
   viewport, and the only media queries widen. There are no fixed pixel widths
   on any layout container — widths are max-width or percentage — so nothing
   can force a horizontal scrollbar at a narrow width.

   One stylesheet, custom properties for the palette, no framework.
   --------------------------------------------------------------------------- */

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --border:    #e3e6ea;
  --text:      #16191d;
  --muted:     #5c6570;
  --primary:   #2563eb;
  --primary-ink:#ffffff;
  --danger:    #b42318;
  --danger-bg: #fef3f2;
  --ok:        #067647;
  --ok-bg:     #ecfdf3;
  --info:      #175cd3;
  --info-bg:   #eff8ff;
  --radius:    10px;
  --gap:       16px;
  --maxw:      1200px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #0f1216;
    --surface: #171b21;
    --border:  #262c34;
    --text:    #e8ebef;
    --muted:   #9aa4b0;
    --primary: #4b83f0;
    --danger:  #ff6b5e;
    --danger-bg:#2a1614;
    --ok:      #4ade80;
    --ok-bg:   #10231a;
    --info:    #7cb0ff;
    --info-bg: #101b2b;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  /* overflow-x is belt and braces: the layout should never need it. */
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Anything that could overflow — a long word, a code span, a URL — wraps
   rather than widening the page. */
p, h1, h2, dd, dt, code, .alert { overflow-wrap: anywhere; }

.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;
}

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

.hdr {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.hdr-in {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  display: flex;
  flex-wrap: wrap;          /* at 360px the three regions stack; no scroll */
  align-items: center;
  gap: 10px;
}

.brand {
  font-weight: 650;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
  min-width: 0;
}

.switcher { display: flex; gap: 6px; order: 3; width: 100%; }
.switcher select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}
.inline { display: inline; margin: 0; }

.nav { border-top: 1px solid var(--border); }
.nav-in {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
  min-height: 0;            /* empty until a module fills it */
  display: flex;
  gap: 4px;
  overflow-x: auto;         /* the nav scrolls, never the page */
  scrollbar-width: thin;
}

/* ----------------------------------------------------------------- main */

.main { flex: 1; padding: var(--gap) 0 32px; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
}

.h1 { font-size: 20px; margin: 0 0 6px; }
.muted { color: var(--muted); margin: 0 0 14px; }
.small { font-size: 13px; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.kv {
  display: grid;
  grid-template-columns: 1fr;   /* stacked at 360px */
  gap: 2px 16px;
  margin: 0 0 14px;
  font-size: 15px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0 0 8px; font-weight: 550; }

.alert {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 14px;
  font-size: 15px;
}

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

.auth {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.auth .card { width: 100%; max-width: 380px; }
.auth-title { font-size: 20px; margin: 0 0 16px; }

.field { display: block; margin: 0 0 14px; }
.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  /* 16px keeps iOS from zooming the viewport on focus, which is a common
     cause of an apparent horizontal scroll on phones. */
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.field input:focus-visible,
.switcher select:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn {
  display: inline-block;
  padding: 11px 16px;
  font: inherit;
  font-size: 15px;
  font-weight: 550;
  line-height: 1.2;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;          /* comfortable touch target */
}
.btn-sm { padding: 7px 11px; font-size: 14px; min-height: 36px; }
.btn-primary {
  width: 100%;
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

/* --------------------------------------------------------------- footer */

.foot {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* --------------------------------------------------------- wider screens */

@media (min-width: 640px) {
  .switcher { order: 0; width: auto; }
  .switcher select { width: auto; min-width: 220px; }
  .brand { font-size: 18px; }
  .who-name { max-width: none; }
  .card { padding: 24px; }
  .kv { grid-template-columns: minmax(160px, max-content) 1fr; }
  .kv dd { margin-bottom: 0; }
  .btn-primary { width: auto; }
}

@media (min-width: 1024px) {
  .hdr-in { padding: 12px 24px; }
  .container { padding-left: 24px; padding-right: 24px; }
  .h1 { font-size: 22px; }
}

/* ---------------------------------------------------------------------------
   V2-03 additions: nav links, tables, badges, hints.
   Same rule as the rest of the file — mobile first, no fixed pixel widths,
   and anything that could overflow scrolls inside its own box rather than
   widening the page.
   --------------------------------------------------------------------------- */

.mt { margin-top: 16px; }
.h2 { font-size: 17px; margin: 0 0 10px; }
.tight { margin: 0; padding-left: 18px; }
.tight-p { margin: 0 0 8px; }

.nav-a {
  display: inline-block;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.nav-a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 550; }

.alert-ok   { background: var(--ok-bg);   border-color: var(--ok);   color: var(--ok); }
.alert-info { background: var(--info-bg); border-color: var(--info); color: var(--info); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.badge-ok   { color: var(--ok);   border-color: var(--ok); }
.badge-warn { color: var(--danger); border-color: var(--danger); }

.hint { display: block; margin-top: 5px; font-size: 13px; color: var(--muted); }

.mono-block {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  /* A token is one long unbreakable string — the single most likely thing on
     any of these pages to force a horizontal scrollbar. It wraps. */
  word-break: break-all;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
}

/* Tables become stacked cards below 640px. A table is the other thing that
   forces horizontal scroll on a phone; this removes the table box entirely
   rather than making the page scroll. */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.tbl th { font-size: 13px; color: var(--muted); font-weight: 600; }

@media (max-width: 639px) {
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl thead { display: none; }
  .tbl tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 10px; }
  .tbl td { border: 0; padding: 5px 0; display: flex; gap: 10px; align-items: baseline; }
  .tbl td::before {
    content: attr(data-l);
    flex: 0 0 34%;
    font-size: 13px;
    color: var(--muted);
  }
  .tbl td:empty { display: none; }
}

.auth-card { max-width: 420px; }
.field select {
  width: 100%; padding: 11px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}

/* ---------------------------------------------------------------------------
   V2-04: module pages (Inventory, Modules admin).
   Same rule throughout — mobile first from 360px, no fixed pixel widths, and
   anything that could overflow is contained inside its own box.
   --------------------------------------------------------------------------- */

.row-between { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; justify-content: space-between; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* auto-fit means the columns collapse to one at 360px with no media query */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.stat {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat-n { font-size: 22px; font-weight: 650; line-height: 1.1; }
.stat-l { font-size: 13px; color: var(--muted); }

.filters {
  display: grid;
  grid-template-columns: 1fr;      /* stacked at 360px */
  gap: 0 12px;
  margin-top: 8px;
}
.filter-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }

.field textarea {
  width: 100%; padding: 11px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); resize: vertical;
}
.field input[type=file] { width: 100%; font-size: 15px; }

.mono-sm { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; overflow-wrap: anywhere; }
.tbl-sm { font-size: 14px; }
.kv-sm { font-size: 14px; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.timeline { margin: 0; padding-left: 18px; font-size: 15px; }
.timeline li { margin-bottom: 6px; overflow-wrap: anywhere; }

.filelist { margin: 0; padding-left: 18px; }
.filelist li { margin-bottom: 8px; overflow-wrap: anywhere; }

.mod { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 16px; }
.mod:first-of-type { border-top: 0; padding-top: 0; margin-top: 8px; }

.btn-danger { color: var(--danger); border-color: var(--danger); }

@media (min-width: 640px) {
  .filters { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .grid2   { grid-template-columns: 1fr 1fr; }
}

/* ---------------------------------------------------------------------------
   V2-05: grouped nav, search, dashboard cards, prize wheel.
   Mobile first from 360px; no fixed pixel widths on any layout box.
   --------------------------------------------------------------------------- */

.nav-group {
  align-self: center; padding: 0 10px 0 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap;
}
.nav-group:not(:first-child) { border-left: 1px solid var(--border); margin-left: 6px; }

.searchbar {
  display: flex; gap: 8px; align-items: center;
  width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding: 8px 16px 10px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  border-top: 1px solid var(--border);
}
.searchbar input {
  flex: 1; min-width: 0;                 /* min-width:0 is what lets it shrink to 360px */
  padding: 9px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}

.results { margin: 0; padding-left: 18px; }
.results li { margin-bottom: 10px; overflow-wrap: anywhere; }

/* auto-fit: one column at 360px, more when there is room, no media query */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.dash-card { min-width: 0; }

.h3 { font-size: 15px; margin: 14px 0 6px; }
.svc-list { margin: 0; padding-left: 18px; }
.svc-list li { margin-bottom: 10px; overflow-wrap: anywhere; }
.mt-sm { margin-top: 6px; }

.check { display: flex; gap: 8px; align-items: center; margin: 0 0 14px; font-size: 15px; }
.check input { width: 18px; height: 18px; }

/* ---- the wheel ---------------------------------------------------------- */

.wheel-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin: 12px 0 16px; flex-wrap: wrap; }
.wheel-tab {
  padding: 9px 14px; font-size: 15px; font-weight: 600; color: var(--muted);
  text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.wheel-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.wheel-wrap { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }

.wheel-stage {
  position: relative;
  /* Sized in relative units so it fits 360px and grows — never a fixed px box. */
  width: min(84vw, 360px);
  aspect-ratio: 1;
  margin: 0 auto;
}

/*
   v1 drew the wheel on a hidden <canvas>, exported it with toDataURL() and
   rotated the resulting <img> — because rotating a live canvas misbehaved in
   Firefox. This keeps the same shape of fix (rotate a static painted surface)
   with one fewer moving part: a CSS conic-gradient on a plain div. No canvas,
   no data URL, nothing to export, and it re-renders at any size for free.
*/
.wheel-disc {
  width: 100%; height: 100%; border-radius: 50%;
  border: 6px solid var(--surface);
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  transform: rotate(0deg);
}
.wheel-disc.spun {
  animation: wheel-land 3.2s cubic-bezier(.15,.85,.25,1) forwards;
}
@keyframes wheel-land {
  from { transform: rotate(0deg); }
  to   { transform: rotate(var(--turn, 0deg)); }
}
/* Respect a stated preference for less motion: the result is identical, it
   simply arrives without the spin. */
@media (prefers-reduced-motion: reduce) {
  .wheel-disc.spun { animation: none; transform: rotate(var(--turn, 0deg)); }
}

.wheel-pointer {
  position: absolute; top: 50%; right: -6px; transform: translateY(-50%);
  width: 0; height: 0; z-index: 2;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-right: 20px solid var(--text);
}

.wheel-side { min-width: 0; }
.wheel-spin { width: 100%; font-size: 17px; font-weight: 700; letter-spacing: .03em; }

.wheel-result {
  display: flex; flex-direction: column; gap: 2px;
  border: 2px solid var(--pc, var(--primary)); border-radius: var(--radius);
  padding: 12px 14px; margin: 12px 0;
}
.wheel-result-l { font-size: 13px; color: var(--muted); }
.wheel-result-p { font-size: 19px; color: var(--pc, var(--primary)); overflow-wrap: anywhere; }

.prize-list { margin: 0; padding: 0; list-style: none; font-size: 15px; }
.prize-list li { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; overflow-wrap: anywhere; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 11px; display: inline-block; }

@media (min-width: 768px) {
  .wheel-wrap { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .wheel-stage { width: 100%; max-width: 420px; }
  .wheel-spin { width: auto; }
}
