/* ============================================
   UI Design - AI 网页设计稿生成系统
   全局样式
   ============================================ */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-tertiary: #1c1f2e;
    --bg-card: #1e2134;
    --border: #2a2d3e;
    --border-light: #343750;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0b0;
    --text-muted: #5f6578;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --transition: 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ---- Layout ---- */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 10;
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-sub {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}

.project-section {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 10px;
}

.section-header h2 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.project-list {
    list-style: none;
}

.project-list li {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text-secondary);
    transition: var(--transition);
    border-left: 3px solid transparent;
    position: relative;
}

.project-list li:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.project-list li.active {
    background: var(--accent-glow);
    color: var(--accent-hover);
    border-left-color: var(--accent);
    font-weight: 500;
}

.project-list li .proj-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-list li .proj-count {
    font-size: 11px;
    padding: 1px 8px;
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-muted);
}

.project-list li .proj-delete {
    opacity: 0;
    cursor: pointer;
    color: var(--danger);
    font-size: 16px;
    line-height: 1;
    transition: var(--transition);
}

.project-list li:hover .proj-delete { opacity: 0.7; }
.project-list li:hover .proj-delete:hover { opacity: 1; }

.empty-hint {
    color: var(--text-muted);
    font-size: 13px;
    padding: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
}

/* ---- Buttons ---- */
.btn-icon {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-sm {
    padding: 4px 12px;
    border-radius: 4px;
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-sm:hover { background: var(--border); }

.btn-primary, .btn-generate, .btn-cancel {
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.btn-generate {
    width: 100%;
    margin-top: 16px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: #fff;
    padding: 14px;
    font-size: 15px;
    letter-spacing: 0.3px;
}

.btn-generate:hover:not(:disabled) {
    box-shadow: 0 4px 20px var(--accent-glow);
    transform: translateY(-1px);
}

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

.btn-modao {
    background: linear-gradient(135deg, #10b981, #059669) !important;
    margin-top: 8px !important;
    font-size: 14px !important;
    padding: 12px !important;
}

.btn-modao:hover:not(:disabled) {
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.25) !important;
}

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

/* ---- Proto Preview ---- */
.proto-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 16px;
    overflow: hidden;
}

.proto-section .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}

.proto-section .section-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--success);
    text-transform: none;
    letter-spacing: 0;
}

.proto-actions {
    display: flex;
    gap: 6px;
}

.proto-preview-wrapper {
    padding: 0;
    background: #fff;
    min-height: 200px;
    max-height: 500px;
    overflow: auto;
}

.proto-iframe {
    width: 100%;
    height: 500px;
    border: none;
    display: block;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-cancel {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

.btn-cancel:hover { background: var(--border); }

.btn-refresh {
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
}

.btn-refresh:hover { color: var(--text-primary); background: var(--bg-card); }

/* ---- Main Area ---- */
.main-area {
    flex: 1;
    padding: 0 32px 40px;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.topbar-left h2 {
    font-size: 18px;
    font-weight: 600;
}

.badge {
    padding: 4px 14px;
    border-radius: 20px;
    background: var(--bg-card);
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

/* ---- Mode Tabs ---- */
.mode-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 4px;
    width: fit-content;
}

.mode-tab {
    padding: 8px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.mode-tab.active {
    background: var(--accent);
    color: #fff;
}

.mode-tab:hover:not(.active) {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* ---- Mode Panels ---- */
.mode-panel { display: none; }
.mode-panel.active { display: block; }

.panel-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 24px;
}

.panel-main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-side {
    position: sticky;
    top: 20px;
    align-self: start;
}

/* ---- Form ---- */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group textarea,
.form-group input[type="text"],
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: var(--transition);
}

.form-group textarea:focus,
.form-group input[type="text"]:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa0b0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-row.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---- Param Card ---- */
.param-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.param-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.param-group {
    margin-bottom: 18px;
}

.param-group > label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.radio-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.radio-item {
    cursor: pointer;
}

.radio-item input { display: none; }

.radio-item span {
    display: block;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    background: var(--bg-secondary);
    font-size: 13px;
    color: var(--text-secondary);
    transition: var(--transition);
    white-space: nowrap;
}

.radio-item span small {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
}

.radio-item input:checked + span {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent-hover);
}

.custom-size-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.custom-size-row input {
    width: 90px;
    padding: 6px 10px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    text-align: center;
}

.custom-size-row input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ---- Upload Zone ---- */
.upload-zone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.upload-zone:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}

.upload-zone.has-image {
    border-style: solid;
    padding: 4px;
}

.upload-placeholder {
    color: var(--text-muted);
    font-size: 13px;
}

.upload-icon {
    display: block;
    font-size: 28px;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.upload-preview {
    max-width: 100%;
    max-height: 160px;
    border-radius: 6px;
    object-fit: contain;
}

/* ---- Color Picker ---- */
.color-picker-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.color-input {
    width: 36px; height: 36px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    padding: 2px;
    background: transparent;
}

.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border-radius: 5px; border: none; }

/* ---- Generate Button Container ---- */
/* .btn-generate is defined above */

/* ---- Generating Overlay ---- */
.generating-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.generating-modal {
    text-align: center;
    background: var(--bg-secondary);
    padding: 40px 60px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.generating-modal p {
    margin-top: 20px;
    font-size: 16px;
    font-weight: 500;
}

.generating-modal small {
    color: var(--text-muted);
}

.spinner {
    width: 48px; height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

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

/* ---- History ---- */
.history-section {
    margin-top: 40px;
}

.history-section .section-header {
    padding: 0;
    margin-bottom: 16px;
}

.history-section .section-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: none;
    letter-spacing: 0;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.history-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
}

.history-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transform: translateY(-2px);
}

.history-card .card-img {
    width: 100%;
    aspect-ratio: 16/10;
    object-fit: cover;
    background: var(--bg-tertiary);
    display: block;
}

.history-card .card-body {
    padding: 12px 14px;
}

.history-card .card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
}

.history-card .card-mode {
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg-secondary);
    font-size: 11px;
}

.history-card .card-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.history-card .card-actions button {
    flex: 1;
    padding: 6px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    transition: var(--transition);
}

.history-card .card-actions button:hover { background: var(--border); }
.history-card .card-actions button.danger:hover {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
}

.pagination button {
    padding: 6px 14px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
}

.pagination button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.pagination button:hover:not(.active) {
    background: var(--border);
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    width: 420px;
    max-width: 90vw;
}

.modal-wide {
    width: 520px;
}

.badge-proto {
    display: inline-block;
    width: 18px; height: 18px;
    line-height: 18px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    background: var(--success);
    color: #fff;
    border-radius: 4px;
    margin-left: 4px;
}

.modal h3 {
    font-size: 16px;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* ---- Lightbox ---- */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.lightbox img {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 36px;
    color: #fff;
    cursor: pointer;
    z-index: 301;
}

.lightbox-info {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* ---- Share Import ---- */
.share-import-row {
    background: var(--bg-card);
    border: 1px dashed var(--border-light);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 12px;
}

.input-btn-row {
    display: flex;
    gap: 8px;
}

.input-btn-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}

.input-btn-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-import {
    background: var(--success) !important;
    color: #fff !important;
    border: none !important;
    padding: 8px 16px !important;
    font-weight: 600 !important;
    white-space: nowrap;
}

.btn-import:hover {
    background: #059669 !important;
}

/* ---- Modao Section ---- */
.modao-section {
    margin-top: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.modao-section .section-header {
    padding: 12px 16px;
    background: var(--bg-tertiary);
}

.modao-section .section-header h2 {
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
    color: var(--text-primary);
}

.toggle-arrow {
    font-size: 12px;
    color: var(--text-muted);
}

.modao-body {
    padding: 16px;
}

.proto-preview-wrapper {
    background: #fff;
    min-height: 150px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.proto-iframe {
    width: 100%;
    border: none;
    display: block;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .app-container { flex-direction: column; }
    .sidebar {
        width: 100%; min-width: 100%; height: auto;
        position: relative; border-right: none; border-bottom: 1px solid var(--border);
    }
    .panel-grid {
        grid-template-columns: 1fr;
    }
    .panel-side { position: static; }
    .main-area { padding: 0 16px 24px; }
}
