/* ==========================================
   VTuber Avatar Creator - Admin CMS Styles
   ========================================== */

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #111111;
    --bg-tertiary: #1a1a1a;
    --bg-hover: #252525;
    --bg-card: #161616;
    
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    
    --border-color: #2a2a2a;
    --border-hover: #404040;
    
    --accent-color: #dc2626;
    --accent-hover: #ef4444;
    --accent-glow: rgba(220, 38, 38, 0.3);
    
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #3b82f6;
    
    --sidebar-width: 220px;
    --preview-width: 320px;
    --header-height: 64px;
    --border-radius: 8px;
    --border-radius-sm: 4px;
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ==========================================
   Layout
   ========================================== */
.admin-container {
    display: flex;
    min-height: 100vh;
}

/* ==========================================
   Sidebar
   ========================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header .logo-icon {
    font-size: 28px;
    color: var(--accent-color);
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition);
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-color);
    color: white;
}

.nav-icon {
    font-size: 18px;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

/* ==========================================
   Main Content
   ========================================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    margin-right: var(--preview-width);
    display: flex;
    flex-direction: column;
}

.content-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.content-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.content-section {
    display: none;
    padding: 24px;
    flex: 1;
}

.content-section.active {
    display: block;
}

/* ==========================================
   Buttons
   ========================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: var(--bg-tertiary);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
}

/* ==========================================
   Forms
   ========================================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.text-input,
.select-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: border-color var(--transition);
}

.text-input:focus,
.select-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.help-text {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ==========================================
   Cards
   ========================================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
}

.card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==========================================
   Stats Grid
   ========================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    font-size: 32px;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-color);
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ==========================================
   Dashboard Grid
   ========================================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==========================================
   Toolbar
   ========================================== */
.section-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ==========================================
   Modules Grid
   ========================================== */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.module-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: all var(--transition);
}

.module-card:hover {
    border-color: var(--border-hover);
}

.module-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.module-thumbnail {
    width: 50px;
    height: 50px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.module-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.module-info {
    flex: 1;
}

.module-info h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.module-info .module-id {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
}

.module-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.module-badge.base { background: #3b82f6; }
.module-badge.hair { background: #8b5cf6; }
.module-badge.eyes { background: #ec4899; }
.module-badge.mouth { background: #f59e0b; }
.module-badge.outfit { background: #22c55e; }
.module-badge.accessories { background: #06b6d4; }

.module-card-body {
    padding: 16px;
}

.module-files {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.module-card-actions {
    display: flex;
    gap: 8px;
}

/* ==========================================
   Assets Grid
   ========================================== */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 48px;
    text-align: center;
    margin-bottom: 24px;
    cursor: pointer;
    transition: all var(--transition);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-color);
    background: rgba(220, 38, 38, 0.05);
}

.upload-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.upload-zone h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 14px;
}

.upload-hint {
    margin-top: 8px;
    font-size: 12px !important;
    color: var(--text-muted) !important;
}

.assets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.asset-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.asset-preview {
    aspect-ratio: 2/3;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.asset-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.asset-info {
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

.asset-name {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    word-break: break-all;
}

.asset-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.asset-actions {
    display: flex;
    gap: 8px;
    padding: 0 12px 12px;
}

/* ==========================================
   Orders Table
   ========================================== */
.orders-table {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.orders-table table {
    width: 100%;
    border-collapse: collapse;
}

.orders-table th,
.orders-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.orders-table th {
    background: var(--bg-tertiary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.orders-table tr:last-child td {
    border-bottom: none;
}

.orders-table tr:hover {
    background: var(--bg-hover);
}

.order-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.order-status.pending {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
}

.order-status.in-progress {
    background: rgba(59, 130, 246, 0.2);
    color: var(--info-color);
}

.order-status.completed {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success-color);
}

.orders-list {
    max-height: 300px;
    overflow-y: auto;
}

.empty-state {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
}

/* ==========================================
   Settings
   ========================================== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.color-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.color-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 2px solid var(--border-color);
}

.color-item .remove-color {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
}

.color-item .remove-color:hover {
    color: var(--danger-color);
}

.layer-order-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    cursor: grab;
}

.layer-item:active {
    cursor: grabbing;
}

.layer-item .layer-handle {
    color: var(--text-muted);
}

.layer-item .layer-name {
    flex: 1;
}

.settings-footer {
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* ==========================================
   Modal
   ========================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-content.modal-large {
    max-width: 700px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

/* ==========================================
   Thumbnail Upload
   ========================================== */
.thumbnail-upload {
    display: flex;
    align-items: center;
    gap: 16px;
}

.thumbnail-upload img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

.thumbnail-upload input {
    flex: 1;
}

/* ==========================================
   Upload Preview Grid
   ========================================== */
.upload-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.upload-preview-item {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    padding: 12px;
    text-align: center;
}

.upload-preview-item img {
    max-width: 100%;
    max-height: 150px;
    object-fit: contain;
    margin-bottom: 8px;
}

.upload-preview-item .filename {
    font-size: 11px;
    color: var(--text-muted);
    word-break: break-all;
}

/* ==========================================
   Toast
   ========================================== */
.toast {
    position: fixed;
    bottom: 24px;
    right: calc(var(--preview-width) + 24px);
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-color);
    padding: 14px 24px;
    border-radius: var(--border-radius);
    font-size: 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 300;
    transition: all 0.3s ease;
}

.toast.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* ==========================================
   Scrollbar
   ========================================== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 1200px) {
    :root { --preview-width: 280px; }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
    
    .main-content {
        margin-left: 200px;
        margin-right: var(--preview-width);
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .main-content {
        margin-left: 0;
        margin-right: 0;
    }

    .preview-panel {
        display: none;
    }
}

/* ==========================================
   Preview Panel
   ========================================== */
.preview-panel {
    width: var(--preview-width);
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99;
}

.preview-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.preview-header h3 {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-header h3 span.preview-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-color);
    display: inline-block;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

.preview-canvas-area {
    flex-shrink: 0;
    padding: 8px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

/* Checkerboard transparency grid */
.checker {
    background-color: #1a1a1a;
    background-image:
        linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
        linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
}

.preview-canvas-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    max-height: 420px;
}

#preview-canvas {
    display: block;
    max-width: 100%;
    max-height: 420px;
    object-fit: contain;
}

.preview-empty-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 12px;
    pointer-events: none;
}

.preview-empty-overlay .preview-empty-icon {
    font-size: 28px;
    opacity: 0.4;
}

/* Build list — which slots are active */
.preview-build-panel {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.preview-build-header {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

#preview-build-list {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
}

.preview-empty-text {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 16px 0;
}

.preview-build-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 12px;
}

.slot-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.preview-build-slot {
    flex: 1;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-build-variant {
    font-family: monospace;
    font-size: 10px;
    color: var(--text-muted);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-build-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
    line-height: 1;
}

.preview-build-remove:hover {
    background: var(--bg-hover);
    color: var(--danger-color);
}

/* Naming guide at the bottom of the preview panel */
.preview-naming-guide {
    padding: 10px 14px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-primary);
}

.preview-guide-header {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.preview-guide-code {
    display: block;
    font-size: 11px;
    font-family: monospace;
    color: var(--accent-color);
    background: var(--bg-tertiary);
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.preview-guide-examples {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.preview-guide-examples span {
    font-size: 10px;
    font-family: monospace;
    color: var(--text-muted);
}

/* ==========================================
   Slot Badges
   ========================================== */
.slot-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

.slot-badge-sm {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
}

/* ==========================================
   Asset Cards (updated)
   ========================================== */
.asset-card {
    cursor: pointer;
    transition: border-color var(--transition), transform var(--transition);
}

.asset-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.asset-card.active {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.asset-preview.checker {
    aspect-ratio: 2/3;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.asset-preview.checker img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.asset-slot {
    margin-top: 4px;
}

/* Module thumb icon */
.module-thumb-icon {
    font-size: 20px;
}

/* Preview button */
.btn-preview {
    background: rgba(220, 38, 38, 0.15);
    color: var(--accent-color);
    border: 1px solid rgba(220, 38, 38, 0.3);
}

.btn-preview:hover {
    background: rgba(220, 38, 38, 0.25);
    border-color: var(--accent-color);
}
