/**
 * Sim Racing Nation Directory - App & Notification Settings Sheet
 * Clean, minimalist, zero-text-clutter dashboard settings for Android app & mobile/tablet web.
 * Synchronized across .simracingnation.com root domain via srn_app_prefs_v1 cookie & localStorage.
 */

:root {
  --srn-settings-z-backdrop: 10040;
  --srn-settings-z-sheet: 10050;
  --srn-red-brand: #D3222A;
  --srn-red-brand-hover: #B91C1C;
}

/* ==========================================================================
   Header & Mobile Nav Trigger Buttons
   ========================================================================== */
.btn-header-settings {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm, 6px);
  background: #FFFFFF !important;
  color: var(--srn-red-brand, #D3222A) !important;
  border: 1px solid rgba(0, 0, 0, 0.12) !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast, 150ms ease);
  flex-shrink: 0;
}

.btn-header-settings svg {
  stroke: var(--srn-red-brand, #D3222A) !important;
  transition: all var(--transition-fast, 150ms ease);
}

.btn-header-settings:hover {
  transform: translateY(-1px);
  background-color: #FFFFFF !important;
  color: var(--srn-red-brand-hover, #B91C1C) !important;
  border-color: var(--srn-red-brand, #D3222A) !important;
  box-shadow: 0 4px 12px rgba(211, 34, 42, 0.22) !important;
}

.btn-header-settings:hover svg {
  stroke: var(--srn-red-brand-hover, #B91C1C) !important;
}

/* Inside Mobile Drawer */
.mobile-nav-settings-btn {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--border-color, #E2E8F0);
  background: var(--bg-surface, #FFFFFF);
  color: var(--text-primary, #0F172A);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm, 6px);
  font-size: 0.875rem;
  font-weight: 700;
  transition: all var(--transition-fast, 150ms ease);
}

.mobile-nav-settings-btn svg {
  stroke: var(--srn-red-brand, #D3222A);
  flex-shrink: 0;
}

.mobile-nav-settings-btn:hover {
  background: var(--bg-surface-elevated, #F8FAFC);
  border-color: var(--srn-red-brand, #D3222A);
  color: var(--srn-red-brand, #D3222A);
}

/* ==========================================================================
   Backdrop & Sheet Container
   ========================================================================== */
.srn-settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.68);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--srn-settings-z-backdrop);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.srn-settings-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.srn-settings-sheet {
  position: fixed;
  z-index: var(--srn-settings-z-sheet);
  background: var(--bg-surface, #FFFFFF);
  color: var(--text-primary, #0F172A);
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s ease;
  visibility: hidden;
  box-sizing: border-box;
}

/* Mobile: Bottom Sheet */
@media (max-width: 640px) {
  .srn-settings-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: calc(90dvh);
    height: auto;
    border-radius: 18px 18px 0 0;
    border-top: 1px solid var(--border-color, #E2E8F0);
    transform: translateY(102%);
  }

  .srn-settings-sheet.is-open {
    transform: translateY(0);
    visibility: visible;
  }
}

/* Desktop & Tablet: Right Sliding Drawer / Floating Sheet */
@media (min-width: 641px) {
  .srn-settings-sheet {
    top: 0;
    right: 0;
    bottom: 0;
    width: 440px;
    max-width: 100vw;
    border-left: 1px solid var(--border-color, #E2E8F0);
    transform: translateX(102%);
  }

  .srn-settings-sheet.is-open {
    transform: translateX(0);
    visibility: visible;
  }
}

/* Lock scrolling when sheet is open */
body.srn-settings-open,
html.srn-settings-open {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}

body.srn-settings-open .srn-corner-launcher {
  display: none !important;
}

/* ==========================================================================
   Sheet Header
   ========================================================================== */
.srn-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #E2E8F0);
  background: var(--bg-surface, #FFFFFF);
  flex-shrink: 0;
  position: relative;
}

/* Mobile top grab handle indicator */
.srn-settings-handle {
  display: none;
}
@media (max-width: 640px) {
  .srn-settings-handle {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-color, #CBD5E1);
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
  }
  .srn-settings-header {
    padding-top: 18px;
  }
}

.srn-settings-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.srn-settings-title-wrap svg {
  stroke: var(--srn-red-brand, #D3222A);
  flex-shrink: 0;
}

.srn-settings-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-primary, #0F172A);
  margin: 0;
}

.srn-settings-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border-color, #CBD5E1);
  background: var(--bg-surface-elevated, #F1F5F9);
  color: var(--text-primary, #0F172A);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s ease;
}

.srn-settings-close-btn:hover {
  background: var(--border-color, #CBD5E1);
  color: var(--srn-red-brand, #D3222A);
}

/* ==========================================================================
   Sheet Content Body
   ========================================================================== */
.srn-settings-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.srn-settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.srn-settings-sec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.srn-settings-sec-header span {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted, #64748B);
}

/* Master Toggle Row */
.srn-settings-master-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-surface-elevated, #F8FAFC);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 8px;
}

.srn-master-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.srn-master-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary, #0F172A);
}

.srn-master-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted, #64748B);
}

/* 2-Column Grid of News Alert Toggles */
.srn-settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  transition: opacity 0.2s ease;
}

.srn-settings-grid.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.srn-pref-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--bg-surface-elevated, #F8FAFC);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 7px;
  box-sizing: border-box;
}

.srn-pref-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary, #0F172A);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stack layout for Events & Directory */
.srn-settings-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.srn-pref-card-wide {
  padding: 10px 14px;
}

.srn-pref-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.srn-pref-sub {
  font-size: 0.72rem;
  color: var(--text-muted, #64748B);
}

/* ==========================================================================
   Sleek iOS / Minimalist Switch Slider
   ========================================================================== */
.srn-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
}

.srn-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.srn-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color, #CBD5E1);
  transition: background-color 0.2s ease;
  border-radius: 22px;
}

.srn-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: #FFFFFF;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.srn-switch input:checked + .srn-slider {
  background-color: var(--srn-red-brand, #D3222A);
}

.srn-switch input:checked + .srn-slider:before {
  transform: translateX(16px);
}

.srn-switch input:focus-visible + .srn-slider {
  outline: 2px solid var(--srn-red-brand, #D3222A);
  outline-offset: 2px;
}

/* ==========================================================================
   Section 3: Segmented Pill (External Links)
   ========================================================================== */
.srn-segmented-pill {
  display: flex;
  background: var(--bg-surface-elevated, #F1F5F9);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #E2E8F0);
  gap: 4px;
}

.srn-segment-btn {
  flex: 1;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted, #64748B);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.srn-segment-btn.active {
  background: var(--bg-surface, #FFFFFF);
  color: var(--srn-red-brand, #D3222A);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.srn-segment-btn:hover:not(.active) {
  color: var(--text-primary, #0F172A);
}

/* ==========================================================================
   Section 4: Compact Tools Bar & Inline Issue Logger
   ========================================================================== */
.srn-settings-tools-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

@media (max-width: 380px) {
  .srn-settings-tools-bar {
    grid-template-columns: 1fr;
  }
}

.srn-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 6px;
  background: var(--bg-surface-elevated, #F8FAFC);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 8px;
  color: var(--text-primary, #0F172A);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  text-align: center;
}

.srn-tool-btn svg {
  stroke: var(--text-primary, #0F172A);
  flex-shrink: 0;
  transition: stroke 0.15s ease;
}

.srn-tool-btn:hover {
  border-color: var(--srn-red-brand, #D3222A);
  color: var(--srn-red-brand, #D3222A);
  background: var(--bg-surface, #FFFFFF);
}

.srn-tool-btn:hover svg {
  stroke: var(--srn-red-brand, #D3222A);
}

.srn-version-chip {
  font-size: 0.625rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(211, 34, 42, 0.1);
  color: var(--srn-red-brand, #D3222A);
  line-height: 1.2;
}

/* Inline Issue Logger */
.srn-issue-logger {
  background: var(--bg-surface-elevated, #F8FAFC);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.srn-issue-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.srn-issue-pill {
  padding: 4px 9px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 20px;
  border: 1px solid var(--border-color, #CBD5E1);
  background: var(--bg-surface, #FFFFFF);
  color: var(--text-muted, #64748B);
  cursor: pointer;
  transition: all 0.15s ease;
}

.srn-issue-pill.active {
  border-color: var(--srn-red-brand, #D3222A);
  background: var(--srn-red-brand, #D3222A);
  color: #FFFFFF;
}

.srn-issue-input-wrap {
  display: flex;
  gap: 6px;
}

.srn-issue-input {
  flex: 1;
  font-family: inherit;
  font-size: 0.8125rem;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color, #CBD5E1);
  background: var(--bg-surface, #FFFFFF);
  color: var(--text-primary, #0F172A);
  outline: none;
  min-width: 0;
}

.srn-issue-input:focus {
  border-color: var(--srn-red-brand, #D3222A);
}

.srn-issue-send-btn {
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  border-radius: 6px;
  border: none;
  background: var(--srn-red-brand, #D3222A);
  color: #FFFFFF;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.srn-issue-send-btn:hover {
  background: var(--srn-red-brand-hover, #B91C1C);
}

.srn-issue-feedback {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 5px;
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

/* Toast feedback notice */
.srn-settings-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0F172A;
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  z-index: 10070;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.srn-settings-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   Dark Mode Adjustments
   ========================================================================== */
body.dark-mode .srn-settings-sheet {
  background: #111620;
  color: #F8FAFC;
  border-color: rgba(255, 255, 255, 0.12);
}

body.dark-mode .srn-settings-header {
  background: #111620;
  border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .srn-settings-close-btn {
  background: #1A2230;
  border-color: rgba(255, 255, 255, 0.15);
  color: #F8FAFC;
}

body.dark-mode .srn-settings-master-row,
body.dark-mode .srn-pref-card,
body.dark-mode .srn-tool-btn,
body.dark-mode .srn-issue-logger {
  background: #161D2A;
  border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .srn-segmented-pill {
  background: #0D121B;
  border-color: rgba(255, 255, 255, 0.12);
}

body.dark-mode .srn-segment-btn.active {
  background: #1E2738;
}

body.dark-mode .srn-slider {
  background-color: #334155;
}

body.dark-mode .srn-issue-input,
body.dark-mode .srn-issue-pill {
  background: #1A2230;
  border-color: rgba(255, 255, 255, 0.15);
  color: #E2E8F0;
}

body.dark-mode .srn-master-title,
body.dark-mode .srn-pref-name,
body.dark-mode .srn-tool-btn,
body.dark-mode .srn-settings-title {
  color: #F8FAFC;
}

body.dark-mode .btn-header-settings {
  background: #18202C !important;
  border-color: rgba(255, 255, 255, 0.16) !important;
}

body.dark-mode .mobile-nav-settings-btn {
  background: #161D2A;
  border-color: rgba(255, 255, 255, 0.12);
  color: #F8FAFC;
}
