/**
 * ThumbGen v4 — Premium Editor UI
 * Dark editor-grade design system — No tabs, scrollable sections
 */

/* ========== Reset & Variables ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

:root {
    --bg-dark: #0c0e14;
    --bg-panel: #13151d;
    --bg-section: #1a1d28;
    --bg-input: #22252f;
    --bg-hover: #2a2d3a;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, .25);
    --accent-2: #ec4899;
    --accent-3: #10b981;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-muted: #64748b;
    --border: #2a2d3a;
    --border-light: #363945;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: .2s ease;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
}

html {
    height: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    line-height: 1.5;
}

/* ========== Top Bar ========== */
.topbar {
    height: 48px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    z-index: 100;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 16px;
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}

.topbar-brand:hover {
    color: var(--accent-hover);
}

.topbar-brand svg {
    opacity: .85;
}

.topbar-brand .brand-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 99px;
    background: var(--accent);
    color: white;
    letter-spacing: .04em;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-actions .btn-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
}

.shortcut-hint {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.shortcut-hint kbd {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 10px;
    font-family: var(--font);
    color: var(--text-dim);
}

/* ========== Main Layout ========== */
.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ========== Sidebar (Left Panel) — No Tabs ========== */
.sidebar {
    width: 370px;
    min-width: 370px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-scroll::-webkit-scrollbar {
    width: 5px;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.sidebar-scroll::-webkit-scrollbar-track {
    background: transparent;
}

/* ========== Sections (details/summary) ========== */
details.section {
    margin-bottom: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-section);
    overflow: hidden;
    transition: border-color var(--transition);
}

details.section:hover {
    border-color: var(--border-light);
}

details.section[open] {
    background: transparent;
    border-color: var(--border-light);
}

details.section > summary {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: all var(--transition);
    position: relative;
}

details.section > summary svg {
    width: 14px;
    height: 14px;
    opacity: .5;
    flex-shrink: 0;
    transition: opacity var(--transition);
}

details.section[open] > summary svg {
    opacity: 1;
    color: var(--accent);
}

details.section > summary::-webkit-details-marker {
    display: none;
}

details.section > summary::before {
    content: '';
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform var(--transition);
    flex-shrink: 0;
    margin-left: auto;
}

details.section[open] > summary::before {
    transform: rotate(45deg);
}

details.section > summary:hover {
    color: var(--text-dim);
    background: var(--bg-hover);
}

details.section > summary:hover svg {
    opacity: .8;
}

details.section[open] > summary {
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
}

details.section[open] > summary::before {
    border-color: var(--accent);
}

details.section > *:not(summary) {
    padding-left: 12px;
    padding-right: 12px;
}

details.section > *:not(summary):first-of-type {
    padding-top: 12px;
}

details.section > *:not(summary):last-child {
    padding-bottom: 12px;
}

/* ========== Form Elements ========== */
.field {
    margin-bottom: 12px;
}

.field-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 5px;
}

.field-label .val {
    font-weight: 500;
    color: var(--accent);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    transition: all var(--transition);
    outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select {
    cursor: pointer;
}

textarea {
    resize: vertical;
    min-height: 40px;
}

/* Range slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    border: 2px solid var(--bg-panel);
    box-shadow: 0 0 6px var(--accent-glow);
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    border: 2px solid var(--bg-panel);
    cursor: pointer;
}

/* Color input */
.color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    background: none;
    overflow: hidden;
    transition: border-color var(--transition);
}

input[type="color"]:hover {
    border-color: var(--accent);
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

/* Checkbox / Toggle */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.toggle-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
}

.toggle {
    position: relative;
    width: 36px;
    height: 20px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}

.toggle input:checked+.toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle input:checked+.toggle-slider::before {
    transform: translateX(16px);
    background: white;
}

/* ========== Style Toggle Buttons ========== */
.style-btns {
    display: flex;
    gap: 4px;
}

.style-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
}

.style-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.style-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:active {
    transform: scale(.97);
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-warning {
    background: transparent;
    color: var(--warning);
    border: 1px solid var(--border);
}

.btn-warning:hover {
    border-color: var(--warning);
    background: rgba(245, 158, 11, .1);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-icon:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-row {
    display: flex;
    gap: 6px;
}

/* ========== Format Presets Grid ========== */
.format-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 12px;
}

.format-card {
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.format-card:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.format-card.active {
    border-color: var(--accent);
    background: rgba(99, 102, 241, .12);
    box-shadow: 0 0 0 1px var(--accent);
}

.format-card .format-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}

.format-card .format-size {
    font-size: 10px;
    color: var(--text-muted);
}

/* Custom size row */
.size-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.size-row input {
    width: 80px;
    text-align: center;
}

.size-row .sep {
    color: var(--text-muted);
    font-weight: 700;
}

/* ========== Template Presets ========== */
.template-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.template-card {
    aspect-ratio: 16/9;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    cursor: pointer;
    overflow: hidden;
    position: relative;
    transition: all var(--transition);
}

.template-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}

.template-card .template-preview {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    color: white;
    text-shadow: 0 1px 4px rgba(0, 0, 0, .5);
    padding: 6px;
    text-align: center;
}

.template-card .template-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, .75);
    backdrop-filter: blur(4px);
    font-size: 9px;
    font-weight: 600;
    color: var(--text-dim);
    padding: 3px 6px;
    text-align: center;
}

/* ========== Gradient Controls ========== */
.gradient-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.gradient-preview {
    flex: 1;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border);
    transition: background .3s ease;
}

/* ========== Palette Swatches ========== */
.palette-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all var(--transition);
}

.swatch:hover {
    transform: scale(1.2);
    border-color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

/* ========== Logo upload area ========== */
.logo-upload-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.logo-preview-box {
    width: 100%;
    height: 60px;
    background: var(--bg-input);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: border-color var(--transition);
}

.logo-preview-box:hover {
    border-color: var(--accent);
}

.logo-preview-box img {
    max-height: 50px;
    max-width: 100%;
    object-fit: contain;
}

.logo-preview-box .placeholder-text {
    font-size: 11px;
    color: var(--text-muted);
}

/* ========== Canvas Area (Preview) ========== */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-dark);
}

.preview-toolbar {
    height: 40px;
    background: var(--bg-section);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.preview-toolbar #canvasInfo {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.zoom-controls span {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    min-width: 40px;
    text-align: center;
}

.canvas-viewport {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: auto;
    background:
        radial-gradient(circle at center, rgba(99, 102, 241, .03) 0%, transparent 70%),
        repeating-conic-gradient(var(--bg-section) 0% 25%, var(--bg-dark) 0% 50%) 50% / 24px 24px;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .05);
    border-radius: 4px;
    transition: box-shadow var(--transition);
}

canvas:hover {
    box-shadow: 0 12px 50px rgba(0, 0, 0, .6), 0 0 0 1px rgba(99, 102, 241, .15);
}

/* ========== Export Bar (Bottom of Preview) ========== */
.export-bar {
    height: 52px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 16px;
    gap: 10px;
    flex-shrink: 0;
}

.export-bar select {
    width: auto;
    min-width: 90px;
    padding: 6px 10px;
    font-size: 12px;
}

.export-bar .quality-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.export-bar .quality-row input[type="range"] {
    width: 70px;
    height: 4px;
}

.export-info {
    font-size: 11px;
    color: var(--text-muted);
    margin-right: auto;
}

/* ========== Toasts ========== */
.alert-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-section);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 12px 18px;
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    max-width: 380px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
    transform: translateY(120%);
    opacity: 0;
    transition: all .3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-toast.show {
    transform: translateY(0);
    opacity: 1;
}

.alert-toast.toast-success {
    border-color: var(--success);
    color: var(--success);
}

.alert-toast.toast-warning {
    border-color: var(--warning);
    color: var(--warning);
}

/* ========== Keyboard Shortcuts Modal ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn .2s ease;
}

.modal-overlay.show {
    display: flex;
}

.modal-box {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.modal-box h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: color var(--transition);
}

.modal-close:hover {
    color: var(--text);
}

.shortcut-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shortcut-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-dim);
}

.shortcut-list kbd {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 12px;
    font-family: var(--font);
    color: var(--accent);
    font-weight: 600;
}

/* ========== Loading Indicator ========== */
.loading-spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

.loading-spinner.active {
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========== Footer / Reset ========== */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    gap: 6px;
}

.sidebar-footer .btn {
    flex: 1;
    font-size: 11px;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: auto;
        max-height: 50vh;
    }

    body {
        overflow: auto;
        height: auto;
    }

    .canvas-viewport {
        min-height: 300px;
    }

    .shortcut-hint {
        display: none;
    }
}

@media (max-width: 600px) {
    .export-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 10px;
    }
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .6;
    }
}

details.section[open] > *:not(summary) {
    animation: fadeIn .2s ease;
}

/* ========== Filters section ========== */
.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.filter-item .field-label {
    margin-bottom: 3px;
}

/* ========== Badge indicator ========== */
.badge-new {
    display: inline-block;
    font-size: 8px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 1px 5px;
    border-radius: 99px;
    background: var(--accent-2);
    color: white;
    vertical-align: middle;
    margin-left: 4px;
}

.badge-v3 {
    display: inline-block;
    font-size: 8px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 1px 5px;
    border-radius: 99px;
    background: var(--accent-3);
    color: white;
    vertical-align: middle;
    margin-left: 4px;
}

/* ========== Scrollbar for selects ========== */
select option {
    background: var(--bg-input);
    color: var(--text);
}

/* ========== File input styling ========== */
input[type="file"] {
    font-size: 12px;
    color: var(--text-dim);
}

input[type="file"]::file-selector-button {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-right: 8px;
    transition: all var(--transition);
}

input[type="file"]::file-selector-button:hover {
    border-color: var(--accent);
    color: var(--accent);
}