/* The top bar shared by every page on the site, Blue Command included (it loads /sitebar.css and /sitebar.js
   from here). Markup comes from sitebar.js; a page only provides <header id="sitebar" data-current="...">, and anything
   inside it (e.g. Blue Command's connection status) is kept in the bar's page slot. Self-contained: it relies only
   on the tokens in theme.css, so it looks the same whatever stylesheet the page itself uses. */

#sitebar {
  display: flex; align-items: center; gap: var(--space-4);
  min-height: 56px; padding: 8px 20px; padding-top: calc(8px + env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right));
  background: var(--surface); border-bottom: 1px solid var(--border); color: var(--text);
  font-family: var(--font-sans); font-size: var(--fs-sm); line-height: 1.2;
  flex: 0 0 auto; position: relative; z-index: 1200; box-sizing: border-box;
}
#sitebar *, #sitebar *::before, #sitebar *::after { box-sizing: border-box; }
#sitebar button { font: inherit; color: inherit; }
#sitebar :focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* logo: the image is 790x264, so it stays sharp up to 7x the 36px it's shown at */
#sitebar .sb-brand { display: flex; align-items: center; flex: none; }
#sitebar .sb-brand img { height: 36px; width: auto; display: block; }
#sitebar .sb-brand .dark-only { display: none; }
:root[data-theme="dark"] #sitebar .sb-brand .light-only { display: none; }
:root[data-theme="dark"] #sitebar .sb-brand .dark-only { display: block; }

/* site links */
#sitebar .sb-nav { display: flex; gap: 2px; flex: none; }
#sitebar .sb-nav a {
  display: flex; align-items: center; min-height: 34px; /* comfortable to tap on tablets too */
  padding: 0 12px; border-radius: var(--radius-sm); white-space: nowrap;
  color: var(--text-muted); font-weight: 500; text-decoration: none;
}
#sitebar .sb-nav a:hover { color: var(--text); background: var(--surface-2); }
#sitebar .sb-nav a[aria-current="page"] { color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); }
#sitebar .sb-nav a[hidden] { display: none; }

/* whatever the page put in its header: status, counts, version */
#sitebar .sb-slot {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  color: var(--text-muted); font-size: var(--fs-xs);
}

/* account button (static/account.js) and theme switch */
#sitebar .sb-icon {
  display: flex; align-items: center; gap: 6px; position: relative; flex: none; min-height: 34px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 6px 10px; cursor: pointer; color: var(--text-muted); font-weight: 500;
}
#sitebar .sb-icon:hover { background: var(--surface-2); color: var(--text); }
#sitebar .sb-icon.open { color: var(--text); }
#sitebar .sb-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#sitebar .sb-icon .avatar { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--primary); color: var(--text-on-primary); font-size: 10px; font-weight: 600; letter-spacing: .02em; }
#sitebar .acct-dot { position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--warn); border: 2px solid var(--surface); }
#sitebar .sb-theme { display: inline-flex; flex: none; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
#sitebar .sb-theme button { background: var(--surface); border: 0; padding: 0 9px; min-height: 32px; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; }
#sitebar .sb-theme button + button { border-left: 1px solid var(--border); }
#sitebar .sb-theme button[aria-pressed="true"] { background: var(--primary); color: var(--text-on-primary); }
#sitebar .sb-theme svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* account dialog (static/account.js) */
#accountDialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: var(--space-5); width: min(92vw, 460px); font-family: var(--font-sans); font-size: var(--fs-md);
}
#accountDialog::backdrop { background: var(--overlay); }
#accountDialog h3 { margin: 0 0 var(--space-2); font-size: var(--fs-lg); }
#accountDialog p { margin: 0 0 var(--space-2); }
#accountDialog .muted { color: var(--text-muted); }
#accountDialog .acct-perms { margin: var(--space-2) 0; padding-left: 1.2em; font-size: var(--fs-sm); }
#accountDialog .acct-perms li { margin: 2px 0; }
#accountDialog a:not(.btn) { color: var(--primary); }
#accountDialog .acct-foot { margin: var(--space-4) 0 0; font-size: var(--fs-xs); color: var(--text-muted); }
#accountDialog .linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--danger); cursor: pointer; text-decoration: underline; }

/* cookie notice (sitebar.js): a notice, not a consent form, since the only cookie is the strictly necessary sign-in one */
#cookieNotice { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 3000;
  max-width: 640px; margin: 0 auto; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px; font-family: var(--font-sans); font-size: var(--fs-sm); line-height: 1.45; }
#cookieNotice p { margin: 0; flex: 1 1 300px; }
#cookieNotice a { color: var(--primary); }
#cookieNotice button { flex: none; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 18px; font: inherit; font-weight: 500; cursor: pointer; min-height: 36px; }
#cookieNotice button:hover { background: var(--surface-2); }
#accountDialog .row { display: flex; gap: var(--space-2); flex-wrap: wrap; margin: var(--space-4) 0 0; }
#accountDialog .btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 14px; cursor: pointer; font: inherit; font-weight: 500; text-decoration: none; display: inline-block;
}
#accountDialog .btn:hover { background: var(--surface-2); }
#accountDialog .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--text-on-primary); }

/* tablets and small laptops: tighter */
@media (max-width: 1024px) {
  #sitebar { gap: var(--space-3); padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  #sitebar .sb-nav a { padding: 0 9px; }
}

/* phones: logo, account and theme on the first row; the site links get a full-width second row that scrolls
   sideways if it ever has to. Account shows just the picture. */
@media (max-width: 760px) {
  #sitebar { flex-wrap: wrap; gap: 8px 10px; min-height: 0; padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 6px; }
  #sitebar .sb-brand img { height: 30px; }
  #sitebar .sb-slot { order: 1; flex: 1 1 0; }
  #sitebar .sb-icon { order: 2; padding: 6px 8px; }
  #sitebar .sb-icon .acct-label { display: none; }
  #sitebar .sb-theme { order: 3; }
  #sitebar .sb-theme button { padding: 7px 8px; }
  #sitebar .sb-nav {
    order: 4; flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
  }
  #sitebar .sb-nav::-webkit-scrollbar { display: none; }
  #sitebar .sb-nav a { padding: 0 10px; min-height: 36px; } /* finger-sized */
}

/* very narrow phones (iPhone SE 1st gen, small Androids): drop the page slot */
@media (max-width: 360px) {
  #sitebar .sb-slot { display: none; }
  #sitebar { justify-content: space-between; }
}
