/*
 * Orbit demos — app shell
 * ----------------------------------------------------------------------------
 * Layout (sidebar + topbar + content), the live config panel, cards, controls
 * and the code preview. All values reference the --ds-* semantic layer defined
 * in theme.css, which in turn maps to the Highsoft design tokens.
 */

/* ---- App scaffold ------------------------------------------------------- */
.app {
    display: grid;
    grid-template-columns: 264px 1fr;
    min-height: 100vh;
    transition: grid-template-columns var(--ds-motion);
}

/* ---- Collapsed sidebar (desktop) — icon rail --------------------------- */
.app.is-nav-collapsed { grid-template-columns: 64px 1fr; }
.app.is-nav-collapsed .app__nav { overflow-x: hidden; }
.app.is-nav-collapsed .app__nav-head { flex-direction: column; align-items: center; gap: var(--ds-space-3); padding-left: 0; padding-right: 0; }
.app.is-nav-collapsed .app__brand { justify-content: center; padding-left: 0; padding-right: 0; }
.app.is-nav-collapsed .app__brand > span:last-child,
.app.is-nav-collapsed .app__nav-group-label,
.app.is-nav-collapsed .app__nav-link > span:not(.ico),
.app.is-nav-collapsed .app__nav-note,
.app.is-nav-collapsed .app__nav-foot { display: none; }
.app.is-nav-collapsed .app__nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
.app.is-nav-collapsed .app__nav-list { padding-left: var(--ds-space-2); padding-right: var(--ds-space-2); }
.app.is-nav-collapsed .app__hide-btn { display: none; }   /* rail mode: expand first, then hide */

/* ---- Fully hidden sidebar (desktop) — off-canvas + floating burger ----- */
.app.is-nav-hidden { grid-template-columns: 0 1fr; }
/* The nav goes position:fixed (below), leaving the grid flow — pin main to the
   1fr track so it doesn't auto-place into the now-empty 0-width first track. */
.app.is-nav-hidden .app__main { grid-column: 2; }
/* Overlay presentation for the peeked sidebar. Keyed off a class on the nav
   itself (not a .app descendant) so the nav can be reparented to <body> when it
   opens — that's how it wins the paint-order tie against Orbit's own popouts,
   which use the same max z-index but append to <body> later in the DOM. */
.app__nav.is-overlay {
    position: fixed; left: 0; top: 0; z-index: 2147483647;
    width: 264px; max-width: 84vw;
    transform: translateX(-100%);
    transition: transform var(--animations-classic-default);
}
.app__nav.is-overlay.is-open { transform: translateX(0); box-shadow: var(--ds-shadow-lg); }
.app__nav.is-overlay .app__collapse-btn { display: none; }  /* rail toggle is moot in the overlay */

/* The floating burger the hidden sidebar collapses to (desktop only). */
.app__fab { display: none; }
.app.is-nav-hidden .app__fab {
    display: inline-flex; align-items: center; justify-content: center;
    position: fixed; left: var(--ds-space-5); bottom: var(--ds-space-5); z-index: 30;
    width: 48px; height: 48px; padding: 0;
    border: none; border-radius: 50%;
    background: var(--ds-accent); color: var(--ds-on-accent);
    box-shadow: var(--ds-shadow-lg);
    cursor: pointer;
    transition: transform var(--ds-motion), background var(--ds-motion);
}
.app.is-nav-hidden .app__fab:hover { transform: translateY(-1px); }
.app.is-nav-hidden.is-nav-peek .app__fab { display: none; }  /* overlay open — burger not needed */
.app__fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Sidebar ------------------------------------------------------------ */
.app__nav {
    position: sticky;
    top: 0;
    z-index: 2147483647;   /* keep the sidebar above chart / Orbit UI */
    align-self: start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--ds-surface);
    border-right: 1px solid var(--ds-border);
    overflow-y: auto;
}
.app__nav-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-2);
    padding: var(--ds-space-5) var(--ds-space-4) var(--ds-space-4);
}
.app__nav-head-actions { display: flex; align-items: center; gap: var(--ds-space-2); flex: 0 0 auto; }
.app__nav-head .app__collapse-btn,
.app__nav-head .app__hide-btn { flex: 0 0 auto; color: var(--ds-text-muted); }
.app__brand {
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
    min-width: 0;
    color: var(--ds-text);
    text-decoration: none;
}
.app__brand:hover { color: var(--ds-text); text-decoration: none; }
.app__brand-mark {
    width: 30px; height: 30px;
    flex: 0 0 auto;
    display: grid; place-items: center;
    border-radius: var(--ds-radius);
    background: var(--ds-accent);
    color: var(--ds-on-accent);
}
.app__brand-mark svg { width: 18px; height: 18px; fill: currentColor; }
.app__brand-name { font-size: var(--ds-fs-md); font-weight: var(--ds-fw-bold); letter-spacing: -0.02em; }
.app__brand-sub { font-size: var(--ds-fs-xs); color: var(--ds-text-faint); }

.app__nav-list { padding: var(--ds-space-2) var(--ds-space-3) var(--ds-space-6); }
.app__nav-group { margin-top: var(--ds-space-5); }
.app__nav-group:first-child { margin-top: 0; }
.app__nav-group-label {
    padding: 0 var(--ds-space-3) var(--ds-space-2);
    font-size: var(--ds-fs-xs);
    font-weight: var(--ds-fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ds-text-faint);
}
.app__nav-link {
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
    padding: var(--ds-space-3) var(--ds-space-3);
    border-radius: var(--ds-radius);
    color: var(--ds-text-muted);
    font-size: var(--ds-fs-sm);
    font-weight: var(--ds-fw-medium);
    text-decoration: none;
    transition: background var(--ds-motion), color var(--ds-motion);
}
.app__nav-link:hover { background: var(--ds-surface-inset); color: var(--ds-text); text-decoration: none; }
.app__nav-link.is-active { background: var(--ds-accent-weak); color: var(--ds-accent-text); }
.app__nav-link .ico { width: 18px; height: 18px; flex: 0 0 auto; opacity: 0.9; }
.app__nav-link .ico svg { width: 100%; height: 100%; display: block; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
/* trailing external-link glyph on a nav link (e.g. Changelog) */
.app__nav-ext { margin-left: auto; width: 14px; height: 14px; flex: 0 0 auto; display: inline-flex; opacity: 0.5; }
.app__nav-ext svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* separated group at the foot of the nav (external links) */
.app__nav-group--extra { border-top: 1px solid var(--ds-border); margin-top: var(--ds-space-4); padding-top: var(--ds-space-4); }

/* Beta warning at the bottom of the sidebar */
.app__nav-note {
    margin: var(--ds-space-2) var(--ds-space-3) var(--ds-space-6);
    padding: var(--ds-space-3) var(--ds-space-4);
    border: 1px solid var(--ds-danger);
    border-radius: var(--ds-radius);
    background: var(--ds-danger-weak);
    color: var(--ds-text-muted);
    font-size: var(--ds-fs-xs);
    line-height: 1.5;
}
.app__nav-note strong { display: block; margin-bottom: 3px; color: var(--ds-danger); }

/* Sidebar footer — pinned to the bottom */
.app__nav-foot {
    margin: auto var(--ds-space-3) 0;
    padding: var(--ds-space-4) var(--ds-space-3) var(--ds-space-5);
    border-top: 1px solid var(--ds-border);
    font-size: var(--ds-fs-xs);
    line-height: 1.5;
    color: var(--ds-text-faint);
}
.app__nav-foot a { color: var(--ds-text-muted); text-decoration: none; }
.app__nav-foot a:hover { color: var(--ds-accent); text-decoration: underline; }

/* ---- Main column -------------------------------------------------------- */
.app__main { display: flex; flex-direction: column; min-width: 0; }
.app__topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--ds-space-4);
    padding: var(--ds-space-4) var(--ds-space-6);
    background: color-mix(in srgb, var(--ds-bg) 80%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--ds-border);
}
.app__topbar-title { min-width: 0; flex: 1; }
.app__topbar-title h1 { font-size: var(--ds-fs-lg); }
.app__topbar-title p { font-size: var(--ds-fs-sm); color: var(--ds-text-muted); margin-top: 2px; }
.app__topbar-actions { display: flex; align-items: center; gap: var(--ds-space-3); }
.app__topbar .app__menu-btn { display: none; }   /* mobile-only; .app__topbar beats .btn's inline-flex */

.app__content { padding: var(--ds-space-6); max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-2);
    padding: var(--ds-space-3) var(--ds-space-4);
    border: 1px solid var(--ds-border-strong);
    border-radius: var(--ds-radius);
    background: var(--ds-surface);
    color: var(--ds-text);
    font: inherit;
    font-size: var(--ds-fs-sm);
    font-weight: var(--ds-fw-medium);
    cursor: pointer;
    transition: background var(--ds-motion), border-color var(--ds-motion), transform var(--ds-motion);
}
.btn:hover { background: var(--ds-surface-inset); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--ds-accent); border-color: var(--ds-accent); color: var(--ds-on-accent); }
.btn--primary:hover { background: var(--ds-accent-hover); }
.btn--icon { padding: var(--ds-space-3); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn .theme-sun { display: none; }
.highcharts-dark .btn .theme-sun { display: inline; }
.highcharts-dark .btn .theme-moon { display: none; }

/* ---- Cards -------------------------------------------------------------- */
.card {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow);
    overflow: hidden;
}
.card + .card { margin-top: var(--ds-space-5); }
.card__head { padding: var(--ds-space-5) var(--ds-space-5) 0; }
.card__head h2 { font-size: var(--ds-fs-md); }
.card__head p { font-size: var(--ds-fs-sm); color: var(--ds-text-muted); margin-top: 4px; }
.card__body { padding: var(--ds-space-5); }
.chart-box { width: 100%; min-height: 380px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--ds-space-5); }
.card-grid .card + .card { margin-top: 0; }

/* One chart per row — keeps each chart wide enough to avoid Orbit's narrow
   (split) toolbar layout. Used for the chart galleries. */
.card-stack { display: flex; flex-direction: column; gap: var(--ds-space-5); }
.card-stack > .card + .card { margin-top: 0; }

/* clickable card (e.g. the "Browse the demos" tiles) */
.card--link { transition: transform var(--ds-motion), border-color var(--ds-motion), box-shadow var(--ds-motion); }
.card--link:hover { transform: translateY(-2px); border-color: var(--ds-accent); box-shadow: var(--ds-shadow-md); }
.card--link:hover h2 { color: var(--ds-accent-text); }

/* per-content config disclosure (shown beneath a chart/grid) */
.content-config { margin-top: var(--ds-space-4); }
.content-config > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
    padding: var(--ds-space-2) 0;
    font-size: var(--ds-fs-xs);
    font-weight: var(--ds-fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ds-text-faint);
}
.content-config > summary::-webkit-details-marker { display: none; }
.content-config > summary::before { content: '▸'; display: inline-block; width: 1.2em; transition: transform var(--ds-motion); }
.content-config[open] > summary::before { transform: rotate(90deg); }
.content-config > summary:hover { color: var(--ds-text); }
.content-config pre.code { margin-top: var(--ds-space-3); }

/* ---- Section intro / callouts ------------------------------------------ */
.lede {
    color: var(--ds-text-muted);
    font-size: var(--typography-size-300);      /* 18px */
    line-height: 1.6;
    font-weight: var(--ds-fw-normal);
    max-width: 60ch;
    margin: var(--ds-space-2) 0 var(--ds-space-8);
    text-wrap: pretty;
}
.lede code { font-size: 0.9em; }
.note {
    border: 1px solid var(--ds-border);
    border-left: 3px solid var(--ds-accent);
    background: var(--ds-surface-2);
    border-radius: var(--ds-radius);
    padding: var(--ds-space-4) var(--ds-space-5);
    font-size: var(--ds-fs-sm);
    color: var(--ds-text-muted);
}
.note strong { color: var(--ds-text); }
.note--danger { border-color: var(--ds-danger); border-left-color: var(--ds-danger); background: var(--ds-danger-weak); }
.note--danger strong { color: var(--ds-danger); }
.note__action { display: inline-block; margin-top: var(--ds-space-3); font-weight: var(--ds-fw-medium); }
.note__action::after { content: " →"; }
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--border_radius-size-32);
    font-size: var(--ds-fs-xs);
    font-weight: var(--ds-fw-medium);
    background: var(--ds-accent-weak);
    color: var(--ds-accent-text);
}

/* ---- KPI tiles (context demos) ----------------------------------------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--ds-space-5); margin-bottom: var(--ds-space-5); }
.kpi {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow);
    padding: var(--ds-space-5);
}
.kpi__value { font-size: var(--typography-size-900); font-weight: var(--ds-fw-bold); letter-spacing: -0.02em; }
.kpi__label { font-size: var(--ds-fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ds-text-faint); margin-top: 4px; }
.kpi__delta { font-size: var(--ds-fs-sm); font-weight: var(--ds-fw-bold); margin-top: 4px; }
.kpi__delta.up { color: var(--ds-success); }
.kpi__delta.down { color: var(--ds-danger); }

/* ---- Tables ------------------------------------------------------------- */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--ds-fs-sm); }
.data-table th { text-align: left; padding: var(--ds-space-3) var(--ds-space-4); border-bottom: 2px solid var(--ds-border-strong); color: var(--ds-text-faint); font-weight: var(--ds-fw-bold); font-size: var(--ds-fs-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.data-table td { padding: var(--ds-space-3) var(--ds-space-4); border-bottom: 1px solid var(--ds-border); }
.data-table tr:last-child td { border-bottom: 0; }

/* ---- Config panel (the centerpiece) ------------------------------------ */
.config-scrim {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.35);
    opacity: 0; visibility: hidden;
    transition: opacity var(--ds-motion), visibility var(--ds-motion);
    z-index: 40;
}
.config-scrim.is-open { opacity: 1; visibility: visible; }
/* The nav's own scrim rides just below the (top-layer) sidebar so the peek /
   mobile drawer dims Orbit UI too. The config panel keeps the default scrim. */
.app__nav-scrim { z-index: 2147483646; }
.config-panel {
    position: fixed; top: 0; right: 0;
    width: 390px; max-width: 92vw; height: 100vh;
    display: flex; flex-direction: column;
    background: var(--ds-surface);
    border-left: 1px solid var(--ds-border);
    box-shadow: var(--ds-shadow-lg);
    transform: translateX(100%);
    transition: transform var(--animations-classic-default);
    z-index: 50;
}
.config-panel.is-open { transform: translateX(0); }
.config-panel__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--ds-space-5);
    border-bottom: 1px solid var(--ds-border);
}
.config-panel__head h2 { font-size: var(--ds-fs-md); }
.config-panel__head p { font-size: var(--ds-fs-xs); color: var(--ds-text-muted); margin-top: 2px; }
.config-panel__close { border: none; background: none; cursor: pointer; color: var(--ds-text-muted); padding: var(--ds-space-2); border-radius: var(--ds-radius); }
.config-panel__close:hover { background: var(--ds-surface-inset); color: var(--ds-text); }
.config-panel__close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.config-panel__body { flex: 1; overflow-y: auto; padding: var(--ds-space-5); }
.config-panel__foot { padding: var(--ds-space-4) var(--ds-space-5); border-top: 1px solid var(--ds-border); display: flex; gap: var(--ds-space-3); }

/* ---- Controls ----------------------------------------------------------- */
.ctl { margin-bottom: var(--ds-space-5); }
.ctl__label { display: block; font-size: var(--ds-fs-sm); font-weight: var(--ds-fw-medium); margin-bottom: 6px; }
.ctl__hint { font-size: var(--ds-fs-xs); color: var(--ds-text-faint); margin-top: 4px; line-height: 1.4; }
.ctl--row { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-4); }
.ctl--row .ctl__label { margin-bottom: 0; }

/* toggle switch */
.switch { position: relative; flex: 0 0 auto; width: 40px; height: 22px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track {
    position: absolute; inset: 0;
    background: var(--ds-border-strong);
    border-radius: 999px;
    transition: background var(--ds-motion);
}
.switch__track::after {
    content: ""; position: absolute; top: 2px; left: 2px;
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--ds-surface);
    box-shadow: var(--ds-shadow);
    transition: transform var(--ds-motion);
}
.switch input:checked + .switch__track { background: var(--ds-accent); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }

/* segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 3px; background: var(--ds-surface-inset); border-radius: var(--ds-radius); }
.segmented button {
    border: none; background: none; cursor: pointer;
    padding: 6px 12px; border-radius: var(--ds-radius-sm);
    font: inherit; font-size: var(--ds-fs-sm); font-weight: var(--ds-fw-medium);
    color: var(--ds-text-muted);
    transition: background var(--ds-motion), color var(--ds-motion);
}
.segmented button.is-on { background: var(--ds-surface); color: var(--ds-text); box-shadow: var(--ds-shadow); }

/* chips (tool multi-select) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    border: 1px solid var(--ds-border-strong);
    background: var(--ds-surface);
    color: var(--ds-text-muted);
    padding: 5px 10px;
    border-radius: var(--border_radius-size-32);
    font: inherit; font-size: var(--ds-fs-xs); font-weight: var(--ds-fw-medium);
    cursor: pointer;
    transition: all var(--ds-motion);
}
.chip:hover { border-color: var(--ds-accent); color: var(--ds-text); }
.chip.is-on { background: var(--ds-accent); border-color: var(--ds-accent); color: var(--ds-on-accent); }
.chips-actions { display: flex; gap: var(--ds-space-4); margin-top: var(--ds-space-3); }
.chips-actions a { font-size: var(--ds-fs-xs); cursor: pointer; }

/* number input */
.ctl input[type="number"] {
    width: 96px; padding: 6px 8px;
    border: 1px solid var(--ds-border-strong); border-radius: var(--ds-radius-sm);
    background: var(--ds-surface); color: var(--ds-text); font: inherit; font-size: var(--ds-fs-sm);
}

/* ---- Code preview ------------------------------------------------------- */
.code-preview { margin-top: var(--ds-space-6); }
.code-preview__label { font-size: var(--ds-fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ds-text-faint); font-weight: var(--ds-fw-bold); margin-bottom: var(--ds-space-3); }
pre.code {
    margin: 0;
    background: var(--ds-surface-inset);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    padding: var(--ds-space-4);
    font-size: var(--ds-fs-xs);
    line-height: 1.6;
    color: var(--ds-text);
    overflow-x: auto;
    white-space: pre;
    tab-size: 2;
}
pre.code .tok-key { color: var(--ds-accent-text); }
pre.code .tok-str { color: var(--ds-success); }
pre.code .tok-num { color: var(--ds-attention); }
pre.code .tok-bool { color: var(--ds-danger); }
pre.code .tok-com { color: var(--ds-text-faint); font-style: italic; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 880px) {
    .app { grid-template-columns: 1fr; }
    .app__nav {
        position: fixed; left: 0; top: 0; z-index: 2147483647;
        width: 264px; max-width: 84vw;
        transform: translateX(-100%);
        transition: transform var(--animations-classic-default);
    }
    .app__nav.is-open { transform: translateX(0); box-shadow: var(--ds-shadow-lg); }
    .app__topbar .app__menu-btn { display: inline-flex; }
    .app__nav-head .app__collapse-btn,
    .app__nav-head .app__hide-btn { display: none; }       /* desktop-only; hamburger handles mobile */
    .app.is-nav-collapsed { grid-template-columns: 1fr; }
    .app.is-nav-hidden { grid-template-columns: 1fr; }
    .app.is-nav-hidden .app__main { grid-column: auto; }   /* single-track grid on mobile */
    .app.is-nav-hidden .app__fab { display: none; }        /* mobile uses the topbar burger, not the FAB */
    .app__content { padding: var(--ds-space-5) var(--ds-space-4); }
    .card-grid { grid-template-columns: 1fr; }
}
