/* The page shell: sidebar, top bar, the tab row under 900 px, the card layout
   and the theme switch. Tokens only (static/css/theme.css holds the colours). */

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
           clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -64px; z-index: 100; padding: 8px 14px;
             background: var(--inv-bg); color: var(--inv-ink); border-radius: var(--radius); text-decoration: none; }
.skip-link:focus { top: 8px; }
/* Focus given to the page by the skip link: the ring sits inside the page's edge. */
main:focus-visible { outline-offset: -2px; }

.brand { display: inline-flex; align-items: center; color: var(--ink); text-decoration: none; flex: none; }
.lockup { width: 125px; height: 20px; color: inherit; display: block; }

/* App layout: the sidebar runs the full height, the top bar and the page sit to its right. */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); grid-template-rows: auto 1fr;
       grid-template-areas: "side top" "side main"; min-height: 100vh; }
/* main keeps an auto margin in styles.css, which would shrink it to its content: the width and the scroll keep a wide table inside it. */
.app > main { grid-area: main; min-width: 0; width: 100%; overflow-x: auto; }

.sidebar { grid-area: side; position: sticky; top: 0; height: 100vh; min-width: 0; display: flex; flex-direction: column;
           background: var(--surface); border-right: 1px solid var(--line); }
.sidebar .brand { padding: 18px 20px 10px; }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; overflow-y: auto; }
.sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius);
                 color: var(--ink-2); text-decoration: none; font-size: 13.5px; font-weight: 500; }
.sidebar-nav a:hover { background: var(--surface-2); color: var(--ink); }
.sidebar-nav a[aria-current="page"] { background: var(--inv-bg); color: var(--inv-ink); }
.sidebar-nav .nav-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer { border-top: 1px solid var(--line); padding: 8px; }
.person-block { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius);
                color: var(--ink); text-decoration: none; min-width: 0; }
.person-block:hover { background: var(--surface-2); }
.person-block[aria-current="page"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--ink); }
.person-avatar, .topbar-account { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
                                  display: inline-flex; align-items: center; justify-content: center;
                                  background: var(--inv-bg); color: var(--inv-ink); font-weight: 600; font-size: 13px;
                                  text-decoration: none; }
.person-text { display: flex; flex-direction: column; min-width: 0; }
.person-name, .person-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-name { font-size: 13px; }
.person-email { font-size: 12.5px; color: var(--ink-3); }
.person-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 8px 4px; }

.topbar { grid-area: top; position: sticky; top: 0; z-index: 10; height: 48px; display: flex; align-items: center;
          justify-content: space-between; gap: 12px; padding: 0 20px;
          background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }
.topbar .brand { display: none; }
.topbar .role-badge { display: none; }
.org-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
            color: var(--ink); font-size: 13.5px; font-weight: 600; text-decoration: none; }
a.org-name:hover { text-decoration: underline; }
.topbar-account { display: none; }
.topbar-account[aria-current="page"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }

.theme-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; flex: none;
             border: 1px solid var(--control-line); border-radius: var(--radius); background: var(--surface);
             color: var(--ink); cursor: pointer; }
.theme-btn:hover { background: var(--surface-2); }
.theme-btn[hidden] { display: none; }
/* The page is dark unless data-theme says light (#1043), so the sun (the way back to light) shows by default. */
.theme-btn .theme-moon { display: none; }
:root[data-theme="light"] .theme-btn .theme-sun { display: none; }
:root[data-theme="light"] .theme-btn .theme-moon { display: inline; }

.account-logout { max-width: 760px; margin: 0 auto; padding: 0 20px 24px; }
@media (min-width: 901px) { .account-logout { display: none; } }

/* Card layout: one card, centred, with the switch in its corner and the logo at its top. */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px 16px; }
.auth-card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
             box-shadow: var(--shadow); padding: 36px; width: 380px; max-width: 100%; min-width: 0; }
.auth-card-wide { width: 720px; max-width: 100%; }
.auth-card .theme-btn { position: absolute; top: 14px; right: 14px; }
.auth-card .brand { margin-bottom: 20px; }
.auth-card h1 { text-align: left; font-size: 24px; font-weight: 600; letter-spacing: -.01em; color: var(--ink); line-height: 1.25; margin: 0 0 4px; }
.auth-sub { color: var(--ink-3); font-size: 13.5px; margin-bottom: 20px; }
.auth-card h1 + form, .auth-card h1 + .form-hint, .auth-card h1 + .form-group, .auth-card h1 + .error-msg, .auth-card h1 + section { margin-top: 16px; }

/* The plan chip in the top bar and the banner above the page (static/js/lib/plan.js). Text says what they mean;
   the colour only follows it: grey for a running trial, amber within 7 days of a change, red once it ended. */
.plan-chip { display: inline-block; padding: 3px 10px; border: 1px solid var(--line-strong); border-radius: 999px;
             background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; text-decoration: none;
             white-space: nowrap; }
a.plan-chip:hover { color: var(--ink); border-color: var(--control-line); }
.plan-chip-warn { background: var(--amber-soft); border-color: var(--amber-line); color: var(--amber-ink); }
.plan-chip-bad { background: var(--red-soft); border-color: var(--red-line); color: var(--red-ink); }
.plan-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
               margin-bottom: 16px; padding: 12px 14px; background: var(--amber-soft); color: var(--amber-ink);
               border: 1px solid var(--amber-line); border-radius: var(--radius); font-size: 13.5px; }
.plan-banner span { min-width: 0; overflow-wrap: anywhere; }

/* The visitor's bar (templates/shell/visit_bar.html): above everything, on every page of a support visit. It stays
   in view; the sidebar and the top bar stick below it (static/js/lib/visitor_bar.js sets --visit-bar-h). */
.visit-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
             gap: 12px; flex-wrap: wrap; padding: 8px 20px; background: var(--amber-soft); color: var(--amber-ink);
             border-bottom: 1px solid var(--amber-line); font-size: 13.5px; }
.visit-bar-emergency { background: var(--red-soft); color: var(--red-ink); border-bottom-color: var(--red-line); }
.visit-bar-text { display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; min-width: 0; flex: 1; }
.visit-bar-text > * { min-width: 0; overflow-wrap: anywhere; }
.visit-bar-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.visit-bar-error { font-weight: 600; }
.visit-bar ~ .app .topbar, .visit-bars ~ .app .topbar { top: var(--visit-bar-h); }
@media (min-width: 901px) {
    .visit-bar ~ .app .sidebar, .visit-bars ~ .app .sidebar { top: var(--visit-bar-h); height: calc(100vh - var(--visit-bar-h)); }
}
/* The organisation's own bars (templates/shell/member_visit_bar.html, static/js/lib/visit_bar.js): one bar for
   each open visit, in one holder that stays in view and is empty (no height) when no visit is open. */
.visit-bars { position: sticky; top: 0; z-index: 30; }
.visit-bars .visit-bar { position: static; }
.visit-bar-note { flex-basis: 100%; margin: 0; }
.visit-bar-changes { flex-basis: 100%; }
.visit-bar-changes ul { margin: 4px 0 0; padding-left: 20px; }

/* Under 900 px the sidebar is one row of links under the top bar, which takes the logo. */
@media (max-width: 900px) {
    .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr;
           grid-template-areas: "top" "side" "main"; }
    .sidebar { position: static; height: auto; flex-direction: row; border-right: none; border-bottom: 1px solid var(--line); }
    .sidebar .brand, .sidebar-footer { display: none; }
    .sidebar-nav { flex-direction: row; gap: 4px; padding: 4px 8px; overflow-x: auto; overflow-y: hidden; min-width: 0; }
    .sidebar-nav a { flex: none; padding: 6px 10px; font-size: 13px; white-space: nowrap; }
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar .brand { display: inline-flex; }
    .topbar-account { display: inline-flex; }
}

/* The top bar's role chip stands in for the person block, which is hidden from 641 to 900 px. */
@media (min-width: 641px) and (max-width: 900px) {
    .topbar .role-badge { display: inline-block; }
}

/* Under 640 px actions wrap onto their own line. */
@media (max-width: 640px) {
    /* The plan chip leaves the top bar; the banner says the same. */
    .plan-chip { display: none; }
    .page-header { flex-wrap: wrap; gap: 8px; }
    .page-header > .btn { flex: 1 1 auto; }
}
