/* Settings Panel Styles */
.settings-btn {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 10000;
}

.settings-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
    transform: rotate(90deg);
}

.settings-btn.active {
    background: var(--color-bg-hover);
    color: var(--color-text);
    transform: rotate(180deg);
}

.settings-btn svg {
    width: 18px;
    height: 18px;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: none !important;
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
}

.settings-panel.active {
    display: block !important;
    pointer-events: all;
    visibility: visible !important;
    opacity: 1 !important;
}

.settings-backdrop {
    display: none;
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.2);
}

.settings-content {
    position: absolute;
    top: 0;
    right: 0;
    width: 25vw;
    min-width: 300px;
    max-width: 400px;
    height: 100vh;
    background: rgba(28, 28, 30, 0.95); /* Default dark theme */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: none;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 20px rgba(0, 0, 0, 0.1);
}

.settings-panel.active .settings-content {
    transform: translateX(0);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
    background: transparent;
}

.settings-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
}

.settings-close {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-secondary);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.settings-close:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px; /* Consistent spacing between sections */
    padding: 8px;
}

.settings-section {
    margin-bottom: 0; /* Use gap for spacing */
}

.settings-section h4 {
    margin: 0 0 12px 0;
    padding: 0 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-item {
    display: flex;
    align-items: center;
    padding: 16px 20px; /* Jobs-level generous padding */
    margin: 0;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* iOS spring curve */
    border: none;
    background: rgba(255, 255, 255, 0.85); /* More opaque for clarity */
    border-radius: 16px; /* More refined, iOS-like radius */
    width: calc(100% - 16px);
    text-align: left;
    backdrop-filter: blur(20px); /* Stronger blur for that iOS magic */
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); /* Subtle depth */
}

.setting-item.clickable {
    cursor: pointer;
}

.setting-item.clickable:hover {
    background: rgba(0, 122, 255, 0.08);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.setting-item.clickable:active {
    transform: translateY(0px) scale(0.98);
    background: rgba(0, 122, 255, 0.12);
    transition: transform 0.1s ease;
}

/* Jobs-level typography for setting elements */
.setting-info {
    display: flex;
    align-items: center;
    gap: 16px; /* Perfect spacing between icon and text */
    flex: 1;
}

.setting-title {
    font-size: 17px; /* iOS standard body text size */
    font-weight: 400; /* SF Pro Display weight */
    color: var(--color-text-primary);
    line-height: 1.29412; /* Apple's precise line height */
    letter-spacing: -0.024em; /* Subtle tracking for clarity */
}

.setting-icon {
    width: 32px; /* iOS app icon size */
    height: 32px;
    margin-right: 0; /* Handled by .setting-info gap */
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #007aff, #5856d6);
    border-radius: 8px; /* iOS-style rounded corners */
    color: white;
    flex-shrink: 0;
    box-shadow: 0 3px 12px rgba(0, 122, 255, 0.25); /* Deeper, more iOS-like shadow */
}

.setting-icon svg {
    width: 18px; /* Perfect icon size within 32px container */
    height: 18px;
    stroke-width: 2.2; /* Jobs-approved stroke weight for clarity */
}

.setting-icon svg {
    fill: currentColor;
    stroke: currentColor;
    width: 12px;
    height: 12px;
}

/* Jobs-level iOS system colors - refined and purposeful */
#downloadPdfOption .setting-icon {
    background: linear-gradient(145deg, #ff3b30, #ff453a); /* iOS Red */
    box-shadow: 0 4px 16px rgba(255, 59, 48, 0.3);
}

#shareOption .setting-icon {
    background: linear-gradient(145deg, #007aff, #0a84ff); /* iOS Blue */
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.3);
}

#settingsThemeToggleBtn .setting-icon {
    background: linear-gradient(145deg, #5856d6, #5e5ce6); /* iOS Purple */
    box-shadow: 0 4px 16px rgba(88, 86, 214, 0.3);
}

#faqOption .setting-icon {
    background: linear-gradient(145deg, #34c759, #30d158); /* iOS Green */
    box-shadow: 0 4px 16px rgba(52, 199, 89, 0.3);
}


/* Highest-specificity override for cases where inline styles or other CSS conflict (force blue) */
#privacyOption.privacy-enhanced .setting-icon {
    background: linear-gradient(135deg, #007aff, #5ac8fa) !important;
    box-shadow: 0 1px 3px rgba(0, 122, 255, 0.35) !important;
}

/* Document-level class to force initial paint state (applied early via inline script) */
.privacy-enhanced #privacyOption .setting-icon {
    background: linear-gradient(135deg, #007aff, #5ac8fa) !important;
    box-shadow: 0 1px 3px rgba(0, 122, 255, 0.35) !important;
}

/* Header shield icon (privacy button) styling - CLEAN PRODUCTION STYLE */
/* Shield icon styling handled by privacy-modal.css - no overrides needed */

/* Nudge header privacy shield 2px to the right for better alignment */
#privacyShieldBtn {
    margin-left: 2px;
}

.setting-info {
    flex: 1;
    margin-right: 12px;
}

/* Mobile-specific nudges: move settings and shield icons slightly to the right on very small screens */
@media (max-width: 480px) {
    .settings-btn {
        margin-left: -5px; /* move settings icon 4px to the right on small screens */
    }

    /* Increase shield button left margin by 5px in addition to default 2px = 7px total */
    #privacyShieldBtn {
        margin-left: 40px; /* move shield icon 5px to the right on small screens */
    }
}

.setting-label {
    font-size: 13px;
    font-weight: 500;
    color: #1d1d1f;
    margin-bottom: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.setting-desc {
    font-size: 11px;
    color: #86868b;
    line-height: 1.2;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.setting-arrow {
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 12px;
}

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

input:checked + .toggle-slider {
    background: #007aff;
    border-color: #007aff;
}

input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .settings-backdrop {
        display: block;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .settings-panel.active .settings-backdrop {
        opacity: 1;
    }

    .settings-content {
        width: 75vw;
        height: auto;
        max-width: 320px;
        min-width: unset;
        border: 0.5px solid rgba(0, 0, 0, 0.1);
        top: calc(var(--header-height) + 10px);
        right: 10px;
        border-radius: 20px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(40px);
        -webkit-backdrop-filter: blur(40px);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 4px 16px rgba(0, 0, 0, 0.1);
        transform-origin: top right;
        transform: scale(0.9) translateY(-20px);
        opacity: 0;
        transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease-out;
    }

    .settings-panel.active .settings-content {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    
    .settings-header {
        display: none; /* Header not needed for mobile popover */
    }
    
    .settings-body {
        padding: 6px;
        gap: 2px;
    }
    
    .setting-item {
        padding: 10px 12px; /* Tighter vertical padding */
        margin: 0;
        width: 100%;
    }
    
    .settings-section h4 {
        margin-bottom: 8px;
        padding: 0 20px;
    }
}

/* Mobile-specific header tweaks: smaller header icons, tighter spacing and centered title */
@media (max-width: 480px) {
    .header-controls {
        gap: 4px; /* tighter gap for compact mobile header */
        margin-right: 0px; /* remove right margin to prevent boundary crossing */
    }

    /* ~20% size reduction from desktop/mobile default */
    .settings-btn {
        width: 24px;
        height: 24px;
    }

    .settings-btn svg,
    .shield-icon svg {
        width: 12px;
        height: 12px;
    }

    .shield-icon {
        width: 14px;
        height: 14px;
        border-radius: 4px;
    }

    /* Center the two-line title block for very small screens */
    .logo-title-container {
        justify-content: center;
    }

    .logo-title-wrapper {
        align-items: center;
        text-align: center;
    }

    .logo-title-wrapper .site-title,
    .logo-title-wrapper .fy-line {
        width: 100%;
        margin: 0;
    }
}

/* Tablet responsive - use 40% width */
@media (max-width: 1024px) and (min-width: 769px) {
    .settings-content {
        width: 40vw;
        min-width: 320px;
    }
}

/* Dark mode styles (default - when body does NOT have .light-mode class) */
body:not(.light-mode) .settings-content {
    background: rgba(28, 28, 30, 0.95) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

body:not(.light-mode) .settings-header {
    background: transparent;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

body:not(.light-mode) .setting-item {
    background: rgba(44, 44, 46, 0.6);
}

body:not(.light-mode) .setting-item.clickable:hover {
    background: rgba(0, 122, 255, 0.15);
}

body:not(.light-mode) .setting-label {
    color: #f2f2f7;
}

body:not(.light-mode) .setting-desc {
    color: #8e8e93;
}

/* Light mode styles (when body has .light-mode class) */
body.light-mode .settings-content {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

body.light-mode .settings-header {
    background: transparent;
    border-bottom-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .setting-item {
    background: rgba(245, 245, 247, 0.6);
}

body.light-mode .setting-item.clickable:hover {
    background: rgba(0, 122, 255, 0.08);
}

body.light-mode .setting-label {
    color: #1d1d1f;
}

body.light-mode .setting-desc {
    color: #86868b;
}

@media (max-width: 768px) {
    body:not(.light-mode) .settings-content {
        background: rgba(28, 28, 30, 0.9) !important;
        backdrop-filter: blur(30px);
        -webkit-backdrop-filter: blur(30px);
    }
    
    body.light-mode .settings-content {
        background: rgba(255, 255, 255, 0.9) !important;
        backdrop-filter: blur(30px);
        -webkit-backdrop-filter: blur(30px);
    }
}

/* Button-based toggle for mobile theme toggle */
.setting-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    padding: 0;
}

.setting-toggle .toggle-slider {
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    left: 3px;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.setting-toggle.active {
    background: #007aff;
    border-color: #007aff;
}

.setting-toggle.active .toggle-slider {
    transform: translateX(20px);
}

body:not(.light-mode) .setting-toggle .toggle-slider {
    background: #f2f2f7;
}

/* --- THEME VARIABLES (scoped to body for easy override) --- */
body:not(.light-mode) {
  --color-bg-secondary: rgba(44, 44, 46, 0.6);
  --color-border: rgba(255, 255, 255, 0.12);
  --color-text-secondary: #8e8e93;
  --color-bg-hover: rgba(255, 255, 255, 0.08);
  --color-text: #f2f2f7;
}

body.light-mode {
  --color-bg-secondary: rgba(245, 245, 247, 0.6);
  --color-border: rgba(0, 0, 0, 0.12);
  --color-text-secondary: #6e6e73;
  --color-bg-hover: rgba(0, 0, 0, 0.06);
  --color-text: #1d1d1f;
}

/* --- SETTINGS BUTTON THEME HOOKS --- */
body:not(.light-mode) .settings-btn {
  background: var(--color-bg-secondary) !important;
  border-color: var(--color-border) !important;
  color: var(--color-text-secondary) !important;
}

body:not(.light-mode) .settings-btn:hover,
body:not(.light-mode) .settings-btn.active {
  background: var(--color-bg-hover) !important;
  color: var(--color-text) !important;
}

body.light-mode .settings-btn {
  background: var(--color-bg-secondary) !important;
  border-color: var(--color-border) !important;
  color: var(--color-text-secondary) !important;
}

body.light-mode .settings-btn:hover,
body.light-mode .settings-btn.active {
  background: var(--color-bg-hover) !important;
  color: var(--color-text) !important;
}

/* Ensure the icon actually follows the text color */
.settings-btn svg {
  display: block; /* keeps sizing tidy */
}
.settings-btn svg *,
.settings-btn svg {
  stroke: currentColor !important;
  fill: none !important; /* SVG should be stroke-only for settings icon */
}

/* Settings panel menu icons - Steve Jobs style refinement */
.setting-icon svg {
  width: 20px;
  height: 20px;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

/* Theme appropriate icon colors */
body:not(.light-mode) .setting-icon svg {
  stroke: #8e8e93 !important;
}

body.light-mode .setting-icon svg {
  stroke: #6e6e73 !important;
}

/* Hover effect for menu icons */
.setting-item.clickable:hover .setting-icon svg {
  opacity: 1 !important;
}

body:not(.light-mode) .setting-item.clickable:hover .setting-icon svg {
  stroke: #f2f2f7 !important;
}

body.light-mode .setting-item.clickable:hover .setting-icon svg {
  stroke: #1d1d1f !important;
}

/* Special handling for the text-based question mark */
.setting-icon svg text {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}