/* ============================================================
   v6 Settings modal + theme overrides
   ============================================================
*/

/* ============================================================
   Theme: Ultra-dark (true black, OLED-friendly)
   Applied via body.v6-theme-ultra-dark from SettingsModal.
   Loaded outside @layer to win the cascade against v5 surfaces.
   ============================================================ */
body.v6-theme-ultra-dark {
  --v6-bg: #000000;
  --surface-100: #000000;
  --surface-200: #050505;
  --surface-300: #0a0a0a;
  --surface-400: #111111;
  --surface-500: #1a1a1a;
  --surface-600: #222222;

  --v6-panel: #0a0a0a;
  --v6-panel-raised: #111111;
  --v6-panel-hover: #1a1a1a;
  --v6-panel-active: #222222;
}

/* ============================================================
   Density: Compact (tighter row heights / paddings)
   ============================================================ */
body.v6-density-compact {
  --row-h-default: 22px;
  --row-h-comfortable: 28px;
  --control-h-md: 26px;
  --control-h-lg: 32px;
}

/* ============================================================
   Reduced-motion override (user-forced, regardless of OS)
   ============================================================ */
body.v6-reduced-motion *,
body.v6-reduced-motion *::before,
body.v6-reduced-motion *::after {
  animation-duration: 0ms !important;
  animation-delay: 0ms !important;
  transition-duration: 0ms !important;
}

@layer v6-components {

  /* ============================================================
     Modal
     ============================================================ */
  .v6-settings {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 900);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-base, 180ms) var(--ease-out-quart);
  }
  .v6-settings--visible {
    opacity: 1;
    pointer-events: auto;
  }
  .v6-settings__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .v6-settings__card {
    position: relative;
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    background: var(--v6-panel, var(--surface-300, #18181b));
    border: 1px solid var(--v6-border-strong, rgba(255,255,255,0.14));
    border-radius: var(--radius-lg, 8px);
    box-shadow: var(--shadow-4, 0 24px 64px rgba(0,0,0,0.7));
    overflow: hidden;
    transform: scale(0.96);
    transition: transform var(--duration-base, 180ms) var(--ease-out-quart);
  }
  .v6-settings--visible .v6-settings__card {
    transform: scale(1);
  }

  .v6-settings__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
  }
  .v6-settings__title {
    display: inline-flex;
    align-items: center;
    gap: 12px;
  }
  .v6-settings__title .v6-icon {
    color: var(--accent-primary, #8b5cf6);
  }
  .v6-settings__title h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #fafafa);
  }
  .v6-settings__close {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
    border-radius: var(--radius-sm, 4px);
    color: var(--text-muted, #71717a);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast, 120ms), color var(--duration-fast, 120ms);
  }
  .v6-settings__close:hover {
    background: var(--surface-500, #27272b);
    color: var(--text-primary, #fafafa);
  }

  .v6-settings__body {
    padding: 16px 20px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
  }

  .v6-settings__section + .v6-settings__section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
  }
  .v6-settings__section h3 {
    margin: 0 0 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, #71717a);
  }
  .v6-settings__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
  }
  .v6-settings__label {
    flex: 1;
    font-size: 13px;
    color: var(--text-primary, #fafafa);
    font-weight: 500;
  }
  .v6-settings__hint {
    font-size: 11px;
    color: var(--text-muted, #71717a);
    line-height: 1.4;
    margin: 4px 0 4px;
  }

  /* Segmented control (radio-like) */
  .v6-settings__seg {
    display: inline-flex;
    background: var(--surface-400, #1f1f23);
    border: 1px solid var(--v6-border, rgba(255,255,255,0.08));
    border-radius: var(--radius-md, 6px);
    overflow: hidden;
    flex-shrink: 0;
  }
  .v6-settings__seg button {
    padding: 6px 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary, #a1a1aa);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--duration-fast, 120ms),
                color var(--duration-fast, 120ms);
  }
  .v6-settings__seg button + button {
    border-left: 1px solid var(--v6-border, rgba(255,255,255,0.08));
  }
  .v6-settings__seg button:hover {
    background: var(--surface-500, #27272b);
    color: var(--text-primary, #fafafa);
  }
  .v6-settings__seg button.v6-settings__seg--active,
  .v6-settings__seg button[aria-checked="true"] {
    background: rgba(139, 92, 246, 0.20);
    color: var(--text-primary, #fafafa);
    box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.40);
  }

  /* Toggle switch (checkbox) */
  .v6-settings__toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
    cursor: pointer;
  }
  .v6-settings__toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
  }
  .v6-settings__toggle-track {
    position: absolute;
    inset: 0;
    background: var(--surface-500, #27272b);
    border: 1px solid var(--v6-border, rgba(255,255,255,0.08));
    border-radius: 999px;
    transition: background var(--duration-fast, 120ms),
                border-color var(--duration-fast, 120ms);
  }
  .v6-settings__toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--duration-fast, 120ms) var(--ease-out-quart);
  }
  .v6-settings__toggle input:checked ~ .v6-settings__toggle-track {
    background: var(--accent-primary, #8b5cf6);
    border-color: var(--accent-primary, #8b5cf6);
  }
  .v6-settings__toggle input:checked ~ .v6-settings__toggle-track .v6-settings__toggle-thumb {
    transform: translateX(16px);
  }

  .v6-settings__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
    background: var(--surface-200, #111113);
  }
}
