/* ── Variables ─────────────────────────────────────────── */
:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-card-hover: #22263a;
    --border: #2a2e3f;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ── App Shell ────────────────────────────────────────── */
.app-shell {
    display: grid;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-columns: 1fr;
    min-height: 100vh;
}

/* ── Top Bar ──────────────────────────────────────────── */
.top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--topbar-height);
}
.top-bar-title { font-weight: 600; font-size: 1.1rem; }
.tenant-select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 10px;
    font-size: 0.85rem;
    font-family: var(--font);
    cursor: pointer;
    max-width: 200px;
}
.tenant-select:focus { outline: none; border-color: var(--primary); }

/* ── Project Switcher ─────────────────────────────────── */
.project-switcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.project-switcher:hover { background: var(--bg-card-hover); }
.project-switcher-name {
    font-weight: 600;
    font-size: 1.05rem;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.project-switcher-chevron {
    transition: transform 0.2s ease;
    color: var(--text-muted);
    flex-shrink: 0;
}
.project-switcher-chevron.open { transform: rotate(180deg); }
.project-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 220px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 200;
    padding: 6px;
    animation: dropdownFadeIn 0.15s ease;
}
@@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.project-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.88rem;
    font-family: var(--font);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
}
.project-dropdown-item:hover { background: var(--bg-card-hover); }
.project-dropdown-item.active { color: var(--primary); }
.project-dropdown-item.active:hover { background: rgba(99,102,241,0.1); }
.menu-toggle {
    background: none; border: none; color: var(--text); cursor: pointer;
    padding: 4px; display: flex; align-items: center;
}
.user-info {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
}
.user-name { color: var(--text-muted); }
.btn-link {
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}
.btn-link:hover { color: var(--primary); }

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: -var(--sidebar-width);
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 90;
    overflow-y: auto;
    padding: 16px 0;
}
.sidebar-open .sidebar { transform: translateX(0); }
.sidebar-overlay {
    position: fixed;
    inset: 0;
    top: var(--topbar-height);
    background: rgba(0,0,0,0.5);
    z-index: 80;
}
.sidebar-header { padding: 0 16px 16px; }
.logo { font-weight: 700; font-size: 1.2rem; color: var(--primary); }
.nav-list { list-style: none; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
    border-radius: 0;
}
.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.logo-icon {
    width: 20px;
    height: 20px;
    stroke: var(--primary);
    vertical-align: middle;
    margin-right: 2px;
}
.nav-item:hover { background: var(--bg-card-hover); color: var(--text); }
.nav-item.active { color: var(--primary); background: rgba(99,102,241,0.1); border-right: 3px solid var(--primary); }
.nav-btn {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-family: var(--font);
    font-size: 0.9rem;
}
.nav-divider { height: 1px; background: var(--border); margin: 8px 16px; }

/* ── Main Content ─────────────────────────────────────── */
.main-content {
    padding: 20px 16px;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.card-title { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.card-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.card-subtitle { font-size: 0.8rem; color: var(--text-dim); margin-top: 4px; }

/* ── Stat Grid ─────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg-card-hover); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-google {
    background: white;
    color: #333;
    font-weight: 500;
    padding: 12px 24px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
    width: 100%;
    max-width: 320px;
}
.btn-google:hover { background: #f1f1f1; color: #333; }
.btn-block { width: 100%; }

/* ── Tables ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:hover td { background: var(--bg-card-hover); }

/* ── Badges ───────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-muted { background: rgba(100,116,139,0.15); color: var(--text-dim); }

/* ── Forms ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.form-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
}
.form-input:focus { outline: none; border-color: var(--primary); }

/* ── Key Display ──────────────────────────────────────── */
.key-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    word-break: break-all;
}
.key-display .key-value { flex: 1; color: var(--text-muted); }

/* ── Progress Bar ─────────────────────────────────────── */
.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 8px;
}
.progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* ── Login Page ───────────────────────────────────────── */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    text-align: center;
    background: var(--bg);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 32px;
    max-width: 400px;
    width: 100%;
}
.login-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 32px; font-size: 0.9rem; }

/* ── Page Headers ─────────────────────────────────────── */
.page-header { margin-bottom: 24px; }
.page-title { font-size: 1.4rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }

/* ── Alerts ───────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
}
.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--success); }
.alert-danger { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }

/* ── Playground Upload ─────────────────────────────────── */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    overflow: hidden;
    background: var(--bg);
}
.upload-zone:hover { border-color: var(--primary); background: rgba(99,102,241,0.05); }
.upload-zone.has-preview { border-style: solid; }
.upload-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-icon { width: 40px; height: 40px; color: var(--text-dim); margin-bottom: 8px; stroke-linecap: round; stroke-linejoin: round; }
.upload-label { font-size: 0.85rem; color: var(--text-dim); }
.upload-preview { width: 100%; height: 100%; object-fit: cover; }
.upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.15s;
}
.upload-zone:hover .upload-overlay { opacity: 1; }

/* ── Indeterminate Progress ───────────────────────────── */
.progress-indeterminate {
    width: 30% !important;
    animation: indeterminate 1.4s ease-in-out infinite;
}
@@keyframes indeterminate {
    0%   { margin-left: 0; width: 30%; }
    50%  { margin-left: 35%; width: 30%; }
    100% { margin-left: 70%; width: 30%; }
}

/* ── Code Block ───────────────────────────────────────── */
.code-block {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ── Desktop ──────────────────────────────────────────── */
@@media (min-width: 768px) {
    .app-shell {
        grid-template-columns: var(--sidebar-width) 1fr;
    }
    .sidebar {
        position: sticky;
        transform: translateX(0);
        top: var(--topbar-height);
    }
    .sidebar-overlay { display: none; }
    .menu-toggle { display: none; }
    .top-bar { grid-column: 1 / -1; }
    .main-content { padding: 28px 32px; }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Credit Packages ──────────────────────────────────── */
.packages-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 20px;
}
.package-card {
    position: relative;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.package-card:hover {
    border-color: var(--primary);
    background: var(--bg-card-hover);
}
.package-card:active { transform: scale(0.98); }
.package-selected {
    border-color: var(--primary) !important;
    background: rgba(99,102,241,0.08) !important;
    box-shadow: 0 0 0 1px var(--primary);
}
.package-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 12px;
    border-radius: 999px;
}
.package-credits {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
}
.package-credits-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.package-price {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
}
.package-per-credit {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 4px;
}
.package-images {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.btn-lg {
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
}

@@media (min-width: 768px) {
    .packages-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@@media (min-width: 1024px) {
    .packages-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
