/* ==========================================================================================
   "Aussehen" dialog + trigger. Built only from the shared palette tokens, so it follows every
   theme (Classic included). Theme files may restyle it further; the Classic thumbnail lives here,
   the other thumbnails (.theme-thumb-<id>) live in their theme file.
   ========================================================================================== */

.appearance-dialog {
  --ap-radius: var(--theme-radius-lg, 10px);
  width: min(760px, calc(100vw - 24px));
  max-height: min(92vh, 920px);
  max-height: min(92dvh, 920px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--ap-radius);
  background: var(--gunmetal);
  color: var(--bone);
  box-shadow: var(--shadow-deep);
  overflow: auto;
  overscroll-behavior: contain;
}
.appearance-dialog::backdrop { background: color-mix(in srgb, var(--shade, #000) 55%, transparent); }
.appearance-dialog[open] { animation: dialog-in var(--t-med) var(--ease-out); }
.appearance-panel { display: grid; gap: var(--sp-5); padding: clamp(16px, 3vw, 28px); }
.appearance-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); }
.appearance-head h2 { font-size: clamp(1.4rem, 1vw + 1.1rem, 1.9rem); }
.appearance-head p { margin: 6px 0 0; color: var(--smoke); font-size: var(--fs-sm); }
.appearance-close { flex: none; min-width: 44px; min-height: 44px; }

.appearance-dialog fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.appearance-dialog legend { margin-bottom: var(--sp-3); padding: 0; color: var(--smoke); font-size: var(--fs-sm); font-weight: 600; }

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-3); }
.theme-card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line-steel);
  border-radius: var(--ap-radius);
  background: color-mix(in srgb, var(--steel) 40%, transparent);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.theme-card:hover { border-color: var(--line-strong); }
.theme-card input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.theme-card:has(input:checked) { border-color: var(--brass); background: color-mix(in srgb, var(--brass) 10%, transparent); box-shadow: 0 0 0 1px var(--brass); }
.theme-card:has(input:focus-visible) { box-shadow: var(--focus); }
.theme-card-text { display: grid; gap: 2px; min-width: 0; }
.theme-card-text strong { font-size: var(--fs-md); line-height: 1.25; }
.theme-card-text small { color: var(--smoke); line-height: 1.4; }
.theme-card-check {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brass);
  color: var(--on-accent, #1a1307);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.theme-card-check svg { width: 16px; height: 16px; }
.theme-card:has(input:checked) .theme-card-check { opacity: 1; transform: none; }

/* thumbnail skeleton: every theme paints its own */
.theme-thumb {
  position: relative;
  display: grid;
  grid-template-rows: 14px 1fr 30px;
  gap: 6px;
  height: 112px;
  padding: 8px;
  overflow: hidden;
  border-radius: calc(var(--ap-radius) - 4px);
  isolation: isolate;
}
.theme-thumb > * { position: relative; z-index: 1; }
.tt-bar { display: flex; align-items: center; gap: 4px; }
.tt-bar i { display: block; width: 18px; height: 4px; border-radius: 2px; background: currentColor; opacity: 0.5; }
.tt-hero { display: flex; align-items: flex-end; padding: 6px 8px; }
.tt-hero b { font-size: 18px; line-height: 1; }
.tt-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tt-card { display: block; }
.tt-deco { position: absolute; inset: 0; z-index: 0; pointer-events: none; }

/* Classic thumbnail */
.theme-thumb-classic { background: radial-gradient(120px 60px at 85% 0, rgba(214, 165, 71, 0.18), transparent 70%), #0b0f10; color: #ece5d3; }
.theme-thumb-classic .tt-bar { border-bottom: 1px solid rgba(214, 165, 71, 0.3); }
.theme-thumb-classic .tt-bar i:first-child { background: #d6a547; opacity: 1; }
.theme-thumb-classic .tt-hero b { font-family: 'Big Shoulders Display', 'Barlow Condensed', sans-serif; font-weight: 800; letter-spacing: 0.02em; color: #f1ca78; }
.theme-thumb-classic .tt-card { background: linear-gradient(180deg, #1f2a2d, #131a1c); clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px); border-top: 1px solid rgba(214, 165, 71, 0.5); }

/* mode switch (segmented control) */
.mode-switch { display: inline-grid; grid-auto-flow: column; grid-auto-columns: minmax(88px, 1fr); max-width: 100%; padding: 4px; gap: 4px; border: 1px solid var(--line-steel); border-radius: calc(var(--ap-radius) + 2px); background: color-mix(in srgb, var(--shade, #000) 18%, transparent); }
.mode-option { position: relative; display: block; cursor: pointer; }
.mode-option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.mode-option span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 14px; border-radius: calc(var(--ap-radius) - 2px); color: var(--bone-2); font-weight: 600; transition: background var(--t-fast), color var(--t-fast); }
.mode-option input:checked + span { background: var(--brass); color: var(--on-accent, #1a1307); }
.mode-option input:focus-visible + span { box-shadow: var(--focus); }
.appearance-modes.is-disabled .mode-option { cursor: not-allowed; }
.appearance-modes.is-disabled .mode-option span { opacity: 0.5; }
.appearance-modes.is-disabled .mode-option input:checked + span { background: var(--steel-2); color: var(--bone); }
.appearance-note { margin: var(--sp-3) 0 0; color: var(--smoke); font-size: var(--fs-sm); }

/* switch */
.appearance-toggle { display: flex; align-items: center; gap: var(--sp-3); min-height: 44px; padding: var(--sp-3); border: 1px solid var(--line-steel); border-radius: var(--ap-radius); cursor: pointer; }
.appearance-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { position: relative; flex: none; width: 48px; height: 28px; border-radius: 14px; background: var(--steel-3); transition: background var(--t-fast); }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--bone); box-shadow: 0 1px 3px color-mix(in srgb, var(--shade, #000) 40%, transparent); transition: transform var(--t-fast) var(--ease-out); }
.appearance-toggle input:checked + .toggle-track { background: var(--brass); }
.appearance-toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); background: var(--on-accent, #1a1307); }
.appearance-toggle input:focus-visible + .toggle-track { box-shadow: var(--focus); }
.toggle-text { display: grid; gap: 2px; }
.toggle-text small { color: var(--smoke); }

.appearance-foot { display: flex; justify-content: flex-end; }
.appearance-foot .btn { min-height: 44px; }

/* The header gained the "Aussehen" button. To keep nav and actions in one row at every desktop
   width (members and admins): search is icon-only in the header (the "/" shortcut stays), and
   below 1240px the user chip shows only the avatar, like Classic already does below 1080px. */
.topbar .search-trigger { min-width: 0; width: 40px; padding: 0; justify-content: center; border-color: transparent; background: none; }
.topbar .search-trigger span, .topbar .search-trigger kbd { display: none; }
@media (max-width: 1240px) {
  .topbar .user-chip > span:not(.avatar) { display: none; }
  .topbar .user-chip { padding: 0 4px; border-color: transparent; background: none; }
}
/* logged-in header at 320px overflowed by ~20px: logout is also in the menu, so drop the header copy */
@media (max-width: 360px) {
  .topbar-actions [data-logout] { display: none; }
}
/* admins have one nav item more: tighten the nav a little earlier than Classic did */
@media (max-width: 1420px) {
  .mainnav .nav-link { padding-left: 9px; padding-right: 9px; }
  .topbar .brand-word small { display: none; }
}
@media (max-width: 1180px) {
  .mainnav .nav-link { padding-left: 6px; padding-right: 6px; }
}

/* triggers: header button on desktop, drawer entry on mobile (the header has no room below 1080px) */
.appearance-menu-item .icon { color: var(--brass); }
@media (max-width: 1080px) {
  .topbar .appearance-trigger { display: none; }
}

@media (max-width: 560px) {
  .appearance-dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: auto 0 0; border-radius: var(--ap-radius) var(--ap-radius) 0 0; border-bottom: 0; }
  .theme-grid { grid-template-columns: 1fr; }
  .theme-card { grid-template-columns: 112px minmax(0, 1fr); grid-template-rows: none; align-items: center; }
  .theme-thumb { height: 84px; grid-template-rows: 10px 1fr 20px; gap: 4px; padding: 6px; }
  .tt-hero b { font-size: 14px; }
  .theme-card-check { top: 8px; right: 8px; width: 22px; height: 22px; }
  .mode-switch { display: grid; width: 100%; grid-auto-columns: 1fr; }
  .appearance-foot .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .appearance-dialog[open] { animation: none; }
  .theme-card, .theme-card-check, .toggle-thumb, .toggle-track, .mode-option span { transition: none; }
}
