/* ========== Settings Pages - Shared Styles ========== */

/* Loading & Error states */
.loading-container, .error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
}

.error-text {
    color: var(--tg-theme-hint-color);
    font-size: 1rem;
}

/* ========== Price Bar ========== */
.price-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    margin: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.price-bar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.price-info, .balance-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.price-label, .balance-label {
    font-size: 0.875rem;
    color: var(--tg-theme-hint-color);
}

.price-value {
    font-size: 1rem;
    font-weight: 500;
    color: var(--tg-theme-text-color);
}

.balance-value {
    font-size: 1rem;
    font-weight: 500;
    color: var(--tg-theme-button-color);
}

/* ========== Field icon buttons (copy / clear) ==========
   Когда внутри текст — это «текстовая» версия (для не-prompt контекстов).
   Когда внутри SVG — иконка. */
.btn-field-clear,
.btn-field-copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity var(--transition-fast);
    line-height: 1.4;
}
.btn-field-clear { color: #c46a6a; }
.btn-field-copy  { color: var(--tg-theme-button-color); }
.btn-field-clear:active,
.btn-field-copy:active { opacity: 0.5; }

/* Когда кнопка содержит SVG — превращается в круглую иконку. */
.btn-field-clear:has(svg),
.btn-field-copy:has(svg) {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
}
.btn-field-clear svg,
.btn-field-copy svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    pointer-events: none;
}

.btn-field-clear:active {
    background: rgba(176, 80, 80, 0.12);
    color: #903030;
}

.field-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.field-hint-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ========== Upload Section ========== */
.upload-section {
    padding: var(--spacing-md);
}

.upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
}

.upload-info {
    flex: 1;
}

.btn-sm {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
}

.upload-preview {
    margin-top: var(--spacing-md);
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--tg-theme-secondary-bg-color);
}

.image-preview-img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    display: block;
    border-radius: var(--radius-md);
}

.upload-remove {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.upload-progress {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--radius-md);
    color: var(--tg-theme-hint-color);
    font-size: 0.875rem;
}

/* ========== Required Mark ========== */
.required-mark {
    color: var(--tg-theme-hint-color);
    font-size: 0.8125rem;
    font-weight: 400;
}

/* ========== Spinner Small ========== */
.spinner-small {
    width: 18px;
    height: 18px;
    border: 2px solid var(--tg-theme-hint-color);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ========== Form Fixes ========== */
.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.slider-label {
    font-size: 0.9375rem;
    color: var(--tg-theme-text-color);
}

.card-item .form-select {
    flex-shrink: 1;
    min-width: 0;
    max-width: 50%;
}

.card-item-content {
    flex: 1 1 40%;
    min-width: 100px;
}

/* ========== Hint Button ========== */
.hint-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 6px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--tg-theme-hint-color);
    color: var(--tg-theme-bg-color);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    vertical-align: middle;
}

.hint-btn:hover,
.hint-btn:active {
    opacity: 1;
    transform: scale(1.1);
}

/* ========== Hint Popup ========== */
.hint-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    animation: settingsFadeIn 0.2s ease-out;
}

.hint-overlay.hidden {
    display: none;
}

.hint-popup {
    background: var(--tg-theme-bg-color);
    border-radius: var(--radius-lg);
    max-width: 360px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.25s ease-out;
}

@keyframes settingsFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.hint-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
}

.hint-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--tg-theme-text-color);
}

.hint-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-hint-color);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hint-body {
    padding: var(--spacing-md);
    overflow-y: auto;
    max-height: calc(80vh - 60px);
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--tg-theme-text-color);
    white-space: pre-line;
}

.hint-body b {
    color: var(--tg-theme-button-color);
}

/* ========== Media Upload + Preview ========== */
/* Общие стили для загрузчиков аудио/файлов с rich-превью.
   Используется как минимум в elevenlabs и wan; при необходимости
   добавлять туда же, а не копировать в inline-<style>. */
.upload-section { padding: var(--spacing-md); }
.upload-header {
    display: flex; align-items: center; gap: var(--spacing-md);
}
.upload-info { flex: 1; min-width: 0; }
.upload-btn { flex-shrink: 0; }
.btn.btn-sm {
    padding: 6px 14px;
    font-size: 0.875rem;
}
.upload-progress {
    display: flex; align-items: center; gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    font-size: 0.875rem;
    color: var(--tg-theme-hint-color);
}
.spinner-small {
    width: 14px; height: 14px;
    border: 2px solid var(--tg-theme-hint-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: settings-spin 0.8s linear infinite;
}
@keyframes settings-spin { to { transform: rotate(360deg); } }

.audio-preview-info {
    display: flex; align-items: center; gap: var(--spacing-sm);
    padding: var(--spacing-md);
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--radius-md);
    margin-top: var(--spacing-md);
}
.audio-preview-icon {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--tg-theme-button-color);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.audio-preview-icon svg {
    width: 18px; height: 18px; fill: var(--tg-theme-button-text-color);
}
.audio-preview-name {
    flex: 1; min-width: 0;
    font-size: 0.9375rem; font-weight: 500;
    color: var(--tg-theme-text-color);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.audio-remove {
    width: 28px; height: 28px; border-radius: 50%;
    background: rgba(0, 0, 0, 0.15);
    color: var(--tg-theme-hint-color);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
}
.theme-dark .audio-remove { background: rgba(255, 255, 255, 0.15); }
.audio-player {
    width: 100%; height: 36px;
    margin-top: var(--spacing-sm);
    border-radius: var(--radius-sm);
}
.video-player {
    width: 100%;
    max-height: 240px;
    object-fit: contain;
    margin-top: var(--spacing-sm);
    border-radius: var(--radius-sm);
    background: #000;
    display: block;
}

/* ========== KIE upstream health badge ========== */
.health-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--color-border, rgba(255,255,255,0.1));
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.health-badge:active { opacity: 0.6; }
.health-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #888;
    flex-shrink: 0;
}
.health-pct {
    font-variant-numeric: tabular-nums;
    color: var(--tg-theme-hint-color);
}
.health-green  .health-dot { background: #2ecc71; }
.health-yellow .health-dot { background: #f1c40f; }
.health-red    .health-dot { background: #e74c3c; animation: health-pulse 1.5s ease-in-out infinite; }
@keyframes health-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ========== Health modal ========== */
.health-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.health-overlay.hidden { display: none; }
.health-modal-content {
    background: var(--tg-theme-bg-color);
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    max-height: 86vh;
    overflow-y: auto;
    padding: 18px;
}
.health-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.health-modal-header h3 { margin: 0; font-size: 18px; color: var(--tg-theme-text-color); }
.health-close {
    background: none;
    border: none;
    color: var(--tg-theme-hint-color);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
}

.health-summary {
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 14px;
}
.health-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.health-pct-large {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.health-pct-small {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.health-green  .health-pct-large, .health-pct-large.health-green,
.health-green  .health-pct-small, .health-pct-small.health-green   { color: #2ecc71; }
.health-yellow .health-pct-large, .health-pct-large.health-yellow,
.health-yellow .health-pct-small, .health-pct-small.health-yellow  { color: #f1c40f; }
.health-red    .health-pct-large, .health-pct-large.health-red,
.health-red    .health-pct-small, .health-pct-small.health-red     { color: #e74c3c; }
.health-foot-note {
    font-size: 11px;
    margin-top: 2px;
    color: var(--tg-theme-hint-color);
}

.health-variants {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 14px;
}
.health-variant {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--color-border, rgba(255,255,255,0.08));
    border-radius: 10px;
    padding: 10px 12px;
}
.health-variant-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.health-variant-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--tg-theme-text-color);
}
.health-variant-slug {
    font-family: monospace;
    font-size: 11px;
    color: var(--tg-theme-hint-color);
    word-break: break-all;
    margin-top: 2px;
    margin-bottom: 6px;
}
.health-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 50px;
    background: rgba(0,0,0,0.25);
    border-radius: 6px;
    padding: 4px;
}
.health-bar {
    flex: 1;
    min-height: 3px;
    border-radius: 2px;
    background: #2ecc71;
    transition: opacity 0.15s;
}
.health-variant-foot {
    margin-top: 6px;
    font-size: 11px;
    color: var(--tg-theme-hint-color);
}
.health-disclaimer {
    font-size: 11px;
    line-height: 1.4;
    padding: 8px 10px;
    background: rgba(255,255,255,0.02);
    border-radius: 8px;
    color: var(--tg-theme-hint-color);
}
