/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f8f9fa;
    min-height: 100vh;
    color: #333;
}

/* ==================== 初始模式 ==================== */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    transition: all 0.3s ease;
}

/* 头部 */
.header {
    text-align: center;
    padding: 80px 0 50px;
    transition: all 0.3s ease;
}

.header h1 {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 16px;
}

.header .subtitle {
    font-size: 1.2rem;
    color: #666;
}

/* 输入区域 */
.input-section {
    background: white;
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    margin-bottom: 24px;
    transition: all 0.3s ease;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

#prompt-input {
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
    border: 2px solid #eee;
    border-radius: 12px;
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
    transition: all 0.2s;
    background: #fafafa;
}

#prompt-input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

#model-select {
    padding: 12px 16px;
    font-size: 0.95rem;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

#model-select:hover {
    border-color: #667eea;
}

#generate-btn {
    padding: 12px 32px;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

#generate-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 推荐 Prompt */
.suggestions-section {
    margin-bottom: 24px;
}

.suggestions-section h3 {
    font-size: 0.95rem;
    font-weight: 500;
    color: #888;
    margin-bottom: 12px;
}

.suggestions-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggestion-chip {
    padding: 10px 18px;
    font-size: 0.9rem;
    color: #555;
    background: white;
    border: 1px solid #e8e8e8;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.suggestion-chip:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* 状态区域 - 初始模式 */
.status-section {
    background: white;
    border-radius: 16px;
    padding: 16px 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    margin-bottom: 20px;
}

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

.status-text {
    font-size: 0.95rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-text::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

.toggle-raw {
    padding: 8px 14px;
    font-size: 0.85rem;
    color: #666;
    background: #f5f5f5;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-raw:hover {
    background: #eee;
}

.raw-output {
    margin-top: 16px;
    padding: 16px;
    background: #1a1a2e;
    color: #a0a0a0;
    border-radius: 12px;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 0.85rem;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* 结果区域 - 初始隐藏 */
.result-section {
    display: none;
}

/* 初始模式下隐藏悬浮元素 */
.hover-trigger,
.floating-bar {
    display: none;
}

/* ==================== 全屏模式 ==================== */
body.fullscreen-mode {
    background: #f0f0f0;
    overflow: hidden;
}

body.fullscreen-mode .container {
    max-width: none;
    padding: 0;
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
}

/* 全屏模式：隐藏初始内容 */
body.fullscreen-mode .header,
body.fullscreen-mode .suggestions-section {
    display: none;
}

/* 隐藏 hover-trigger */
body.fullscreen-mode .hover-trigger {
    display: none;
}

/* 底部控制栏 */
body.fullscreen-mode .floating-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: white;
    padding: 16px 24px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.1);
    align-items: center;
    gap: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* 控制条内的 Logo */
.floating-bar .logo {
    font-size: 1.3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    padding-right: 12px;
    border-right: 2px solid #eee;
    margin-right: 4px;
}

/* 控制条内的输入框 - 单行布局 */
body.fullscreen-mode .input-section {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    background: transparent;
    padding: 0;
    margin: 0;
    box-shadow: none;
    border-radius: 0;
    border: none;
}

body.fullscreen-mode #generate-form {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

body.fullscreen-mode #prompt-input {
    flex: 1;
    min-height: auto;
    height: 44px;
    padding: 10px 16px;
    font-size: 0.95rem;
    border: 2px solid #eee;
    border-radius: 12px;
    resize: none;
    background: #f8f9fa;
}

body.fullscreen-mode #prompt-input:focus {
    border-color: #667eea;
    background: white;
}

body.fullscreen-mode .form-actions {
    margin-top: 0;
    gap: 8px;
    flex-shrink: 0;
}

body.fullscreen-mode #model-select {
    padding: 10px 12px;
    font-size: 0.85rem;
    border-radius: 8px;
    height: 44px;
}

body.fullscreen-mode #generate-btn {
    padding: 10px 20px;
    font-size: 0.9rem;
    border-radius: 8px;
    height: 44px;
}

/* 状态区域 - 全屏模式 */
body.fullscreen-mode .status-section {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: white;
    border-radius: 50px;
    padding: 12px 24px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    margin: 0;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

body.fullscreen-mode .status-header {
    gap: 16px;
}

body.fullscreen-mode .raw-output {
    position: fixed;
    bottom: 140px;
    left: 24px;
    right: 24px;
    max-height: 50vh;
    margin: 0;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    font-size: 0.8rem;
    line-height: 1.5;
}

/* 结果区域 - 全屏模式 */
body.fullscreen-mode .result-section {
    display: block;
    flex: 1;
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    position: relative;
    /* 为底部控制栏留出空间 */
    margin-bottom: 80px;
}

body.fullscreen-mode .result-header {
    display: none;
}

body.fullscreen-mode .iframe-container {
    position: absolute;
    inset: 0;
    border: none;
    border-radius: 0;
    background: white;
}

body.fullscreen-mode #result-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* 统计信息悬浮显示 */
body.fullscreen-mode .result-stats {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    background: rgba(26, 26, 46, 0.85);
    backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.9);
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 0.8rem;
    transition: all 0.2s;
    display: flex;
    gap: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

body.fullscreen-mode .result-stats:hover {
    background: rgba(26, 26, 46, 0.95);
}

body.fullscreen-mode .result-stats span {
    margin: 0;
    opacity: 0.85;
}

body.fullscreen-mode .result-stats span:first-child {
    opacity: 1;
    font-weight: 500;
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
    .header h1 {
        font-size: 2.5rem;
    }

    .header {
        padding: 50px 0 30px;
    }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    #model-select, #generate-btn {
        width: 100%;
    }

    body.fullscreen-mode .floating-bar {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        gap: 8px;
    }

    body.fullscreen-mode .floating-bar .logo {
        display: none;
    }

    body.fullscreen-mode #generate-form {
        flex-wrap: wrap;
        gap: 8px;
    }

    body.fullscreen-mode #prompt-input {
        width: 100%;
        flex: none;
        height: 40px;
    }

    body.fullscreen-mode .form-actions {
        flex: 1;
        justify-content: stretch;
    }

    body.fullscreen-mode #model-select {
        flex: 1;
        height: 40px;
        font-size: 0.8rem;
    }

    body.fullscreen-mode #generate-btn {
        flex: none;
        height: 40px;
        padding: 8px 16px;
        font-size: 0.85rem;
    }

    body.fullscreen-mode .result-stats {
        top: 8px;
        right: 8px;
        left: 8px;
        font-size: 0.7rem;
        padding: 6px 10px;
        justify-content: center;
        flex-wrap: wrap;
        gap: 6px;
    }

    body.fullscreen-mode .status-section {
        bottom: 110px;
        left: 12px;
        right: 12px;
        transform: none;
        padding: 10px 16px;
    }

    body.fullscreen-mode .result-section {
        margin-bottom: 100px;
    }
}

/* ==================== 用户栏 ==================== */
.user-bar {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 200;
}

.login-btn {
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.user-logged-in {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 12px 4px 4px;
    background: white;
    border-radius: 24px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    position: relative;
}

.user-logged-in[hidden] {
    display: none;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-avatar-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: #333;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    min-width: 140px;
}

.user-dropdown.show {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    font-size: 0.9rem;
    color: #333;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: #f5f5f5;
}

.dropdown-item:last-child {
    color: #e53935;
}

/* ==================== 弹窗 ==================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal[hidden] {
    display: none;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

.modal-content.modal-large {
    max-width: 640px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
}

.modal-close {
    width: 32px;
    height: 32px;
    font-size: 1.5rem;
    color: #999;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: #f5f5f5;
    color: #333;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.modal-hint {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 16px;
}

/* Credits 余额 */
.credits-balance {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid #eee;
    margin-bottom: 12px;
}

.balance-label {
    font-size: 0.9rem;
    color: #666;
}

.balance-amount {
    font-size: 1.4rem;
    font-weight: 700;
    color: #333;
}

.credits-tiers {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.credit-tier {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid #eee;
}

.credit-tier .tier-amount {
    font-size: 1.1rem;
    font-weight: 700;
    color: #333;
}

.credit-tier .tier-bonus {
    font-size: 0.85rem;
    color: #2e7d32;
}

.credit-tier .tier-total {
    font-size: 0.85rem;
    color: #666;
}

.credit-tier button {
    margin-top: 6px;
    padding: 10px 12px;
    font-size: 0.9rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.credit-tier button:hover:not(:disabled) {
    opacity: 0.9;
}

.credit-tier button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.credits-empty,
.credits-error {
    font-size: 0.9rem;
    color: #888;
    text-align: center;
    padding: 20px;
}

.credits-error {
    color: #e53935;
}

/* API Key 列表 */
.api-key-list {
    margin-bottom: 20px;
}

.api-key-list .empty,
.api-key-list .error {
    font-size: 0.9rem;
    color: #888;
    text-align: center;
    padding: 20px;
}

.api-key-list .error {
    color: #e53935;
}

.api-key-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 10px;
    margin-bottom: 8px;
}

.key-provider {
    font-weight: 600;
    color: #333;
    min-width: 80px;
}

.key-hint {
    flex: 1;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 0.85rem;
    color: #666;
}

.key-status {
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px;
}

.key-status.active {
    background: #e8f5e9;
    color: #2e7d32;
}

.key-status.inactive {
    background: #fce4ec;
    color: #c62828;
}

.key-delete {
    padding: 6px 12px;
    font-size: 0.8rem;
    color: #e53935;
    background: none;
    border: 1px solid #e53935;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.key-delete:hover {
    background: #e53935;
    color: white;
}

/* API Key 表单 */
.api-key-form {
    display: flex;
    gap: 8px;
}

.api-key-form select {
    padding: 10px 12px;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
}

.api-key-form input {
    flex: 1;
    padding: 10px 14px;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.api-key-form input:focus {
    outline: none;
    border-color: #667eea;
}

.api-key-form button {
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.api-key-form button:hover:not(:disabled) {
    opacity: 0.9;
}

.api-key-form button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 历史记录统计 */
.history-stats {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 0.8rem;
    color: #888;
}

/* 历史记录列表 */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-list .empty,
.history-list .error {
    font-size: 0.9rem;
    color: #888;
    text-align: center;
    padding: 40px;
}

.history-item {
    padding: 14px 16px;
    background: #f8f9fa;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
}

.history-item:hover {
    background: #f0f0f0;
}

.history-prompt {
    font-size: 0.95rem;
    color: #333;
    line-height: 1.4;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-meta {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: #888;
}

.history-loading {
    text-align: center;
    padding: 20px;
    color: #888;
}

.load-more-btn {
    width: 100%;
    padding: 12px;
    margin-top: 16px;
    font-size: 0.9rem;
    color: #667eea;
    background: none;
    border: 1px solid #667eea;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
}

.load-more-btn:hover {
    background: #667eea;
    color: white;
}

/* 全屏模式下隐藏用户栏 */
body.fullscreen-mode .user-bar {
    display: none;
}
