/* =====================================================
   STREAMERHUB DIALOG DESIGN SYSTEM - GLASSMORPHISM
   ===================================================== */

/* ---- Dialog open animation ---- */
@keyframes dialogSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

/* ---- Z-index hierarchy ---- */
.modal {
    z-index: 10000;
}

#customSoundPickerModal {
    z-index: 10040;
}

#mediaSearchModal {
    z-index: 10040;
}

#mediaSearchModal .media-search-modal-card {
    display: flex;
    flex-direction: column;
    width: min(920px, 96vw);
    height: min(88vh, 760px);
    max-height: 90vh;
}

#mediaSearchModal .media-search-modal-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
    overflow: hidden;
}

#mediaSearchModal .giphy-search-header {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
    flex-shrink: 0;
}

#mediaSearchModal .giphy-tabs {
    display: flex;
    margin-bottom: 8px;
    border-bottom: 1px solid #ddd;
}

#mediaSearchModal .giphy-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: #666;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    font-size: 14px;
}

#mediaSearchModal .giphy-tab:hover {
    background: #f0f0f0;
    color: #333;
}

#mediaSearchModal .giphy-tab.active {
    color: #ff6b6b;
    border-bottom-color: #ff6b6b;
    background: #fff;
    font-weight: 600;
}

#mediaSearchModal .giphy-search-input {
    width: 100%;
}

#mediaSearchModal .sound-filters {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e8e8e8;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#mediaSearchModal .sound-filters[hidden] {
    display: none !important;
}

#mediaSearchModal .sound-filters__row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    flex-wrap: wrap;
}

#mediaSearchModal .sound-filters__label {
    flex: 0 0 72px;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    padding-top: 6px;
}

#mediaSearchModal .sound-filters__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
}

#mediaSearchModal .sound-filter-chip {
    border: 1px solid #ddd;
    background: #fff;
    color: #444;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#mediaSearchModal .sound-filter-chip:hover {
    border-color: #ff6b6b;
    color: #c0392b;
}

#mediaSearchModal .sound-filter-chip.is-active {
    background: #ff6b6b;
    border-color: #ff6b6b;
    color: #fff;
}

#mediaSearchModal .sound-filters__select {
    flex: 1 1 auto;
    min-width: 140px;
    max-width: 220px;
    font-size: 13px;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 5px 8px;
    background: #fff;
    color: #333;
}

#mediaSearchModal .giphy-results {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 16px;
}

#mediaSearchModal .giphy-results.is-loading .giphy-grid {
    visibility: hidden;
}

#mediaSearchModal .giphy-results.is-loading .giphy-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex !important;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    background: #f8f9fa;
}

html[data-theme="dark"] #mediaSearchModal .giphy-results.is-loading .giphy-loading,
body[data-theme="dark"] #mediaSearchModal .giphy-results.is-loading .giphy-loading {
    background: var(--surface);
}

#mediaSearchModal .giphy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

#mediaSearchModal .giphy-item {
    position: relative;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    transition: transform 0.2s ease;
}

#mediaSearchModal .giphy-item:hover {
    transform: scale(1.03);
}

#mediaSearchModal .giphy-item img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}

#mediaSearchModal .giphy-loading,
#mediaSearchModal .giphy-error,
#mediaSearchModal .giphy-no-results {
    text-align: center;
    padding: 24px;
}

#mediaSearchModal .giphy-loading,
#mediaSearchModal .giphy-no-results {
    color: #666;
}

#mediaSearchModal .giphy-error {
    color: #e74c3c;
}

/* ---- Sound search (Freesound) ---- */
#mediaSearchModal .giphy-grid.is-sounds {
    grid-template-columns: 1fr;
    gap: 6px;
}

#mediaSearchModal .sound-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border: 1px solid #eee;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

#mediaSearchModal .sound-item:hover {
    background: #fff5f5;
    border-color: #ff6b6b;
}

#mediaSearchModal .sound-item__play {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #ff6b6b;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: transform 0.15s ease;
}

#mediaSearchModal .sound-item__play:hover {
    transform: scale(1.08);
}

#mediaSearchModal .sound-item__play.is-playing {
    background: #c0392b;
}

#mediaSearchModal .sound-item__body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    gap: 2px;
}

#mediaSearchModal .sound-item__title {
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#mediaSearchModal .sound-item__uploaded {
    font-size: 11px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#mediaSearchModal .sound-item__time {
    font-size: 12px;
    color: #999;
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

#mediaSearchModal .sound-item__time.is-playing {
    color: #c0392b;
}

#mediaSearchModal .sound-item__time-sep {
    opacity: 0.7;
}

#mediaSearchModal .sound-item__waveform {
    position: relative;
    flex: 0 0 120px;
    width: 120px;
    height: 28px;
    align-self: center;
}

#mediaSearchModal .sound-item__waveform-track {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

#mediaSearchModal .sound-item__waveform-track img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    opacity: 0.35;
    display: block;
}

/* Clip from the left only — do not use inset:0 here or width % stretches the image. */
#mediaSearchModal .sound-item__waveform-progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    max-width: 100%;
    overflow: hidden;
    pointer-events: none;
    will-change: width;
}

#mediaSearchModal .sound-item__waveform-progress img {
    width: 120px;
    min-width: 120px;
    max-width: 120px;
    height: 28px;
    object-fit: fill;
    display: block;
    filter: invert(48%) sepia(79%) saturate(2476%) hue-rotate(325deg) brightness(98%) contrast(101%);
}

#mediaSearchModal .sound-item.is-playing .sound-item__waveform-progress img {
    filter: invert(27%) sepia(51%) saturate(2878%) hue-rotate(346deg) brightness(92%) contrast(97%);
}

html[data-theme="dark"] #mediaSearchModal .sound-item,
body[data-theme="dark"] #mediaSearchModal .sound-item {
    background-color: var(--surface-elev) !important;
    border-color: var(--border) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-item:hover,
body[data-theme="dark"] #mediaSearchModal .sound-item:hover {
    background-color: #2a2a2a !important;
    border-color: #ff6b6b !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-item__title,
body[data-theme="dark"] #mediaSearchModal .sound-item__title {
    color: var(--text) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-item__uploaded,
body[data-theme="dark"] #mediaSearchModal .sound-item__uploaded {
    color: var(--muted) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-item__time,
body[data-theme="dark"] #mediaSearchModal .sound-item__time {
    color: var(--muted) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-item__time.is-playing,
body[data-theme="dark"] #mediaSearchModal .sound-item__time.is-playing {
    color: #ff8a8a !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-item__waveform-track img,
body[data-theme="dark"] #mediaSearchModal .sound-item__waveform-track img {
    opacity: 0.45;
    filter: invert(1);
}

html[data-theme="dark"] #mediaSearchModal .sound-item__waveform-progress img,
body[data-theme="dark"] #mediaSearchModal .sound-item__waveform-progress img {
    filter: invert(48%) sepia(79%) saturate(2476%) hue-rotate(325deg) brightness(98%) contrast(101%);
}

html[data-theme="dark"] #mediaSearchModal .media-search-warning,
body[data-theme="dark"] #mediaSearchModal .media-search-warning {
    color: #ffce7a !important;
    background-color: rgba(245, 215, 122, 0.12) !important;
    border-color: rgba(245, 215, 122, 0.35) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-search-header,
body[data-theme="dark"] #mediaSearchModal .giphy-search-header {
    background-color: var(--surface-elev) !important;
    border-bottom: 1px solid var(--border) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-tabs,
body[data-theme="dark"] #mediaSearchModal .giphy-tabs {
    border-bottom-color: var(--border) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-tab,
body[data-theme="dark"] #mediaSearchModal .giphy-tab {
    color: var(--muted) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-tab:hover,
body[data-theme="dark"] #mediaSearchModal .giphy-tab:hover {
    background-color: #2a2a2a !important;
    color: var(--text) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-tab.active,
body[data-theme="dark"] #mediaSearchModal .giphy-tab.active {
    color: #ff6b6b !important;
    border-bottom-color: #ff6b6b !important;
    background-color: var(--surface) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-filters,
body[data-theme="dark"] #mediaSearchModal .sound-filters {
    border-top-color: var(--border) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-filters__label,
body[data-theme="dark"] #mediaSearchModal .sound-filters__label {
    color: var(--muted) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-filter-chip,
body[data-theme="dark"] #mediaSearchModal .sound-filter-chip {
    background-color: var(--surface-elev) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-filter-chip.is-active,
body[data-theme="dark"] #mediaSearchModal .sound-filter-chip.is-active {
    background-color: #ff6b6b !important;
    border-color: #ff6b6b !important;
    color: #fff !important;
}

html[data-theme="dark"] #mediaSearchModal .sound-filters__select,
body[data-theme="dark"] #mediaSearchModal .sound-filters__select {
    background-color: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--input-text) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-search-input,
body[data-theme="dark"] #mediaSearchModal .giphy-search-input {
    background-color: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--input-text) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-search-input::placeholder,
body[data-theme="dark"] #mediaSearchModal .giphy-search-input::placeholder {
    color: var(--muted) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-search-input:focus,
body[data-theme="dark"] #mediaSearchModal .giphy-search-input:focus {
    border-color: #ff6b6b !important;
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.2) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-results,
body[data-theme="dark"] #mediaSearchModal .giphy-results {
    background-color: var(--surface) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-loading,
body[data-theme="dark"] #mediaSearchModal .giphy-loading,
html[data-theme="dark"] #mediaSearchModal .giphy-no-results,
body[data-theme="dark"] #mediaSearchModal .giphy-no-results {
    color: var(--muted) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-error,
body[data-theme="dark"] #mediaSearchModal .giphy-error {
    color: #ff6b6b !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-item,
body[data-theme="dark"] #mediaSearchModal .giphy-item {
    background-color: var(--surface-elev) !important;
    border: 1px solid var(--border) !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-item:hover,
body[data-theme="dark"] #mediaSearchModal .giphy-item:hover {
    background-color: #2a2a2a !important;
    border-color: #3a3a3a !important;
}

html[data-theme="dark"] #mediaSearchModal .giphy-item img,
body[data-theme="dark"] #mediaSearchModal .giphy-item img {
    filter: brightness(0.9);
}

html[data-theme="dark"] #mediaSearchModal .giphy-item:hover img,
body[data-theme="dark"] #mediaSearchModal .giphy-item:hover img {
    filter: brightness(1);
}

/* Sound picker modal: match customSounds.html data-card browser */
#customSoundPickerModal .modal-card {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

#customSoundPickerModal .custom-sound-picker-body {
    overflow: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
}

#customSoundPickerMount .data-card {
    border: none;
    border-radius: 0;
    box-shadow: none;
}

#customSoundPickerMount .breadcrumb {
    margin-bottom: 0 !important;
}

#customSoundPickerMount .data-table tbody tr[data-row-type="sound"] {
    cursor: pointer;
}

.csf-mount .csf-pick-play-cell {
    text-align: center;
    width: 3.5rem;
}

.csf-mount .csf-pick-play-cell .icon-btn {
    vertical-align: middle;
}

.csf-mount .csf-pick-cell {
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted, rgba(99, 115, 129, 0.9));
    white-space: nowrap;
}

.csf-mount tr[data-row-type="sound"]:hover .csf-pick-cell {
    color: var(--accent);
}

/* Reusable sound pick trigger (config dialogs + settings pages) */
.sound-pick-btn--inline {
    flex: 1;
    min-width: 0;
}

.sound-pick-clear-btn {
    margin-top: 0.35rem;
    padding-left: 0;
    height: auto;
}

#confirmDialogModal {
    z-index: 10050;
}

#textPromptModal {
    z-index: 10055;
}

/* ---- Custom sound folder browser (manage + picker): folder row readability ---- */
.csf-mount tr.csf-folder-row {
    cursor: pointer;
}

.csf-inherited-hidden {
    opacity: 0.45;
}

.csf-inherited-hidden .csf-folder-icon {
    opacity: 0.7;
}

/* Manage-mode drag: folder row highlight (id beats customSounds zebra on tr) */
#customSoundsBrowserRoot .data-table tbody tr.csf-folder-row.csf-folder-drop-target {
    background-color: rgba(251, 191, 36, 0.28) !important;
    box-shadow: inset 0 0 0 2px rgba(217, 119, 6, 0.65);
    transition: background-color 0.08s ease, box-shadow 0.08s ease;
}

#customSoundsBrowserRoot .data-table tbody tr.csf-folder-row.csf-folder-drop-target td {
    background-color: rgba(251, 191, 36, 0.22) !important;
    box-shadow: inset 0 0 0 2px rgba(217, 119, 6, 0.55);
}

[data-theme="dark"] #customSoundsBrowserRoot .data-table tbody tr.csf-folder-row.csf-folder-drop-target {
    background-color: rgba(251, 191, 36, 0.18) !important;
    box-shadow: inset 0 0 0 2px rgba(252, 211, 77, 0.55);
}

[data-theme="dark"] #customSoundsBrowserRoot .data-table tbody tr.csf-folder-row.csf-folder-drop-target td {
    background-color: rgba(251, 191, 36, 0.12) !important;
    box-shadow: inset 0 0 0 2px rgba(252, 211, 77, 0.45);
}

.csf-mount .csf-folder-name {
    color: #1f2937;
    font-weight: 600;
}

.csf-mount .csf-folder-icon {
    color: #b8892a;
}

.csf-mount tr.csf-back-row td {
    color: #4a5568;
}

[data-theme="dark"] .csf-mount .csf-folder-name {
    color: #f8fafc;
}

[data-theme="dark"] .csf-mount tr[data-row-type="folder"] td {
    color: #f1f5f9;
}

[data-theme="dark"] .csf-mount .csf-folder-icon {
    color: #fcd34d !important;
}

[data-theme="dark"] .csf-mount tr.csf-back-row td {
    color: #cbd5e1;
}

[data-theme="dark"] .csf-mount .breadcrumb a {
    color: #e2e8f0;
}

[data-theme="dark"] .csf-mount .breadcrumb a:hover {
    color: #f8fafc;
}

[data-theme="dark"] .csf-mount .breadcrumb li.is-active a,
[data-theme="dark"] .csf-mount .breadcrumb li:last-child a {
    color: #f8fafc;
    font-weight: 600;
}

/* ---- Modal background - blur overlay ---- */
.modal-background {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background: rgba(0, 0, 0, 0.45);
}

/* ---- Modal card - Glassmorphism base ---- */
.modal-card {
    border-radius: 16px !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.22), 0 8px 16px rgba(0, 0, 0, 0.12) !important;
    overflow: hidden;
}

.modal.is-active .modal-card {
    animation: dialogSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Modal header ---- */
.modal-card-head {
    padding: 1.25rem 1.5rem !important;
    border-bottom: 1px solid var(--border) !important;
    background: var(--surface) !important;
    gap: 0.75rem;
    align-items: center;
}

.modal-card-title {
    font-size: 1rem !important;
    font-weight: 700 !important;
    color: var(--text) !important;
    letter-spacing: -0.01em;
    flex: 1;
}

/* ---- Modal body ---- */
.modal-card-body {
    background: var(--surface) !important;
    color: var(--text) !important;
    padding: 1.5rem !important;
}

/* ---- Modal footer ---- */
.modal-card-foot {
    background: var(--surface) !important;
    border-top: 1px solid var(--border) !important;
    padding: 1rem 1.5rem !important;
    display: flex !important;
    justify-content: flex-end !important;
    gap: 0.75rem !important;
}

/* ---- Dialog icon badge (colored circle in header) ---- */
.dialog-icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex-shrink: 0;
    font-size: 1rem;
    color: #fff;
}

/* ---- Category color classes ---- */
/* Create dialogs - Indigo */
.dialog-create .dialog-icon-badge {
    background: #4f46e5;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

/* Manage dialogs - Teal */
.dialog-manage .dialog-icon-badge {
    background: #0d9488;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

/* Config dialogs - Amber */
.dialog-config .dialog-icon-badge {
    background: #d97706;
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.35);
}

/* AI dialogs - Purple */
.dialog-ai .dialog-icon-badge {
    background: #7c3aed;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}

/* Danger dialogs - Red */
.dialog-danger .dialog-icon-badge {
    background: #dc2626;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35);
}

/* Primary button accent per category */
.dialog-create .button.is-primary-action,
.dialog-create .button.is-success {
    background-color: #4f46e5;
    border-color: #4f46e5;
    color: #fff;
}
.dialog-create .button.is-primary-action:hover,
.dialog-create .button.is-success:hover {
    background-color: #4338ca;
    border-color: #4338ca;
}

.dialog-manage .button.is-primary-action,
.dialog-manage .button.is-success {
    background-color: #0d9488;
    border-color: #0d9488;
    color: #fff;
}
.dialog-manage .button.is-primary-action:hover,
.dialog-manage .button.is-success:hover {
    background-color: #0f766e;
    border-color: #0f766e;
}

.dialog-config .button.is-primary-action,
.dialog-config .button.is-success {
    background-color: #d97706;
    border-color: #d97706;
    color: #fff;
}
.dialog-config .button.is-primary-action:hover,
.dialog-config .button.is-success:hover {
    background-color: #b45309;
    border-color: #b45309;
}

.dialog-ai .button.is-primary-action,
.dialog-ai .button.is-success {
    background-color: #7c3aed;
    border-color: #7c3aed;
    color: #fff;
}
.dialog-ai .button.is-primary-action:hover,
.dialog-ai .button.is-success:hover {
    background-color: #6d28d9;
    border-color: #6d28d9;
}

.dialog-danger .button.is-primary-action,
.dialog-danger .button.is-success {
    background-color: #dc2626;
    border-color: #dc2626;
    color: #fff;
}
.dialog-danger .button.is-primary-action:hover,
.dialog-danger .button.is-success:hover {
    background-color: #b91c1c;
    border-color: #b91c1c;
}

/* ---- Form field pattern ---- */
.dialog-field {
    margin-bottom: 1rem;
}

.dialog-field .label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.375rem !important;
}

/* ---- Toggle row ---- */
.dialog-toggle-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.dialog-toggle-row label {
    flex: 1;
    margin: 0;
    cursor: pointer;
    color: var(--text);
    font-size: 0.9375rem;
}

/* Switch groups: prefer 3 columns (auto-fill + minmax jumps 3→2 when the modal hits max-width) */
.dialog-toggle-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem 1rem;
    align-items: start;
}

.dialog-toggle-grid > .control {
    min-width: 0;
}

.dialog-toggle-grid > .control label {
    line-height: 1.35;
    word-break: break-word;
    hyphens: auto;
}

@media (max-width: 520px) {
    .dialog-toggle-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 360px) {
    .dialog-toggle-grid {
        grid-template-columns: 1fr;
    }
}

/* ---- Section dividers ---- */
.dialog-section-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 0.75rem;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.dialog-section-label:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* Input/select/textarea styles inherit from global --input-* tokens.
   Modal-scoped overrides were removed; only the label color tweak remains. */
[data-theme="dark"] .modal-card .label {
    color: var(--text);
}

/* ---- Close button in dark mode ---- */
[data-theme="dark"] .modal-card-head .delete {
    background-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .modal-card-head .delete:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* ---- Cancel button style ---- */
.modal-card-foot .button:not(.is-success):not(.is-danger):not(.is-info):not(.is-warning):not(.is-primary-action) {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
}

.modal-card-foot .button:not(.is-success):not(.is-danger):not(.is-info):not(.is-warning):not(.is-primary-action):hover {
    border-color: var(--text);
    color: var(--text);
}

/* ---- Drag-drop list items ---- */
.dialog-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: move;
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.dialog-list-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.dialog-list-item.drag-over {
    border-color: #4f46e5;
    background: rgba(79, 70, 229, 0.05);
}

.dialog-manage .dialog-list-item.drag-over {
    border-color: #0d9488;
    background: rgba(13, 148, 136, 0.05);
}

.dialog-list-item-drag-handle {
    cursor: grab;
    color: var(--muted);
    margin-right: 0.75rem;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}

.dialog-list-item-drag-handle:active {
    cursor: grabbing;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .modal-card {
        width: calc(100vw - 2rem) !important;
        margin: 1rem !important;
        border-radius: 12px !important;
    }

    .modal-card-head {
        padding: 1rem 1.25rem !important;
    }

    .modal-card-body {
        padding: 1.25rem !important;
    }

    .modal-card-foot {
        padding: 0.875rem 1.25rem !important;
    }
}

/* ============================================================
   Shared form helpers
   ============================================================ */
.label-header {
    font-weight: bold;
}

.range-row {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
}

/* Disabled inputs use the global .input:disabled / .textarea:disabled rule
   (token-driven, applies to both light and dark themes). */

/* ---- Field-disabled label ---- */
.field-disabled label {
    color: #7a7a7a !important;
    opacity: 0.7;
}

[data-theme="dark"] .field-disabled label {
    color: #a0a0a0 !important;
}

/* ============================================================
   Generate Soundeffect dialog
   ============================================================ */
#generateModal .gen-section {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

#generateModal .gen-section-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
    margin-bottom: 0.75rem;
}

#generateModal .gen-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 580px) {
    #generateModal .gen-settings-grid {
        grid-template-columns: 1fr;
    }
}

#generateModal .gen-preview {
    background: #f8f9fa;
    border: 1px dashed #d1d5db;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    min-height: 60px;
    transition: all 0.3s ease;
}

#generateModal .gen-preview:has(audio) {
    border-style: solid;
    border-color: #667eea;
}

#generateModal .gen-preview-hint {
    color: #9ca3af;
    font-size: 0.875rem;
    text-align: center;
    padding: 0.5rem 0;
}

#generateModal #generateDescription {
    font-size: 1.05rem;
    padding: 0.75rem 1rem;
}

[data-theme="dark"] #generateModal .gen-section,
[data-theme="dark"] #generateModal .gen-preview {
    background: #2a2a2a;
    border-color: #4a4a4a;
}

[data-theme="dark"] #generateModal .gen-preview:has(audio) {
    border-color: #5a8fff;
}

[data-theme="dark"] #generateModal .gen-section-label {
    color: #9ca3af;
}

[data-theme="dark"] #generateModal .gen-preview-hint {
    color: #6b7280;
}

/* ============================================================
   Chat Commands list items
   ============================================================ */
.command-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--surface, #f5f5f5);
    border: 1px solid var(--border, #dbdbdb);
    border-radius: 4px;
    cursor: move;
    transition: background-color 0.2s, border-color 0.2s;
}

.command-list-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.command-list-item.drag-over {
    border-color: #3273dc;
    background-color: var(--surface, #f0f8ff);
}

.command-list-item-drag-handle {
    cursor: grab;
    color: var(--muted, #7a7a7a);
    margin-right: 0.75rem;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}

.command-list-item-drag-handle:active {
    cursor: grabbing;
}

.command-list-item-info {
    flex: 1;
    min-width: 0;
}

.command-list-item-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
    word-break: break-word;
}

.command-list-item-command {
    font-size: 0.875rem;
    color: var(--muted, #7a7a7a);
    word-break: break-all;
    font-family: monospace;
}

.command-list-item-actions {
    margin-left: 1rem;
}

.command-list-item-color {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 2px solid var(--border, #dbdbdb);
    flex-shrink: 0;
    margin-right: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

input[type="color"]::-webkit-color-swatch {
    border: none;
}

input[type="color"]::-moz-color-swatch {
    border: none;
}

/* Modal scrolling constraints */
#manageChatCommandsModal .modal-card {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

#manageChatCommandsModal .modal-card-body {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

#existingChatCommandsList {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* ============================================================
   Iframes list items
   ============================================================ */
.iframe-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--surface, #f5f5f5);
    border: 1px solid var(--border, #dbdbdb);
    border-radius: 4px;
    cursor: move;
    transition: background-color 0.2s, border-color 0.2s;
}

.iframe-list-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.iframe-list-item.drag-over {
    border-color: #3273dc;
    background-color: var(--surface, #f0f8ff);
}

.iframe-list-item-drag-handle {
    cursor: grab;
    color: var(--muted, #7a7a7a);
    margin-right: 0.75rem;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}

.iframe-list-item-drag-handle:active {
    cursor: grabbing;
}

.iframe-list-item-info {
    flex: 1;
    min-width: 0;
}

.iframe-list-item-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
    word-break: break-word;
}

.iframe-list-item-url {
    font-size: 0.875rem;
    color: var(--muted, #7a7a7a);
    word-break: break-all;
}

.iframe-list-item-actions {
    margin-left: 1rem;
}

/* Modal scrolling constraints */
#manageIframesModal .modal-card {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

#manageIframesModal .modal-card-body {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

#existingIframesList {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* ---- Sound upload dropzone ---- */
.sound-dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 1.5rem 1rem;
    min-height: 140px;
    border: 2px dashed var(--border);
    border-radius: 12px;
    background: var(--surface-alt, rgba(0, 0, 0, 0.02));
    color: var(--text);
    cursor: pointer;
    text-align: center;
    transition: border-color 180ms ease, background-color 180ms ease, transform 180ms ease;
    outline: none;
}

.sound-dropzone:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.06);
}

.sound-dropzone:focus-visible {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.28);
}

.sound-dropzone.is-dragover {
    border-color: #667eea;
    border-style: solid;
    background: rgba(102, 126, 234, 0.10);
    transform: scale(1.01);
}

.sound-dropzone.is-invalid {
    border-color: #f14668;
    background: rgba(241, 70, 104, 0.08);
    animation: soundDropzoneShake 0.3s ease;
}

@keyframes soundDropzoneShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.sound-dropzone-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.12);
    color: #667eea;
    font-size: 1.25rem;
    transition: transform 180ms ease;
}

.sound-dropzone.is-dragover .sound-dropzone-icon {
    transform: translateY(-3px);
}

.sound-dropzone-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.sound-dropzone-hint {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted, rgba(99, 115, 129, 0.9));
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
}

.sound-dropzone-dot {
    opacity: 0.5;
}

.sound-dropzone-filename {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #667eea;
    word-break: break-all;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    max-width: 100%;
}

.sound-dropzone-filename .icon {
    flex-shrink: 0;
}

.sound-dropzone-filename-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.sound-dropzone-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(241, 70, 104, 0.35);
    border-radius: 50%;
    background: #fff;
    color: #e63950;
    cursor: pointer;
    padding: 0;
    font-size: 0.95rem;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: background-color 150ms ease, transform 150ms ease, border-color 150ms ease;
    z-index: 2;
}

.sound-dropzone.has-file .sound-dropzone-remove {
    display: inline-flex;
}

.sound-dropzone-remove:hover {
    background: #e63950;
    color: #fff;
    border-color: #e63950;
    transform: scale(1.08);
}

.sound-dropzone-remove:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(241, 70, 104, 0.35);
}

html[data-theme="dark"] .sound-dropzone-remove,
body[data-theme="dark"] .sound-dropzone-remove {
    background: #2a2a2a;
    color: #ff6b8a;
    border-color: rgba(255, 107, 138, 0.45);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

html[data-theme="dark"] .sound-dropzone-remove:hover,
body[data-theme="dark"] .sound-dropzone-remove:hover {
    background: #ff6b8a;
    color: #2a2a2a;
    border-color: #ff6b8a;
}

.sound-dropzone:not(.has-file) .sound-dropzone-filename {
    display: none;
}

.sound-dropzone.has-file .sound-dropzone-title,
.sound-dropzone.has-file .sound-dropzone-hint {
    display: none;
}

/* Visually-hidden native file input (keeps accessibility while hiding it) */
.sound-dropzone-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Dark mode */
html[data-theme="dark"] .sound-dropzone,
body[data-theme="dark"] .sound-dropzone {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border);
}

html[data-theme="dark"] .sound-dropzone:hover,
body[data-theme="dark"] .sound-dropzone:hover {
    border-color: #5a8fff;
    background: rgba(90, 143, 255, 0.10);
}

html[data-theme="dark"] .sound-dropzone.is-dragover,
body[data-theme="dark"] .sound-dropzone.is-dragover {
    border-color: #5a8fff;
    background: rgba(90, 143, 255, 0.16);
}

html[data-theme="dark"] .sound-dropzone-icon,
body[data-theme="dark"] .sound-dropzone-icon {
    background: rgba(90, 143, 255, 0.16);
    color: #5a8fff;
}

html[data-theme="dark"] .sound-dropzone-filename,
body[data-theme="dark"] .sound-dropzone-filename {
    color: #9cb8ff;
}

@media (prefers-reduced-motion: reduce) {
    .sound-dropzone,
    .sound-dropzone-icon {
        transition: none;
    }
    .sound-dropzone.is-invalid {
        animation: none;
    }
}
