:root {
    --bg-primary: #f5f6fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f2f5;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --border: #e5e7eb;
    --border-hover: #d1d5db;
    --accent: #75c1c4;
    --accent-hover: #5fa8ab;
    --accent-light: #eaf6f7;
    --accent-text: #ffffff;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --border: #334155;
    --border-hover: #475569;
    --accent: #75c1c4;
    --accent-hover: #8fd5d8;
    --accent-light: #1a3a3c;
    --accent-text: #0f172a;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-tertiary: #64748b;
        --border: #334155;
        --border-hover: #475569;
        --accent: #75c1c4;
        --accent-hover: #8fd5d8;
        --accent-light: #1a3a3c;
        --accent-text: #0f172a;
    }
}

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

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

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent);
}

.logo h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

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

.editor-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    background: var(--bg-tertiary);
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    transition: background var(--transition);
}

.editor-status.connected .status-dot {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

/* Main Content */
.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    min-height: calc(100vh - 64px);
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon {
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Config Grid */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

/* Config Card */
.config-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.config-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
    transform: translateY(-2px);
}

.config-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 6px;
}

.config-card-author {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    width: fit-content;
}

.config-card-author svg {
    color: var(--text-tertiary);
}

.config-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

.config-date {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.config-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.config-meta-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.config-meta-item .meta-label {
    color: var(--text-tertiary);
    min-width: 70px;
}

.config-meta-item .meta-value {
    color: var(--text-primary);
    font-weight: 500;
}

.theme-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.theme-badge.light {
    background: #f0f9ff;
    color: #0369a1;
}

.theme-badge.dark {
    background: #1e293b;
    color: #cbd5e1;
}

.theme-badge.midnight {
    background: #1a1a3e;
    color: #a5b4fc;
}

.accent-swatch {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.config-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 16px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    min-height: 40px;
}

.config-desc:empty::before {
    content: '无描述';
    color: var(--text-tertiary);
}

.config-actions {
    display: flex;
    gap: 8px;
}

.config-actions .btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
}

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
    transition: all var(--transition);
    z-index: 50;
}

.fab:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5);
}

.fab:active {
    transform: scale(0.95);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
}

.modal-content.small {
    max-width: 400px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

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

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* Upload Sources */
.upload-sources {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.source-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 16px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 14px;
}

.source-btn:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
}

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

.source-btn small {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: normal;
}

/* File Info */
.file-info {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    display: block;
}

.file-info-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.file-info-row + .file-info-row {
    margin-top: 4px;
}

.file-info-row .label {
    color: var(--text-tertiary);
}

.file-info-row .value {
    color: var(--text-primary);
    font-weight: 500;
}

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

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-group .required {
    color: var(--danger);
}

.form-group .optional {
    color: var(--text-tertiary);
    font-weight: normal;
    font-size: 12px;
}

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

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

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.counter {
    display: block;
    text-align: right;
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* Theme Detection */
.theme-detection {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 16px;
}

.theme-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.theme-item + .theme-item {
    border-top: 1px solid var(--border);
}

.theme-label {
    font-size: 13px;
    color: var(--text-tertiary);
}

.theme-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.accent-display {
    display: flex;
    align-items: center;
    gap: 8px;
}

.accent-color {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 2px solid var(--border);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    font-family: inherit;
}

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

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

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-danger {
    background: var(--danger);
    color: white;
}

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

/* Apply URL Display */
.apply-url-display {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
}

.url-label {
    display: block;
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}

.apply-url {
    display: block;
    word-break: break-all;
    font-size: 12px;
    color: var(--accent);
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.apply-hint {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-secondary);
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    z-index: 2000;
    animation: toastIn 0.3s ease;
}

.toast.success {
    background: var(--success);
    color: white;
}

.toast.error {
    background: var(--danger);
    color: white;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Responsive */
@media (max-width: 640px) {
    .header-inner {
        padding: 12px 16px;
    }

    .logo h1 {
        font-size: 16px;
    }

    .editor-status {
        display: none;
    }

    .main {
        padding: 16px;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }

    .upload-sources {
        grid-template-columns: 1fr;
    }

    .modal-content {
        margin: 10px;
        max-height: 95vh;
    }

    .fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}
