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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #1a1d23;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex: 1;
    gap: 0;
    overflow: hidden;
}

.left-panel {
    width: 40%;
    background: #2d3748;
    padding: 16px 12px 12px;
    overflow: hidden;
    border-right: 1px solid #4a5568;
    display: flex;
    flex-direction: column;
}

.right-panel {
    width: 60%;
    background: #1a1d23;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.section {
    margin-bottom: 8px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.section h3 {
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    color: #e2e8f0;
    margin-bottom: 8px;
    padding: 10px 0;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    text-align: center;
    background: #374151;
    border-radius: 4px;
}

.filter-buttons {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.filter-btn, .mode-btn, .action-btn {
    padding: 8px 12px;
    font-size: 12px;
    border: 1px solid #4a5568;
    background: #2d3748;
    color: #e2e8f0;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.filter-btn:hover, .mode-btn:hover, .action-btn:hover {
    background: #4a5568;
    border-color: #5a7a8f;
}

.filter-btn.active, .mode-btn.active {
    background: #0ea5e9;
    border-color: #0284c7;
    color: #fff;
}

.search-box {
    width: 100%;
    padding: 6px 10px;
    background: #1a1d23;
    border: 1px solid #4a5568;
    color: #e2e8f0;
    border-radius: 4px;
    font-size: 12px;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.search-box::placeholder {
    color: #718096;
}

.grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 0;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.card {
    padding: 10px 12px;
    background: #1a1d23;
    border: 1px solid #4a5568;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: #e2e8f0;
    text-align: left;
    transition: all 0.15s;
    overflow: visible;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.8;
    min-height: 38px;
    flex-shrink: 0;
}

.card:hover {
    border-color: #5a7a8f;
    background: #2d3748;
}

.card.selected {
    background: #0ea5e9;
    border-color: #0284c7;
    color: #fff;
}

.card.has-image {
    border-left: 3px solid #10b981;
}

.char-card {
    font-size: 15px;
    line-height: 1.6;
    display: flex;
    gap: 8px;
    align-items: center;
}

.char-id { font-weight: 600; }
.char-info { color: #cbd5e0; font-size: 13px; }

.scene-card {
    text-align: left;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 15px;
}

.scene-name { font-weight: 600; font-size: 15px; }
.scene-type { font-size: 13px; color: #cbd5e0; }

.scene-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.mode-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    font-weight: 600;
}

.action-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1;
    min-width: 100px;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    background: #0ea5e9;
    border-color: #0284c7;
    color: #fff;
}

.action-btn:hover { background: #0284c7; }

.action-btn:disabled {
    background: #4a5568;
    border-color: #4a5568;
    color: #a0aec0;
    cursor: not-allowed;
}

/* Quick Settings Bar */
.quick-settings {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px;
    background: #2d3748;
    border-radius: 4px;
    border: 1px solid #4a5568;
}

.qs-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.qs-group label {
    font-size: 11px;
    color: #a0aec0;
    white-space: nowrap;
}

.qs-group input[type="number"] {
    width: 70px;
    padding: 4px 6px;
    background: #1a1d23;
    border: 1px solid #4a5568;
    color: #e2e8f0;
    border-radius: 3px;
    font-size: 12px;
}

.qs-group input[type="range"] { width: 80px; }

.qs-group span:not([class]) {
    font-size: 12px;
    color: #e2e8f0;
    min-width: 16px;
}

.qs-x {
    font-size: 11px;
    color: #718096;
}

/* Progress */
.progress-bar {
    height: 4px;
    background: #4a5568;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
    display: none;
}

.progress-bar.active { display: block; }

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #0ea5e9, #10b981);
    width: 0%;
    transition: width 0.2s;
}

.progress-label {
    font-size: 11px;
    color: #a0aec0;
    margin-bottom: 8px;
    height: 16px;
}

.progress-stats {
    font-size: 11px;
    color: #a0aec0;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #4a5568;
    margin-bottom: 12px;
}

.tab-btn {
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    background: transparent;
    border: none;
    color: #a0aec0;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn.active {
    color: #0ea5e9;
    border-bottom-color: #0ea5e9;
}

.tab-btn:hover { color: #cbd5e0; }

.tabs-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.panel {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.panel.active {
    display: flex;
    flex-direction: column;
}

/* Prompt Cards */
.prompt-card {
    background: #2d3748;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 12px;
    border: 1px solid #4a5568;
}

.prompt-card h4 {
    font-size: 12px;
    font-weight: 600;
    color: #0ea5e9;
    margin-bottom: 8px;
}

.prompt-card textarea {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    background: #1a1d23;
    border: 1px solid #4a5568;
    color: #e2e8f0;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    line-height: 1.5;
    resize: vertical;
}

.prompt-card textarea:focus {
    outline: none;
    border-color: #0ea5e9;
}

/* Gallery */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    height: 100%;
    overflow-y: auto;
}

.gallery-item {
    background: #2d3748;
    border: 1px solid #4a5568;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}

.gallery-item:hover {
    border-color: #0ea5e9;
    transform: translateY(-2px);
}

.gallery-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    background: #1a1d23;
}

.gallery-label {
    padding: 8px;
    font-size: 10px;
    color: #a0aec0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-top: 1px solid #4a5568;
}

/* History */
.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.history-item {
    background: #2d3748;
    border: 1px solid #4a5568;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.history-item:hover {
    border-color: #0ea5e9;
    transform: translateY(-2px);
}

.history-checkbox {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    z-index: 10;
}

.history-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    background: #1a1d23;
}

.history-label {
    padding: 6px;
    font-size: 9px;
    color: #a0aec0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-top: 1px solid #4a5568;
}

.history-timestamp {
    font-size: 8px;
    color: #718096;
    padding: 2px 6px 6px 6px;
}

.history-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.history-toolbar button {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #4a5568;
    background: #2d3748;
    color: #e2e8f0;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.history-toolbar button:hover:not(:disabled) {
    background: #4a5568;
    border-color: #5a7a8f;
}

.history-toolbar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.save-btn {
    background: #10b981 !important;
    border-color: #059669 !important;
    color: #fff !important;
}
.save-btn:hover { background: #059669 !important; }

.delete-btn {
    background: #ef4444 !important;
    border-color: #dc2626 !important;
    color: #fff !important;
}
.delete-btn:hover { background: #dc2626 !important; }

/* Image Reference */
.image-ref-section {
    background: #2d3748;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 12px;
    border: 1px solid #4a5568;
}

.image-ref-section h4 {
    font-size: 12px;
    font-weight: 600;
    color: #10b981;
    margin-bottom: 8px;
}

.image-ref-info {
    font-size: 11px;
    color: #cbd5e0;
    margin-bottom: 8px;
    padding: 8px;
    background: #1a1d23;
    border-radius: 3px;
    border: 1px solid #4a5568;
}

.image-ref-upload {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.image-ref-upload input[type="file"] { display: none; }

.image-ref-upload button {
    flex: 1;
    padding: 8px 12px;
    font-size: 12px;
    background: #10b981;
    border: 1px solid #059669;
    color: #fff;
    cursor: pointer;
    border-radius: 3px;
    font-weight: 600;
}

.image-ref-upload button:hover { background: #059669; }

.image-ref-preview {
    width: 100%;
    height: 120px;
    background: #1a1d23;
    border: 1px solid #4a5568;
    border-radius: 3px;
    object-fit: contain;
    margin-bottom: 8px;
}

.image-ref-preview.hidden { display: none; }

/* Fullscreen Viewer */
.fullscreen-viewer {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.fullscreen-viewer.active { display: flex; }

.fullscreen-viewer img {
    max-width: 90%;
    max-height: 85%;
    object-fit: contain;
}

.fullscreen-close {
    position: absolute;
    top: 20px; right: 20px;
    width: 40px; height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    border-radius: 4px;
    z-index: 10001;
}

.fullscreen-close:hover { background: rgba(255, 255, 255, 0.2); }

.fullscreen-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 40px; height: 40px;
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
    z-index: 10001;
}

.fullscreen-nav:hover { background: rgba(255, 255, 255, 0.2); }
.fullscreen-nav.prev { left: 20px; }
.fullscreen-nav.next { right: 20px; }

.fullscreen-info {
    position: absolute;
    bottom: 20px;
    color: #fff;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 4px;
}

/* Settings Modal */
.settings-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 5000;
    align-items: center;
    justify-content: center;
}

.settings-modal.active { display: flex; }

.settings-content {
    background: #2d3748;
    padding: 24px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    border: 1px solid #4a5568;
}

.settings-content h2 {
    font-size: 18px;
    margin-bottom: 16px;
}

.settings-field {
    margin-bottom: 16px;
}

.settings-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #a0aec0;
}

.settings-field input, .settings-field select {
    width: 100%;
    padding: 8px 12px;
    background: #1a1d23;
    border: 1px solid #4a5568;
    color: #e2e8f0;
    border-radius: 4px;
    font-size: 13px;
}

.settings-field input:focus, .settings-field select:focus {
    outline: none;
    border-color: #0ea5e9;
}

.strength-slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.strength-slider-container input[type="range"] { flex: 1; }

.strength-value {
    min-width: 40px;
    text-align: right;
    font-size: 12px;
    color: #a0aec0;
}

.settings-buttons {
    display: flex;
    gap: 8px;
}

.settings-buttons button {
    flex: 1;
    padding: 10px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #4a5568;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-buttons button:first-child {
    background: #0ea5e9;
    border-color: #0284c7;
    color: #fff;
}

.settings-buttons button:first-child:hover { background: #0284c7; }

.settings-buttons button:last-child {
    background: #2d3748;
    color: #e2e8f0;
}

.settings-buttons button:last-child:hover { background: #4a5568; }

/* Footer */
.footer {
    padding: 8px 20px;
    background: #0f1116;
    border-top: 1px solid #4a5568;
    font-size: 11px;
    color: #a0aec0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Generic buttons */
.btn {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #4a5568;
    background: #2d3748;
    color: #e2e8f0;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn:hover { background: #4a5568; }
.btn-teal { background: #0ea5e9; border-color: #0284c7; color: #fff; }
.btn-teal:hover { background: #0284c7; }
.btn-green { background: #10b981; border-color: #059669; color: #fff; }
.btn-green:hover { background: #059669; }
.btn-gray { background: #4a5568; border-color: #718096; color: #e2e8f0; }
.btn-gray:hover { background: #718096; }
