/* Compact, accessible preference disclosure shared by every page. */

.header-tools {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-shrink: 0;
}

.preferences-menu {
  position: relative;
  flex-shrink: 0;
}

.preferences-trigger {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  list-style: none;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    color var(--motion-duration-base) ease,
    border-color var(--motion-duration-base) ease,
    background-color var(--motion-duration-base) ease,
    box-shadow var(--motion-duration-base) ease;
}

.preferences-trigger::-webkit-details-marker {
  display: none;
}

.preferences-trigger:hover {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
  color: var(--accent-primary);
}

.preferences-trigger:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
}

.preferences-menu[open] .preferences-trigger {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.preferences-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
}

.preferences-panel {
  position: absolute;
  z-index: 50;
  top: calc(100% + var(--space-sm));
  right: 0;
  width: min(19rem, calc(100vw - 2rem));
  padding: var(--space-md);
  border: 1px solid var(--control-border);
  border-radius: 14px;
  background: var(--bg-card);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

.preferences-title {
  margin-bottom: var(--space-md);
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.25;
}

.preference-field {
  display: grid;
  gap: var(--space-xs);
}

.preference-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
}

.language-select {
  width: 100%;
  height: 44px;
  padding: 0 2.25rem 0 0.75rem;
  appearance: none;
  border: 1px solid var(--control-border);
  border-radius: 9px;
  background-color: var(--bg-secondary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238888a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
}

.language-select:hover {
  border-color: var(--accent-primary);
}

.language-select:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.preference-fieldset {
  margin-top: var(--space-md);
  border: 0;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.theme-option {
  position: relative;
  cursor: pointer;
}

.theme-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.theme-option-control {
  display: flex;
  min-height: 60px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: var(--space-xs);
  border: 1px solid var(--control-border);
  border-radius: 9px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  transition:
    color var(--motion-duration-fast) ease,
    border-color var(--motion-duration-fast) ease,
    background-color var(--motion-duration-fast) ease;
}

.theme-option-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-option-label {
  line-height: 1;
}

.theme-option:hover .theme-option-control {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.theme-option input:checked + .theme-option-control {
  border-color: var(--accent-primary);
  background: var(--bg-card);
  box-shadow: inset 0 0 0 1px var(--accent-primary);
  color: var(--accent-primary);
}

.theme-option input:focus-visible + .theme-option-control {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.history-preference {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-sm);
  min-height: 44px;
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--card-border);
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
}

.history-preference-input {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 44px;
  height: 44px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.history-preference-copy {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.history-preference-label {
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 600;
}

.history-preference-hint {
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1.4;
}

.history-switch-control {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 10px;
}

.history-switch {
  position: relative;
  width: 42px;
  height: 24px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--bg-secondary);
  transition:
    border-color var(--motion-duration-fast) ease,
    background-color var(--motion-duration-fast) ease;
}

.history-switch::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-secondary);
  content: "";
  transition:
    background-color var(--motion-duration-fast) ease,
    transform var(--motion-duration-fast) ease;
}

.history-preference:hover .history-switch {
  border-color: var(--accent-primary);
}

.history-preference-input:checked + .history-switch {
  border-color: var(--accent-primary);
  background: var(--accent-primary);
}

.history-preference-input:checked + .history-switch::after {
  background: var(--bg-card);
  transform: translateX(18px);
}

.history-preference-input:focus-visible + .history-switch {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  .server-info {
    display: none;
  }
}

@media (max-width: 480px) {
  .header {
    gap: var(--space-sm);
  }

  .brand {
    max-width: calc(100% - 60px);
  }

  .server-name {
    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;
  }

  .header-tools {
    gap: 0;
  }
}
