/* header, page tabs, SPA iframes, user menu, System Info, buttons. Part of the stylesheet split by page; public/css/README.md says why. */
/* ── Header ───────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

/* Non-production deployment (APP_ENV, e.g. staging): a badge beside the title
   and a coloured rule under the header, so it cannot be taken for production
   at a glance — including in a screenshot. */
.env-badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  color: #fff; background: #c2410c;
  white-space: nowrap; cursor: help;
}
.env-badge.hidden { display: none; }
body.non-production header { border-bottom: 3px solid #c2410c; }
.env-badge-login { margin: -18px auto 24px; cursor: default; }

/* ── View tab switcher ─────────────────────────────────────── */
/* Scrolls sideways when there are more tabs than fit, at every width, not
   just on a phone. Left to overflow, seven tabs pushed the header past a
   1024–1300px window and the user menu — Sign Out with it — off the right
   edge of the screen. */
#view-tabs { display: flex; align-items: center; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#view-tabs::-webkit-scrollbar { display: none; }
#view-tabs .tab-btn { flex: none; }

.tab-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.tab-btn.active { background: var(--accent); color: #fff; }
.tab-btn:hover:not(.active) { background: var(--bg); color: var(--text); }

/* ── SPA iframes (Claude / Github Analytics) ──────────────── */
#analytics-frame,
#github-frame {
  display: none;
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0; bottom: 0;
  width: 100%;
  height: calc(100vh - var(--header-h));
  border: none;
}

header h1 { font-size: 16px; font-weight: 700; color: var(--accent-text); white-space: nowrap; }
/* margin-right:auto rather than space-between on <header>: the revenue-only
   action group is display:none on the other tabs, and the user menu has to
   stay pinned right either way. */
.header-left { display: flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.header-logo { height: 22px; width: auto; display: block; }


/* The Revenue Tracker's actions, at the top of its own view rather than in
   the header: beside seven tabs they did not fit, and sat on top of the tab
   names. Right-aligned, so they read as belonging to the page, and free to
   wrap on a narrow screen. */
.revenue-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 0;
  background: var(--bg);
}
.revenue-toolbar .btn-primary,
.revenue-toolbar .btn-secondary,
.revenue-toolbar .btn-ghost {
  padding: 5px 10px;
  font-size: 11px;
  white-space: nowrap; /* two-line buttons were making the bar look broken */
}
.tab-btn { white-space: nowrap; }

/* ── User menu ────────────────────────────────────────────── */
.user-menu { position: relative; margin-left: 12px; flex: none; }
.user-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 3px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}
.user-chip:hover,
.user-chip[aria-expanded="true"] { background: var(--bg); border-color: var(--border-strong); }
.user-initials {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
}
.user-name {
  max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; color: var(--text-muted);
}
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 150;
  min-width: 220px; max-width: calc(100vw - 20px); padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  display: flex; flex-direction: column;
}
.user-menu-email {
  padding: 6px 10px 8px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted); overflow-wrap: anywhere;
}
.user-menu-item {
  padding: 7px 10px; border: none; border-radius: 6px;
  background: none; text-align: left; cursor: pointer;
  font: inherit; font-size: 12px; color: var(--text);
}
.user-menu-item:hover,
.user-menu-item:focus-visible { background: var(--bg); outline: none; }
.theme-choice {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 10px 8px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.theme-choice-label { font-size: 12px; color: var(--text); }
.theme-seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); }
.theme-seg button {
  padding: 3px 8px; border: none; border-radius: 4px;
  background: none; color: var(--text-muted); cursor: pointer;
  font: inherit; font-size: 11px;
}
.theme-seg button:hover { color: var(--text); }
.theme-seg button[aria-checked="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.theme-seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── System Info (admin-only) ─────────────────────────────── */
.system-info { display: flex; flex-direction: column; gap: 14px; max-height: 65vh; overflow-y: auto; }
.system-section h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-text); margin: 0 0 4px; }
.system-row { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.system-label { color: var(--text-muted); flex: none; }
.system-value { text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.system-value--ok  { color: var(--growth-pos); font-weight: 600; }
.system-value--off { color: var(--text-muted); }
.system-value--bad { color: var(--danger); font-weight: 600; }
.system-value--warn { color: var(--amber-fg); font-weight: 600; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  padding: 7px 14px;
  background: var(--surface);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--hover-bg); }

.btn-ghost {
  padding: 7px 14px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); }

.btn-danger {
  padding: 7px 14px;
  background: var(--red-bg);
  color: var(--danger);
  border: 1px solid var(--red-border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: var(--red-bg-strong); }

/* ── Pills ────────────────────────────────────────────────────
   One small rounded label for a status, a count or a category, on every
   page. The tone is the colour family, not the meaning: a page maps its own
   states onto it (pass → green, fail → red), so the same state reads the same
   everywhere. No tone is neutral. A page class beside it adds only what is
   specific to that place (a min-width, a margin). */
.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 1px 7px; border: 0; border-radius: 999px;
  background: var(--total-bg); color: var(--text-muted);
  font-family: inherit; font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.pill--sm { padding: 0 6px; font-size: 10px; }
.pill--caps { text-transform: uppercase; letter-spacing: .04em; }
.pill--green  { background: var(--green-bg-strong); color: var(--green-fg); }
.pill--red    { background: var(--red-bg); color: var(--red-fg); }
.pill--amber  { background: var(--amber-bg); color: var(--amber-fg); }
.pill--orange { background: var(--orange-bg); color: var(--orange-fg); }
.pill--blue   { background: var(--blue-bg); color: var(--blue-fg); }
.pill--purple { background: var(--purple-bg); color: var(--purple-fg); }
.pill--cyan   { background: var(--cyan-bg); color: var(--cyan-fg); }
.pill--accent { background: var(--accent); color: #fff; }
.pill--outline { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
button.pill { cursor: pointer; }

/* ── Page toolbar ─────────────────────────────────────────
   The heading, summary, filter and banner row at the top of a page. Named
   for the contract pages, where it started; every page uses it. */
.contracts-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}
.contracts-heading h2 { font-size: 16px; font-weight: 700; color: var(--accent-text); }
.contracts-summary { display: flex; align-items: center; gap: .5rem .75rem; flex-wrap: wrap; margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.contracts-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.contracts-filter {
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
input.contracts-filter { width: 260px; max-width: 100%; }

.contracts-banner {
  margin-bottom: .75rem;
  padding: 8px 12px;
  border: 1px solid var(--amber-border);
  border-radius: 6px;
  background: var(--forecast-bg);
  font-size: 12px;
}

@media (max-width: 760px) {
  input.contracts-filter { width: 100%; }
}

/* ── Header on narrow viewports ───────────────────────────
   Tablet & small laptop: the header wraps. */
@media (max-width: 900px) {
  header {
    height: auto;
    min-height: var(--header-h);
    flex-wrap: wrap;
    padding: 8px 14px;
    gap: 8px;
  }
  .header-left { flex-wrap: wrap; gap: 8px; }

  /* Once the header wraps, logo+title and the user chip share the first row,
     then the tabs. The chip has to stay on that first row — wrapped onto a row of its own it sat
     at the LEFT edge, and its menu (anchored right: 0) then opened off the
     left side of the screen. */
  /* flex-basis 0, not auto: with auto the tabs' intrinsic width makes
     .header-left claim the whole row during line-breaking, so the chip is
     pushed onto a row of its own before it can ever sit beside it. */
  .header-left { flex: 1 1 0; }
  #view-tabs {
    order: 3;
    flex-basis: 100%;
    min-width: 0;
    /* Scrolls sideways, as at every width — see the rule under Header. */
  }
  .user-menu { order: 2; align-self: flex-start; margin-left: 8px; }
}

/* Phone: hide cosmetic labels. */
@media (max-width: 600px) {
  :root { --header-h: 96px; }

  header { padding: 6px 10px; }

  header h1 { font-size: 14px; }
  .header-logo { height: 18px; }

  /* Phone: the initials alone identify the account; the name is in the menu. */
  #user-label { display: none; }
  .user-chip { padding: 3px; }

  .tab-btn { padding: 5px 10px; font-size: 13px; }

  .btn-primary,
  .btn-secondary,
  .btn-ghost,
  .btn-danger {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* ── Toast ────────────────────────────────────────────────
   The short message at the foot of the page (public/js/toast.js), on every
   page. Named for the Revenue Tracker tooltip it started as. */
.toggle-hint {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--band-bg);
  color: #fff;
  font-size: 11px;
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  z-index: 300;
}
.toggle-hint.visible { opacity: 1; }
