/* ========================================
   ConsoleSkins.co — PS5 Skin Designer
   Sketchfab Viewer API + Fabric.js
   ======================================== */

:root {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef0f2;
    --bg-card: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #555566;
    --text-muted: #999aaa;
    --accent: #2cd2dd;
    --accent-hover: #25bcc6;
    --accent-glow: rgba(44, 210, 221, 0.25);
    --success: #00b894;
    --danger: #e63946;
    --warning: #f4a261;
    --border: #dde0e4;
    --border-light: #c8ccd0;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 4px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --transition: 0.2s ease;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    text-align: center;
}

.loader-ring {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.loader-text {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}

/* Header */
#main-header {
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    z-index: 100;
    position: relative;
}

.header-inner {
    width: 100%;
    max-width: 100%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: 1px;
}

.logo span {
    color: var(--accent);
}

.page-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.back-link {
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

.back-link:hover {
    color: var(--accent);
}

/* Main Layout */
#app {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* 3D Viewer (Sketchfab iframe) */
#viewer-section {
    flex: 1;
    position: relative;
    background: var(--bg-primary);
    min-width: 0;
}

#viewer-container {
    width: 100%;
    height: 100%;
    position: relative;
}

#viewer-container iframe,
#api-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

#viewer-hint {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    pointer-events: none;
    animation: fadeInUp 0.6s ease 1s both;
    z-index: 10;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Controls Panel */
#controls-panel {
    width: 400px;
    min-width: 400px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

#controls-panel::-webkit-scrollbar {
    width: 6px;
}

#controls-panel::-webkit-scrollbar-track {
    background: transparent;
}

#controls-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.control-section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.title-hint {
    font-size: 11px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
}

.title-actions {
    display: flex;
    gap: 4px;
}

.section-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
    margin-top: -8px;
}

/* Device Tabs */
.device-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.device-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.device-tab:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
}

.device-tab.active {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.1);
    color: var(--text-primary);
    box-shadow: 0 0 20px var(--accent-glow);
}

/* Material List (replaces panel-grid) */
.material-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.material-loading {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 20px;
}

.material-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    transition: all var(--transition);
}

.material-item:hover {
    border-color: var(--border-light);
    background: var(--bg-tertiary);
}

.material-item.active {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.1);
}

.material-item.has-design {
    border-color: var(--success);
}

.material-item.has-design.active {
    border-color: var(--accent);
}

.material-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    flex-shrink: 0;
}

.material-info {
    flex: 1;
    min-width: 0;
}

.material-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-channels {
    font-size: 10px;
    color: var(--text-muted);
}

.material-badge {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--accent);
    color: white;
    flex-shrink: 0;
}

/* Search Bar */
.search-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.search-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

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

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

.search-btn {
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    transition: all var(--transition);
    white-space: nowrap;
}

.search-btn:hover {
    background: var(--accent-hover);
}

.quick-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.tag {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.tag:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.search-results {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.search-results:empty::after {
    content: '';
}

.search-result-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-xs);
    cursor: pointer;
    border: 2px solid transparent;
    transition: all var(--transition);
}

.search-result-img:hover {
    border-color: var(--accent);
    transform: scale(1.03);
}

.search-loading {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 20px;
}

/* URL Input */
.url-input-wrap {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

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

.divider-text::before,
.divider-text::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.divider-text::before { left: 0; }
.divider-text::after { right: 0; }

/* Text & Sticker Tools */
.tool-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.tool-section > label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 8px;
}

.text-tool {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.text-options {
    display: flex;
    gap: 6px;
    align-items: center;
}

.text-select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 12px;
    font-family: inherit;
    outline: none;
    flex: 1;
}

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
}

.sticker-btn {
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    padding: 0;
}

.sticker-btn:hover {
    border-color: var(--accent);
    transform: scale(1.1);
    background: var(--bg-tertiary);
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-card);
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.05);
}

.dropzone.dragover {
    transform: scale(1.02);
}

.dropzone-content svg {
    color: var(--text-muted);
    margin-bottom: 12px;
}

.dropzone-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.dropzone-subtext {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

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

/* Editor Section */
#editor-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 16px;
    position: relative;
    aspect-ratio: 1 / 1;
}

#editor-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.editor-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-row label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 65px;
    font-weight: 500;
}

.slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
    box-shadow: 0 0 8px var(--accent-glow);
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
}

.rot-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

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

.slider-val {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Color Options */
.color-options {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.color-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
    padding: 0;
}

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

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

.color-picker {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background: none;
    padding: 0;
    overflow: hidden;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

/* Button Icon */
.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
}

.btn-icon:hover {
    color: var(--danger);
    background: rgba(230, 57, 70, 0.1);
}

#btn-change-image:hover {
    color: var(--accent);
    background: rgba(108, 92, 231, 0.1);
}

/* Panel Thumbnails */
.panel-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.panel-thumb {
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    overflow: hidden;
    position: relative;
    background: var(--bg-card);
    cursor: pointer;
    transition: all var(--transition);
}

.panel-thumb:hover {
    border-color: var(--border-light);
}

.panel-thumb.active {
    border-color: var(--accent);
}

.panel-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.panel-thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 3px 6px;
    background: rgba(0, 0, 0, 0.7);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.panel-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-muted);
    height: 100%;
}

/* Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    flex: 1;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 16px var(--accent-glow);
}

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

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

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

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 700px;
    width: 90%;
    box-shadow: var(--shadow);
}

.modal-content h2 {
    font-size: 18px;
    margin-bottom: 20px;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

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

#preview-canvas-wrap {
    width: 100%;
    aspect-ratio: 16/9;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 20px;
}

#preview-canvas-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-actions .btn {
    flex: unset;
    min-width: 140px;
}

/* Responsive */
@media (max-width: 900px) {
    #app {
        flex-direction: column;
        overflow-y: auto;
    }

    #viewer-section {
        height: 50vh;
        min-height: 350px;
        flex: none;
    }

    #controls-panel {
        width: 100%;
        min-width: unset;
        border-left: none;
        border-top: 1px solid var(--border);
        overflow-y: visible;
    }

    .page-title {
        display: none;
    }
}

@media (max-width: 500px) {
    .header-inner {
        padding: 0 16px;
    }

    .control-section {
        padding: 16px;
    }

    .action-buttons {
        flex-direction: column;
    }
}

/* Smooth transitions for section visibility */
.control-section {
    animation: fadeIn 0.3s ease;
}

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

/* Notification Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    z-index: 2000;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow);
}

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

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

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