/* ==========================================================================
 *  Settings Modal
 *  ========================================================================== */

.settings-modal {
    display: flex;
    flex-direction: column;
    width: 60vw;
    height: 85vh;
    padding: 0;
    max-width: 1200px;
}

.settings-modal .modal-header {
    flex-shrink: 0;
    padding: 20px 24px;
}

.settings-modal .modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.settings-body {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

.settings-sidebar {
    flex-shrink: 0;
    width: 200px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-x: clip;
    overflow-y: auto;
}

.settings-nav {
    padding: 12px 0;
}

.settings-nav-item {
    display: flex;
    gap: 10px;
    width: 100%;
    padding: 12px 16px 12px 20px;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    font-size: 0.9rem;
    text-align: left;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    align-items: center;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    margin-bottom: 2px;
}

.settings-nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateX(4px);
}

.settings-nav-item.active {
    background: var(--bg-tertiary);
    border-left-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.settings-nav-item svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

@media (min-width: 768px) {
    .settings-nav-divider {
        border-top: 1px solid var(--border-color);
        margin-top: 7px;
        margin-bottom: 7px;
    }
}
@media (max-width: 768px) {
    .settings-nav-top, .settings-nav-bottom {
        display: flex;
    }

    .settings-nav-divider {
        border-left: 1px solid var(--border-color);
    }
}

.settings-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    position: relative;
    animation: settingsContentFadeIn 0.3s ease-out forwards;
}

.settings-content a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease;
    border-bottom: 1px solid transparent;
}

.settings-content a:hover {
    text-decoration: underline;
    color: var(--accent-light);
}

@keyframes settingsContentFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading & Error States */
.settings-loading,
.settings-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    text-align: center;
    color: var(--text-muted);
    animation: settingsContentFadeIn 0.3s ease-out forwards;
}

/* Smooth scrollbar for settings */
.settings-sidebar::-webkit-scrollbar,
.settings-content::-webkit-scrollbar {
    width: 6px;
}

.settings-sidebar::-webkit-scrollbar-thumb,
.settings-content::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: var(--radius-full);
    transition: background 0.2s ease;
}

.settings-sidebar::-webkit-scrollbar-thumb:hover,
.settings-content::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}

.settings-loading {
    gap: 16px;
}

.settings-error svg {
    color: var(--error);
}

.settings-error p {
    margin: 0;
    color: var(--error);
}

.settings-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.settings-retry-btn {
    margin-top: 8px;
    padding: 8px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.settings-retry-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Settings Form */
.settings-form {
    animation: settings-fade-in 0.2s ease;
}

@keyframes settings-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.settings-section {
    display: none;
}

.settings-section.active {
    display: block;
}

.settings-section-title {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.settings-section-desc {
    margin: 0 0 24px 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Setting Items */
.setting-item {
    margin-bottom: 20px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-label {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    align-items: center;
}

.setting-label .required {
    color: var(--error);
}

.setting-description {
    margin: 0 0 8px 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-muted);
}

/* Input Styles */
.setting-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.setting-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.setting-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.setting-input.error {
    border-color: var(--error);
}

.setting-input[type="number"] {
    max-width: 200px;
}

.setting-textarea {
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
}

/* ==========================================================================
 *  Setting Descriptions (Hints)
 *  ========================================================================== */

/* Standard settings: appears below the input field */
.setting-description {
    margin: 4px 0 12px 0;
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

/* Optional: Highlight the description when the input is focused
 *  to guide the user's eye to the explanation */
.setting-item:focus-within .setting-description {
    color: var(--text-primary);
    transition: all 0.2s ease;
}

/* Select description: appears below the select dropdown */
.setting-select-description {
    margin: 4px 0 12px 0;
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

/* Module Card: appears inside the small card container */
.toggle-list-item-description {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    white-space: pre-wrap;

    /* Keep it clean inside the card; no heavy borders needed here */
    margin-top: 4px;
    padding-left: 2px;
    opacity: 0.85;
}

/* ==========================================================================
 *  Toggle Switches - Fixed
 *  ========================================================================== */

/* Toggle Switch Container */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Hide the default checkbox */
.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* The sliding track */
.toggle-slider {
    position: absolute;
    inset: 0;
    background-color: var(--bg-secondary, #333);
    border: 1px solid var(--border-color, #444);
    border-radius: 24px;
    transition: all 0.2s ease;
}

/* The sliding circle */
.toggle-slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted, #888);
    border-radius: 50%;
    transition: all 0.2s ease;
}

/* Hover state */
.toggle-switch:hover .toggle-slider {
    border-color: var(--accent, #4a9eff);
}

/* Checked state - track */
.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent, #4a9eff);
    border-color: var(--accent, #4a9eff);
}

/* Checked state - circle position and color */
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background-color: white;
}

/* Focus state */
.toggle-switch input:focus-visible + .toggle-slider {
    outline: 2px solid var(--accent, #4a9eff);
    outline-offset: 2px;
}

/* Setting Toggle Wrapper */
.setting-toggle-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Sound Toggle Wrapper - ensure proper alignment */
.sound-footer .setting-toggle-wrapper {
    gap: 10px;
}

.sound-footer .setting-toggle-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Sound toggle - match module toggle sizing */
.sound-footer .toggle-switch {
    width: 36px;
    height: 20px;
}

.sound-footer .toggle-slider {
    border-radius: 20px;
}

.sound-footer .toggle-slider::before {
    width: 14px;
    height: 14px;
    left: 3px;
    bottom: 3px;
}

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

.setting-toggle-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ==========================================================================
 *  Improved Toggle List Styles
 *  ========================================================================== */


.toggle-list {
    overflow: hidden;
}

.toggle-list-status {
    padding: 2px 0px;
    background: var(--bg-secondary);
}

.toggle-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.toggle-list-grid {
    display: grid;
    gap: 10px;
    padding: 2px 0px;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

/* Base style for ALL toggle items */
.toggle-list-item {
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.15s ease;
    box-sizing: border-box;
}

.toggle-list-item.enabled {
    background: rgba(var(--accent-rgb), 0.1);
    border-color: var(--accent);
}

/* --- STANDARD STYLE (Default) --- */
/* Used for normal setting lists (Row layout) */
.toggle-list-item:not(.module-card) {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-list-item:not(.module-card) .toggle-list-name {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* --- MODULE CARD STYLE (Special) --- */
/* Used for Modules/Channels (Column layout with scroll) */
.toggle-list-item.module-card {
    display: flex;
    flex-direction: column;
    height: 115px; /* Fixed height to enable description scrolling */
}

.toggle-list-item.module-card .toggle-list-top-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    margin-bottom: 6px;
}

.toggle-list-item.module-card .toggle-list-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.2;
    word-break: break-word;
}

.toggle-list-item.module-card .toggle-list-name.enabled {
    color: var(--text-primary);
}

/* Scrollable Description Area */
.toggle-list-desc-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.toggle-list-item-description {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    white-space: pre-wrap;
}

/* Custom Scrollbar for descriptions */
.toggle-list-desc-container::-webkit-scrollbar {
    width: 4px;
}
.toggle-list-desc-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* Common Switch Sizing */
.toggle-list-item .toggle-switch {
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.toggle-list-item .toggle-slider::before {
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
}

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

/* The main container stays as a vertical stack (normal layout) */
.settings-groups-grid {
    display: block; /* Remove grid */
    column-gap: 16px; /* Space between columns */
}

/* Responsive column counts */
@media (min-width: 600px) {
    .settings-groups-grid {
        column-count: 2;
    }
}

/*@media (min-width: 900px) {
    .settings-groups-grid {
        column-count: 3;
    }
}*/

/*
@media (min-width: 1200px) {
    .settings-groups-grid { grid-template-columns: repeat(4, 1fr); }
}
*/

/* Special class for items that should span the full width of their container */
.full-width-item {
    grid-column: 1 / -1;
    width: 100%;
}


/* Select Dropdown */
.setting-select {
    max-width: 300px;
    padding: 10px 36px 10px 12px;
    background: var(--bg-secondary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
    background-size: 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text-primary);
    appearance: none;
}

.setting-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

/* Array Editor */
.setting-array {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.setting-array-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    border-radius: 8px 8px 0 0;
}

.setting-array-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.setting-array-add {
    display: flex;
    gap: 4px;
    padding: 6px 12px;
    background: var(--accent);
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    color: white;
    cursor: pointer;
    transition: opacity 0.15s;
    align-items: center;
}

.setting-array-add:hover {
    opacity: 0.9;
}

.setting-array-items {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.setting-array-item {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.setting-array-item:last-child {
    border-bottom: none;
}

.setting-array-item input {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.setting-array-item input:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-array-item input[readonly] {
    background: var(--bg-secondary);
    cursor: default;
}

.setting-array-remove {
    padding: 6px;
    background: none;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.setting-array-remove:hover {
    background: var(--error-bg);
    color: var(--error);
}

.setting-array-empty {
    padding: 20px;
    font-size: 0.85rem;
    text-align: center;
    color: var(--text-muted);
}

/* Object Editor */
.setting-object {
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.setting-object-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.setting-object-header span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.setting-object-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-object-item {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 2fr auto;
    align-items: center;
}

.setting-object-item input {
    padding: 8px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.setting-object-item input:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-object-add {
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.setting-object-add:hover {
    border-color: var(--accent);
}

/* Nested Settings */
.setting-nested {
    margin-top: 12px;
    margin-left: 20px;
    padding-left: 16px;
    border-left: 2px solid var(--border-color);
}

.setting-nested-title {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    align-items: center;
}

.setting-nested-title svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

/* Collapsible Sections */
.setting-collapsible {
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.setting-collapsible-header {
    display: flex;
    padding: 12px 16px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: background 0.15s ease;
    align-items: center;
    justify-content: space-between;
}

.setting-collapsible-header:hover {
    background: var(--bg-tertiary);
}

.setting-collapsible-title {
    display: flex;
    gap: 10px;
    font-weight: 500;
    color: var(--text-primary);
    align-items: center;
}

.setting-collapsible-title svg {
    width: 18px;
    height: 18px;
    color: var(--accent);
}

.setting-collapsible-toggle {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.setting-collapsible.expanded .setting-collapsible-toggle {
    transform: rotate(180deg);
}

.setting-collapsible-content {
    display: none;
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.setting-collapsible.expanded .setting-collapsible-content {
    display: block;
}

/* Validation & Status Messages */
.setting-error-msg {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--error);
    align-items: center;
}

.setting-error-msg svg {
    width: 14px;
    height: 14px;
}

.setting-success-msg {
    display: flex;
    gap: 8px;
    padding: 12px;
    margin-bottom: 16px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 6px;
    font-size: 0.9rem;
    color: #22c55e;
    align-items: center;
    justify-content: center;
}

.setting-success-msg svg {
    width: 18px;
    height: 18px;
}

.settings-unsaved {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    margin: -8px 0 16px 0;
    background: rgba(234, 179, 8, 0.1);
    border: 1px solid rgba(234, 179, 8, 0.3);
    border-radius: 6px;
    font-size: 0.85rem;
    color: #eab308;
    align-items: center;
}

.settings-unsaved svg {
    width: 16px;
    height: 16px;
}

/* Settings Groups */
.settings-group {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;

    /* Add these three lines */
    break-inside: avoid;    /* Prevents the group from splitting across columns */
    display: inline-block;   /* Required for break-inside to work reliably in columns */
    width: 100%;             /* Ensures it fills the column width */
    margin-bottom: 16px;     /* Adds vertical spacing between groups in the same column */
}


.settings-group-header {
    display: flex;
    padding: 12px 16px;
    background: var(--bg-secondary);
    align-items: center;
}

.settings-group-title {
    display: flex;
    gap: 8px;
    font-weight: 500;
    color: var(--text-primary);
    align-items: center;
}

.settings-group-title svg {
    transition: transform 0.2s;
}

.settings-group-content {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.settings-separator {
    margin: 24px 0;
}

.settings-separator hr {
    margin: 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* Toggle List */
.toggle-list {
    overflow: hidden;
}

.toggle-list-status {
    padding: 2px 0px;
    background: var(--bg-secondary);
}

.toggle-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.toggle-list-grid {
    display: grid;
    gap: 8px;
    padding: 2px 0px;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.toggle-list-item.enabled {
    background: rgba(var(--accent-rgb), 0.1);
    border-color: var(--accent);
}

.toggle-list-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.toggle-list-item.enabled .toggle-list-name {
    color: var(--text-primary);
}

.toggle-list-switch {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.toggle-list-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.toggle-list-switch.active {
    background: var(--accent);
}

.toggle-list-switch.active::after {
    background: var(--bg-primary);
}

/* Sensitive Input */
.sensitive-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.sensitive-input-wrapper .setting-input {
    padding-right: 40px;
}

.sensitive-input {
    font-family: monospace;
    background: var(--bg-secondary);
}

.sensitive-input::placeholder {
    color: var(--text-muted);
}

.sensitive-toggle {
    position: absolute;
    right: 8px;
    padding: 6px;
    background: none;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s;
}

.sensitive-toggle:hover {
    color: var(--text-primary);
}

.sensitive-toggle svg {
    display: block;
}

/* Footer */
.settings-footer {
    flex-shrink: 0;
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    justify-content: flex-end;
}

.settings-btn {
    display: flex;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    align-items: center;
}

.settings-btn.primary {
    background: var(--accent);
    border: none;
    color: var(--bg-primary);
}

.settings-btn.primary:hover:not(:disabled) {
    filter: brightness(1.15);
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}

.settings-btn.primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.settings-btn.secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.settings-btn.secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--accent);
}

.btn-loading {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Theme Grid */
.theme-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
}

.theme-preview {
    position: relative;
    width: 100%;
    height: 24px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
}

.theme-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    pointer-events: none;
    opacity: 0.8;
}

.theme-name {
    margin-top: 4px;
    font-size: 0.75rem;
}

.theme-btn {
    padding: 10px 6px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    text-align: center;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.theme-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

/* Theme Mode Toggle */
.theme-mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, #333);
}

.theme-mode-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    color: var(--text-muted, #888);
    transition: color 0.2s ease;
}

.theme-mode-label svg {
    opacity: 0.7;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

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

.theme-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background-color: var(--bg-tertiary, #222);
    border: 1px solid var(--border-color, #444);
    border-radius: 24px;
    transition: 0.3s;
}

.theme-slider:before {
    position: absolute;
    bottom: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    content: "";
    background-color: var(--text-primary, #fff);
    border-radius: 50%;
    transition: 0.3s;
}

.theme-switch input:checked + .theme-slider {
    background-color: var(--accent, #4a9eff);
    border-color: var(--accent, #4a9eff);
}

.theme-switch input:checked + .theme-slider:before {
    transform: translateX(24px);
    background-color: var(--bg-primary);
}

/* Export Options */
.export-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.export-btn {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    text-align: left;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.export-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent);
}

.export-btn-title {
    margin-bottom: 4px;
    font-weight: 600;
}

.export-btn-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Model dropdown input styles */
.model-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.model-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-select {
    flex: 1;
    padding: 8px 32px 8px 12px;
    border-radius: var(--radius-sm, 6px);
    border: 1px solid var(--border-color, #444);
    background: var(--bg-secondary, #222);
    color: var(--text-primary, #fff);
    font-size: 14px;
    cursor: pointer;
    max-width: 100%;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.model-select:hover {
    border-color: var(--accent, #4a9eff);
}

.model-select:focus {
    outline: none;
    border-color: var(--accent, #4a9eff);
    box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.2);
}

.model-select option {
    background: var(--bg-secondary, #222);
    color: var(--text-primary, #fff);
    padding: 8px;
}

.model-select option:checked {
    background: var(--accent, #4a9eff);
    color: #fff;
}

.model-refresh-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 8px;
    border-radius: var(--radius-sm, 6px);
    border: 1px solid var(--border-color, #444);
    background: var(--bg-tertiary, #1a1a1a);
    color: var(--text-muted, #888);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.model-refresh-btn:hover {
    background: var(--bg-hover, #2a2a2a);
    color: var(--text-primary, #fff);
    border-color: var(--accent, #4a9eff);
}

.model-refresh-btn:active {
    transform: scale(0.95);
}

.model-refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.model-refresh-btn.loading svg {
    animation: spin 1s linear infinite;
}

.model-refresh-btn svg {
    width: 16px;
    height: 16px;
}

.model-error-msg {
    color: var(--error-color, #ff6b6b);
    font-size: 12px;
    margin: 4px 0 0 0;
}

.font-size-container {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 8px;
}

.font-size-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.font-size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.font-size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.font-size-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.font-size-value {
    min-width: 45px;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
 * Custom Font Select (Theme Aware)
 * ========================================================================== */

.custom-font-select {
    position: relative;
    width: 100%;
    font-family: var(--font-primary);
}

/* Trigger Button */
.custom-font-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 42px;
    color: var(--text-primary);
}

.custom-font-trigger:hover {
    border-color: var(--accent);
}

.custom-font-trigger:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-glow); /* Uses theme glow */
}

.custom-font-value {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-font-arrow {
    flex-shrink: 0;
    margin-left: 8px;
    transition: transform 0.2s ease;
    color: var(--text-muted);
}

.custom-font-dropdown.show + .custom-font-trigger .custom-font-arrow {
    transform: rotate(180deg);
}

/* Dropdown Panel */
.custom-font-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft);
    z-index: 1000;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.2s ease;
}

.custom-font-dropdown.show {
    max-height: 320px;
    opacity: 1;
    overflow-y: visible; /* Allow scrollbar to show */
}

/* Search Input */
.custom-font-search {
    position: sticky;
    top: 0;
    padding: 8px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 1;
}

.custom-font-search-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    font-family: var(--font-primary);
}

.custom-font-search-input:focus {
    border-color: var(--accent);
}

.custom-font-search-input::placeholder {
    color: var(--text-muted);
}

/* Options List */
.custom-font-options {
    padding: 4px 0;
    max-height: 250px;
    overflow-y: auto;
}

/* Option Item */
.custom-font-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 14px;
    color: var(--text-primary);
    gap: 12px;
}

.custom-font-option:hover {
    background: var(--bg-tertiary);
}

.custom-font-option.selected {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.custom-font-option .option-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Badges */
.font-badge {
    flex-shrink: 0;
    font-size: 9px;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    /* Reset font to system default for readability */
    font-family: var(--font-primary);
}

.font-badge.system {
    background: rgba(74, 222, 128, 0.1); /* Fallback */
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--accent);
}

.font-badge.google {
    background: rgba(66, 133, 244, 0.1); /* Fallback */
    background: color-mix(in srgb, var(--info) 10%, transparent);
    color: var(--info);
}

/* Scrollbar for dropdown */
.custom-font-options::-webkit-scrollbar {
    width: 6px;
}

.custom-font-options::-webkit-scrollbar-track {
    background: transparent;
}

.custom-font-options::-webkit-scrollbar-thumb {
    background: var(--border-color, #444);
    border-radius: 3px;
}

.custom-font-options::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted, #666);
}

/* Light theme overrides */
[data-theme="light"] .model-select,
.theme-light .model-select {
    background-color: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #222);
    border-color: var(--border-color, #ddd);
}

[data-theme="light"] .model-select option,
.theme-light .model-select option {
    background-color: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #222);
}

[data-theme="light"] .model-refresh-btn,
.theme-light .model-refresh-btn {
    background: var(--bg-tertiary, #fff);
    color: var(--text-muted, #666);
    border-color: var(--border-color, #ddd);
}

[data-theme="light"] .model-refresh-btn:hover,
.theme-light .model-refresh-btn:hover {
    background: var(--bg-hover, #f0f0f0);
    color: var(--text-primary, #222);
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
 *  Settings Section Styling (Typography, Audio)
 *  ========================================================================== */

.typography-settings-section,
.audio-settings-section,
.streaming-sound-section {
    padding: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.audio-settings-section {
    margin-top: 20px;
}

.streaming-sound-section {
    margin-top: 20px;
}

.settings-section-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 20px;
}

.settings-section-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    flex-shrink: 0;
}

.settings-section-icon.typography-icon {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
}

.settings-section-icon.audio-icon {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.settings-section-icon.streaming-sound-icon {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.settings-section-title h4 {
    margin: 0 0 4px 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.settings-section-title p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.settings-control-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Font Family Row */
.font-family-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.font-family-wrapper {
    position: relative;
}

/* Font Size Row */
.font-size-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-label,
.slider-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

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

.slider-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    min-width: 50px;
    text-align: right;
}

.slider-track-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Slider Track with Handle */
.slider-track {
    position: relative;
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: visible;
}

.slider-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    margin: 0;
    z-index: 2;
}

.slider-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 80%, white));
    border-radius: 3px;
    pointer-events: none;
    transition: width 0.05s ease;
}

/* Slider Handle/Thumb */
.slider-handle {
    position: absolute;
    top: 50%;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border: 2px solid var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

.slider-track:hover .slider-handle {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.slider-input:active ~ .slider-handle {
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.4);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Font Preview */
.font-preview {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-family, inherit);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Toggle Row */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    gap: 16px;
}

.toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.toggle-description {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ==========================================================================
 *  Audio Control Group - Animated Show/Hide
 *  ========================================================================== */

.audio-control-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.audio-control-group.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Slider Row */
.slider-row {
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

/* Volume Row */
.volume-row .slider-header {
    gap: 10px;
}

.volume-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.volume-row .slider-label {
    flex: 1;
}

/* Sound Inputs Container */
.sound-inputs-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Sound Input Card */
.sound-input-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.sound-input-card:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 5%, var(--bg-tertiary));
}

.sound-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

/* Sound Footer - contains toggle and action buttons */
.sound-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sound-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border-radius: 8px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.sound-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sound-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.sound-filename {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.sound-filename.loaded {
    color: var(--accent);
}

.sound-filename.error {
    color: var(--error);
}

.sound-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.sound-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.sound-action-btn:hover:not(:disabled) {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--accent);
}

.sound-action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sound-action-btn.preview:hover:not(:disabled) {
    color: var(--success);
    border-color: var(--success);
}

.sound-action-btn.upload:hover:not(:disabled) {
    color: var(--accent);
    border-color: var(--accent);
}

.sound-action-btn.clear:hover:not(:disabled) {
    color: var(--error);
    border-color: var(--error);
}

.sound-action-btn svg {
    pointer-events: none;
}

.sound-action-btn.playing {
    color: var(--accent);
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--bg-secondary));
}

.sound-action-btn.playing svg {
    animation: audio-pulse 1s ease-in-out infinite;
}

@keyframes audio-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Theme Mode Section */
.theme-mode-section {
}

.theme-mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.theme-mode-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-muted);
    transition: color 0.2s ease;
}

.theme-mode-label svg {
    opacity: 0.7;
}

.theme-mode-label.dark-label {
    color: var(--text-primary);
}

/* Color Theme Section */
.color-theme-section {
    margin-top: 24px;
}

.section-heading {
    margin: 0 0 16px 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Theme Grid */
.theme-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
}

.theme-preview {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
}

.theme-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.75rem;
    text-align: center;
    padding: 4px 2px;
    line-height: 1.2;
}

.theme-btn {
    padding: 8px 6px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    text-align: center;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.theme-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

/* Theme Switch */
.theme-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

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

.theme-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    transition: 0.3s;
}

.theme-slider:before {
    position: absolute;
    bottom: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    content: "";
    background-color: var(--text-primary);
    border-radius: 50%;
    transition: 0.3s;
}

.theme-switch input:checked + .theme-slider {
    background-color: var(--accent);
    border-color: var(--accent);
}

.theme-switch input:checked + .theme-slider:before {
    transform: translateX(24px);
    background-color: var(--bg-primary);
}

/* Responsive */
@media (max-width: 600px) {
    .typography-settings-section,
    .audio-settings-section,
    .streaming-sound-section {
        padding: 16px;
    }

    .settings-section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .settings-section-icon {
        width: 36px;
        height: 36px;
    }

    .toggle-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .sound-input-card {
        flex-wrap: wrap;
        gap: 10px;
    }

    .sound-info {
        min-width: calc(100% - 52px);
    }

    .sound-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .sound-filename {
        max-width: 100%;
    }

    .font-preview {
        font-size: inherit !important;
    }
}

/* Unsafe Module Warning Styling */
.module-unsafe {
    border: 1px solid rgba(255, 99, 99, 0.4) !important;
    background: linear-gradient(135deg, rgba(255, 99, 99, 0.05) 0%, rgba(255, 99, 99, 0.02) 100%) !important;
    transition: all 0.2s ease;
}

.module-unsafe-badge {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.7em;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #ff6363;
    background: rgba(255, 99, 99, 0.15);
    border: 1px solid rgba(255, 99, 99, 0.3);
    border-radius: 4px;
    text-transform: uppercase;
    vertical-align: middle;
    line-height: 1.2;
}

/* Slightly dim disabled unsafe modules for visual hierarchy */
.module-unsafe:not(.enabled) {
    opacity: 0.75;
    filter: grayscale(0.2);
}

.setting-item-unsafe {
    border-left: 3px solid #ef4444 !important; /* Red warning border */
    padding: 4px;
    background-color: rgba(239, 68, 68, 0.05); /* Very faint red background */
    position: relative;
}

.setting-item-unsafe::after {
    content: "⚠️ UNSAFE";
    position: absolute;
    right: 8px;
    font-size: 10px;
    font-weight: bold;
    color: #ef4444;
    opacity: 0.7;
}

/* the main setting that controls whether unsafe settings are visible */
.toggle-unsafe {
    background-color: rgba(239, 68, 68, 0.05);
    border: none;
    width: 80%;
    margin: 0 auto;
}

/* ==========================================================================
 *  Utilities & Accessibility
 *  ========================================================================== */

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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .settings-modal {
        width: 100vw;
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }

    .settings-body {
        flex-direction: column;
    }

    .settings-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .settings-nav {
        display: flex;
        gap: 4px;
        padding: 8px 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .settings-nav::-webkit-scrollbar {
        display: none;
    }

    .settings-nav-item {
        padding: 8px 12px;
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: 4px;
        white-space: nowrap;
    }

    .settings-nav-item.active {
        border-left-color: transparent;
        border-bottom-color: var(--accent);
    }
}

@media (min-width: 768px) {
    .settings-content {
        padding: 24px 40px;
    }
}

/* Reasoning Effort Slider */
.setting-slider-container {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.setting-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.setting-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.setting-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.setting-slider-value {
    min-width: 70px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.settings-sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.settings-sidebar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.9rem;
}
.settings-sidebar-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
}
.settings-sidebar-btn.restart-btn {
    border-color: var(--warning);
    color: var(--warning-text);
}

/* ==========================================================================
 *  Modules Layout (Desktop & Mobile)
 * ========================================================================== */

/* Desktop: Nested Sidebar List */
.module-sub-list {
    margin-top: 8px;
    padding-left: 20px;
    border-left: 1px solid var(--border-color);
}

.module-sub-list button {
    width: 100%;
    text-align: left;
    padding: 6px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 2px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.module-sub-list button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.module-sub-list button.active {
    background: var(--bg-tertiary);
    color: var(--accent);
    font-weight: 600;
}

/* Mobile: Embedded Toggle List */
@media (max-width: 768px) {
    /* iOS-style Category List */
    .mobile-category-list {
        display: flex;
        flex-direction: column;
        background: var(--bg-secondary);
        border-radius: 12px;
        overflow: hidden;
        margin-bottom: 16px;
    }

    .mobile-category-btn {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 16px 20px;
        background: none;
        border: none;
        border-bottom: 1px solid var(--border-color);
        cursor: pointer;
        text-align: left;
        font-size: 0.95rem;
        color: var(--text-primary);
        transition: background 0.15s ease;
        width: 100%;
        margin: 0;
    }

    .mobile-category-btn:last-child {
        border-bottom: none;
    }

    .mobile-category-btn:hover {
        background: var(--bg-tertiary);
    }

    .mobile-category-btn:active {
        background: var(--bg-tertiary);
        opacity: 0.8;
    }

    .mobile-category-btn svg {
        width: 20px;
        height: 20px;
        color: var(--accent);
        flex-shrink: 0;
    }

    .mobile-category-btn span {
        font-weight: 500;
    }

    .mobile-module-list {
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        padding: 7px;
        display: flex;
        flex-direction: column;
        background: transparent;
        overflow: visible;
    }

    /* iOS-style Module List Items */
    .module-list-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        background: var(--bg-secondary);
        border: none;
        border-bottom: 1px solid var(--border-color);
        cursor: pointer;
        transition: background 0.15s ease;
        margin: 0;
        width: 100%;
        text-align: left;
        color: var(--text-primary);
        font-weight: 500;
        font-size: 0.95rem;
    }

    .module-list-item:last-child {
        border-bottom: none;
    }

    .module-list-item:hover {
        background: var(--bg-tertiary);
    }

    .module-list-item:active {
        background: var(--bg-tertiary);
        opacity: 0.8;
    }

    .module-list-item .module-name {
        font-weight: 500;
        color: var(--text-primary);
        font-size: 0.95rem;
        margin: 0;
    }

    .module-list-item .chevron {
        width: 16px;
        height: 16px;
        color: var(--text-muted);
        flex-shrink: 0;
        margin-left: 8px;
    }

    /* Back Button for Mobile Drill-Down */
    .mobile-back-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        background: none;
        border: none;
        color: var(--accent);
        font-size: 0.9rem;
        font-weight: 600;
        cursor: pointer;
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
        width: 100%;
        margin-bottom: 8px;
    }

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

    .mobile-back-btn:active {
        opacity: 0.7;
    }

    /* ==========================================================================
     *  Unified Module & Channel Lists (Mobile)
     *  ========================================================================== */

    .module-unified-list,
    .channel-unified-list {
        display: flex;
        flex-direction: column;
        gap: 1px;
        background: var(--bg-secondary);
        border-radius: var(--radius-sm);
        overflow: hidden;
        margin-bottom: 14px;
    }

    .module-unified-card,
    .channel-unified-card {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        background: var(--bg-secondary);
        border: none;
        border-bottom: 1px solid var(--border-color);
        cursor: pointer;
        transition: background 0.15s ease;
        margin: 0;
        width: 100%;
        text-align: left;
        color: var(--text-primary);
    }

    .module-unified-card:last-child,
    .channel-unified-card:last-child {
        border-bottom: none;
    }

    .module-unified-card:hover,
    .channel-unified-card:hover {
        background: var(--bg-tertiary);
    }

    .module-unified-card:active,
    .channel-unified-card:active {
        background: var(--bg-tertiary);
        opacity: 0.8;
    }

    .module-unified-card.enabled,
    .channel-unified-card.enabled {
        background: rgba(var(--accent-rgb), 0.05);
    }

    .module-card-left,
    .channel-card-left {
        display: flex;
        flex-direction: column;
        gap: 4px;
        flex: 1;
        min-width: 0;
    }

    .module-card-name,
    .channel-card-name {
        font-weight: 500;
        font-size: 0.95rem;
        color: var(--text-primary);
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .module-card-desc {
        font-size: 0.8rem;
        color: var(--text-muted);
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .module-card-right,
    .channel-card-right {
        display: flex;
        align-items: center;
        gap: 12px;
        flex-shrink: 0;
    }

    .chevron {
        color: var(--text-muted);
        width: 18px;
        height: 18px;
        transition: transform 0.15s ease;
    }

    .module-unified-card:hover .chevron,
    .channel-unified-card:hover .chevron {
        color: var(--text-primary);
    }

    /* Toggle sizing for unified lists */
    .module-unified-card .toggle-switch,
    .channel-unified-card .toggle-switch {
        width: 36px;
        height: 20px;
    }

    .module-unified-card .toggle-slider::before,
    .channel-unified-card .toggle-slider::before {
        height: 14px;
        width: 14px;
        left: 3px;
        bottom: 3px;
    }

    .module-unified-card .toggle-switch input:checked + .toggle-slider::before,
    .channel-unified-card .toggle-switch input:checked + .toggle-slider::before {
        transform: translateX(16px);
    }
}
