/* Settings page + profile identity header (design round 26 website sections
   1 and 4). Loaded LAST in index.html's head, so the few rules that override
   css/style.css do it by cascade order, never with !important. */

/* Pre-paint guard for the livery chrome: index.html ships
   <body class="pre-scheme">, js/lib/scheme.js removes it as soon as the
   cached palette is on :root. The delayed 0s animation is the failsafe: if
   the module never runs, the page reveals itself after 1.2s instead of
   staying blank forever. */
body.pre-scheme { visibility: hidden; animation: scheme-reveal 0s linear 1.2s forwards; }
@keyframes scheme-reveal { to { visibility: visible; } }

/* ---------- layout: left rail + stacked sections ---------- */

#view-settings .page { max-width: 1040px; }

.settings-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  align-items: start;
}

.settings-rail {
  position: sticky;
  top: calc(var(--nav-h) + 16px);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-rail a {
  display: block;
  padding: 9px 12px;
  min-height: 44px;
  line-height: 26px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.settings-rail a:hover { color: var(--text); background: var(--bg-raised); }
.settings-rail a.active { color: var(--brand-accent); background: var(--brand-accent-soft); }

.settings-content { min-width: 0; }

.settings-section {
  scroll-margin-top: calc(var(--nav-h) + 16px);
  margin-bottom: 28px;
}

.settings-section > h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.settings-section > .section-note { margin-top: 0; }

/* The page has no default anchor styling to inherit, so give its links the
   accent and take the underline off the ones that are buttons. */
.settings-section a { color: var(--brand-accent); }
.settings-section a.btn { color: var(--text); text-decoration: none; }
.about-links { display: flex; gap: 16px; }

/* ---------- map display: the livery tiles ---------- */

.scheme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.scheme-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.scheme-tile:hover { border-color: var(--muted); }
.scheme-tile.selected { border-color: var(--brand-accent); background: var(--brand-accent-soft); }

/* Visually hidden, still focusable and still keyboard operable. */
.scheme-tile input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.scheme-tile:focus-within { outline: 2px solid var(--brand-accent); outline-offset: 2px; }

.scheme-swatch {
  flex: none;
  width: 44px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, var(--sw-day) 0 50%, var(--sw-night) 50% 100%);
}

/* Wrap the long livery names instead of ellipsizing them: on a phone the
   tiles are two per row and "Mattighofen Orange" must stay readable. */
.scheme-name { min-width: 0; }

/* ---------- switches ---------- */

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.switch-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: none;
  accent-color: var(--brand-accent);
}

/* ---------- sign-in methods + passkeys ---------- */

.method-row,
.pk-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.method-row:last-child,
.pk-row:last-child { border-bottom: none; }

.method-main,
.pk-main { flex: 1; min-width: 0; }

.method-main > .muted,
.pk-main > .muted { margin: 2px 0 0; }

.pk-list { margin: 4px 0 10px; }

/* ---------- profile identity header ---------- */

.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 4px 0 18px;
}

.profile-disc {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand-accent-soft);
  color: var(--brand-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  border: 2px solid var(--brand-accent);
}

.profile-id { flex: 1; min-width: 160px; }
.profile-id .profile-title { font-weight: 700; font-size: 20px; }
.profile-id .profile-sub { color: var(--muted); font-size: 13px; }
.profile-actions { display: flex; gap: 8px; align-items: center; }
.profile-edit-form { width: 100%; }
.profile-link-row { width: 100%; display: flex; gap: 8px; align-items: center; }
.profile-link-row input { flex: 1; min-width: 0; }

/* ---------- mobile: rail becomes a chip strip ---------- */

@media (max-width: 720px) {
  .settings-layout { grid-template-columns: 1fr; gap: 14px; }
  .settings-rail {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 4px;
  }
  .settings-rail a { border: 1px solid var(--border); }
  #view-settings .btn,
  #view-settings input,
  #view-settings select { min-height: 44px; }
  .about-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  /* The scheme-tile radio is the standard visually-hidden-but-focusable
     a11y input (clip-path'd to nothing, real target = the wrapping
     label) - the blanket rule above must not inflate it back to a real
     44px box, or it becomes an invisible-but-present tap target that
     eats touches meant for whatever sits under it. */
  #view-settings .scheme-tile input { min-height: 1px; }
  .profile-header .btn { min-height: 44px; }
}
