/* TG-APP-multi - Vanilla CSS */
/* Uses Telegram theme variables when available */

:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0f0f0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom);
}

#app {
    max-width: 500px;
    margin: 0 auto;
    padding: 16px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    margin-bottom: 16px;
}

.balance {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
}

.balance-icon {
    font-size: 24px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--tg-theme-secondary-bg-color);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border: 2px solid var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-hint-color);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tab:hover {
    background: var(--tg-theme-secondary-bg-color);
}

.tab.active {
    border-color: var(--tg-theme-button-color);
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

.tab-icon {
    font-size: 20px;
}

/* Main content */
.main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Model section */
.model-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.model-section > label {
    font-weight: 500;
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

/* Model grid */
.model-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.model-loading,
.model-error,
.model-empty {
    padding: 24px;
    text-align: center;
    color: var(--tg-theme-hint-color);
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
}

.model-error {
    color: #721c24;
    background: #f8d7da;
}

/* Model category */
.model-category {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--tg-theme-hint-color);
    padding-left: 4px;
}

.category-models {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Model card */
.model-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 2px solid var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    background: var(--tg-theme-bg-color);
    cursor: pointer;
    transition: all 0.2s;
}

.model-card:hover {
    background: var(--tg-theme-secondary-bg-color);
}

.model-card.selected {
    border-color: var(--tg-theme-button-color);
    background: rgba(36, 129, 204, 0.1);
}

.model-icon {
    font-size: 28px;
    width: 40px;
    text-align: center;
}

.model-info {
    flex: 1;
    min-width: 0;
}

.model-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-desc {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-badges {
    display: flex;
    gap: 4px;
}

.badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-new {
    background: #28a745;
    color: white;
}

.badge-popular {
    background: #ff6b35;
    color: white;
}

/* Advanced options */
.advanced-options {
    border: 1px solid var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    overflow: hidden;
}

.advanced-options summary {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    background: var(--tg-theme-secondary-bg-color);
}

.advanced-options summary:hover {
    opacity: 0.8;
}

.advanced-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.advanced-content input[type="text"],
.advanced-content input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--tg-theme-hint-color);
    border-radius: 8px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 14px;
}

.advanced-content input:focus {
    outline: none;
    border-color: var(--tg-theme-button-color);
}

select {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--tg-theme-hint-color);
    border-radius: 12px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 16px;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--tg-theme-button-color);
}

/* Prompt section */
.prompt-section {
    width: 100%;
}

textarea {
    width: 100%;
    padding: 16px;
    border: 1px solid var(--tg-theme-hint-color);
    border-radius: 16px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 16px;
    resize: none;
    font-family: inherit;
}

textarea:focus {
    outline: none;
    border-color: var(--tg-theme-button-color);
}

textarea::placeholder {
    color: var(--tg-theme-hint-color);
}

/* Options */
.options-section {
    display: flex;
    gap: 16px;
}

.option {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.option label {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.option select {
    padding: 10px;
}

/* Generate button */
.generate-btn {
    width: 100%;
    padding: 16px;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 16px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.generate-btn:hover {
    opacity: 0.9;
}

.generate-btn:active {
    transform: scale(0.98);
}

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

.generate-btn.loading {
    position: relative;
}

.generate-btn.loading::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Status */
.status {
    padding: 12px 16px;
    border-radius: 12px;
    text-align: center;
    font-size: 14px;
}

.status.info {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-hint-color);
}

.status.success {
    background: #d4edda;
    color: #155724;
}

.status.error {
    background: #f8d7da;
    color: #721c24;
}

.hidden {
    display: none !important;
}

/* Gallery */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 8px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 16px;
    overflow: hidden;
    background: var(--tg-theme-secondary-bg-color);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s;
}

.gallery-item img:hover {
    transform: scale(1.02);
}

.gallery-item .download-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-content {
    background: var(--tg-theme-bg-color);
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
}

.modal-header h2 {
    font-size: 18px;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--tg-theme-hint-color);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.stats-content {
    padding: 20px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
}

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

.stat-label {
    color: var(--tg-theme-hint-color);
}

.stat-value {
    font-weight: 600;
}

.provider-stats {
    margin-top: 16px;
}

.provider-stats h3 {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    margin-bottom: 8px;
}

.provider-stat {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 14px;
}

/* Image viewer (fullscreen) */
.image-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-viewer img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.image-viewer .close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    color: white;
    font-size: 36px;
}

/* Video viewer */
.video-viewer video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Video items in gallery */
.video-item {
    position: relative;
}

.video-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
}

.video-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 14px;
}

/* Responsive */
@media (max-width: 360px) {
    .options-section {
        flex-direction: column;
    }

    .model-card {
        padding: 10px;
    }

    .model-icon {
        font-size: 24px;
        width: 32px;
    }
}
