/* Sidebar rail for the brief page. Custom CSS on purpose: tailwind.css is prebuilt.
   Tokens mirror the paper scheme in tailwind.input.css (warm stone light, slate-950 dark, amber accent).
   State lives on <html data-sb="expanded|collapsed">, set before paint by the inline script in page.html. */
:root {
  --sb-w: 14.5rem; --sb-wc: 3.5rem;
  --sb-bg: #ece7dc; --sb-fg: #3b362e; --sb-mute: #6f665b; --sb-line: #cfc6b6; --sb-hover: #e0d8c8;
  --sb-accent: #b45309; --sb-on-accent: #fbf8f1;
  --sb-ok: #4d7c0f; --sb-warn: #b45309; --sb-err: #b91c1c;
}
html.dark {
  --sb-bg: #0b1016; --sb-fg: #cbd5e1; --sb-mute: #94a3b8; --sb-line: #1e293b; --sb-hover: #162033;
  --sb-accent: #fbbf24; --sb-on-accent: #0b1016;
  --sb-ok: #86efac; --sb-warn: #fbbf24; --sb-err: #fca5a5;
}
html[data-sb="expanded"] { --sb-cur: var(--sb-w); }
html[data-sb="collapsed"] { --sb-cur: var(--sb-wc); }

.sb-content { margin-left: var(--sb-cur, var(--sb-w)); padding-top: env(titlebar-area-height, 0); transition: margin-left .2s ease; }

/* Drag region across the top of the Electron window, matching titleBarOverlay.height.
   Empty element: its only job is to let the user drag the window from anywhere in the top strip.
   Native caption buttons (min/max/close) are drawn by the OS above this layer. */
#titlebar {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 32px;                 /* match titleBarOverlay.height */
  -webkit-app-region: drag;
  z-index: 1000;
  pointer-events: auto;
}
#titlebar button, #titlebar input {
  -webkit-app-region: no-drag;
}

.sb {
  position: fixed; inset: 0 auto 0 0; z-index: 50; width: var(--sb-cur, var(--sb-w));
  display: flex; flex-direction: column; gap: .25rem; padding: .5rem;
  background: var(--sb-bg); color: var(--sb-fg); border-right: 1px solid var(--sb-line);
  font: 13px/1.25 system-ui, sans-serif; overflow: hidden auto; transition: width .2s ease;
}
.sb-group { display: flex; flex-direction: column; gap: .125rem; padding-top: .375rem; border-top: 1px solid var(--sb-line); }
.sb-brand + .sb-group { margin-top: .25rem; }
.sb-foot { margin-top: auto; }

.sb-btn {
  display: flex; align-items: center; gap: .75rem; width: 100%; min-height: 2.5rem; padding: 0 .625rem;
  border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit;
  text-align: left; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.sb-btn i, .sb-btn .theme-icon { flex: none; width: 1.25rem; font-size: 1.1rem; text-align: center; }
.sb-btn:hover:not(:disabled) { background: var(--sb-hover); }
.sb-btn:disabled { opacity: .5; cursor: default; }
.sb :focus-visible, .sb-pop :focus-visible, .sb-fab:focus-visible { outline: 2px solid var(--sb-accent); outline-offset: -2px; }
.sb-brand { font: 700 1rem/1.2 var(--font-paper, Georgia, serif); }
.sb-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sb-primary { font-weight: 600; }
.sb-primary i { color: var(--sb-accent); }

/* Picker: stepper chevrons around a trigger that opens the flyout list */
.sb-picker { display: flex; align-items: center; gap: .125rem; }
.sb-trigger { flex: 1; min-width: 0; }
.sb-step { flex: none; width: 2rem; padding: 0; justify-content: center; }
.sb-step i { width: auto; font-size: .9rem; }

/* Status: dot + text; the dot alone carries it when collapsed */
.sb-status { display: flex; align-items: flex-start; gap: .75rem; padding: .125rem .625rem .375rem; color: var(--sb-mute); font-size: 12px; }
.sb-status .sb-label { overflow: visible; white-space: normal; }
.sb-dot { flex: none; width: 1.25rem; padding-top: .2rem; font-size: .55rem; text-align: center; color: var(--sb-ok); }
.sb-dot[data-state="stale"] { color: var(--sb-warn); }
.sb-dot[data-state="error"] { color: var(--sb-err); }
.sb-dot[data-state="busy"] { color: var(--sb-accent); animation: sb-pulse 1.1s ease-in-out infinite; }
#status.stale { color: var(--sb-warn); }
#status.error { color: var(--sb-err); }
@keyframes sb-pulse { 50% { opacity: .3; } }

/* Engine: segmented control when expanded, single icon trigger when collapsed */
.sb-seg { display: flex; margin: .125rem .25rem; border: 1px solid var(--sb-line); border-radius: 6px; overflow: hidden; }
.sb-seg button { flex: 1; padding: .4rem 0; border: 0; border-left: 1px solid var(--sb-line); background: transparent; color: inherit; font: inherit; cursor: pointer; }
.sb-seg button:first-child { border-left: 0; }
.sb-seg button:hover:not(:disabled) { background: var(--sb-hover); }
.sb-seg button[aria-pressed="true"] { background: var(--sb-accent); color: var(--sb-on-accent); font-weight: 600; }
.sb-seg button:disabled { opacity: .5; cursor: default; }
#sb-engine { display: none; }

/* Collapsed rail: icons only. Labels stay in the accessibility tree (clipped, not display:none). */
html[data-sb="collapsed"] .sb-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
html[data-sb="collapsed"] .sb-step, html[data-sb="collapsed"] .sb-seg { display: none; }
html[data-sb="collapsed"] #sb-engine { display: flex; }
html[data-sb="collapsed"] .sb-status { padding-left: .625rem; }
html[data-sb="collapsed"] #sb-toggle i { transform: scaleX(-1); }

.sb-vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); opacity: 0; pointer-events: none; }

/* Flyout list (shared by the brief picker and the collapsed engine picker) */
.sb-pop {
  position: fixed; z-index: 60; min-width: 12.5rem; max-height: min(60vh, 24rem); overflow-y: auto; padding: .25rem;
  background: var(--sb-bg); color: var(--sb-fg); border: 1px solid var(--sb-line); border-radius: 8px;
  box-shadow: 0 6px 28px #0004; font: 13px/1.25 system-ui, sans-serif;
}
.sb-pop[hidden] { display: none; }
.sb-pop-day { padding: .5rem .6rem .2rem; font-size: 12px; font-weight: 600; color: var(--sb-mute); }
.sb-opt { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: .45rem .6rem; border-radius: 5px; cursor: pointer; }
.sb-opt:hover, .sb-opt:focus { background: var(--sb-hover); outline: 0; }
.sb-opt[aria-selected="true"] { font-weight: 700; box-shadow: inset 2px 0 var(--sb-accent); }
.sb-opt-meta { color: var(--sb-mute); font-size: 12px; font-variant-numeric: tabular-nums; }

.sb-toast {
  position: fixed; left: calc(var(--sb-cur, var(--sb-w)) + 1rem); bottom: 1rem; z-index: 55; max-width: min(28rem, 80vw);
  padding: .6rem .8rem; border: 1px solid var(--sb-err); border-radius: 8px;
  background: var(--sb-bg); color: var(--sb-err); font: 13px/1.3 system-ui, sans-serif; box-shadow: 0 4px 20px #0004;
}
.sb-toast[hidden] { display: none; }

.sb-fab, .sb-backdrop { display: none; }

/* About block: blurb, GitHub + commit chips, copyright. Hidden on the icon-only rail. */
.sb-about { display: flex; flex-direction: column; gap: .5rem; padding: .5rem .625rem .25rem; }
.sb-blurb { margin: 0; font: italic 12.5px/1.45 var(--font-paper, Georgia, serif); color: var(--sb-fg); }
.sb-blurb b { font-style: normal; font-weight: 600; color: var(--sb-accent); }
.sb-links { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem; }
.sb-chip {
  display: inline-flex; align-items: center; gap: .375rem; padding: .2rem .55rem; border: 1px solid var(--sb-line); border-radius: 999px;
  background: transparent; color: var(--sb-mute); font: 500 11.5px/1.2 ui-monospace, Consolas, monospace; text-decoration: none; white-space: nowrap;
}
a.sb-chip:hover { background: var(--sb-hover); color: var(--sb-fg); }
.sb-chip--gh { font: 600 12px/1.2 system-ui, sans-serif; color: var(--sb-fg); }
.sb-chip--gh i { font-size: .95rem; }
.sb-chip--dirty { border-style: dashed; color: var(--sb-warn); }
.sb-legal { margin: 0; font-size: 11px; color: var(--sb-mute); }
.sb-hr { margin: .25rem .25rem .125rem; border: 0; border-top: 1px solid var(--sb-line); }
html[data-sb="collapsed"] .sb-about { display: none; }

/* Narrow screens and embeds in small panes: off-canvas drawer */
@media (max-width: 719px) {
  .sb-content { margin-left: 0; padding-top: 3rem; }
  .sb { width: var(--sb-w); transition: transform .2s ease, visibility 0s; box-shadow: 0 0 28px #0005; }
  html[data-sb="collapsed"] .sb { transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility 0s .2s; }
  html[data-sb="collapsed"] .sb-label { position: static; width: auto; height: auto; clip: auto; }
  html[data-sb="collapsed"] .sb-step, html[data-sb="collapsed"] .sb-seg { display: flex; }
  html[data-sb="collapsed"] #sb-engine { display: none; }
  .sb-fab {
    position: fixed; top: .5rem; left: .5rem; z-index: 45; width: 2.5rem; height: 2.5rem; padding: 0;
    align-items: center; justify-content: center; font-size: 1.3rem;
    border: 1px solid var(--sb-line); border-radius: 6px; background: var(--sb-bg); color: var(--sb-fg); cursor: pointer;
  }
  html[data-sb="collapsed"] .sb-fab { display: flex; }
  .sb-backdrop { position: fixed; inset: 0; z-index: 49; background: #0006; }
  html[data-sb="expanded"] .sb-backdrop { display: block; }
  .sb-toast { left: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .sb, .sb-content { transition: none; } .sb-dot[data-state="busy"] { animation: none; }
}
