/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: #1f2940;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --text-muted: #6c6c6c;
    --accent-primary: #00d9ff;
    --accent-secondary: #7b2cbf;
    --accent-success: #00c853;
    --accent-warning: #ffab00;
    --accent-danger: #ff5252;
    --border-color: #2d3748;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --transition: all 0.3s ease;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    padding: 1rem 2rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin-bottom: 0.25rem;
}

.header .subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Main Container */
.main-container {
    display: flex;
    flex: 1;
    gap: 1rem;
    padding: 1rem;
    overflow: hidden;
}

/* Editor Panels */
.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
    min-width: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

.editor-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.editor-wrapper .CodeMirror {
    height: 100%;
    font-size: 14px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* Config Panel */
.config-panel {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.config-header {
    padding: 0.75rem 1rem;
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.config-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.config-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

/* Config Cards */
.config-card {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.config-card:hover {
    border-color: var(--accent-primary);
}

.config-card h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* Checkbox Labels */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: var(--transition);
}

.checkbox-label:hover {
    color: var(--text-primary);
}

.checkbox-label:last-child {
    margin-bottom: 0;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* Input Groups */
.input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.input-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.input-group input[type="number"] {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    max-width: 80px;
}

.input-group input[type="text"] {
    flex: 1;
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.input-group-stacked {
    flex-direction: column;
    align-items: stretch;
}

.input-group-stacked label {
    margin-bottom: 0.25rem;
}

.input-group input[type="number"]:focus,
.input-group input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Select */
.config-card select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

.config-card select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.config-copy-btn {
    width: 100%;
    justify-content: center;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    padding: 0.35rem 0.5rem;
}

.config-json-import {
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
}

.config-json-import summary {
    color: var(--accent-primary);
    cursor: pointer;
    font-size: 0.8rem;
    user-select: none;
}

.config-json-import textarea {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.75rem;
    resize: vertical;
}

.config-json-import textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.output-search {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.output-search input {
    width: 140px;
    padding: 0.42rem 0.55rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.8rem;
}

.output-search input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

#outputSearchStatus {
    min-width: 42px;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.cm-output-search-match {
    background: rgba(255, 211, 105, 0.28);
}

.cm-output-search-active {
    background: rgba(34, 197, 94, 0.45);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 217, 255, 0.4);
}

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

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

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

.btn-success:hover {
    background-color: #00e676;
    box-shadow: 0 4px 12px rgba(0, 200, 83, 0.4);
}

.btn-mini {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-large {
    width: 100%;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    justify-content: center;
}

.btn-icon {
    font-size: 1.1rem;
}

.action-buttons {
    margin-top: 0.5rem;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.75rem 2rem;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    color: var(--accent-primary);
    font-weight: 600;
}

.status-ready {
    color: var(--accent-success);
}

.status-processing {
    color: var(--accent-warning);
}

.status-error {
    color: var(--accent-danger);
}

.status-success {
    color: var(--accent-success);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    gap: 1rem;
}

.loading-overlay p {
    color: var(--text-primary);
    font-size: 1rem;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75rem 1.5rem;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 1001;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--accent-success);
}

.toast.error {
    border-left: 4px solid var(--accent-danger);
}

.toast.warning {
    border-left: 4px solid var(--accent-warning);
}

/* Hidden Class */
.hidden {
    display: none !important;
}

/* Console Section */
.size-hints-section {
    border-top: 1px solid var(--border-color);
    background-color: rgba(255, 255, 255, 0.02);
    padding: 0.75rem 1rem;
}

.size-hints-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.size-hints-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-warning);
}

.size-hints-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.size-hints-primary {
    margin-bottom: 0.45rem;
}

.size-hints-details[hidden] {
    display: none;
}

.size-hints-toggle {
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    color: var(--accent-primary);
    font-size: 0.78rem;
    user-select: none;
}

.size-hints-toggle::-webkit-details-marker {
    display: none;
}

.size-hints-toggle::before {
    content: '▸';
    font-size: 0.72rem;
    transition: transform 0.2s ease;
}

.size-hints-details[open] .size-hints-toggle::before {
    transform: rotate(90deg);
}

.size-hints-toggle-count {
    color: var(--text-muted);
    font-size: 0.74rem;
}

.size-hints-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.45rem;
}

.size-hint-item {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.size-hint-item.high {
    border-color: rgba(255, 171, 0, 0.35);
}

.size-hint-item.medium {
    border-color: rgba(0, 217, 255, 0.25);
}

.size-hint-badge {
    flex-shrink: 0;
    min-width: 52px;
    text-align: center;
    padding: 0.1rem 0.35rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
}

.size-hint-item.high .size-hint-badge {
    background-color: rgba(255, 171, 0, 0.85);
}

.size-hint-item.medium .size-hint-badge {
    background-color: rgba(0, 217, 255, 0.75);
}

.size-hint-empty {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 0.1rem 0;
}

.console-section {
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-card);
    max-height: 200px;
    display: flex;
    flex-direction: column;
}

.console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.console-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-warning);
}

.console-output {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
}

.console-line {
    margin-bottom: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
}

.console-line.log {
    color: var(--text-primary);
}

.console-line.error {
    color: var(--accent-danger);
    background-color: rgba(255, 82, 82, 0.1);
}

.console-line.warn {
    color: var(--accent-warning);
    background-color: rgba(255, 171, 0, 0.1);
}

.console-line.info {
    color: var(--accent-primary);
}

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

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

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

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

/* Responsive Design */
@media (max-width: 1200px) {
    .main-container {
        flex-direction: column;
    }

    .config-panel {
        width: 100%;
        max-height: 300px;
    }

    .config-content {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .config-card {
        flex: 1;
        min-width: 200px;
        margin-bottom: 0;
    }

    .editor-panel {
        min-height: 300px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0.75rem 1rem;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .main-container {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .panel-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }

    .panel-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .stats-bar {
        flex-direction: column;
        padding: 1rem;
    }

    .stat-item {
        width: 100%;
        justify-content: space-between;
    }
}
