/* App shell: sidebar, topbar, page container and the grid helpers views use. */

.shell {
    display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh;
    transition: grid-template-columns var(--t-slow) var(--ease-out);
}
.shell.rail { grid-template-columns: var(--sidebar-rail) minmax(0, 1fr); }

/* ---------- Sidebar ---------- */

.sidebar {
    position: sticky; top: 0; height: 100vh; z-index: 30;
    display: flex; flex-direction: column; gap: 14px;
    padding: 18px 12px 14px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, .03);
    backdrop-filter: blur(24px) saturate(1.7);
    -webkit-backdrop-filter: blur(24px) saturate(1.7);
    overflow: hidden;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px 6px; min-height: 48px; }
.brand:hover { text-decoration: none; }
.brand-logo {
    width: 40px; height: 40px; border-radius: 50%; flex: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .08), 0 6px 20px rgba(110, 90, 255, .35);
    transition: transform var(--t-slow) var(--ease-spring);
}
.brand:hover .brand-logo { transform: rotate(-8deg) scale(1.06); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.brand-name {
    font-family: var(--brand); font-weight: 700; font-size: 16px; letter-spacing: -.01em; color: var(--text);
}
.brand-sub { font-size: 10px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: var(--faint); }

.sidebar nav {
    position: relative; flex: 1; overflow-y: auto; overflow-x: hidden;
    display: flex; flex-direction: column; gap: 16px; padding: 2px; margin: 0 -2px;
    scrollbar-width: none;
}
.sidebar nav::-webkit-scrollbar { display: none; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-heading {
    font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--faint);
    padding: 0 12px 4px; white-space: nowrap; height: 18px;
    transition: opacity var(--t) var(--ease-out);
}
.sidebar nav a {
    position: relative; z-index: 1;
    display: flex; align-items: center; gap: 12px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    color: var(--muted); font-weight: 600; white-space: nowrap;
    transition: color var(--t-fast), background var(--t-fast);
}
.sidebar nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { color: var(--text); background: transparent; }
.nav-icon {
    display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: none;
    background: var(--surface-2); color: var(--muted);
    transition: background var(--t) var(--ease-out), color var(--t), transform var(--t) var(--ease-spring), box-shadow var(--t);
}
.sidebar nav a:hover .nav-icon { transform: scale(1.06); color: var(--text); }
.sidebar nav a.active .nav-icon { background: var(--nebula); color: #fff; box-shadow: 0 4px 14px rgba(110, 100, 255, .45); }
.nav-label { overflow: hidden; text-overflow: ellipsis; transition: opacity var(--t) var(--ease-out); }
.nav-badge {
    margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
    display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
    color: #fff; background: var(--nebula); box-shadow: 0 2px 8px rgba(110, 100, 255, .35);
    animation: pop-in var(--t) var(--ease-spring);
}
/* On the icon rail the count shrinks to a dot on the icon. */
.shell.rail .nav-badge { position: absolute; left: 34px; top: 5px; min-width: 9px; height: 9px; padding: 0; font-size: 0; }

/* A soft pill that slides between items as the page changes (positioned in JS). */
.nav-indicator {
    position: absolute; left: 2px; right: 2px; top: 0; height: 0; z-index: 0;
    border-radius: var(--radius-sm); background: var(--glass), var(--nebula-soft);
    box-shadow: inset 0 0 0 1px var(--border-strong), inset 0 1px 0 var(--glass-edge), 0 6px 20px rgba(110, 100, 255, .18);
    transition: transform var(--t-slow) var(--ease-out), height var(--t-slow) var(--ease-out), opacity var(--t);
    pointer-events: none;
}
.nav-indicator::before {
    content: ""; position: absolute; left: -2px; top: 22%; bottom: 22%; width: 3px; border-radius: 99px; background: var(--nebula);
}

.me {
    display: flex; align-items: center; gap: 10px; padding: 9px;
    border-radius: var(--radius); background: var(--glass), var(--surface-2); border: 1px solid var(--border);
    box-shadow: inset 0 1px 0 var(--glass-edge);
    white-space: nowrap;
}
.me img { width: 34px; height: 34px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--border-strong); }
.me > div { flex: 1; min-width: 0; }
.me-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.tier {
    display: inline-block; font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em;
    padding: 1px 7px; border-radius: 99px; background: var(--surface-3); color: var(--muted);
}
.tier-admin { color: var(--gold); background: rgba(247, 201, 92, .12); }
.tier-staff { color: var(--violet); background: rgba(167, 139, 250, .14); }
.tier-support { color: var(--sky); background: rgba(124, 196, 250, .13); }

.rail-toggle { align-self: flex-end; }

/* Icon rail: labels fade out, the column narrows, tooltips take over. */
.shell.rail .sidebar { padding-left: 14px; padding-right: 14px; }
.shell.rail .brand-text,
.shell.rail .nav-label,
.shell.rail .me > div,
.shell.rail .me .icon-btn { opacity: 0; pointer-events: none; }
.shell.rail .nav-heading { opacity: 0; height: 6px; padding: 0; }
.shell.rail .me { padding: 6px; border-color: transparent; background: none; }
.shell.rail .rail-toggle { align-self: center; }
.shell.rail .rail-toggle .ico { transform: scaleX(-1); }
.brand-text, .nav-label, .me > div, .me .icon-btn { transition: opacity var(--t) var(--ease-out); }

/* ---------- Topbar ---------- */

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 15;
    display: flex; align-items: center; gap: 12px;
    padding: 14px 34px; min-height: 68px;
    background: var(--topbar);
    backdrop-filter: blur(20px) saturate(1.7);
    -webkit-backdrop-filter: blur(20px) saturate(1.7);
    border-bottom: 1px solid transparent;
    transition: border-color var(--t), box-shadow var(--t);
}
.topbar.scrolled { border-bottom-color: var(--border); box-shadow: 0 10px 30px rgba(3, 4, 18, .18); }
.crumbs { display: flex; flex-direction: column; min-width: 0; }
.crumb-group { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); }
.topbar h1 { font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.search-trigger {
    display: inline-flex; align-items: center; gap: 10px; min-width: 240px;
    padding: 8px 10px 8px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--glass), var(--surface-2); color: var(--faint); box-shadow: inset 0 1px 0 var(--glass-edge);
    font: inherit; font-weight: 500; cursor: pointer;
    transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast), box-shadow var(--t);
}
.search-trigger:hover { border-color: var(--border-strong); color: var(--muted); background: var(--surface-3); }
.search-trigger .kbd { margin-left: auto; }
.kbd {
    display: inline-flex; align-items: center; gap: 2px;
    font: 600 11px/1 var(--mono); color: var(--muted);
    padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2);
}

.live-dot {
    position: relative; display: inline-flex; align-items: center; gap: 7px;
    font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 8px;
}
.live-dot i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(94, 230, 160, .6); animation: pulse 2.4s infinite; }
.live-dot.off i { background: var(--warn); animation: none; }

.page-wrap { padding: 8px 34px 64px; flex: 1; }

.icon-btn.menu { display: none; }
.scrim { display: none; }

/* ---------- Grids views use ---------- */

.stack { display: flex; flex-direction: column; gap: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-2.top { align-items: start; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* ---------- Small screens: sidebar becomes a drawer ---------- */

@media (max-width: 1100px) { .search-trigger { min-width: 0; } .search-trigger .label, .search-trigger .kbd { display: none; } }

@media (max-width: 960px) {
    .shell, .shell.rail { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: fixed; left: 0; top: 0; width: min(var(--sidebar-w), 86vw);
        transform: translateX(-104%); transition: transform var(--t-slow) var(--ease-out), box-shadow var(--t-slow);
        background: var(--surface-solid);
    }
    .shell.rail .sidebar .brand-text, .shell.rail .sidebar .nav-label,
    .shell.rail .sidebar .me > div, .shell.rail .sidebar .me .icon-btn, .shell.rail .sidebar .nav-heading { opacity: 1; pointer-events: auto; }
    .shell.rail .nav-heading { height: 18px; padding: 0 12px 4px; }
    .rail-toggle { display: none; }
    .shell.rail .nav-badge { position: static; min-width: 20px; height: 20px; padding: 0 6px; font-size: 11px; }
    .nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
    .scrim {
        display: block; position: fixed; inset: 0; z-index: 25; background: rgba(4, 5, 16, .55);
        backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: opacity var(--t-slow) var(--ease-out);
    }
    .nav-open .scrim { opacity: 1; pointer-events: auto; }
    .icon-btn.menu { display: inline-grid; }
    .topbar { padding: 10px 16px; min-height: 60px; }
    .topbar h1 { font-size: 19px; }
    .crumb-group, .live-dot span { display: none; }
    .page-wrap { padding: 6px 16px 48px; }
    .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- First paint while /me loads ---------- */

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { width: 72px; height: 72px; border-radius: 50%; box-shadow: 0 0 60px rgba(var(--accent-rgb), .5); animation: float 2.4s ease-in-out infinite, fade-in .6s var(--ease-out); }
.page-wrap:focus { outline: none; }
.stack > .seg { align-self: flex-start; }

/* ---------- Installed app: keep clear of the notch and home bar ---------- */

@media (display-mode: standalone) {
    .topbar { padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
    .sidebar { padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom)); }
    .page-wrap { padding-bottom: max(48px, calc(env(safe-area-inset-bottom) + 24px)); }
    .toasts { bottom: max(16px, env(safe-area-inset-bottom)); }
}
