/* ══════════════════════════════════════════════════
   Jewel Studio — Design System v2
   Light theme, mobile-first, premium & simple
   ══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ──── CSS Variables ──── */
:root {
    --gold: #B8860B;
    --gold-light: #DAA520;
    --gold-dark: #8B6914;
    --gold-bg: rgba(184, 134, 11, 0.08);
    --gold-border: rgba(184, 134, 11, 0.2);

    --bg-primary: #FFFFFF;
    --bg-secondary: #F8F9FA;
    --bg-card: #FFFFFF;
    --bg-input: #F1F3F5;
    --bg-hover: #F0F0F0;

    --text-primary: #1A1A2E;
    --text-secondary: #495057;
    --text-muted: #868E96;
    --text-white: #FFFFFF;

    --border-color: #E9ECEF;
    --border-light: #F1F3F5;

    --success: #2ECC71;
    --error: #E74C3C;
    --warning: #F39C12;
    --info: #3498DB;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 100px;

    --nav-height: 56px;
    --bottom-nav-height: 60px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

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

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-dark); }

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

/* ──── Typography ──── */
h1, h2, h3 { font-weight: 700; color: var(--text-primary); line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }
.text-muted { color: var(--text-muted); }
.text-gold { color: var(--gold); }
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }

/* ──── Top Navigation ──── */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.top-nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.top-nav-brand img {
    height: 28px;
    width: auto;
    border-radius: 4px;
}

.top-nav-brand .brand-icon {
    font-size: 1.3rem;
}

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

/* ──── Bottom Navigation (Mobile) ──── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item .nav-icon { font-size: 1.3rem; }
.bottom-nav-item.active { color: var(--gold); }
.bottom-nav-item:hover { color: var(--gold); }

/* ──── Page Container ──── */
.page-container {
    padding-top: calc(var(--nav-height) + 12px);
    padding-bottom: calc(var(--bottom-nav-height) + 16px);
    padding-left: 16px;
    padding-right: 16px;
    max-width: 600px;
    margin: 0 auto;
    min-height: 100dvh;
}

/* ──── Cards ──── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body { padding: 16px; }

/* ──── Buttons ──── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-gold {
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    color: white;
    box-shadow: 0 2px 8px rgba(184,134,11,0.3);
}
.btn-gold:hover { box-shadow: 0 4px 16px rgba(184,134,11,0.4); }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 6px 10px;
}
.btn-ghost:hover { background: var(--bg-hover); }

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    border-radius: var(--radius-md);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-full);
    font-size: 1rem;
}

/* ──── Inputs ──── */
.input-group { margin-bottom: 14px; }
.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: border-color 0.2s;
    outline: none;
}

.input:focus { border-color: var(--gold); }
.input::placeholder { color: var(--text-muted); }

select.input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23868E96' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

textarea.input {
    resize: vertical;
    min-height: 80px;
}

/* ──── Pill Selector (Category/Design) ──── */
.pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.pill:hover { border-color: var(--gold-border); }
.pill.active {
    background: var(--gold-bg);
    border-color: var(--gold);
    color: var(--gold-dark);
    font-weight: 600;
}

.pill .pill-icon { font-size: 1rem; }

/* ──── Design Cards (Horizontal Scroll) ──── */
.design-scroll {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0;
    scrollbar-width: none;
}
.design-scroll::-webkit-scrollbar { display: none; }

.design-card {
    flex: 0 0 120px;
    scroll-snap-align: start;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.design-card:hover { border-color: var(--gold-border); }
.design-card.active { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-bg); }

.design-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.design-card .design-name {
    padding: 6px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: var(--bg-secondary);
}

/* ──── Option Chips (Resolution, Ratio) ──── */
.chip-group {
    display: flex;
    gap: 6px;
}

.chip {
    flex: 1;
    padding: 8px;
    text-align: center;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.chip.active {
    background: var(--gold-bg);
    border-color: var(--gold);
    color: var(--gold-dark);
}

/* ──── Upload Area ──── */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: var(--bg-secondary);
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--gold);
    background: var(--gold-bg);
}

.upload-area .upload-icon { font-size: 2rem; margin-bottom: 8px; }
.upload-area .upload-text { font-size: 0.85rem; color: var(--text-muted); }
.upload-area .upload-count {
    margin-top: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gold);
}

.upload-preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.upload-thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border-color);
}

.upload-thumb-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--error);
    color: white;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
}

.upload-thumb-wrapper {
    position: relative;
    display: inline-block;
}

/* ──── Toggle ──── */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-color);
    border-radius: 24px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 3px;
    left: 3px;
    transition: transform 0.3s;
    box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider { background: var(--gold); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ──── Badges ──── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-gold { background: var(--gold-bg); color: var(--gold-dark); }
.badge-success { background: rgba(46,204,113,0.1); color: #27ae60; }
.badge-error { background: rgba(231,76,60,0.1); color: #c0392b; }
.badge-info { background: rgba(52,152,219,0.1); color: #2980b9; }
.badge-processing { background: rgba(243,156,18,0.1); color: #e67e22; }

/* ──── Stats Row ──── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
}

.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--gold); }
.stat-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

/* ──── Job List ──── */
.job-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.15s;
}

.job-item:hover { background: var(--bg-secondary); }
.job-item:last-child { border-bottom: none; }

.job-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--gold-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.job-info { flex: 1; min-width: 0; }
.job-title { font-size: 0.85rem; font-weight: 600; }
.job-meta { font-size: 0.75rem; color: var(--text-muted); }

/* ──── Image Grid (Results) ──── */
.image-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.image-grid-item {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.image-grid-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.image-grid-item .image-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.image-grid-item .image-status {
    position: absolute;
    top: 8px;
    left: 8px;
}

/* ──── Progress Bar ──── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--gold-light));
    border-radius: 3px;
    transition: width 0.5s;
}

/* ──── Toast ──── */
.toast-container {
    position: fixed;
    top: calc(var(--nav-height) + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 400px;
    pointer-events: none;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideDown 0.3s;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-success { background: #2ECC71; color: white; }
.toast-error { background: #E74C3C; color: white; }
.toast-info { background: #3498DB; color: white; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ──── Modal ──── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: none;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 85dvh;
    overflow-y: auto;
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 1;
}

.modal-body { padding: 16px; }

.modal-footer {
    display: flex;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
    background: var(--bg-primary);
}

.modal-footer .btn { flex: 1; }

/* ──── Auth Page ──── */
.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg-secondary);
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.auth-header {
    text-align: center;
    padding: 32px 24px 24px;
}

.auth-logo { font-size: 2.5rem; margin-bottom: 8px; }
.auth-title { font-size: 1.5rem; font-weight: 700; }
.auth-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: 12px;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.auth-tab.active {
    color: var(--gold);
    border-bottom-color: var(--gold);
}

.auth-body { padding: 24px; }
.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-footer {
    text-align: center;
    padding: 16px 24px 24px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ──── Section Header ──── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

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

/* ──── Data Table ──── */
.data-table { overflow-x: auto; }

.data-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

/* ──── Empty State ──── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-icon { font-size: 2.5rem; margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 1rem; margin-bottom: 4px; color: var(--text-secondary); }
.empty-state p { font-size: 0.85rem; }

/* ──── Spinner ──── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.spinner-gold { border: 2px solid var(--gold-bg); border-top-color: var(--gold); }

/* ──── Admin Tabs ──── */
.admin-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.admin-tabs::-webkit-scrollbar { display: none; }

.admin-tab {
    padding: 8px 14px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-input);
    border: 1.5px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    font-family: inherit;
}

.admin-tab.active {
    background: var(--gold-bg);
    border-color: var(--gold);
    color: var(--gold-dark);
}

.admin-panel { display: none; }
.admin-panel.active { display: block; }

/* ──── Logo Toggle ──── */
.logo-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ──── Lightbox ──── */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.lightbox.active { display: flex; }

.lightbox img {
    max-width: 100%;
    max-height: 90dvh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ──── Section Divider ──── */
.divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

/* ──── Generating Animation ──── */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.generating { animation: pulse 1.5s infinite; }

/* ──── Responsive: Tablet+ ──── */
@media (min-width: 768px) {
    .page-container {
        max-width: 700px;
        padding-left: 24px;
        padding-right: 24px;
    }

    .bottom-nav { display: none; }

    .page-container {
        padding-bottom: 24px;
    }

    .image-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .modal {
        border-radius: var(--radius-lg);
        max-width: 500px;
        margin-bottom: 10vh;
    }

    .modal-overlay {
        align-items: center;
    }

    .stats-row {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ──── PWA Standalone Mode ──── */
@media (display-mode: standalone) {
    .top-nav {
        padding-top: env(safe-area-inset-top, 0);
        height: calc(var(--nav-height) + env(safe-area-inset-top, 0));
    }
}

/* ──── Utility ──── */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.w-full { width: 100%; }
