/* ============================================
   Photo Studio Editor — Stylesheet
   ============================================ */

/* ---------- CSS Variables / Design Tokens ---------- */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-surface: #1e2a3a;
    --bg-hover: #253447;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a8b8;
    --text-muted: #6b7280;
    --accent: #0ea5e9;
    --accent-hover: #38bdf8;
    --accent-glow: rgba(14, 165, 233, 0.25);
    --success: #22c55e;
    --success-hover: #16a34a;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: #2a3548;
    --border-light: #354560;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --font-sans: 'Inter', 'Segoe UI', system-ui, sans-serif;
    --transition: 0.2s ease;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========== APP LAYOUT ========== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ========== TOP BAR ========== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
    min-height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

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

.logo h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

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

/* ========== MAIN LAYOUT ========== */
.main-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ========== CANVAS AREA ========== */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
    min-width: 0;
}

/* ========== UPLOAD ZONE ========== */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 480px;
    max-width: 90%;
    padding: 60px 40px;
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(14, 165, 233, 0.05);
    box-shadow: 0 0 30px var(--accent-glow);
}

.upload-zone.drag-over {
    transform: scale(1.02);
}

.upload-icon {
    color: var(--accent);
    margin-bottom: 16px;
    opacity: 0.8;
}

.upload-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-text strong {
    color: var(--accent);
}

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

/* ========== CANVAS CONTAINER ========== */
.canvas-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 16px;
}

#main-canvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
}

/* Canvas toolbar overlay */
.canvas-toolbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    padding: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 5;
}

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

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

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

/* ========== CONTROL PANEL ========== */
.control-panel {
    width: 320px;
    min-width: 320px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Panel Tabs */
.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    border-bottom: 2px solid transparent;
    font-family: var(--font-sans);
}

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

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(14, 165, 233, 0.08);
}

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-content.active {
    display: block;
}

/* Panel Sections */
.panel-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.panel-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 10px;
    line-height: 1.4;
}

/* ========== FORM ELEMENTS ========== */
.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

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

.inline-inputs input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.inline-inputs input:focus {
    border-color: var(--accent);
}

.inline-inputs span {
    color: var(--text-muted);
    font-size: 14px;
}

/* ========== SLIDERS ========== */
.slider-group {
    margin-bottom: 14px;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.slider-group label span {
    color: var(--accent);
    font-weight: 600;
    min-width: 40px;
    text-align: right;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-primary);
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
    box-shadow: 0 0 4px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
}

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

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

.btn-icon:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 0 16px var(--accent-glow);
}

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

.btn-primary.btn-large {
    padding: 14px 20px;
    font-size: 14px;
    margin-top: 8px;
}

.btn-primary.btn-success {
    background: var(--success);
}

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

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
}

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

.btn-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
}

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

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

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

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

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.btn-text:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.control-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

/* ========== MODE TOGGLE ========== */
.mode-toggle {
    display: flex;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.mode-btn {
    flex: 1;
    padding: 9px 12px;
    border: none;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
}

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

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

/* ========== COLOR PRESETS ========== */
.color-presets {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 8px;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.color-custom-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
}

.color-custom-wrap input[type="color"] {
    -webkit-appearance: none;
    width: 32px;
    height: 32px;
    border: 2px solid var(--border-light);
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    background: transparent;
}

.color-custom-wrap input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-custom-wrap input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.color-custom-wrap label {
    font-size: 11px;
    color: var(--text-muted);
}

.color-custom-wrap.inline input[type="color"] {
    width: 28px;
    height: 28px;
}

/* ========== BRUSH CONTROLS ========== */
.brush-controls {
    margin-bottom: 10px;
}

.brush-modes {
    display: flex;
    gap: 6px;
}

.brush-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
}

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

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

.brush-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========== TEXT CONTROLS ========== */
.toggle-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 38px;
    height: 20px;
    background: var(--bg-primary);
    border-radius: 10px;
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}

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

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

.toggle-switch input:checked + .toggle-slider::after {
    left: 20px;
    background: white;
}

.toggle-label {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ========== PASSPORT PREVIEW ========== */
.passport-preview {
    display: flex;
    justify-content: center;
    margin: 12px 0;
    padding: 12px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

#passport-canvas {
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow-md);
}

.passport-info {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 10px;
}

/* ========== GALLERY BAR ========== */
.gallery-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    min-height: 80px;
    max-height: 100px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.gallery-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.gallery-thumbs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    flex: 1;
    padding: 4px 0;
}

.gallery-thumb {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    cursor: pointer;
    object-fit: cover;
    flex-shrink: 0;
    transition: all var(--transition);
}

.gallery-thumb:hover {
    border-color: var(--accent);
}

/* ========== LOADING OVERLAY ========== */
.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 20, 35, 0.85);
    z-index: 1000;
    backdrop-filter: blur(8px);
}

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

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

.loading-text {
    margin-top: 20px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.loading-subtext {
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

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

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

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }

    .control-panel {
        width: 100%;
        min-width: 0;
        max-height: 45vh;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .canvas-area {
        min-height: 40vh;
    }

    .tab-btn span {
        display: none;
    }

    .upload-zone {
        width: 90%;
        padding: 40px 24px;
    }
}

@media (max-width: 600px) {
    .top-bar {
        padding: 0 12px;
        height: 48px;
    }

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

    .panel-tabs {
        padding: 0;
    }

    .tab-btn {
        font-size: 10px;
        padding: 8px 4px;
    }
}
