/* ─────────────────────────────────────────────────────────────────────────
   Boring Analytics — Django chrome
   Editorial-precision aesthetic: serif display, technical sans body,
   warm-neutral palette, restrained ornament. The tenant's --primary
   colour drives accents only.
   ─────────────────────────────────────────────────────────────────────── */

:root {
  /* tenant accent (set inline in base.html from branding.primary_colour) */
  --primary: #1f2937;

  /* ink */
  --ink-1: #0e1116;
  --ink-2: #3d434d;
  --ink-3: #6b7280;
  --ink-4: #9aa0aa;

  /* surfaces */
  --paper: #faf8f3;
  --surface: #ffffff;
  --surface-sunk: #f4f1ea;

  /* hairlines */
  --rule: #e6e2d8;
  --rule-strong: #1b1d22;

  /* state */
  --danger-bg: #fdf2f0;
  --danger-border: #f1c5be;
  --danger-ink: #8b2418;

  /* type stacks */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Cambria",
           "Georgia", "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono",
          "Consolas", monospace;

  /* layout */
  --nav-w: 248px;
  --header-h: 64px;
  --content-max: 64rem;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-1);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

button { font-family: inherit; }

::selection { background: var(--primary); color: #fff; }

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

header.brand {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--header-h);
  padding: 0 1.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  /* a fine accent rule the width of the page, in the tenant colour */
  box-shadow: 0 1px 0 0 var(--rule);
}

/* Brand lockup: a purely typographic masthead — the tenant name set
   in the display serif, a hairline, then the BORING ANALYTICS by-line.
   No logo image: resolution-independent and consistent for every
   tenant. */
.brand-mark {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 6px;
}
.brand-mark:hover { text-decoration: none; }
.brand-mark:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

header.brand .wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  line-height: 1;
}
header.brand .wordmark .client {
  font-family: var(--sans);
  font-size: 1.02rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-3);
}
header.brand .wordmark .rule {
  width: 1px;
  height: 1.15rem;
  background: var(--rule-strong);
  opacity: 0.26;
}
header.brand .wordmark .app {
  font-family: var(--sans);
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.185em;
  color: var(--ink-3);
}

header.brand .user-info {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.84rem;
  color: var(--ink-3);
}

header.brand .user-info .email {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

header.brand .user-info a,
header.brand .user-info button {
  color: var(--ink-2);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  position: relative;
}

header.brand .user-info a::after,
header.brand .user-info button::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  border-bottom: 1px solid currentColor;
  opacity: 0;
  transition: opacity 120ms ease;
}

header.brand .user-info a:hover,
header.brand .user-info button:hover { text-decoration: none; color: var(--ink-1); }
header.brand .user-info a:hover::after,
header.brand .user-info button:hover::after { opacity: 1; }

header.brand .logout-form { margin: 0; display: inline; }

/* ─── layout ──────────────────────────────────────────────────────────── */

.layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - var(--header-h));
}

nav.side {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--rule);
  padding: 1.25rem 0 2rem;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  max-height: calc(100vh - var(--header-h));
  transition: width 180ms ease, flex-basis 180ms ease, opacity 120ms ease;
}

nav.side a {
  display: block;
  padding: 0.45rem 1.5rem;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.93rem;
  line-height: 1.35;
  border-left: 2px solid transparent;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

nav.side a:hover {
  background: var(--surface-sunk);
  color: var(--ink-1);
  text-decoration: none;
}

nav.side a.active {
  border-left-color: var(--primary);
  background: var(--surface-sunk);
  color: var(--ink-1);
  font-weight: 600;
}

nav.side a.home-link {
  margin-bottom: 0.5rem;
}

/* ─── nav: collapsible groups ─────────────────────────────────────────── */

nav.side .nav-group { margin: 0; }
nav.side .nav-group > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1.5rem;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
}
nav.side .nav-group > summary::-webkit-details-marker { display: none; }
nav.side .nav-group > summary:hover { color: var(--ink-1); }

/* chevron — rotates when <details open> */
nav.side .nav-group > summary::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 140ms ease;
  flex: 0 0 auto;
  margin-top: -2px;
}
nav.side .nav-group[open] > summary::before {
  transform: rotate(45deg);
  margin-top: -4px;
}

/* hairline at the right of the summary, in the same style as the old h2 */
nav.side .nav-group > summary::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* parent "Dashboards" group: a touch larger, sits above its folders */
nav.side .nav-root > summary {
  color: var(--ink-2);
  font-size: 0.72rem;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

/* folder groups: indent body slightly so the hierarchy reads */
nav.side .nav-folder > summary {
  padding-left: 1.75rem;
  font-size: 0.66rem;
}
nav.side .nav-folder .nav-group-body a {
  padding-left: 2.25rem;
}

nav.side .nav-group-body {
  padding-bottom: 0.4rem;
}

/* ─── sidebar toggle button ───────────────────────────────────────────── */

header.brand .sidebar-toggle {
  appearance: none;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 4px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-2);
  margin-right: 0.25rem;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
header.brand .sidebar-toggle:hover {
  background: var(--surface-sunk);
  color: var(--ink-1);
  border-color: var(--ink-4);
}
header.brand .sidebar-toggle .bars {
  display: block;
  width: 16px;
  height: 11px;
  position: relative;
}
header.brand .sidebar-toggle .bars::before,
header.brand .sidebar-toggle .bars::after,
header.brand .sidebar-toggle .bars {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-size: 100% 1.5px;
}
header.brand .sidebar-toggle .bars {
  background-position: 0 0, 0 50%, 0 100%;
  background-size: 100% 1.5px;
  background-image:
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor);
}

/* ─── collapsed state ─────────────────────────────────────────────────── */

html.sidebar-collapsed nav.side {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

main {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 3rem;
}

/* When there's no side nav (anonymous pages) let the content breathe wider. */
.layout:not(:has(nav.side)) main {
  padding: 0;
}

/* ─── prose & headings on main content ───────────────────────────────── */

main h1.page-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 2.25rem;
  line-height: 1.1;
  letter-spacing: -0.015em;
  margin: 0 0 0.3rem;
  color: var(--ink-1);
}

main .kicker {
  font-family: var(--sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-3);
  margin: 0 0 1rem;
  font-weight: 600;
}

main p.lede {
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.55;
  color: var(--ink-2);
  max-width: 38rem;
}

/* ─── auth pages (login, password change) ────────────────────────────── */

.auth-shell {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(0,0,0,0.025), transparent 60%),
    radial-gradient(800px 400px at -10% 110%, rgba(0,0,0,0.02), transparent 60%),
    var(--paper);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 2.25rem 2.25rem 1.75rem;
  position: relative;
}

/* Hairline accent strip across the top of the card, in the tenant colour. */
.auth-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--primary);
  border-radius: 4px 4px 0 0;
}

.auth-card h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 0 0 1.5rem;
  color: var(--ink-1);
}

.auth-card label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  margin: 1rem 0 0.4rem;
  font-weight: 600;
}

.auth-card input[type="email"],
.auth-card input[type="text"],
.auth-card input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-1);
  border-radius: 3px;
  font-size: 0.95rem;
  font-family: var(--sans);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.auth-card button[type="submit"] {
  margin-top: 1.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--ink-1);
  color: var(--surface);
  border: 0;
  border-radius: 3px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.auth-card button[type="submit"]:hover { background: #000; }
.auth-card button[type="submit"]:active { transform: translateY(1px); }

.auth-card .errors {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-ink);
  padding: 0.6rem 0.8rem;
  border-radius: 3px;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.auth-card .help {
  font-size: 0.8rem;
  color: var(--ink-3);
}

.auth-card p.help {
  margin: 1.5rem 0 0;
  text-align: center;
  border-top: 1px solid var(--rule);
  padding-top: 1.25rem;
}

/* When the auth page wants the brand wordmark above the card. */
.auth-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
}

.auth-stack .auth-wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  line-height: 1;
}
.auth-stack .auth-wordmark .client {
  font-family: var(--sans);
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-3);
}
.auth-stack .auth-wordmark .rule {
  width: 1px;
  height: 1.35rem;
  background: var(--rule-strong);
  opacity: 0.26;
}
.auth-stack .auth-wordmark .app {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.185em;
  color: var(--ink-3);
}

/* ─── welcome / home ──────────────────────────────────────────────────── */

.welcome {
  max-width: var(--content-max);
}

.welcome header {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.dashboard-grid .group {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 1.5rem 0 0.25rem;
}

.dashboard-grid .group h3 {
  font-family: var(--sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-3);
  font-weight: 600;
  margin: 0;
}

.dashboard-grid .group .rule {
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.dashboard-grid .card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem 1.1rem 1.05rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--ink-1);
  text-decoration: none;
  position: relative;
  transition: border-color 120ms ease, transform 120ms ease;
}

.dashboard-grid .card:hover {
  border-color: var(--rule-strong);
  text-decoration: none;
}

.dashboard-grid .card .num {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-4);
  letter-spacing: 0.04em;
}

.dashboard-grid .card .title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: -0.005em;
}

.dashboard-grid .empty {
  grid-column: 1 / -1;
  padding: 2rem;
  border: 1px dashed var(--rule);
  border-radius: 3px;
  color: var(--ink-3);
  text-align: center;
  font-size: 0.92rem;
}

/* ─── dashboard detail (iframe wrapper) ──────────────────────────────── */

.dashboard {
  margin: -2.5rem -3rem;
  padding: 1.75rem 2.25rem 0;
  background: var(--surface);
  min-height: calc(100vh - var(--header-h));
}

.dashboard-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1rem;
}

.dashboard-header .title-block { min-width: 0; }

.dashboard-header h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.65rem;
  letter-spacing: -0.012em;
  margin: 0;
  color: var(--ink-1);
  line-height: 1.15;
}

.dashboard-header .folder {
  font-family: var(--sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-3);
  font-weight: 600;
  display: block;
  margin-bottom: 0.4rem;
}

.dashboard-header .actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-shrink: 0;
}

.dashboard-header .actions a,
.dashboard-header .actions button {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-2);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  position: relative;
}

.dashboard-header .actions a::after,
.dashboard-header .actions button::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  border-bottom: 1px solid currentColor;
  opacity: 0;
  transition: opacity 120ms ease;
}

.dashboard-header .actions a:hover,
.dashboard-header .actions button:hover { color: var(--ink-1); text-decoration: none; }
.dashboard-header .actions a:hover::after,
.dashboard-header .actions button:hover::after { opacity: 1; }

.dashboard-frame {
  width: 100%;
  height: calc(100vh - var(--header-h) - 92px);
  border: 0;
  background: transparent;
  display: block;
}

.dashboard-frame:fullscreen { background: #000; }

/* Bare detail view: no Django title/kicker, rely on Grafana's own title
   inside the iframe. Actions sit in a slim toolbar above the embed so
   they never overlap Grafana's variable bar (which can wrap wide). */
.dashboard--bare {
  margin: -2.5rem -3rem;
  padding: 0;
  background: var(--surface);
  height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
}

.dashboard--bare .dashboard-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  padding: 0.3rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

.dashboard--bare .dashboard-actions a,
.dashboard--bare .dashboard-actions button {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 0.75rem;
  margin: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--ink-3);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.dashboard--bare .dashboard-actions a:hover,
.dashboard--bare .dashboard-actions button:hover {
  color: var(--ink-1);
  border-color: var(--ink-4);
  background: var(--surface-sunk);
  text-decoration: none;
}

.dashboard--bare .dashboard-actions a:focus-visible,
.dashboard--bare .dashboard-actions button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.dashboard--bare .dashboard-frame {
  /* Fill the column below the actions toolbar (no page scroll). */
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}

/* Tabbed variant: the embed shares the page with a companion panel (e.g. the
   Marketing spend grid), switched by CSS-only radio tabs. The dashboard tab
   keeps the full-height no-scroll embed; the companion tab scrolls within the
   same column. */
.dashboard--tabbed .tab-radio {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dashboard--tabbed .tabset {
  display: flex;
  gap: 0.25rem;
  margin-right: auto;          /* push the action buttons to the right */
}
.dashboard--tabbed .tab {
  height: 28px;
  padding: 0 0.85rem;
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-3);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
}
.dashboard--tabbed .tab:hover { color: var(--ink-1); border-color: var(--ink-4); }
#mkt-tab-dash:checked ~ .dashboard-actions .tab--dash,
#mkt-tab-spend:checked ~ .dashboard-actions .tab--spend {
  color: var(--surface);
  background: var(--primary);
  border-color: var(--primary);
}
.dashboard--tabbed .tab-panel { display: none; }
#mkt-tab-dash:checked ~ .tab-panel--dash {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
#mkt-tab-spend:checked ~ .tab-panel--spend {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* not-found page inside the dashboard route */
.dashboard-notfound {
  max-width: 32rem;
  margin: 4rem auto;
  text-align: center;
}
.dashboard-notfound h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.8rem;
  margin: 0 0 0.75rem;
}
.dashboard-notfound code {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--surface-sunk);
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
}

/* ─── responsive: collapse the nav on narrow screens ─────────────────── */

@media (max-width: 880px) {
  :root { --nav-w: 200px; }
  main { padding: 1.5rem 1.5rem; }
  .dashboard { margin: -1.5rem; padding: 1.25rem 1.25rem 0; }
}

@media (max-width: 640px) {
  nav.side { display: none; }
  main { padding: 1.25rem; }
  header.brand { padding: 0 1.25rem; gap: 0.75rem; }
  header.brand .user-info { gap: 0.85rem; font-size: 0.78rem; }
  header.brand .wordmark .client { font-size: 1.1rem; }
  header.brand .wordmark .app { display: none; }
}

/* dashboard detail: favourite toggle (base styling from .dashboard-actions button) */
.dashboard--bare .dashboard-actions form { display: contents; }
.dashboard--bare .dashboard-actions .fav-toggle .fav-star { font-size: 0.95rem; margin-right: 0.3rem; line-height: 1; }
.dashboard--bare .dashboard-actions .fav-toggle.is-fav { color: #8a6d00; border-color: #e6c200; }
.dashboard--bare .dashboard-actions .fav-toggle.is-fav .fav-star { color: #f1c40f; }
