/* ==========================================================================
   Rust+ Bot — shell layer (header + top tab navigation + page frame)

   Loads AFTER app.css on every page. app.css owns palette/typography/components;
   this file owns the app chrome only: the slim header, the top tab bar, the
   page toolbar, flash messages and the footer.

   Sizes follow a touch-first rule: every interactive target in the chrome is at
   least 42px tall (44px on phones), and nothing in the header wraps — the tab
   strip scrolls horizontally instead, which is what makes a 390px viewport
   usable with one thumb.
   ========================================================================== */

/* ── self-hosted Inter (no third-party font request) ───────────────────── */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/static/fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/static/fonts/inter-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --sh-head-row-h: 56px;
  --sh-tab-h: 40px;
  --sh-gutter: clamp(12px, 2.6vw, 26px);
  --sh-ring: 0 0 0 3px rgba(226, 84, 58, .30);
  /* Real header height; shell.js overwrites this with a measured value so
     sticky page sub-bars can use top: var(--sh-head-h) at any breakpoint. */
  --sh-head-h: 101px;
}

/* ── page frame ───────────────────────────────────────────────────────── */

body.sh {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.sh-skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  background: var(--surface-2);
  color: var(--text);
  padding: .6rem 1rem;
  border-radius: 0 0 var(--r-sm) 0;
}
.sh-skip:focus { left: 0; }

.sh-view {
  flex: 1 1 auto;
  padding: var(--sh-gutter) var(--sh-gutter) 3.5rem;
  min-width: 0;               /* lets wide tables scroll instead of stretching */
  animation: sh-view-in .22s var(--ease) both;
}
@keyframes sh-view-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ── header ───────────────────────────────────────────────────────────── */

.sh-head {
  position: sticky;
  top: 0;
  z-index: 130;
  background: rgba(9, 12, 20, .84);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
  /* app.css styles every <nav>; the tab strip is chrome and pads itself */
  padding-left: 0;
  padding-right: 0;
}

.sh-head-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 0;
  column-gap: .45rem;
  min-height: var(--sh-head-row-h);
  padding: .3rem var(--sh-gutter) 0;
}

.sh-brand {
  order: 1;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  color: var(--text);
  flex: 0 0 auto;
  min-height: 42px;
}
.sh-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: .92rem;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), #a8331f);
  box-shadow: 0 2px 10px rgba(226, 84, 58, .35), inset 0 1px 0 rgba(255,255,255,.22);
  flex: 0 0 auto;
}
.sh-brand-name {
  font-weight: 700;
  letter-spacing: -.02em;
  font-size: .96rem;
  white-space: nowrap;
}

/* live status pill (dashboard-level truth, in the chrome of every page) */
.sh-live {
  order: 2;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .28rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: rgba(255,255,255,.03);
  font-size: .76rem;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  min-height: 30px;
  min-width: 0;
  overflow: hidden;
}
.sh-live[hidden] { display: none; }
.sh-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
  flex: 0 0 auto;
}
.sh-live.is-running .sh-live-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(46,194,126,.16); animation: sh-pulse 2.6s var(--ease) infinite; }
.sh-live.is-down    .sh-live-dot { background: var(--red); box-shadow: 0 0 0 3px rgba(248,113,113,.16); }
.sh-live.is-stale   .sh-live-dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(251,191,36,.16); }
.sh-live-text { color: var(--text-2); }
.sh-live.is-running .sh-live-text { color: var(--green-soft); }
.sh-live.is-down .sh-live-text { color: #fca5a5; }
.sh-live.is-stale .sh-live-text { color: var(--amber); }
.sh-live-meta { color: var(--muted); font-weight: 500; }
@keyframes sh-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .45; }
}

/* account menu: <details> so it works without JS, styled as a small popover */
.sh-acct {
  order: 3;
  position: relative;
  margin-left: auto;
  flex: 0 0 auto;
}
.sh-acct-sum {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  height: 38px;
  padding: 0 .6rem 0 .35rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: rgba(255,255,255,.03);
  color: var(--text-2);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  list-style: none;
  transition: border-color var(--fast), background var(--fast), color var(--fast);
}
.sh-acct-sum::-webkit-details-marker { display: none; }
.sh-acct-sum:hover { border-color: var(--line-strong); background: rgba(255,255,255,.06); color: var(--text); }
.sh-acct-sum:focus-visible { outline: none; box-shadow: var(--sh-ring); }
.sh-acct-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .78rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(145deg, #2b3a54, #1a2436);
  border: 1px solid var(--line-strong);
  flex: 0 0 auto;
}
.sh-acct-label {
  font-family: var(--mono);
  font-size: .74rem;
  max-width: 12ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sh-caret {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: .7;
  transition: transform var(--fast);
}
.sh-acct[open] .sh-caret { transform: rotate(180deg); }

.sh-acct-menu {
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  min-width: 248px;
  padding: .35rem;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-3);
  z-index: 140;
  animation: sh-menu-in .16s var(--ease) both;
}
@keyframes sh-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.sh-acct-menu a,
.sh-acct-menu button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: .45rem .6rem;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2) !important;
  font: inherit;
  font-size: .84rem;
  font-weight: 560;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.sh-acct-menu a:hover,
.sh-acct-menu button:hover { background: rgba(255,255,255,.06); color: var(--text) !important; }
.sh-acct-menu a:focus-visible,
.sh-acct-menu button:focus-visible { outline: none; box-shadow: var(--sh-ring); }
.sh-acct-head {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .6rem .5rem;
}
.sh-acct-id {
  font-size: .74rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.sh-acct-sep { height: 1px; margin: .3rem .4rem; background: var(--line-soft); }
.sh-acct-form { margin: 0; }

/* ── top tab bar ──────────────────────────────────────────────────────── */

.sh-tabs {
  order: 4;
  position: relative;
  flex: 1 0 100%;
  min-width: 0;
  border-top: 1px solid var(--line-soft);
  padding: 0 !important;   /* beats app.css's blanket <nav> padding */
}
.sh-tabs-track {
  display: flex;
  align-items: center;
  gap: .18rem;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: .2rem var(--sh-gutter) .3rem;
  min-width: 0;
}
.sh-tabs-track::-webkit-scrollbar { display: none; }

.sh-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  height: var(--sh-tab-h);
  padding: 0 .9rem;
  border-radius: 10px;
  border: 1px solid transparent;
  color: var(--muted) !important;
  font-size: .855rem;
  font-weight: 600;
  letter-spacing: -.005em;
  text-decoration: none;
  white-space: nowrap;
  scroll-snap-align: center;
  flex: 0 0 auto;
  transition: color var(--fast), background var(--fast), border-color var(--fast);
}
.sh-tab:hover { color: var(--text) !important; background: rgba(255,255,255,.05); }
.sh-tab:focus-visible { outline: none; box-shadow: var(--sh-ring); }
.sh-tab.is-active {
  color: #fff !important;
  background: var(--accent-dim);
  border-color: rgba(226, 84, 58, .34);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
.sh-tab.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  transform: translateX(-50%);
  background: var(--accent);
}
/* optimistic state while the clicked page is loading (prerender makes this moot
   most of the time, but it keeps a slow link from feeling dead) */
.sh-tab.is-pending { color: var(--text) !important; background: rgba(255,255,255,.06); }
.sh-tab.is-pending .sh-tab-label { opacity: .75; }

/* thin top progress line for real navigations */
.sh-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 200;
  background: linear-gradient(90deg, transparent, var(--accent-hi));
  transform-origin: 0 50%;
  transform: scaleX(0);
}
.sh-progress[hidden] { display: none; }
.sh-progress.is-on { animation: sh-prog 8s var(--ease) forwards; }
@keyframes sh-prog {
  0%   { transform: scaleX(0); }
  35%  { transform: scaleX(.55); }
  70%  { transform: scaleX(.8); }
  100% { transform: scaleX(.94); }
}

/* ── page toolbar (title + page-level actions) ────────────────────────── */

.sh-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: .75rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.sh-toolbar-main { min-width: 0; }
.sh-toolbar h1,
.sh-toolbar .sh-title {
  margin: 0;
  font-size: clamp(1.15rem, 1rem + .7vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -.022em;
  line-height: 1.25;
}
.sh-toolbar .sh-sub {
  margin-top: .3rem;
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.5;
}
.sh-toolbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.sh-toolbar-actions form { margin: 0; display: inline-flex; }

/* ── flash messages ───────────────────────────────────────────────────── */

.sh-flashes { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.sh-flashes .flash { margin: 0; }
.flash.success { background: rgba(46,194,126,.12) !important; border-color: rgba(46,194,126,.4) !important; color: var(--green-soft) !important; }
.flash.error, .flash.danger { background: rgba(248,113,113,.12) !important; border-color: rgba(248,113,113,.4) !important; color: #fca5a5 !important; }
.flash.info { background: rgba(96,165,250,.12) !important; border-color: rgba(96,165,250,.4) !important; color: #93c5fd !important; }

/* ── footer ───────────────────────────────────────────────────────────── */

.sh-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
  flex-wrap: wrap;
  padding: 1rem var(--sh-gutter);
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-soft);
  color: var(--muted-2);
  font-size: .74rem;
}
.sh-foot-links { display: inline-flex; gap: .9rem; }
.sh-foot-links a { color: var(--muted); text-decoration: none; }
.sh-foot-links a:hover { color: var(--text); }

/* ── responsive ───────────────────────────────────────────────────────── */

/* desktop: everything on ONE slim row — brand · tabs · status · account.
   The tab strip takes the free space and scrolls internally if a section is
   added, so the header height never grows. */
@media (min-width: 860px) {
  :root { --sh-head-row-h: 60px; --sh-tab-h: 36px; --sh-head-h: 60px; }
  .sh-head-row { flex-wrap: nowrap; padding: .3rem var(--sh-gutter); column-gap: .6rem; }
  .sh-tabs { order: 2; flex: 1 1 auto; border-top: 0; }
  .sh-tabs-track { padding: 0 .3rem; }
  .sh-live { order: 3; margin-left: auto; }
  .sh-acct { order: 4; margin-left: 0; }
}

@media (max-width: 780px) {
  :root { --sh-head-row-h: 52px; --sh-tab-h: 44px; }
  .sh-brand-name { display: none; }
  .sh-live-meta { display: none; }
  .sh-acct-label { display: none; }
  .sh-acct-sum { padding: 0 .55rem 0 .3rem; }
  .sh-toolbar { align-items: stretch; }
  .sh-toolbar-actions { width: 100%; }
  .sh-toolbar-actions > .btn,
  .sh-toolbar-actions > form > .btn,
  .sh-toolbar-actions > a.btn { flex: 1 1 auto; min-height: 42px; }
  .sh-view { padding-bottom: 2.5rem; }
}

@media (max-width: 460px) {
  .sh-tab { padding: 0 .75rem; }
  .sh-acct-menu {
    position: fixed;
    top: calc(var(--sh-head-row-h) + env(safe-area-inset-top, 0px) + .35rem);
    left: .5rem;
    right: .5rem;
    min-width: 0;
  }
  .sh-acct-menu a, .sh-acct-menu button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .sh-view { animation: none; }
  .sh-live.is-running .sh-live-dot { animation: none; }
  .sh-acct-menu { animation: none; }
  .sh-progress.is-on { animation-duration: .6s; }
}

/* ── feedback widget (one implementation, in the chrome) ──────────────── */

.fb-float {
  position: fixed;
  right: clamp(12px, 2.4vw, 22px);
  bottom: calc(clamp(12px, 2.4vw, 22px) + env(safe-area-inset-bottom, 0px));
  z-index: 150;
  min-height: 40px;
  padding: 0 1rem;
  border-radius: var(--r-pill);
  border: 1px solid rgba(139, 92, 246, .45);
  background: linear-gradient(180deg, #7c4ff0, #6d3fe0);
  color: #fff;
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 640;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(109, 63, 224, .4);
  transition: transform var(--fast), box-shadow var(--med), filter var(--fast);
}
.fb-float:hover { transform: translateY(-1px); filter: brightness(1.08); box-shadow: 0 12px 30px rgba(109, 63, 224, .5); }
.fb-float:focus-visible { outline: none; box-shadow: var(--sh-ring); }
.fb-float[hidden] { display: none; }

.fb-overlay {
  position: fixed;
  inset: 0;
  z-index: 160;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.fb-overlay[hidden] { display: none; }
.fb-card {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  padding: 1.1rem 1.15rem 1rem;
  animation: sh-menu-in .18s var(--ease) both;
}
.fb-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.fb-head h3 { margin: 0; font-size: 1rem; font-weight: 680; }
.fb-close {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.fb-close:hover { color: var(--text); border-color: var(--line-strong); }
.fb-hint { margin: .35rem 0 .7rem; color: var(--muted); font-size: .8rem; }
.fb-msg {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  padding: .6rem .7rem;
  font-family: var(--font);
  font-size: .88rem;
  resize: vertical;
}
.fb-msg:focus { outline: none; border-color: rgba(226, 84, 58, .5); box-shadow: 0 0 0 3px rgba(226, 84, 58, .14); }
.fb-foot { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: .7rem; }
.fb-status { font-size: .8rem; color: var(--muted); }
.fb-status.is-ok { color: var(--green-soft); }
.fb-status.is-error { color: #fca5a5; }

@media (max-width: 460px) {
  .fb-card { max-width: none; }
  .fb-foot .btn { min-height: 44px; flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .fb-card { animation: none; }
  .fb-float { transition: none; }
}

@media print {
  .sh-head, .sh-foot, .sh-progress, .sh-toolbar-actions, .fb-float, .fb-overlay { display: none !important; }
}
