/* Palette ported from v1 (honka-t13-omatoimi-2026-cloudfare) for visual
   continuity — see docs/spec.md §1. Extended with neutral/semantic tokens
   so spacing, borders, and "destructive action" styling stay consistent
   instead of scattered inline hex codes. */
:root {
  --color-primary: #1b6b35;
  --color-dark: #0f3d1e;
  --color-light: #e8f5ec;
  --color-accent: #f5a623;
  --color-text: #1a1a1a;
  --color-white: #ffffff;

  --color-muted: #6b7280;
  --color-border: #d6dbd8;
  --color-danger: #b3261e;
  --color-danger-bg: #fdecea;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 2px rgba(15, 61, 30, 0.08), 0 2px 8px rgba(15, 61, 30, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--color-text);
  background: var(--color-light);
  line-height: 1.45;
}

h1, h2, h3 {
  font-weight: 700;
  line-height: 1.25;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 0.9rem;
}

h3 {
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
  color: #333;
}

header.app-header {
  background: var(--color-dark);
  color: var(--color-white);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

header.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
  /* Truncate instead of squeezing the lang-toggle (see below) out of
     the visible row on a narrow phone screen — a long title + the
     toggle + the help icon easily add up to more than the viewport
     width, and without this the flex box was shrinking everything
     proportionally, which could compress the second lang-toggle button
     down far enough to be effectively invisible/unclickable. */
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Both options are always visible — see public/i18n.js's ensureLangButtons,
   which mounts the two .lang-btn children into this (otherwise empty)
   container. flex-shrink:0 so it never loses the fight for space against
   the header title above. */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 0.2rem;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 8px;
  padding: 0.2rem;
}

.lang-btn {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 0.2rem 0.35rem;
  font-size: 1.05rem;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background-color 0.15s;
}

.lang-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.lang-btn.active {
  background: rgba(255, 255, 255, 0.3);
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* Staff-facing pages only (public/version-footer.js fills this in) — kept
   off the player page on purpose, see that file's comment. */
.app-footer {
  text-align: center;
  padding: 0.5rem 1rem 1.25rem;
  font-size: 0.75rem;
  color: var(--color-muted);
}

/* Desktop-friendly layout for the admin/superadmin ("ylläpito") consoles —
   the mobile layout stays the default; this only widens things out past a
   tablet-ish breakpoint. Player/coach stay mobile-first intentionally. */
@media (min-width: 860px) {
  main.wide {
    max-width: 1100px;
  }
  .two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
  }
  .two-col > .card {
    margin-bottom: 0;
  }
  .card-narrow {
    max-width: 480px;
  }
}

.card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
}

button,
select,
input,
textarea {
  font-size: 1rem;
  font-family: inherit;
}

/* Every plain, un-classed <button> (rename/reset/remove/prev-next/etc.) gets
   this by default — previously only button.primary and button.tab-btn had
   any styling at all, so everything else fell back to the browser's bare
   square default. */
button {
  background: var(--color-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.05s;
}

button:hover {
  background: var(--color-light);
  border-color: #b7c2bd;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

button.primary {
  background: var(--color-primary);
  color: var(--color-white);
  border: none;
  border-radius: var(--radius);
  padding: 0.8rem 1.25rem;
  width: 100%;
  font-weight: 700;
  cursor: pointer;
}

button.primary:hover {
  background: var(--color-dark);
}

button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* "Sign in with Google" button, styled per Google's official branding
   guidelines (white/neutral theme) rather than this app's own button
   styles — it's a recognizable brand mark, not meant to be restyled. */
button.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #747775;
  border-radius: 4px;
  padding: 0.6rem 1rem;
  width: 100%;
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

button.google-btn:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
}

button.google-btn:active {
  background: #f1f3f4;
}

.google-btn-icon {
  display: inline-flex;
  flex-shrink: 0;
}

/* A clearly-marked destructive/leave action (remove player, remove coach,
   deactivate) — an outlined red treatment, not solid, so it reads as
   "careful" rather than screaming at every glance. */
button.btn-danger {
  background: var(--color-white);
  color: var(--color-danger);
  border: 1px solid #e3a8a4;
}

button.btn-danger:hover {
  background: var(--color-danger-bg);
  border-color: var(--color-danger);
}

button.tab-btn {
  background: var(--color-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  font-weight: 600;
  cursor: pointer;
}

/* 2x2 on mobile, a single row of however many on desktop — replaces plain
   flex-wrap, which left an odd tab stranded full-width on its own row. */
.tab-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
@media (min-width: 560px) {
  .tab-row {
    grid-template-columns: repeat(var(--tab-count, 4), 1fr);
  }
}

/* Icon-only link (currently just sign-out) — public/icons.js mounts the
   SVG; this just sizes/positions it like a small round button. */
.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  padding: 0.3rem;
  border-radius: var(--radius);
  vertical-align: middle;
}

/* Same idea as .icon-link, but for an icon sitting on the dark header bar
   (next to the lang-toggle) instead of a white card — the help ("?") link. */
.header-icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-white);
  padding: 0.3rem;
  border-radius: var(--radius);
}

.header-icon-link:hover {
  background: rgba(255, 255, 255, 0.12);
}

.icon-link:hover {
  background: var(--color-light);
}

a.text-link {
  color: var(--color-primary);
  font-size: 0.9rem;
  text-decoration: none;
}

a.text-link:hover {
  text-decoration: underline;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 0.3rem;
}

select,
textarea,
input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  background: var(--color-white);
  color: var(--color-text);
}

select:focus,
textarea:focus,
input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(27, 107, 53, 0.12);
  outline: none;
}

/* A field meant to sit inline at its natural width (a role dropdown next to
   an email field, a page-size select, etc.) rather than stretching full width. */
.field-auto {
  width: auto !important;
  flex: 0 0 auto;
}

.form-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.form-row > input {
  flex: 1;
  min-width: 160px;
  margin-bottom: 0;
}
.form-row > select {
  margin-bottom: 0;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--color-light);
  gap: 0.5rem;
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-label {
  color: var(--color-muted);
}

.stat-value {
  font-weight: 600;
}

.error-text {
  color: var(--color-danger);
  font-size: 0.9rem;
}

.pill {
  display: inline-block;
  background: var(--color-accent);
  color: var(--color-dark);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Small composable utilities, used instead of one-off inline style="..."
   attributes scattered through the page markup. */
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.row-gap {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.col-start {
  flex-direction: column;
  align-items: flex-start;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--color-muted);
}

.text-2xs {
  font-size: 0.7rem;
}

.text-xs {
  font-size: 0.75rem;
}

.text-sm {
  font-size: 0.85rem;
}

.text-lg {
  font-size: 1.3rem;
}

.text-primary-strong {
  color: var(--color-primary);
  font-weight: 600;
}

.mt-0 {
  margin-top: 0;
}

.mt-sm {
  margin-top: 0.3rem;
}

.mb-sm {
  margin-bottom: 0.3rem;
}

.mt-md {
  margin-top: 0.5rem;
}

.mt-md-lg {
  margin-top: 0.75rem;
}

.mt-lg {
  margin-top: 1rem;
}

.mt-xl {
  margin-top: 1.5rem;
}

.mr-md {
  margin-right: 1rem;
}

.block {
  display: block;
}

.w-full {
  width: 100%;
}

.fw-normal {
  font-weight: 400;
}

.bg-accent {
  background: var(--color-accent);
}

.clickable {
  cursor: pointer;
}

/* A fixed side drawer (coach's player detail pane) — shown by removing the
   `hidden` attribute rather than toggling inline style.display. */
.player-pane {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 380px;
  overflow-y: auto;
  border-radius: 0;
  margin: 0;
  z-index: 10;
}

.player-pane:not([hidden]) {
  display: block;
}

/* Dashboard widgets (public/dashboard-widgets.js) — the coach dashboard and
   the admin builder's live preview share these so a widget looks identical
   in both places. */
.kpi-value {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0.3rem 0;
}

/* Fixed-size box for a KPI's donut/gauge canvas — Chart.js is told
   maintainAspectRatio:false (see dashboard-widgets.js) so it fills this
   exactly instead of blowing up to match the card's full width. */
.kpi-donut-wrap {
  position: relative;
  max-width: 220px;
  margin: 0 auto;
}

/* Fixed-height box for a horizontal 2-bar comparison chart (player home
   screen's "this week" / "all weeks average" charts) — full card width,
   just a controlled height so Chart.js's responsive sizing doesn't
   balloon it (same reasoning as .kpi-donut-wrap). */
.hbar-wrap {
  position: relative;
  height: 90px;
}

/* A little "phone" frame around the landing-page preview iframe (admin's
   "player's form" tab) — it's the real live page, just boxed down so it
   reads as a preview rather than a broken-looking full-width iframe. */
.phone-preview {
  width: 100%;
  max-width: 300px;
  height: 540px;
  margin: 0 auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.phone-preview iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.trend-badge {
  font-size: 1.15rem;
  font-weight: 700;
}

.kpi-compare {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.kpi-bar-track {
  background: var(--color-light);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.kpi-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
}

.kpi-bar-fill-muted {
  background: var(--color-muted);
}

.trend-up {
  color: var(--color-primary);
}

.trend-down {
  color: var(--color-danger);
}

.trend-flat {
  color: var(--color-muted);
}

.avatar-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  margin-right: 0.4rem;
  vertical-align: middle;
}

/* Interactive choice-options builder (admin "player's form" tab) — chips
   for existing options, a round "+" that turns into an inline text input
   when clicked, committed on Enter or on blur (click outside). */
.option-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--color-light);
  border-radius: 999px;
  padding: 0.3rem 0.4rem 0.3rem 0.75rem;
  font-size: 0.85rem;
}

.option-remove-btn {
  background: transparent;
  border: none;
  padding: 0;
  width: 1.2rem;
  height: 1.2rem;
  line-height: 1;
  font-size: 1rem;
  color: var(--color-muted);
  cursor: pointer;
}

.option-remove-btn:hover {
  color: var(--color-danger);
}

.option-add-btn {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

/* #q-options-builder (an id selector) deliberately outranks the generic
   `input:not(...)` rule's width:100% — see the .pin-box fix above for why
   a bare class here would silently lose that fight. */
#q-options-builder input.option-input {
  width: auto;
  flex: 0 0 140px;
  margin-bottom: 0;
}

/* Shared modal (public/modal.js) — replaces window.alert/confirm/prompt. */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
}

.modal-sheet {
  display: none;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(90vw, 360px);
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  z-index: 41;
  box-shadow: var(--shadow-card);
}

/* Shared loading placeholder — dropped into a container's innerHTML while
   its data is in flight, so a slow connection shows *something* changing
   instead of stale content that looks clickable but isn't current yet. */
.loading-spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}

.loading-text {
  color: var(--color-muted);
  padding: 0.5rem 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 4-box PIN entry (see public/pin-input.js) — each box holds one digit,
   auto-advances focus, keeps a hidden input in sync so existing form code
   (document.getElementById("...").value) needs no changes. */
.pin-boxes {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

/* Selector (not just .pin-box) is deliberate: the generic
   `input:not([type=checkbox]):not([type=radio])` rule above sets
   width:100% with higher specificity (0,2,1) than a bare .pin-box
   (0,1,0), which silently won and stretched these full-width. This
   selector matches that specificity so the later rule (this one) wins. */
.pin-boxes > input.pin-box {
  width: 2.5rem;
  height: 2.9rem;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 0;
  margin-bottom: 0;
  letter-spacing: 0;
}

/* Table defaults — previously no th/td padding existed anywhere, so every
   table's cells ran edge-to-edge with no breathing room. */
table {
  border-collapse: collapse;
  width: 100%;
}

th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--color-muted);
  font-weight: 700;
  padding: 0.5rem 0.6rem;
  border-bottom: 2px solid var(--color-light);
}

td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--color-light);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:nth-child(even) {
  background: rgba(15, 61, 30, 0.025);
}

td button {
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  margin: 0.1rem 0.15rem 0.1rem 0;
}
