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

:root {
    --bg: #0b0d12;
    --bg-elevated: #12151c;
    --bg-card: #161a22;
    --bg-hover: #1c212b;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #f3f5f9;
    --text-muted: #9aa3b2;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-soft: rgba(99, 102, 241, 0.15);
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --sidebar-w: 260px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

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

/* ── Guest (login, invite) ── */
body.guest {
    background:
        radial-gradient(ellipse 80% 60% at 20% 0%, rgba(99, 102, 241, 0.18), transparent),
        radial-gradient(ellipse 60% 50% at 80% 100%, rgba(139, 92, 246, 0.12), transparent),
        var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1.5rem, env(safe-area-inset-top)) max(1.5rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
}

.guest-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.guest-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.5rem;
}

.guest-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: grid;
    place-items: center;
    font-size: 1.25rem;
}

.guest-brand h1 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.guest-brand p {
    margin: .125rem 0 0;
    font-size: .8125rem;
    color: var(--text-muted);
}

/* ── App shell ── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: grid;
    place-items: center;
    font-size: 1.1rem;
}

.sidebar-brand-text strong {
    display: block;
    font-size: .9375rem;
    font-weight: 600;
}

.sidebar-brand-text span {
    font-size: .75rem;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: .75rem .5rem;
    overflow-y: auto;
}

.nav-section {
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: .75rem .75rem .375rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .625rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: .875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent-hover);
}

.nav-link svg {
    width: 18px;
    height: 18px;
    opacity: .85;
}

.sidebar-user {
    padding: .75rem;
    border-top: 1px solid var(--border);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .625rem;
    border-radius: var(--radius-sm);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    display: grid;
    place-items: center;
    font-size: .75rem;
    font-weight: 600;
    color: #fff;
}

.user-meta {
    flex: 1;
    min-width: 0;
}

.user-meta strong {
    display: block;
    font-size: .8125rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta span {
    font-size: .6875rem;
    color: var(--text-muted);
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 56px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: rgba(11, 13, 18, 0.8);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-title {
    font-size: .9375rem;
    font-weight: 600;
    margin: 0;
}

.page-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1200px;
    width: 100%;
}

/* ── Cards & content ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card h1, .card h2 {
    margin: 0 0 .5rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.card p { color: var(--text-muted); margin: 0 0 1rem; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color .15s;
}

.stat-card:hover { border-color: var(--border-strong); }

.stat-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    margin-bottom: .75rem;
    font-size: 1.1rem;
}

.stat-card-icon.purple { background: rgba(99, 102, 241, 0.15); }
.stat-card-icon.green { background: rgba(34, 197, 94, 0.15); }
.stat-card-icon.blue { background: rgba(59, 130, 246, 0.15); }

.stat-card h3 {
    margin: 0 0 .25rem;
    font-size: .9375rem;
    font-weight: 600;
}

.stat-card p {
    margin: 0;
    font-size: .8125rem;
    color: var(--text-muted);
}

/* ── Forms ── */
label, .form-label {
    display: block;
    margin: .75rem 0 .375rem;
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select,
.form-control {
    width: 100%;
    max-width: 400px;
    padding: .625rem .875rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    transition: border-color .15s, box-shadow .15s;
}

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

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

/* ── Buttons ── */
.btn, button[type="submit"] {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    padding: .5625rem 1rem;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, transform .1s;
}

.btn:hover, button[type="submit"]:hover {
    background: var(--accent-hover);
    text-decoration: none;
    color: #fff;
}

.btn-secondary {
    background: var(--bg-hover);
    border: 1px solid var(--border-strong);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--bg-card);
    color: var(--text);
}

/* ── Table ── */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

th, td {
    text-align: left;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    background: var(--bg-elevated);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

.badge {
    display: inline-block;
    padding: .2rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 500;
}

.badge-success { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.badge-muted { background: rgba(154, 163, 178, 0.15); color: var(--text-muted); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-warning { background: rgba(234, 179, 8, 0.15); color: #facc15; }

.alert {
    padding: .875rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.alert-warning {
    background: rgba(234, 179, 8, 0.08);
    border-color: rgba(234, 179, 8, 0.25);
    color: var(--text);
}

.text-muted { color: var(--text-muted); }

.btn-sm { padding: .35rem .65rem; font-size: .8125rem; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-3); }

/* ── Flash ── */
.flash {
    padding: .875rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: .875rem;
    border: 1px solid transparent;
}

.flash-success { background: rgba(34, 197, 94, 0.1); border-color: rgba(34, 197, 94, 0.25); color: #86efac; }
.flash-danger { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.25); color: #fca5a5; }
.flash-warning { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.25); color: #fcd34d; }

.error { color: var(--danger); font-size: .875rem; }

/* ── Agent full page ── */
.agent-page .card {
    padding: 0;
    overflow: hidden;
    min-height: calc(100vh - 8rem);
}

.agent-page .dev-agent-layout {
    min-height: calc(100vh - 8rem);
}

/* ── Mobile utilities ── */
.mobile-only { display: none; }

/* ── Mobile bottom nav ── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

.mobile-bottom-nav-row {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
}

.mobile-bottom-nav-link {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    min-height: 56px;
    padding: .5rem .25rem .375rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: .6875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: color .15s, background .15s;
}

.mobile-bottom-nav-link svg {
    width: 22px;
    height: 22px;
}

.mobile-bottom-nav-link.active {
    color: var(--accent-hover);
    background: var(--accent-soft);
}

.mobile-bottom-nav-link:active {
    background: var(--bg-hover);
}

/* ── Mobile drawer ── */
.mobile-drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 48;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
}

.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-right: .5rem;
    margin-left: -.5rem;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.mobile-menu-btn svg {
    width: 22px;
    height: 22px;
}

.mobile-menu-btn:active {
    background: var(--bg-hover);
}

.topbar-start {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
}

/* ── Mobile ── */
@media (max-width: 768px) {
    .mobile-only,
    .mobile-menu-btn,
    .mobile-bottom-nav {
        display: flex;
    }

    .mobile-bottom-nav-row {
        width: 100%;
    }

    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(300px, 88vw);
        height: 100%;
        height: 100dvh;
        transform: translateX(-105%);
        transition: transform .22s ease;
        z-index: 50;
        box-shadow: var(--shadow);
    }

    body.mobile-drawer-open .sidebar {
        transform: translateX(0);
    }

    body.mobile-drawer-open .mobile-drawer-overlay {
        display: block;
    }

    .topbar {
        padding: 0 1rem;
        padding-top: env(safe-area-inset-top, 0px);
        height: auto;
        min-height: 56px;
    }

    .page-content {
        padding: 1rem;
        padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    }

    .agent-page .card {
        min-height: calc(100dvh - 8rem - env(safe-area-inset-bottom, 0px));
    }

    /* FAB above bottom nav */
    .dev-agent-fab {
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px)) !important;
    }
}
