/* ============================================================
   Abstract Serenity — Main Stylesheet
   Palette: black/white base · purple/lavender accents
   ============================================================ */

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

:root {
    /* Base Neutrals */
    --black:       #000000;
    --near-black:  #1a1a1a;
    --dark-gray:   #2e2e2e;
    --mid-gray:    #666666;
    --light-gray:  #b0b0b0;
    --pale-gray:   #e8e8e8;
    --off-white:   #f5f5f3;
    --white:       #FFFFFF;

    /* Abstract Serenity — Brand Purple Palette */
    --as-purple-deep:     #7200B0;
    --as-purple-mid:      #B175EC;
    --as-purple-lavender: #C4A3F0;
    --as-purple-pale:     #DEBBF5;
    --as-purple-faint:    #F4EAFF;

    /* Abstract Serenity — Earth Tones */
    --as-earth:           #856D5B;
    --as-earth-dark:      #59493D;

    /* Semantic — accent points to AS deep purple */
    --accent:      #7200B0;
    --accent-hover:#5800A0;
    --accent-light:#DEBBF5;
    --danger:      #c0392b;
    --success:     #1a7a3c;
    --warning:     #b07d00;

    --font-serif:  Georgia, 'Times New Roman', serif;
    --font-sans:   'Segoe UI', Calibri, system-ui, -apple-system, sans-serif;
    --font-mono:   'Courier New', monospace;

    --radius-sm:   4px;
    --radius-md:   8px;
    --radius-lg:   12px;

    --shadow-sm:     0 1px 3px rgba(0,0,0,0.12);
    --shadow-md:     0 4px 12px rgba(0,0,0,0.15);
    --shadow-lg:     0 8px 24px rgba(0,0,0,0.18);
    --shadow-purple: 0 4px 16px rgba(114,0,176,0.15);

    --nav-h:       60px;
    --sidebar-w:   280px;
    --transition:  0.2s ease;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    background: var(--off-white);
    color: var(--near-black);
    line-height: 1.6;
    min-height: 100vh;
}

h1, h2, h3, h4 {
    font-family: var(--font-serif);
    font-weight: normal;
    line-height: 1.3;
}

a { color: var(--near-black); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ---- Typography ------------------------------------------- */
.text-serif  { font-family: var(--font-serif); }
.text-sans   { font-family: var(--font-sans); }
.text-sm     { font-size: 0.875rem; }
.text-xs     { font-size: 0.75rem; }
.text-muted  { color: var(--mid-gray); }
.text-center { text-align: center; }

/* ---- Layout Utilities ------------------------------------- */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-2  { margin-bottom: 1rem; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ---- Buttons --------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.25rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}
.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    text-decoration: none;
}

.btn-outline {
    background: transparent;
    color: var(--near-black);
    border-color: var(--near-black);
}
.btn-outline:hover {
    background: var(--near-black);
    color: var(--white);
    text-decoration: none;
}

.btn-ghost {
    background: transparent;
    color: var(--mid-gray);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--pale-gray);
    color: var(--near-black);
    text-decoration: none;
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover {
    background: var(--danger);
    color: var(--white);
    text-decoration: none;
}

.btn-sm { padding: 0.35rem 0.85rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }

/* ---- Forms ------------------------------------------------ */
.form-group { margin-bottom: 1.25rem; }

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--dark-gray);
    margin-bottom: 0.4rem;
    font-family: var(--font-sans);
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
    display: block;
    width: 100%;
    padding: 0.6rem 0.9rem;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    border: 1.5px solid var(--pale-gray);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--near-black);
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(114,0,176,0.12);
}

input::placeholder { color: var(--light-gray); }

.form-error {
    font-size: 0.8rem;
    color: var(--danger);
    margin-top: 0.3rem;
}

/* ---- Alerts ----------------------------------------------- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    border-left: 3px solid;
    margin-bottom: 1rem;
}
.alert-error   { background: #fdf0f0; border-color: var(--danger);  color: var(--danger); }
.alert-success { background: #f0fdf4; border-color: var(--success); color: var(--success); }
.alert-info    { background: #f5f5f3; border-color: var(--mid-gray);color: var(--dark-gray); }

/* ---- Top Navigation --------------------------------------- */
.topnav {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--nav-h);
    background: var(--white);
    border-bottom: 1px solid var(--pale-gray);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.topnav__logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
}
.topnav__logo img {
    height: 36px;
    width: auto;
}
.topnav__logo-text {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    color: var(--near-black);
}

.topnav__spacer { flex: 1; }

.topnav__user {
    font-size: 0.85rem;
    color: var(--mid-gray);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ---- Login Page ------------------------------------------- */
.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: linear-gradient(160deg, var(--as-purple-faint) 0%, var(--off-white) 50%, var(--as-purple-pale) 100%);
}

.login-card {
    background: var(--white);
    border: 1px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
}

.login-card__logo {
    text-align: center;
    margin-bottom: 2rem;
}
.login-card__logo img {
    height: 64px;
    margin: 0 auto 0.75rem;
}
.login-card__logo h1 {
    font-size: 1.4rem;
    color: var(--near-black);
}
.login-card__logo p {
    font-size: 0.85rem;
    color: var(--mid-gray);
    margin-top: 0.25rem;
    font-family: var(--font-sans);
}

.login-divider {
    text-align: center;
    margin: 2rem 0 1rem;
    font-size: 0.75rem;
    color: var(--light-gray);
    font-family: var(--font-sans);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* ---- Dashboard -------------------------------------------- */
.dashboard-layout {
    display: flex;
    min-height: calc(100vh - var(--nav-h));
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--pale-gray);
    padding: 1.5rem 0;
    flex-shrink: 0;
    overflow-y: auto;
    position: sticky;
    top: var(--nav-h);
    height: calc(100vh - var(--nav-h));
}

.sidebar__section-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--light-gray);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0 1.25rem;
    margin-bottom: 0.5rem;
    font-family: var(--font-sans);
}

.sidebar__file-list { list-style: none; }

.sidebar__file-item a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    color: var(--dark-gray);
    border-left: 2px solid transparent;
    transition: background var(--transition), border-color var(--transition);
    text-decoration: none;
    word-break: break-word;
}
.sidebar__file-item a:hover {
    background: var(--off-white);
    border-left-color: var(--mid-gray);
}
.sidebar__file-item a.active {
    background: var(--off-white);
    border-left-color: var(--near-black);
    font-weight: 500;
    color: var(--near-black);
}

.file-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.6;
}

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    min-width: 0;
}

/* ---- File Grid (dashboard cards) -------------------------- */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.25rem;
}

.file-card {
    background: var(--white);
    border: 1px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
    text-decoration: none;
    color: var(--near-black);
}
.file-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--near-black);
    transform: translateY(-2px);
    text-decoration: none;
}

.file-card__icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    background: var(--off-white);
}
.file-card__icon--stl { background: #f0f0ee; }
.file-card__icon--pdf { background: #fdf0f0; }
.file-card__icon--txt { background: #f5f5f3; }
.file-card__icon--xls { background: #f0fdf4; }
.file-card__icon--other { background: var(--pale-gray); }

.file-card__name {
    font-size: 0.82rem;
    text-align: center;
    word-break: break-word;
    line-height: 1.4;
    font-family: var(--font-sans);
}

.file-card__meta {
    font-size: 0.73rem;
    color: var(--light-gray);
    font-family: var(--font-sans);
}

/* ---- Viewer Page ------------------------------------------ */
.viewer-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "sidebar toolbar"
        "sidebar canvas";
    height: calc(100vh - var(--nav-h));
}

.viewer-sidebar {
    grid-area: sidebar;
    width: 320px;
    background: var(--white);
    border-right: 1px solid var(--pale-gray);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.viewer-sidebar__header {
    padding: 1.75rem 1.5rem 1.5rem;
    border-bottom: 1px solid var(--pale-gray);
}
.viewer-sidebar__header .btn {
    width: auto;
    display: inline-flex;
}
.viewer-sidebar__logo {
    height: 38px;
    width: auto;
    margin-bottom: 1.25rem;
}
.viewer-sidebar__header h3 {
    font-size: 1rem;
    font-family: var(--font-serif);
    color: var(--near-black);
    line-height: 1.3;
    word-break: break-word;
}

.viewer-toolbar {
    grid-area: toolbar;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #1c1c1c;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-wrap: wrap;
}

.viewer-toolbar__title {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
    font-family: var(--font-sans);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewer-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    transition: background var(--transition);
    font-family: var(--font-sans);
    white-space: nowrap;
}
.viewer-btn:hover { background: rgba(0,0,0,0.65); }
.viewer-btn.active { background: rgba(0,0,0,0.7); border-color: rgba(255,255,255,0.35); }

/* ---- Viewer filename overlay ------------------------------ */
.viewer-file-label {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    background: rgba(0, 0, 0, 0.5);
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.72rem;
    font-family: var(--font-sans);
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    max-width: 55%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 5;
}

#stl-canvas-container {
    grid-area: canvas;
    position: relative;
    overflow: hidden;
    background: #1a1a1a;
}

#stl-canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
}

.viewer-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    color: rgba(255,255,255,0.6);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    gap: 1rem;
    z-index: 10;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 2.5px solid rgba(255,255,255,0.15);
    border-top-color: rgba(255,255,255,0.7);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.viewer-hint {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: rgba(255,255,255,0.3);
    font-family: var(--font-sans);
    pointer-events: none;
    white-space: nowrap;
    z-index: 4;
}

/* ---- Viewer Color Swatches -------------------------------- */
.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.15);
    flex-shrink: 0;
    transition: border-color var(--transition), transform var(--transition);
}
.color-swatch:hover  { border-color: rgba(255,255,255,0.5);  transform: scale(1.15); }
.color-swatch.active { border-color: rgba(255,255,255,0.9);  transform: scale(1.1); }

/* ---- Viewer Sidebar Sections ------------------------------ */
.viewer-sidebar__section {
    padding: 1.5rem 1.5rem;
    border-bottom: 1px solid var(--pale-gray);
    flex-shrink: 0;
}

.viewer-sidebar__section-title {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--light-gray);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 0.75rem;
    font-family: var(--font-sans);
}

.viewer-stats {
    width: 100%;
    border-collapse: collapse;
}
.viewer-stats td {
    padding: 0.28rem 0;
    border-bottom: none;
    vertical-align: middle;
}
.viewer-stats tr:hover td { background: transparent; }
.viewer-stats__label {
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--mid-gray);
    width: 45%;
}
.viewer-stats__val {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--near-black);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ---- Model Stats dark section ----------------------------- */
.viewer-stats-section {
    background: #1e1e1e;
}
.viewer-stats-section .viewer-sidebar__section-title {
    color: rgba(255,255,255,0.45);
}
.viewer-stats-section .viewer-stats__label {
    color: rgba(255,255,255,0.6);
}
.viewer-stats-section .viewer-stats__val {
    color: rgba(255,255,255,0.95);
    font-weight: 600;
}

.viewer-share {
    background: var(--off-white);
}
.viewer-share__input {
    font-size: 0.8rem !important;
    color: var(--mid-gray) !important;
    background: var(--white) !important;
}

.viewer-cta__brand {
    margin-top: 1rem;
    font-size: 0.72rem;
    color: var(--light-gray);
    text-align: center;
    font-family: var(--font-sans);
}
.viewer-cta__brand a { color: var(--mid-gray); }
.viewer-cta__brand a:hover { color: var(--near-black); text-decoration: underline; }

/* ---- Viewer Colour Picker --------------------------------- */
.viewer-color-picker {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
    flex-shrink: 0;
}
.viewer-color-picker:hover { border-color: rgba(255,255,255,0.5); }
.viewer-color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.viewer-color-picker::-webkit-color-swatch { border: none; border-radius: 2px; }
.viewer-color-picker::-moz-color-swatch { border: none; border-radius: 2px; }

/* ---- Admin Panel ------------------------------------------ */
.admin-layout {
    display: flex;
    min-height: calc(100vh - var(--nav-h));
}

.admin-sidebar {
    width: 220px;
    background: var(--near-black);
    padding: 1.5rem 0;
    flex-shrink: 0;
}

.admin-sidebar__title {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    color: var(--as-purple-lavender);
    padding: 0 1.25rem 1rem;
    border-bottom: 1px solid rgba(195,163,240,0.15);
    margin-bottom: 0.75rem;
}

.admin-nav { list-style: none; }
.admin-nav a {
    display: block;
    padding: 0.55rem 1.25rem;
    font-size: 0.88rem;
    color: rgba(255,255,255,0.65);
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
    font-family: var(--font-sans);
}
.admin-nav a:hover {
    background: rgba(255,255,255,0.08);
    color: var(--white);
    text-decoration: none;
}
.admin-nav a.active {
    background: rgba(114,0,176,0.28);
    color: var(--as-purple-pale);
    text-decoration: none;
    border-left: 2px solid var(--as-purple-mid);
    padding-left: calc(1.25rem - 2px);
}

.admin-main { flex: 1; padding: 2rem; overflow-y: auto; }
.admin-main h2 {
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--pale-gray);
}

/* ---- Tables ----------------------------------------------- */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    font-family: var(--font-sans);
}

th {
    text-align: left;
    padding: 0.65rem 1rem;
    background: var(--off-white);
    color: var(--mid-gray);
    font-weight: 500;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--pale-gray);
}

td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--pale-gray);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--off-white); }

/* ---- Stat Cards (admin dashboard) ------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.stat-card__value {
    font-family: var(--font-serif);
    font-size: 2rem;
    color: var(--near-black);
    line-height: 1;
    margin-bottom: 0.3rem;
}

.stat-card__label {
    font-size: 0.78rem;
    color: var(--mid-gray);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-sans);
}

/* ---- Modal ------------------------------------------------ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
}

.modal__title {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    font-family: var(--font-serif);
}

.modal__actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ---- Badge ------------------------------------------------ */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 500;
    font-family: var(--font-sans);
    letter-spacing: 0.02em;
}
.badge-active   { background: #eaf7ee; color: var(--success); }
.badge-inactive { background: var(--pale-gray); color: var(--mid-gray); }

/* ---- Page Header ------------------------------------------ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-header h2 { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

/* ---- Empty State ------------------------------------------ */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--mid-gray);
}
.empty-state__icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.4; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--dark-gray); }
.empty-state p { font-size: 0.9rem; }

/* ---- Footer ----------------------------------------------- */
.footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.78rem;
    color: var(--light-gray);
    font-family: var(--font-sans);
    border-top: 1px solid var(--pale-gray);
    margin-top: auto;
}

/* ---- Mobile Sidebar Toggle -------------------------------- */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    color: var(--near-black);
}

/* ============================================================
   RESPONSIVE — Mobile
   ============================================================ */
@media (max-width: 768px) {

    .sidebar-toggle { display: flex; align-items: center; }

    /* Dashboard sidebar becomes a slide-in drawer */
    .sidebar {
        position: fixed;
        top: var(--nav-h);
        left: -100%;
        height: calc(100vh - var(--nav-h));
        z-index: 50;
        transition: left var(--transition);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { left: 0; }

    .main-content { padding: 1rem; }

    /* Viewer: flex column stack — toolbar → canvas → sidebar */
    .viewer-layout {
        display: flex;
        flex-direction: column;
        height: auto;
    }
    .viewer-toolbar {
        width: 100%;
        padding: 0.5rem 0.75rem;
        gap: 6px;
        flex-shrink: 0;
    }
    .viewer-btn {
        padding: 0.28rem 0.6rem;
        font-size: 0.75rem;
    }
    .viewer-toolbar__title {
        font-size: 0.8rem;
        flex-basis: 100%;
        order: -1;
    }
    #stl-canvas-container {
        width: 100%;
        height: 45vh;
        min-height: 280px;
        flex-shrink: 0;
    }
    .viewer-hint {
        display: none;
    }
    .viewer-sidebar {
        width: 100%;
        border-right: none;
        border-top: 1px solid var(--pale-gray);
        overflow: visible;
        flex-shrink: 0;
    }

    /* Mobile sidebar typography */
    .viewer-sidebar__header { padding: 1.1rem 1.1rem 0.9rem; }
    .viewer-sidebar__logo { height: 26px; margin-bottom: 0.65rem; }
    .viewer-sidebar__section { padding: 1rem 1.1rem; }
    .viewer-stats__label { font-size: 0.78rem; }
    .viewer-stats__val { font-size: 0.8rem; }

    /* Admin: sidebar becomes top bar */
    .admin-layout { flex-direction: column; }
    .admin-sidebar { width: 100%; padding: 0; }
    .admin-sidebar__title { display: none; }
    .admin-nav { display: flex; overflow-x: auto; }
    .admin-nav a { padding: 0.75rem 1rem; white-space: nowrap; }
    .admin-main { padding: 1rem; }

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

    .login-card { padding: 2rem 1.25rem; }

    .topnav__logo-text { display: none; }
}

@media (max-width: 480px) {
    .file-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .page-header { flex-direction: column; align-items: flex-start; }
}

/* ============================================================
   Shared Site Header (includes/header.php)
   ============================================================ */

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--nav-h);
    background: var(--white);
    border-bottom: 1px solid var(--pale-gray);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
}

.site-header__logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--near-black);
    flex-shrink: 0;
}
.site-header__logo:hover { text-decoration: none; }
.site-header__logo img { height: 36px; width: auto; }
.site-header__logo-text { font-family: var(--font-serif); font-size: 1.1rem; }

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex: 1;
}

.site-nav a {
    font-size: 0.875rem;
    font-family: var(--font-sans);
    color: var(--mid-gray);
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.site-nav a:hover { background: var(--off-white); color: var(--near-black); text-decoration: none; }
.site-nav a.active { color: var(--near-black); font-weight: 500; }

.site-header__right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
    flex-shrink: 0;
}

.site-header__username {
    font-size: 0.85rem;
    color: var(--mid-gray);
    font-family: var(--font-sans);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

/* Back link used on model.php */
.model-back-link {
    display: inline-block;
    font-size: 0.82rem;
    color: var(--mid-gray);
    text-decoration: none;
    margin-bottom: 0.65rem;
    font-family: var(--font-sans);
    transition: color var(--transition);
}
.model-back-link:hover { color: var(--near-black); text-decoration: none; }

@media (max-width: 768px) {
    .site-header {
        height: auto;
        flex-wrap: wrap;
        padding: 0;
        gap: 0;
        align-items: stretch;
    }

    /* Row 1: logo + right actions */
    .site-header__logo {
        flex: 1;
        height: 56px;
        padding: 0 1rem;
    }
    .site-header__logo img { height: 28px; }
    .site-header__logo-text { font-size: 0.95rem; }

    .site-header__right {
        height: 56px;
        padding: 0 1rem;
        margin-left: 0;
        gap: 0.5rem;
    }
    .site-header__username { display: none; }

    /* Row 2: nav full-width pill strip */
    .site-nav {
        order: 3;
        width: 100%;
        border-top: 1px solid var(--pale-gray);
        padding: 0.4rem 0.75rem;
        gap: 0.4rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
        align-items: center;
    }
    .site-nav::-webkit-scrollbar { display: none; }

    .site-nav a {
        font-size: 0.8rem;
        padding: 0.45rem 0.85rem;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        border-radius: var(--radius-md);
        background: var(--off-white);
        border: 1px solid var(--pale-gray);
        color: var(--dark-gray);
        white-space: nowrap;
        flex-shrink: 0;
    }
    .site-nav a:hover,
    .site-nav a.active {
        background: var(--near-black);
        border-color: var(--near-black);
        color: var(--white);
    }
}

/* ============================================================
   Model Product Page (model.php)
   ============================================================ */

.model-header {
    height: var(--nav-h);
    background: var(--white);
    border-bottom: 1px solid var(--pale-gray);
    display: flex;
    align-items: center;
    padding: 0 2rem;
    box-shadow: var(--shadow-sm);
}

.model-header__logo {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: var(--near-black);
}
.model-header__logo:hover { text-decoration: none; }
.model-header__logo img { height: 34px; width: auto; }
.model-header__logo-text { font-family: var(--font-serif); font-size: 1.1rem; }

.model-main {
    max-width: 1240px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 4rem;
}

.model-back-wrap { margin-bottom: 1rem; }

.model-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 2rem;
    align-items: start;
}

.model-viewer-col { min-width: 0; }

.model-viewer-wrap {
    background: #1a1a1a;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.model-viewer-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    background: #1c1c1c;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-wrap: wrap;
}

.model-viewer-wrap #stl-canvas-container {
    height: 72vh;
    min-height: 460px;
}

.model-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: calc(var(--nav-h) + 1rem);
}

.model-title {
    font-size: 1.65rem;
    font-weight: normal;
    color: var(--near-black);
    line-height: 1.25;
    font-family: var(--font-serif);
    margin: 0;
}

.model-section {
    background: var(--white);
    border: 1px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.model-section__title {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--light-gray);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-family: var(--font-sans);
    margin-bottom: 0.9rem;
}

.model-cta-text {
    font-size: 0.9rem;
    color: var(--dark-gray);
    line-height: 1.65;
    margin-bottom: 1.1rem;
    font-family: var(--font-sans);
}

.model-attribution-text {
    font-size: 0.875rem;
    color: var(--dark-gray);
    line-height: 1.65;
    font-family: var(--font-sans);
}
.model-attribution-text a { color: var(--mid-gray); text-decoration: underline; }
.model-attribution-text a:hover { color: var(--near-black); }

.model-share-row {
    display: flex;
    gap: 0.5rem;
}
.model-share-row input {
    flex: 1;
    min-width: 0;
    font-size: 0.82rem !important;
    color: var(--mid-gray) !important;
}

@media (max-width: 900px) {
    .model-main { padding: 0 0 3rem; }
    .model-back-wrap { padding: 1rem 1rem 0; }
    .model-layout { grid-template-columns: 1fr; gap: 0; }
    .model-viewer-col { order: 1; }
    .model-sidebar { order: 2; padding: 1rem; position: static; gap: 0.75rem; }
    .model-viewer-wrap { border-radius: 0; box-shadow: none; }
    .model-viewer-wrap #stl-canvas-container { height: 50vh; min-height: 280px; }
    .model-viewer-toolbar { padding: 0.5rem 0.75rem; gap: 5px; }
    .model-title { font-size: 1.45rem; }
    .model-share-row { flex-direction: column; }
    .model-share-row .btn { width: 100%; }
}

/* ============================================================
   Site Footer (includes/footer.php)
   ============================================================ */

.site-footer {
    margin-top: 4rem;
    border-top: 1px solid var(--pale-gray);
    background: var(--off-white);
    padding: 1.25rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--light-gray);
}

.site-footer__copy {
    white-space: nowrap;
    flex-shrink: 0;
}

.site-footer__links {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

.site-footer a {
    color: var(--mid-gray);
    text-decoration: none;
    transition: color var(--transition);
}
.site-footer a:hover { color: var(--near-black); text-decoration: none; }

@media (max-width: 600px) {
    .site-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 1.25rem 1rem;
    }
    .site-footer__links {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        width: 100%;
    }
    .site-footer__links a {
        display: block;
        padding: 0.55rem 0;
        border-bottom: 1px solid var(--pale-gray);
        width: 100%;
    }
    .site-footer__links a:last-child { border-bottom: none; }
}

/* ============================================================
   Static Content Pages (privacy.php, terms.php, contact.php)
   ============================================================ */

.content-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 3rem 1.5rem 5rem;
}

.content-page h1 {
    font-weight: normal;
    font-size: 2rem;
    margin-bottom: 0.4rem;
    font-family: var(--font-serif);
}

.content-page h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 2rem 0 0.5rem;
    font-family: var(--font-sans);
    color: var(--near-black);
}

.content-page p {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--dark-gray);
    margin-bottom: 0.6rem;
}

.content-page section {
    border-bottom: 1px solid var(--pale-gray);
    padding-bottom: 1.5rem;
    margin-bottom: 0.5rem;
}

.content-page section:last-child { border-bottom: none; }

/* ============================================================
   Abstract Serenity — Admin Sidebar Enhancements
   ============================================================ */

.admin-nav__section {
    font-size: 0.63rem;
    font-weight: 700;
    color: rgba(255,255,255,0.28);
    text-transform: uppercase;
    letter-spacing: 0.13em;
    padding: 1rem 1.25rem 0.3rem;
    font-family: var(--font-sans);
    pointer-events: none;
    user-select: none;
}

/* Card utility (used across admin pages) */
.card {
    background: var(--white);
    border: 1px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

/* ============================================================
   Abstract Serenity — Status Badges
   ============================================================ */

.badge-visible    { background: #e8f5e9; color: #2e7d32; }
.badge-hidden     { background: var(--pale-gray); color: var(--mid-gray); }
.badge-draft      { background: #fff8e1; color: #b07d00; }
.badge-sold       { background: #fce4ec; color: #c62828; }
.badge-featured   { background: var(--as-purple-faint); color: var(--as-purple-deep); }
.badge-requested  { background: #e3f2fd; color: #1565c0; }
.badge-confirmed  { background: #e8f5e9; color: #2e7d32; }
.badge-completed  { background: var(--as-purple-faint); color: var(--as-purple-deep); }
.badge-cancelled  { background: var(--pale-gray); color: var(--mid-gray); }

/* ============================================================
   Abstract Serenity — Piece Cards (admin/pieces.php)
   ============================================================ */

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

.piece-card {
    background: var(--white);
    border: 1.5px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
}
.piece-card:hover {
    box-shadow: var(--shadow-purple);
    border-color: var(--as-purple-lavender);
    transform: translateY(-2px);
}

.piece-card__thumb {
    width: 100%;
    aspect-ratio: 1;
    background: var(--as-purple-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--as-purple-lavender);
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}
.piece-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.piece-card__body {
    padding: 0.9rem 1rem 0.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.piece-card__name {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    color: var(--near-black);
    line-height: 1.3;
    font-weight: normal;
}

.piece-card__price {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--as-purple-deep);
    font-family: var(--font-sans);
}

.piece-card__collection {
    font-size: 0.73rem;
    color: var(--mid-gray);
    font-family: var(--font-sans);
}

.piece-card__footer {
    padding: 0.65rem 1rem;
    border-top: 1px solid var(--pale-gray);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background: var(--off-white);
    flex-shrink: 0;
}

/* ============================================================
   Abstract Serenity — Virtual Shopping Session Cards
   ============================================================ */

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

.session-card {
    background: var(--white);
    border: 1.5px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: box-shadow var(--transition), border-color var(--transition);
}
.session-card:hover {
    box-shadow: var(--shadow-purple);
    border-color: var(--as-purple-lavender);
}
.session-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}
.session-card__name {
    font-family: var(--font-serif);
    font-size: 1rem;
    color: var(--near-black);
}
.session-card__meta {
    font-size: 0.8rem;
    color: var(--mid-gray);
    font-family: var(--font-sans);
    line-height: 1.6;
}

/* ============================================================
   Abstract Serenity — Public Header (centered logo treatment)
   ============================================================ */

.as-site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--white);
    border-bottom: 1px solid var(--pale-gray);
    box-shadow: var(--shadow-sm);
}

.as-site-header__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 2rem;
    gap: 1rem;
    min-height: 72px;
}

.as-site-header__logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    gap: 0.15rem;
    flex: 1;
    justify-content: center;
}
.as-site-header__logo:hover { text-decoration: none; }
.as-site-header__logo img {
    height: 44px;
    width: auto;
}
.as-site-header__logo-name {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    color: var(--near-black);
    letter-spacing: 0.04em;
}
.as-site-header__logo-tagline {
    font-size: 0.68rem;
    color: var(--as-purple-mid);
    font-family: var(--font-sans);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.as-site-header__side {
    min-width: 130px;
    display: flex;
    align-items: center;
}
.as-site-header__side--right {
    justify-content: flex-end;
    gap: 0.75rem;
}
.as-site-header__side--left {
    justify-content: flex-start;
}

.as-site-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.45rem 2rem;
    border-top: 1px solid var(--as-purple-faint);
    background: linear-gradient(to right, var(--white) 0%, var(--as-purple-faint) 50%, var(--white) 100%);
}

.as-site-nav a {
    font-size: 0.8rem;
    font-family: var(--font-sans);
    color: var(--dark-gray);
    padding: 0.3rem 0.9rem;
    border-radius: 999px;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
    letter-spacing: 0.025em;
}
.as-site-nav a:hover {
    background: var(--as-purple-faint);
    color: var(--as-purple-deep);
    text-decoration: none;
}
.as-site-nav a.active {
    background: var(--as-purple-faint);
    color: var(--as-purple-deep);
    font-weight: 500;
}

/* Minimal admin header (dark bar with purple accent) */
.as-admin-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 52px;
    background: var(--near-black);
    border-bottom: 2px solid var(--as-purple-deep);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
}
.as-admin-header__logo {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    flex: 1;
}
.as-admin-header__logo:hover { text-decoration: none; }
.as-admin-header__logo img {
    height: 26px;
    width: auto;
    filter: brightness(0) invert(1);
    opacity: 0.88;
}
.as-admin-header__logo-text {
    font-family: var(--font-serif);
    font-size: 0.98rem;
    color: rgba(255,255,255,0.82);
}
.as-admin-header__user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.45);
    font-family: var(--font-sans);
}
.as-admin-header__user a {
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    padding: 0.25rem 0.6rem;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    transition: background var(--transition), color var(--transition);
}
.as-admin-header__user a:hover {
    background: rgba(255,255,255,0.08);
    color: var(--white);
    text-decoration: none;
}

/* ============================================================
   Abstract Serenity — Site Content Editor
   ============================================================ */

.content-section-card {
    background: var(--white);
    border: 1px solid var(--pale-gray);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.content-section-card h3 {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: normal;
    color: var(--near-black);
    margin-bottom: 0.25rem;
}
.content-section-card .section-hint {
    font-size: 0.8rem;
    color: var(--mid-gray);
    margin-bottom: 0.85rem;
    font-family: var(--font-sans);
}

/* ============================================================
   Abstract Serenity — Responsive Adjustments
   ============================================================ */

@media (max-width: 768px) {
    .as-site-header__top { padding: 0.6rem 1rem; min-height: 64px; }
    .as-site-header__logo img { height: 34px; }
    .as-site-header__logo-name { font-size: 1rem; }
    .as-site-header__side { min-width: 80px; }
    .as-site-nav { padding: 0.4rem 0.75rem; overflow-x: auto; flex-wrap: nowrap; justify-content: flex-start; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .as-site-nav::-webkit-scrollbar { display: none; }
    .piece-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.85rem; }
    .session-grid { grid-template-columns: 1fr; }
}
