/* The BEAM site's layout and tokens, shared by Home (/) and Usage (/dashboard/): a top bar, a side menu (when there
   is more than Home), the page, and a centred card for signing in. Light looks like MKS's portal (api-dev): grey
   page, white cards, hairline borders, deep blue buttons; dark follows data-theme on <html> (theme.js).
   Plain CSS, no build step. */

:root {
    --blue: #1db7f1;
    --blue-dark: #0a77a6;
    --button: #1db7f1;
    --button-hover: #0ea5d9;
    --blue-wash: rgba(29, 183, 241, 0.1);
    --blue-line: rgba(10, 119, 166, 0.35);
    --accent-text: #0e8fbf;
    --ink: #111114;
    --ink-2: #3a3a42;
    --ink-3: #66666e;
    --line: rgba(0, 0, 0, 0.07);
    --grid: #ebebee;
    --surface: #ffffff;
    --surface-2: #fbfbfd;
    --page: #f5f5f7;
    --panel: rgba(251, 251, 253, 0.92);
    --backdrop: rgba(0, 0, 0, 0.035);
    --mark: #0a77a6;
    --error: #b42318;
    --error-wash: #fdecec;
    --good: #166534;
    --good-wash: #ecfdf3;
    --warn: #8a4b0a;
    --warn-wash: #fff4e5;
    --trial: #5b21b6;
    --trial-wash: #f3eefe;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    --lift: 0 24px 60px -24px rgba(22, 32, 48, 0.3);
    --radius: 10px;

    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
    --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

    color-scheme: light;
}

:root[data-theme="dark"] {
    --blue-dark: #33bff2;
    --button: #1597cc;
    --button-hover: #33bff2;
    --surface-2: #1d252e;
    --trial: #c4b5fd;
    --trial-wash: rgba(124, 58, 237, 0.18);
    --blue-wash: #10303d;
    --blue-line: rgba(51, 191, 242, 0.4);
    --accent-text: #4cc8f4;
    --ink: #e8edf2;
    --ink-2: #b4bfca;
    --ink-3: #8794a1;
    --line: #2b3540;
    --grid: #252e38;
    --surface: #1a2129;
    --page: #12171d;
    --panel: rgba(22, 28, 35, 0.9);
    --backdrop: rgba(120, 200, 240, 0.05);
    --mark: #2bb8ec;
    --error: #ef7a7a;
    --error-wash: rgba(239, 122, 122, 0.12);
    --good: #6fd08a;
    --good-wash: rgba(111, 208, 138, 0.12);
    --warn: #f5b947;
    --warn-wash: rgba(245, 185, 71, 0.12);
    --shadow: 0 12px 32px -18px rgba(0, 0, 0, 0.6);
    --lift: 0 24px 60px -24px rgba(0, 0, 0, 0.7);

    color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--page);
    color: var(--ink);
    font: 14px/1.5 var(--sans);
    letter-spacing: -0.006em;
    -webkit-font-smoothing: antialiased;
}

/* A faint grid behind the top of the page, as on Rhino Sync's account pages */
body::before {
    content: "";
    position: fixed; inset: 0; z-index: -1; pointer-events: none;
    background-image:
        linear-gradient(var(--backdrop) 1px, transparent 1px),
        linear-gradient(90deg, var(--backdrop) 1px, transparent 1px);
    background-size: 64px 64px;
    -webkit-mask-image: radial-gradient(120% 70% at 50% 0%, #000 15%, transparent 70%);
            mask-image: radial-gradient(120% 70% at 50% 0%, #000 15%, transparent 70%);
}

h1, h2 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent-text); }

.icon { flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.caption {
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.error { color: var(--error); }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- buttons ---------- */

.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 34px;
    padding: 0 14px;
    color: var(--ink);
    font: inherit; font-weight: 600;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}
.button:hover { border-color: var(--blue); }
.button:disabled { opacity: 0.45; cursor: default; }
.button.primary { color: #fff; background: var(--button); border-color: var(--button); box-shadow: 0 1px 2px rgba(29, 183, 241, .22), 0 4px 12px -6px rgba(29, 183, 241, .40); transition: transform .18s cubic-bezier(.2, .7, .3, 1), background .18s, box-shadow .18s; }
.button.primary:hover { background: var(--button-hover); border-color: var(--button-hover); transform: translateY(-1px); box-shadow: 0 1px 3px rgba(29, 183, 241, .28), 0 6px 16px -6px rgba(29, 183, 241, .48); }
.button.small { min-height: 28px; padding: 0 10px; font-size: 12px; }
.button.large { min-height: 44px; padding: 0 18px; border-radius: 10px; }
.button .icon { width: 16px; height: 16px; }

/* ---------- gate: loading, signed out, sign-in errors ---------- */

.gate {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: calc(100% - 32px); max-width: 440px; max-height: calc(100% - 32px);
    overflow-y: auto;
    display: flex; flex-direction: column; align-items: center; gap: 14px;
    padding: 36px 32px 32px;
    text-align: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-top: 3px solid var(--blue);
    border-radius: 16px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--lift);
}
.gate-logo { width: 72px; height: 72px; display: block; }
.gate h1 { font-size: 22px; letter-spacing: -0.02em; line-height: 1.2; }
.gate .error { overflow-wrap: anywhere; }
.gate .button { width: 100%; }

/* ---------- shell ---------- */

.shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "top top" "side page";
    min-height: 100vh;
}

.top {
    grid-area: top;
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 16px;
    min-height: 59px;
    padding: 10px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; border-radius: 8px; }
.brand img { width: 30px; height: 30px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.06em; color: var(--blue); }
.brand-area { font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); }

.team-chip {
    margin-left: 8px;
    padding: 4px 10px;
    font-size: 13px; font-weight: 500;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 260px;
}
.team-chip:empty { display: none; }

.top-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; min-width: 0; }
.top-tools .account-menu { margin-left: 4px; }

.icon-button {
    display: grid; place-items: center;
    width: 34px; height: 34px;
    padding: 0;
    color: var(--ink-2);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
}
.icon-button:hover { color: var(--ink); background: var(--blue-wash); border-color: var(--line); }
:root[data-theme="dark"] .icon-button .moon, :root:not([data-theme="dark"]) .icon-button .sun { display: none; }

.side {
    grid-area: side;
    position: sticky; top: 59px;
    align-self: start;
    display: flex; flex-direction: column; gap: 2px;
    padding: 18px 12px;
}
.side a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    color: var(--ink-2);
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 10px;
}
.side a:hover { color: var(--ink); background: var(--surface); border-color: var(--line); }
.side a[aria-current="page"] { color: var(--ink); background: var(--blue-wash); border-color: var(--blue-line); }
.side a[aria-current="page"] .icon { color: var(--accent-text); }

.page { grid-area: page; width: 100%; max-width: 1080px; padding: 30px 36px 56px; position: relative; isolation: isolate; }

/* Hairline page rails either side of the content, as MKS's old portal */
.page::before, .page::after { content: ""; position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); pointer-events: none; z-index: -1; }
.page::before { left: 12px; }
.page::after { right: 12px; }
.page.wide { max-width: 1300px; }
.page > h1 { font-size: 26px; letter-spacing: -0.03em; line-height: 1.2; margin-bottom: 24px; }

/* ---------- cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.cards > .card { display: flex; flex-direction: column; gap: 10px; padding: 20px 22px; min-width: 0; }
.cards > .card.wide { grid-column: 1 / -1; }
.card .value { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; overflow-wrap: anywhere; }
.card .value.quiet { color: var(--ink-3); }
.card .note { color: var(--ink-3); font-size: 13px; overflow-wrap: anywhere; }
.card .error { font-size: 13px; overflow-wrap: anywhere; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.rows { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 18px; margin: 0; font-size: 13.5px; }
.rows dt { color: var(--ink-3); }
.rows dd { margin: 0; overflow-wrap: anywhere; }

.pill {
    align-self: flex-start;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 10px;
    font-size: 12px; font-weight: 600;
    color: var(--ink-2);
    border: 1px solid var(--line);
    border-radius: 999px;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.good { color: var(--good); background: var(--good-wash); border-color: transparent; }
.pill.bad { color: var(--error); background: var(--error-wash); border-color: transparent; }
.pill.warn { color: var(--warn); background: var(--warn-wash); border-color: transparent; }
.pill.info { color: var(--accent-text); background: var(--blue-wash); border-color: var(--blue-line); }

.meter { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 4px; background: var(--blue); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-top: 3px solid var(--blue); border-radius: var(--radius); }
.stat-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { color: var(--ink-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- only Home: no side menu, the page centred ---------- */

.shell.solo { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "page"; }
.shell.solo .side { display: none; }
.shell.solo .page { justify-self: center; }

/* ---------- home: the portal's overview ---------- */

.overview { display: block; min-width: 0; }
.overview .stat { background: var(--surface); box-shadow: var(--shadow); }
.overview .stats > .skeleton { border-radius: var(--radius); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 28px 0 12px; }
.section-head.first { margin-top: 0; }
.section-head h2 { font-size: 17px; letter-spacing: -0.015em; }
.section-head a { font-size: 13.5px; text-decoration: none; }


.tile {
    display: flex; flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.tile-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; }
.tile-logo { width: 52px; height: 52px; flex: none; display: block; }
.tile-title { flex: 1; min-width: 0; display: grid; gap: 1px; }
.tile-name { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; color: var(--blue); }
.tile-plan { color: var(--ink); }
.tile-plan.free { color: var(--ink-3); }
.tile-name.none { color: var(--ink); font-size: 17px; }
.tile-sub { font-size: 13.5px; color: var(--ink-2, var(--ink-3)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-body { display: grid; gap: 10px; padding: 14px 18px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }
.tile-body .rows { font-size: 13px; }
/* MKS didn't answer: the card faded, its logo grey */
.tile.unavailable { border-style: dashed; box-shadow: none; }
.tile.unavailable .tile-logo { filter: grayscale(1); opacity: .45; }
.tile-foot { border-top: 1px solid var(--line); }
/* A team's card: the team's name easy to read, as the portal's side menu */
.tile-team { color: var(--ink); font-weight: 600; font-size: 14px; }
/* What you can do with the licence, as the legacy portal's card: Download, Manage, Team, Usage */
/* A team's card and your own for the same app, one under the other */
.tile + .tile { margin-top: 14px; }
.tile-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
/* A paid licence that ended, under the free plan that replaced it */
.tile-ended { padding: 10px 18px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-3); }
/* The whole strip is the link: it fills with a tint, the bolt flashes and an arrow slides in */
.tile-upgrade { position: relative; display: flex; align-items: center; gap: 7px; padding: 12px 18px; font-size: 14px; font-weight: 600; color: var(--accent-text); text-decoration: none; transition: background .2s ease; }
.tile-upgrade:hover, .tile-upgrade:focus-visible { background: var(--blue-wash); text-decoration: none; }
.tile-upgrade svg { width: 18px; height: 18px; fill: currentColor; stroke: none; transition: transform .25s cubic-bezier(.2, .7, .3, 1); }
.tile-upgrade:hover svg { animation: bolt-flash .5s ease; transform: scale(1.12); }
.tile-upgrade::after { content: "\2192"; margin-left: auto; font-size: 16px; opacity: 0; transform: translateX(-8px); transition: opacity .2s ease, transform .25s cubic-bezier(.2, .7, .3, 1); }
.tile-upgrade:hover::after, .tile-upgrade:focus-visible::after { opacity: 1; transform: none; }
@keyframes bolt-flash { 0% { opacity: 1; } 30% { opacity: .35; } 60% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tile-upgrade svg, .tile-upgrade::after { transition: none; animation: none; } }
.tile-message { font-size: 13px; color: var(--warn); }

/* Tags: a dot, then a word (as the portal's) */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--grid); color: var(--ink-2); }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.tag.good { background: var(--good-wash); color: var(--good); }
.tag.warn { background: var(--warn-wash); color: var(--warn); }
.tag.bad { background: var(--error-wash); color: var(--error); }
.tag.trial { background: var(--trial-wash); color: var(--trial); }
.tag.info { background: var(--blue-wash); color: var(--accent-text); }

.team { display: grid; gap: 14px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.team-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.team-avatar { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--blue-wash); color: var(--accent-text); font-weight: 700; font-size: 15px; }
.team-name { font-size: 18px; font-weight: 600; letter-spacing: -0.015em; }
.team-head .tag { margin-left: auto; }
.team .rows { font-size: 13.5px; }

/* Loading: shimmering placeholders shaped like what comes */
.skeleton { display: block; border-radius: 8px; background: linear-gradient(90deg, var(--grid) 0%, var(--surface-2) 50%, var(--grid) 100%); background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite; }
.skeleton.round { border-radius: 50%; }
.skeleton.line { height: 12px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* The sign-in card while loading: the BEAM mark breathing */
.gate.loading .gate-logo { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: .55; transform: scale(.97); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .gate.loading .gate-logo { animation: none; } }

/* ---------- narrow ---------- */

@media (max-width: 760px) {
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "side" "page"; }
    .top { padding: 10px 14px; gap: 10px; }
    .side {
        position: static;
        flex-direction: row; gap: 4px;
        padding: 10px 12px;
        overflow-x: auto;
        border-bottom: 1px solid var(--line);
    }
    .side a { flex: none; padding: 7px 10px; }
    .team-chip, .brand-area { display: none; }
    .page { padding: 22px 16px 48px; }
    .page::before, .page::after { display: none; }
    .page > h1 { font-size: 22px; margin-bottom: 18px; }
    .cards { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 420px) {
    .stats { grid-template-columns: minmax(0, 1fr); }
}
