/* ============================================================================
   Robomates 3D Models — Light Theme
   ============================================================================ */

:root {
    --bg-gradient-1: #f5f4f2;
    --bg-gradient-2: #efeee9;
    --bg-gradient-3: #e5e3dc;
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-border: rgba(140, 125, 105, 0.22);
    --card-hover: rgba(255, 255, 255, 1);
    --text-primary: #1a1816;
    --text-secondary: #3d3733;
    --text-muted: #6b635a;
    --accent-red: #c06b65;
    --accent-orange: #c08a45;
    --accent-green: #4a9964;
    --accent-blue: #5089b5;
    --accent-purple: #7d6bab;
    --scrollbar-thumb: rgba(140, 125, 105, 0.3);
    --scrollbar-hover: rgba(140, 125, 105, 0.45);
}

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

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 50%, var(--bg-gradient-3) 100%);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ============================================================================
   Scrollbar
   ============================================================================ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }

/* ============================================================================
   Header
   ============================================================================ */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.25rem;
    background: var(--card-bg);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    box-shadow: 0 2px 10px rgba(140, 125, 105, 0.12);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo { font-size: 2rem; filter: drop-shadow(0 0 6px rgba(192, 107, 101, 0.3)); }

.logo-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    color: inherit;
}

.logo-link:hover { opacity: 0.9; }

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-red), var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: var(--accent-red);
}

.header-divider {
    width: 2px;
    height: 1.75rem;
    background: linear-gradient(180deg, transparent 0%, var(--text-muted) 20%, var(--text-muted) 80%, transparent 100%);
    border-radius: 1px;
    margin: 0 0.05rem;
}

.page-name, .page-name-link .page-name {
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: var(--accent-purple);
}

.page-name-link {
    text-decoration: none;
}

.page-name-link:hover .page-name {
    opacity: 0.8;
}

/* Navigation */

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(125, 107, 171, 0.08);
}

/* ============================================================================
   Main Content / Grid
   ============================================================================ */

.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

/* ============================================================================
   Model Card
   ============================================================================ */

.model-card {
    background: var(--card-bg);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid var(--card-border);
    box-shadow: 0 2px 10px rgba(140, 125, 105, 0.12);
    overflow: hidden;
    transition: all 0.25s ease;
}

.model-card:hover {
    border-color: rgba(125, 107, 171, 0.5);
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(140, 125, 105, 0.2);
}

.card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.card-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #ffffff;
    overflow: hidden;
}

.card-preview canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.card-preview .preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.card-preview .no-stl-badge {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 0.5rem;
}

.no-stl-badge .file-icon {
    font-size: 2.5rem;
    opacity: 0.5;
}

.card-info {
    padding: 1rem 1.25rem;
}

.card-name {
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card-sizes {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.5rem;
}

.card-downloads {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.format-tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(125, 107, 171, 0.1);
    color: var(--accent-purple);
    border-radius: 4px;
    letter-spacing: 0.3px;
}

/* ============================================================================
   Tag Filter Bar (main page)
   ============================================================================ */

.tag-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
    padding: 0.75rem 0;
}

.tag-filter-btn {
    padding: 0.35rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid var(--card-border);
    border-radius: 20px;
    background: var(--card-bg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    text-transform: lowercase;
}

.tag-filter-btn:hover {
    border-color: rgba(125, 107, 171, 0.5);
    color: var(--accent-purple);
}

.tag-filter-btn.active {
    background: linear-gradient(145deg, #7d6bab, #5089b5);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(125, 107, 171, 0.25);
}

/* Card tags */

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
}

.card-tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    font-size: 0.68rem;
    font-weight: 500;
    background: rgba(80, 137, 181, 0.08);
    color: var(--accent-blue);
    border-radius: 10px;
    text-transform: lowercase;
}

/* Model page tags */

.model-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.model-tag {
    display: inline-block;
    padding: 0.2rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 500;
    background: rgba(80, 137, 181, 0.08);
    color: var(--accent-blue);
    border-radius: 14px;
    text-decoration: none;
    text-transform: lowercase;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.model-tag:hover {
    background: rgba(80, 137, 181, 0.15);
    border-color: rgba(80, 137, 181, 0.3);
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
    padding: 0.55rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.btn-stl,
.btn-step {
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-primary);
    border: 1px solid rgba(140, 125, 105, 0.35);
}

.btn-stl:hover,
.btn-step:hover {
    background: rgba(255, 255, 255, 1);
    border-color: rgba(80, 137, 181, 0.6);
    transform: translateY(-1px);
}

/* ============================================================================
   Loading / Empty State
   ============================================================================ */

.loading-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
    gap: 1rem;
    color: var(--text-muted);
}

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

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

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.6;
}

.empty-state h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.empty-state a {
    color: var(--accent-purple);
}

/* ============================================================================
   Model Detail Page
   ============================================================================ */

.model-page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

@media (min-width: 1024px) {
    .model-page {
        display: grid;
        grid-template-columns: 1fr 380px;
        gap: 1.5rem;
        align-items: start;
    }
}

.model-viewer-wrap {
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid var(--card-border);
    box-shadow: 0 4px 20px rgba(140, 125, 105, 0.15);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

@media (min-width: 1024px) {
    .model-viewer-wrap {
        margin-bottom: 0;
    }
}

.model-viewer {
    position: relative;
    width: 100%;
    height: 65vh;
    min-height: 350px;
    max-height: 700px;
    background: #ffffff;
}

@media (min-width: 1024px) {
    .model-viewer {
        height: 75vh;
        max-height: 800px;
    }
}

.model-viewer canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.viewer-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    z-index: 5;
}

.viewer-no-stl {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.viewer-no-stl .file-icon {
    font-size: 3rem;
    opacity: 0.5;
}

/* Model details */

.model-details {
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--card-border);
    box-shadow: 0 2px 10px rgba(140, 125, 105, 0.12);
    overflow: hidden;
}

@media (min-width: 1024px) {
    .model-details {
        position: sticky;
        top: calc(3.5rem + 1.5rem);
        max-height: calc(100vh - 3.5rem - 3rem);
        overflow-y: auto;
    }
}

.model-details-top {
    padding: 1.5rem 2rem;
}

.model-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.model-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.model-downloads-badge {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.model-formats {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.model-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.model-actions .btn {
    padding: 0.65rem 1.5rem;
    font-size: 0.9rem;
}

/* Description */

.model-description {
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--card-border);
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

.model-description h1,
.model-description h2,
.model-description h3 {
    color: var(--text-primary);
    margin: 1rem 0 0.5rem;
}

.model-description h1 { font-size: 1.4rem; }
.model-description h2 { font-size: 1.2rem; }
.model-description h3 { font-size: 1.05rem; }

.model-description p {
    margin-bottom: 0.75rem;
}

.model-description a {
    color: var(--accent-purple);
    text-decoration: underline;
}

.model-description ul,
.model-description ol {
    margin: 0.5rem 0 0.75rem 1.5rem;
}

.model-description li {
    margin-bottom: 0.3rem;
}

.model-description strong {
    color: var(--text-primary);
    font-weight: 600;
}

.model-description img {
    max-width: 100%;
    border-radius: 8px;
    margin: 0.5rem 0;
}

.model-description blockquote {
    border-left: 3px solid var(--accent-purple);
    padding: 0.5rem 1rem;
    margin: 0.75rem 0;
    background: rgba(125, 107, 171, 0.05);
    border-radius: 0 8px 8px 0;
}

.model-description code {
    font-family: 'Consolas', 'Monaco', 'Ubuntu Mono', monospace;
    font-size: 0.88em;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

/* ============================================================================
   Footer
   ============================================================================ */

.site-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.site-footer a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.site-footer a:hover {
    color: var(--accent-purple);
}

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 768px) {
    .header {
        padding: 0.5rem 0.75rem;
    }

    .header h1 {
        display: none;
    }

    .page-name, .page-name-link .page-name {
        font-size: 1.15rem;
    }

    .header-nav {
        gap: 0.25rem;
    }

    .nav-link {
        padding: 0.35rem 0.5rem;
        font-size: 0.78rem;
    }

    .main-content {
        padding: 0.75rem;
    }

    .tag-filter-bar {
        gap: 0.3rem;
        margin-bottom: 0.75rem;
        padding: 0.5rem 0;
    }

    .tag-filter-btn {
        padding: 0.3rem 0.65rem;
        font-size: 0.75rem;
    }

    .models-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 0.75rem;
    }

    .card-info {
        padding: 0.75rem 1rem;
    }

    .model-page {
        padding: 0.75rem;
    }

    .model-viewer {
        height: 45vh;
        min-height: 280px;
    }

    .model-details-top {
        padding: 1rem 1.25rem;
    }

    .model-title {
        font-size: 1.3rem;
    }

    .model-description {
        padding: 1rem 1.25rem;
    }

    .model-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .models-grid {
        grid-template-columns: 1fr;
    }

    .header-divider {
        display: none;
    }

    .model-viewer {
        height: 40vh;
        min-height: 240px;
    }

    .model-title-row {
        flex-direction: column;
        gap: 0.25rem;
    }
}
