/* CSS Variables - Clean Dark Theme */
:root {
    /* Deep dark backgrounds */
    --bg-primary: #09090b;
    --bg-secondary: #111113;
    --bg-tertiary: #1a1a1d;
    --bg-hover: #252529;
    --bg-active: #303036;

    /* Text hierarchy */
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;

    /* Clean modern blue accent */
    --accent: #2563eb;
    --accent-secondary: #3b82f6;
    --accent-hover: #1d4ed8;
    --accent-glow: rgba(37, 99, 235, 0.25);

    /* Status colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Borders */
    --border: rgba(255, 255, 255, 0.1);
    --border-light: rgba(255, 255, 255, 0.15);

    /* Radiuses */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition: 0.2s ease;
    --transition-slow: 0.3s ease;

    --sidebar-width: 240px;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f4f4f5;
    --bg-hover: #e4e4e7;
    --bg-active: #d4d4d8;

    --text-primary: #18181b;
    --text-secondary: #52525b;
    --text-muted: #a1a1aa;

    --border: rgba(0, 0, 0, 0.1);
    --border-light: rgba(0, 0, 0, 0.06);
}

/* Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: inherit;
}



html {
    font-size: 16px;
}

body {
    font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Layout */
.app {
    display: flex;
    height: 100vh;
    background: var(--bg-primary);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    margin-bottom: 24px;
}

.logo svg {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.logo span {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.nav-items {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    position: relative;
    z-index: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent);
    color: white;
}

.nav-item svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.nav-bottom {
    list-style: none;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 12px;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    background: var(--bg-primary);
}


/* Pages */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-header {
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.page-header p {
    color: var(--text-secondary);
    font-size: 1.05rem;
}

/* Generate Page */
.generate-container {
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 40px;
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.input-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    letter-spacing: -0.01em;
}

.cost-estimate {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--accent-secondary);
    background: rgba(37, 99, 235, 0.15);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-accent);
}

textarea {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    min-height: 120px;
    transition: all var(--transition);
    direction: auto;
}

textarea:hover {
    border-color: var(--border-light);
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow-md);
    background: var(--bg-tertiary);
}

textarea::placeholder {
    color: var(--text-muted);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-muted);
}

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

.upload-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.upload-zone svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

.upload-zone p {
    font-size: 0.9rem;
}

.upload-link {
    color: var(--accent);
    cursor: pointer;
}

.uploaded-preview {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.uploaded-preview img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius-md);
}

.remove-image {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition);
}

.remove-image:hover {
    transform: scale(1.1);
}

/* Style Selector */
.style-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.style-option {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.style-option:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.style-option.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Style Mode Toggle */
.style-mode-toggle {
    display: inline-flex;
    gap: 4px;
    margin-right: auto;
    background: var(--bg-tertiary);
    padding: 3px;
    border-radius: var(--radius-sm);
}

.mode-btn {
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.mode-btn:hover {
    color: var(--text-primary);
}

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

/* Multi-Style Panel */
.multi-style-panel {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-top: 8px;
}

.multi-style-panel[hidden] {
    display: none;
}

.style-distribution {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.style-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.style-row:has(.counter-value:not(:empty)) {
    border-color: var(--accent);
}

.style-row.has-count {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.1);
}

.style-name {
    font-size: 0.85rem;
    color: var(--text-primary);
}

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

.counter-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

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

.counter-btn.minus:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.counter-value {
    min-width: 24px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.multi-style-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Slider */
.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.btn-generate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-generate:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-generate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    padding: 12px 24px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    padding: 12px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

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

.btn-danger {
    padding: 12px 24px;
    background: transparent;
    border: 1px solid var(--danger);
    border-radius: var(--radius-md);
    color: var(--danger);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

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

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

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

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

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

/* Results Section */
.results-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.results-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

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

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

.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.3;
}

/* Result Card */
.result-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    transition: all var(--transition);
    cursor: pointer;
}

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

.result-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.result-card-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    opacity: 0;
    transition: opacity var(--transition);
}

.result-card:hover .result-card-actions {
    opacity: 1;
}

.result-card-actions button {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.result-card-actions button:hover {
    background: var(--accent);
}

.result-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

/* Style badge for compare mode */
.result-style-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-full);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: capitalize;
    z-index: 2;
}

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

.loading-state[hidden] {
    display: none;
}

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

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

.progress-bar {
    width: 200px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 12px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s ease;
}

/* Thumbnail Styles Page */
.thumb-styles-container {
    max-width: 1200px;
}

.thumb-styles-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.thumb-style-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.thumb-style-images {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.thumb-style-image {
    flex: 1;
    position: relative;
}

.thumb-style-image img {
    width: 100%;
    border-radius: var(--radius-md);
    aspect-ratio: 16/9;
    object-fit: cover;
}

.thumb-style-label {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

.thumb-style-analysis {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    max-height: 300px;
    overflow-y: auto;
}

.thumb-style-analysis pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0;
}

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

.thumb-style-actions button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.thumb-style-actions .btn-copy {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: white;
}

.thumb-style-actions .btn-copy:hover {
    opacity: 0.9;
}

.thumb-style-actions .btn-delete {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.thumb-style-actions .btn-delete:hover {
    border-color: #ef4444;
    color: #ef4444;
}

/* Templates Page */
.templates-container {
    max-width: 1200px;
}

.templates-categories {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.category {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.category:hover {
    background: var(--bg-hover);
}

.category.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.template-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
}

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

.template-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.template-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.template-card code {
    display: block;
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: pre-wrap;
    direction: ltr;
}

/* Library Page */
.library-container {
    max-width: 1400px;
}

.library-toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    align-items: center;
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    flex: 1;
    max-width: 300px;
}

.search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.library-filters select {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

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

.library-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    transition: all var(--transition);
    cursor: pointer;
}

.library-card:hover {
    border-color: var(--accent);
    transform: translateY(-4px);
}

.library-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.library-card-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: 2px solid white;
    cursor: pointer;
    transition: all var(--transition);
}

.library-card-checkbox.checked {
    background: var(--accent);
    border-color: var(--accent);
}

.library-card-checkbox.checked::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 7px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.library-card-favorite {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.library-card-favorite:hover,
.library-card-favorite.active {
    color: var(--warning);
}

.library-card-analyze {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    opacity: 0;
}

.library-card:hover .library-card-analyze {
    opacity: 1;
}

.library-card-analyze:hover {
    color: var(--accent);
    background: rgba(0, 0, 0, 0.7);
}

/* Editor Page */
.editor-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
}

.editor-toolbar {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.tool-group {
    display: flex;
    gap: 4px;
    align-items: center;
}

.tool-group+.tool-group {
    padding-right: 16px;
    border-right: 1px solid var(--border);
}

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

.tool:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tool.active {
    background: var(--accent);
    color: white;
}

#brush-color {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: none;
}

#brush-size {
    width: 100px;
}

.editor-canvas-container {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
}

.canvas-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
}

#editor-canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    background: var(--bg-tertiary);
}

.canvas-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.canvas-placeholder svg {
    margin-bottom: 16px;
    opacity: 0.3;
}

.canvas-placeholder p {
    margin-bottom: 16px;
}

.editor-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* Settings Page */
.settings-container {
    max-width: 600px;
}

.settings-group {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
}

.settings-group h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.setting-item {
    margin-bottom: 16px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.setting-item input[type="password"],
.setting-item input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.setting-item input:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-item select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.setting-item small {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.api-key-input {
    display: flex;
    gap: 8px;
}

.api-key-input input {
    flex: 1;
}

.storage-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.storage-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.storage-fill {
    height: 100%;
    background: var(--accent);
    transition: width var(--transition);
}

/* API Setup Info Boxes */
.api-free-credit-box,
.api-cost-box {
    margin-top: 14px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.api-free-credit-box {
    border-color: #4ade80;
    background: rgba(74, 222, 128, 0.08);
}

.api-free-credit-box strong,
.api-cost-box strong {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.api-free-credit-box p,
.api-cost-box p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.api-free-credit-box a {
    color: #4ade80;
    text-decoration: none;
    font-weight: 600;
}

.api-free-credit-box a:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

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

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

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

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

.export-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.export-option label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.export-option select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.export-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}

.export-preview img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1001;
}

.toast {
    padding: 14px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInLeft 0.3s ease;
    min-width: 280px;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

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

.toast.warning {
    border-color: var(--warning);
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

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

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

.toast.warning .toast-icon {
    color: var(--warning);
}

.toast-message {
    flex: 1;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .generate-container {
        grid-template-columns: 1fr;
    }

    .input-section {
        max-width: 500px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        right: -100%;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: right var(--transition);
    }

    .sidebar.open {
        right: 0;
    }

    .main-content {
        padding: 20px;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }
}

/* Image Preview Modal */
.image-preview-modal {
    z-index: 1002;
}

.image-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
}

.image-preview-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 60px;
}

.image-preview-content img {
    max-width: 100%;
    max-height: calc(100% - 80px);
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.image-preview-actions {
    position: absolute;
    bottom: 40px;
    display: flex;
    gap: 12px;
    z-index: 10;
}

.image-preview-actions button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
}

.image-preview-actions button:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.image-preview-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    z-index: 10;
}

.image-preview-close:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* Image Preview Navigation */
.image-preview-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    z-index: 10;
}

.image-preview-nav:hover {
    background: var(--accent);
    border-color: var(--accent);
    transform: translateY(-50%) scale(1.1);
}

.image-preview-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.image-preview-nav:disabled:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%);
}

.image-preview-nav.prev {
    left: 24px;
}

.image-preview-nav.next {
    right: 24px;
}

.image-preview-counter {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 10;
}

/* ============================================
   BOOK VISUALIZER STYLES
   ============================================ */

.visualizer-container {
    display: grid;
    grid-template-columns: 1fr 320px 1fr;
    gap: 24px;
    min-height: calc(100vh - 200px);
    align-items: start;
}

/* Left Panel - Input */
.visualizer-input {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.visualizer-input textarea {
    min-height: 200px;
    font-size: 0.95rem;
    line-height: 1.7;
}

.visualizer-input input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: all var(--transition);
}

.visualizer-input input[type="text"]:hover {
    border-color: var(--border-light);
}

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

.visualizer-input input[type="text"]::placeholder {
    color: var(--text-muted);
}

.label-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 8px;
}

/* Compact upload zone */
.upload-zone.compact {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-direction: row;
}

.upload-zone.compact svg {
    margin-bottom: 0;
    flex-shrink: 0;
}

.upload-zone.compact span {
    font-size: 0.85rem;
}

/* Middle Panel - Presets */
.visualizer-presets {
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    height: fit-content;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    overflow-x: hidden;
    position: sticky;
    top: 20px;
    width: 320px;
    flex-shrink: 0;
}

.preset-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.preset-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preset-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.preset-btn {
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.preset-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.preset-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Style options - more room for many styles */
.preset-options.style-options {
    gap: 6px;
}

.preset-options.style-options .preset-btn {
    flex: 0 0 auto;
}

/* Style Mode Toggle */
.style-mode-toggle {
    display: inline-flex;
    gap: 2px;
    background: var(--bg-tertiary);
    padding: 2px;
    border-radius: var(--radius-sm);
    margin-left: auto;
}

.style-mode-toggle .mode-btn {
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition);
}

.style-mode-toggle .mode-btn:hover {
    color: var(--text-primary);
}

.style-mode-toggle .mode-btn.active {
    background: var(--accent);
    color: white;
}

/* Style Compare Panel */
.style-compare-panel {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-top: 8px;
}

.style-compare-panel[hidden] {
    display: none;
}

/* Ensure hidden attribute works on all elements */
[hidden] {
    display: none !important;
}

.compare-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.style-compare-grid {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.style-compare-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.style-compare-row.has-count {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.1);
}

.style-compare-name {
    font-size: 0.75rem;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
}

.style-counter {
    display: flex;
    align-items: center;
    gap: 6px;
}

.counter-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    line-height: 1;
}

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

.counter-btn.minus:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.counter-value {
    min-width: 20px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.style-compare-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Visualizer Generate Button - Sticky at bottom */
.visualizer-presets .btn-generate {
    margin-top: 12px;
    width: 100%;
    position: sticky;
    bottom: -20px;
    z-index: 5;
    margin-bottom: -20px;
    padding-top: 16px;
    padding-bottom: 16px;
    border-radius: var(--radius-md);
}

/* ===== API Key Missing Modal ===== */
.api-key-modal-content {
    text-align: center;
    padding: 40px 32px 32px;
    max-width: 480px;
}

.api-key-modal-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(37, 99, 235, 0.1);
    border: 2px solid rgba(37, 99, 235, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    color: var(--accent);
    animation: keyPulse 2s ease-in-out infinite;
}

@keyframes keyPulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.2);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 12px rgba(37, 99, 235, 0);
    }
}

.api-key-modal-content h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.api-key-modal-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 28px;
}

.api-key-modal-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 28px;
    text-align: right;
}

.api-key-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.api-key-step:hover {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.05);
}

.step-number {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    margin-top: 2px;
}

.step-content {
    flex: 1;
}

.step-content strong {
    font-size: 0.9rem;
    color: var(--text-primary);
    display: block;
    margin-bottom: 4px;
}

.step-content p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.step-content a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.step-content a:hover {
    text-decoration: underline;
}

.api-key-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.api-key-modal-actions .btn-primary,
.api-key-modal-actions .btn-secondary {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.api-key-step.highlight-step {
    border-color: #4ade80;
    background: rgba(74, 222, 128, 0.08);
}

.api-key-step.highlight-step .step-number {
    background: #4ade80;
    color: #052e16;
    font-size: 1rem;
}

.api-key-cost-info {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    text-align: right;
    margin-bottom: 24px;
}

.api-key-cost-info strong {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.api-key-cost-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.api-key-external-link {
    text-decoration: none;
    background: var(--accent);
    color: white;
}

.api-key-external-link:hover {
    background: var(--accent-hover);
}

/* Right Panel - Results */
.visualizer-results {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.visualizer-results .results-header {
    margin-bottom: 16px;
}

.visualizer-results .results-grid {
    flex: 1;
    min-height: 300px;
}

.visualizer-results .empty-state {
    padding: 40px 20px;
}

.empty-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
    opacity: 0.7;
}

/* Responsive for Visualizer */
@media (max-width: 1200px) {
    .visualizer-container {
        grid-template-columns: 1fr 300px;
        grid-template-rows: auto auto;
    }

    .visualizer-input {
        grid-column: 1;
        grid-row: 1;
    }

    .visualizer-presets {
        grid-column: 2;
        grid-row: 1 / 3;
    }

    .visualizer-results {
        grid-column: 1;
        grid-row: 2;
    }
}

@media (max-width: 900px) {
    .visualizer-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .visualizer-input {
        grid-column: 1;
        grid-row: 1;
    }

    .visualizer-presets {
        grid-column: 1;
        grid-row: 2;
        position: static;
    }

    .visualizer-results {
        grid-column: 1;
        grid-row: 3;
    }

    .preset-options {
        justify-content: flex-start;
    }
}

/* ==================== Story Page ==================== */
.story-container {
    display: grid;
    grid-template-columns: 1fr 320px 1.2fr;
    gap: 24px;
    height: calc(100vh - 140px);
}

.story-input {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    padding-right: 8px;
}

.story-input textarea {
    min-height: 200px;
    resize: vertical;
}

.story-presets {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    padding-right: 8px;
    position: sticky;
    top: 0;
    max-height: calc(100vh - 140px);
}

.story-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

/* Story Number Pickers */
.story-numbers {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border);
}

.story-number-inputs {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 12px;
}

.story-number-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.story-number-group>label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.number-picker {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.number-picker input {
    width: 60px;
    text-align: center;
    border: none;
    background: transparent;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    padding: 8px 0;
    -moz-appearance: textfield;
}

.number-picker input::-webkit-outer-spin-button,
.number-picker input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.number-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.number-btn:hover {
    background: var(--primary);
    color: white;
}

.number-hint {
    font-size: 11px;
    color: var(--text-muted);
}

.story-total-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    color: var(--text);
}

.story-total-info strong {
    color: var(--primary);
    font-size: 18px;
}

/* Story Results Container */
.story-results-container {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
}

/* Story Batch Group */
.story-batch-group {
    margin-bottom: 24px;
}

.story-batch-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.story-batch-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.story-batch-badge {
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Story Image Grid (horizontal scroll for story sequence) */
.story-image-grid {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 12px;
    scroll-snap-type: x mandatory;
}

.story-image-card {
    position: relative;
    flex: 0 0 auto;
    width: 200px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    scroll-snap-align: start;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.story-image-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.story-image-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.story-image-number {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--primary);
    color: white;
    font-size: 12px;
    font-weight: 700;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.story-image-card-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 4px;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    opacity: 0;
    transition: opacity 0.2s ease;
}

.story-image-card:hover .story-image-card-actions {
    opacity: 1;
}

.story-image-card-actions button {
    flex: 1;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.story-image-card-actions button:hover {
    background: var(--primary);
}

/* Story Part Info Tooltip */
.story-part-info {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text);
    max-width: 250px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 10;
    white-space: pre-wrap;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    margin-bottom: 8px;
}

.story-image-card:hover .story-part-info {
    opacity: 1;
    visibility: visible;
}

/* Responsive Story Page */
@media (max-width: 1200px) {
    .story-container {
        grid-template-columns: 1fr 280px;
        grid-template-rows: auto auto;
    }

    .story-input {
        grid-column: 1;
        grid-row: 1;
    }

    .story-presets {
        grid-column: 2;
        grid-row: 1 / 3;
    }

    .story-results {
        grid-column: 1;
        grid-row: 2;
    }
}

@media (max-width: 900px) {
    .story-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .story-input {
        grid-column: 1;
        grid-row: 1;
    }

    .story-presets {
        grid-column: 1;
        grid-row: 2;
        position: static;
    }

    .story-results {
        grid-column: 1;
        grid-row: 3;
    }

    .story-image-card {
        width: 160px;
    }
}

/* ==================== Thumbnail Lab Page ==================== */
.thumblab-container {
    display: grid;
    grid-template-columns: 1fr 360px 1.2fr;
    gap: 24px;
    min-height: calc(100vh - 200px);
    align-items: start;
}

/* Left Panel - Uploads */
.thumblab-upload {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.thumblab-upload .upload-zone {
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.thumblab-upload .uploaded-preview {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    max-height: 280px;
}

.thumblab-upload .uploaded-preview img {
    width: 100%;
    height: auto;
    max-height: 280px;
    object-fit: contain;
    border-radius: var(--radius-md);
}

/* Face Photos Grid */
.face-photos-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.face-slot {
    position: relative;
}

.face-upload {
    min-height: 80px !important;
    padding: 8px !important;
    font-size: 0.8rem;
}

.face-upload svg {
    opacity: 0.6;
}

.face-upload span {
    font-size: 0.75rem;
}

.face-preview {
    max-height: 80px !important;
}

.face-preview img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.face-remove {
    width: 20px !important;
    height: 20px !important;
    padding: 2px !important;
}

.thumblab-upload textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    width: 100%;
}

.thumblab-upload textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.thumblab-upload textarea::placeholder {
    color: var(--text-muted);
}

/* Middle Panel - Presets */
.thumblab-presets {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: sticky;
    top: 0;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

/* Container for batch config boxes */
.thumblab-batch-configs {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Individual batch config box */
.thumblab-batch-config {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.thumblab-batch-config.batch-generating {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-glow);
}

.thumblab-batch-config.batch-done {
    border-color: #22c55e44;
}

.thumblab-batch-config.batch-error {
    border-color: #ef444444;
}

/* Batch config header */
.batch-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.batch-config-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent);
}

.btn-batch-config-delete {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all var(--transition-fast);
}

.btn-batch-config-delete:hover {
    color: #ef4444;
    border-color: #ef4444;
}

.thumblab-presets .input-group {
    margin-top: 4px;
}

.thumblab-presets textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
    width: 100%;
}

.thumblab-presets textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.thumblab-presets textarea::placeholder {
    color: var(--text-muted);
}

/* Preset Category Tabs */
.thumblab-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 4px;
}

.thumblab-tab {
    flex: 1;
    padding: 8px 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.thumblab-tab:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.thumblab-tab.active {
    background: var(--accent);
    color: white;
}

/* Tab Panels */
.thumblab-tab-panel {
    display: none;
    flex-direction: column;
    gap: 10px;
}

.thumblab-tab-panel.active {
    display: flex;
}

.thumblab-tab-panel .preset-group {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
}

.thumblab-tab-panel .preset-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* Preset sublabels */
.preset-sublabel {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    margin-bottom: 4px;
    display: block;
}

/* Slider labels */
.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 2px;
}

/* Toggle Row */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.toggle-row+.toggle-row {
    padding-top: 0;
}

.toggle-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Toggle Switch (iOS-style) */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 24px;
    transition: all var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-switch input:checked+.toggle-slider::before {
    background: white;
    transform: translateX(20px);
}

/* Tab change controls (shown when toggle is OFF) */
.tab-change-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tab-change-controls textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
    width: 100%;
}

.tab-change-controls textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.tab-change-controls textarea::placeholder {
    color: var(--text-muted);
}

/* Bottom controls area */
.thumblab-bottom-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.btn-full-width {
    width: 100%;
    justify-content: center;
}

/* Right Panel - Results */
.thumblab-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 400px;
}

/* Batches container */
.thumblab-batches-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Individual batch */
.thumblab-batch {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.thumblab-batch.batch-error {
    border-color: #ef4444;
}

/* Batch header */
.batch-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.batch-header h3 {
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    margin: 0;
}

.batch-summary {
    font-size: 0.8rem;
    color: var(--text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.batch-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.batch-actions button {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.batch-actions button:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
    background: var(--bg-hover);
}

.batch-actions .btn-batch-delete:hover {
    color: #ef4444;
    border-color: #ef4444;
}

/* Results grid inside batch */
.thumblab-batch .results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    padding: 16px;
}

.thumblab-batch .results-grid .result-card img {
    aspect-ratio: 16/9;
    object-fit: cover;
}

/* Add New Batch button */
.btn-add-batch {
    width: 100%;
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-add-batch:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(37, 99, 235, 0.05);
}

.thumblab-results .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border);
}

.thumblab-results .empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.thumblab-results .empty-state p {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.thumblab-results .empty-hint,
.thumblab-style-guides .empty-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Style Guides Section */
.thumblab-style-guides {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.thumblab-style-guides h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.thumblab-style-guides-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.style-guide-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast);
}

.style-guide-card:hover {
    border-color: var(--accent);
}

.style-guide-card .guide-preview {
    width: 80px;
    height: 45px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.style-guide-card .guide-info {
    flex: 1;
    min-width: 0;
}

.style-guide-card .guide-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.style-guide-card .guide-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.style-guide-card .guide-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.style-guide-card .guide-actions button {
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.style-guide-card .guide-actions button:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.style-guide-card .guide-actions .btn-delete-guide:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* Char count */
.char-count {
    display: block;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Input description */
.input-description {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Thumb Lab responsive */
@media (max-width: 1200px) {
    .thumblab-container {
        grid-template-columns: 1fr 340px;
        grid-template-rows: auto auto;
    }

    .thumblab-upload {
        grid-column: 1;
        grid-row: 1;
    }

    .thumblab-presets {
        grid-column: 2;
        grid-row: 1 / 3;
    }

    .thumblab-results {
        grid-column: 1;
        grid-row: 2;
    }
}

@media (max-width: 900px) {
    .thumblab-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .thumblab-upload {
        grid-column: 1;
        grid-row: 1;
    }

    .thumblab-presets {
        grid-column: 1;
        grid-row: 2;
        position: static;
    }

    .thumblab-results {
        grid-column: 1;
        grid-row: 3;
    }
}

/* ==================== Generates Page (Simple Generator) ==================== */
.generates-container {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 32px;
    min-height: calc(100vh - 200px);
    align-items: start;
}

.generates-input {
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.generates-input textarea {
    min-height: 150px;
    font-size: 1rem;
    line-height: 1.6;
}

.generates-input .btn-generate {
    margin-top: 8px;
}

.generates-results {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.generates-results .results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    min-height: 300px;
}

.generates-results .empty-state {
    grid-column: 1 / -1;
}

/* Responsive for Generates Page */
@media (max-width: 900px) {
    .generates-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
    }

    .generates-input {
        grid-column: 1;
        grid-row: 1;
    }

    .generates-results {
        grid-column: 1;
        grid-row: 2;
    }
}

/* ==================== Editing Page (Image Edit with Prompt) ==================== */
.editing-container {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 32px;
    min-height: calc(100vh - 200px);
    align-items: start;
}

.editing-input {
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.editing-input textarea {
    min-height: 120px;
    font-size: 1rem;
    line-height: 1.6;
}

.editing-input .btn-generate {
    margin-top: 8px;
}

.reference-image-group .optional-tag {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 400;
    margin-left: 6px;
}

.reference-upload-zone {
    padding: 16px !important;
    min-height: auto !important;
    gap: 8px !important;
}

.reference-upload-zone svg {
    opacity: 0.5;
}

.reference-preview img {
    max-height: 120px;
    object-fit: contain;
}

.editing-results {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.editing-results .results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    min-height: 300px;
}

.editing-results .empty-state {
    grid-column: 1 / -1;
}

/* Responsive for Editing Page */
@media (max-width: 900px) {
    .editing-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
    }

    .editing-input {
        grid-column: 1;
        grid-row: 1;
    }

    .editing-results {
        grid-column: 1;
        grid-row: 2;
    }
}