:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1f2430;
  --muted: #565c68;      /* AA contrast (>=4.5:1) on --bg and white (WCAG 1.4.3) */
  --primary: #f2c811;      /* Power BI yellow */
  --primary-ink: #1f2430;
  --error-bg: #fdecea;
  --error-ink: #a1281f;
  --info-bg: #e8f1fd;
  --info-ink: #1d4e89;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  /* Baseline line-height so user text-spacing overrides (WCAG 1.4.12)
     apply cleanly without clipping. */
  line-height: 1.5;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: 0.2px; color: var(--text); text-decoration: none; }
a.brand:hover { text-decoration: underline; }
.topbar-nav { display: flex; align-items: center; gap: 1rem; }
.user { color: var(--muted); font-size: 0.9rem; }
/* Role badge. Uses --muted for the text (an AA-contrast token, WCAG 1.4.3)
   rather than a lighter grey, so the small type stays readable. */
.user-role {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.logout-form { margin: 0; }

/* Layout */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); font-weight: 600; width: 100%; }
.btn-primary:hover { filter: brightness(0.96); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: #d92d20; color: #fff; }
.btn-danger:hover { background: #b42318; }
/* Buttons need their own visible focus indicator (WCAG 2.4.7 / 2.4.11): the
   default browser outline is easy to miss, and on .btn-primary it blends into
   the button's own --primary background. A dark outline plus offset keeps it
   visible against every button variant and the surrounding page background. */
.btn:focus-visible {
  outline: 3px solid var(--primary-ink);
  outline-offset: 2px;
}

/* Flash messages */
/* The live region renders on every page (see base.html) so announcements work;
   collapse it when empty so it costs no vertical space. */
.flashes { margin-bottom: 1rem; }
.flashes:empty { margin: 0; }
/* The flash region receives focus on load so screen readers announce it (see
   base.html). It is not an interactive control, so no persistent ring — but
   :focus-visible still shows one for keyboard users who Shift+Tab back to it.
   The ring is tinted per category by the rules below, so it reads as part of the
   message rather than as a stray black box around it. */
.flashes:focus { outline: none; }
/* Same treatment as .form-errors on the login page: matching padding, radius and
   type size, plus a 4px left bar so the message's nature is carried by more than
   colour alone (WCAG 1.4.1). */
.flash {
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  border-left: 4px solid currentColor;
}
.flash:last-child { margin-bottom: 0; }
.flash-error { background: var(--error-bg); color: var(--error-ink); }
.flash-info { background: var(--info-bg); color: var(--info-ink); }
/* Ring colour follows the message it surrounds, so it reads as part of the
   message. The app only flashes "info" today; the :has() rule is here so an
   error flash gets the right ring if one is ever added. Browsers without :has()
   simply keep the info ring — a colour nuance, not a loss of the indicator. */
.flashes:focus-visible { outline: 3px solid var(--info-ink); outline-offset: 2px; }
.flashes:focus-visible:has(.flash-error) { outline-color: var(--error-ink); }
/* Fade applied 10s after load, just before the region is removed (see base.html).
   Honours reduced-motion by cutting straight to the removal (WCAG 2.3.3). */
.flashes-dismissing { opacity: 0; transition: opacity 0.4s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .flashes-dismissing { transition: none; }
}

/* Login */
.login-page .content { align-items: center; justify-content: center; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  /* Grow in height as needed; never a fixed height, so content is not clipped
     when users apply the WCAG 1.4.12 text-spacing overrides. */
  height: auto;
  overflow: visible;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
/* Explicit paragraph spacing (>= 2x font size) satisfies the paragraph-spacing
   portion of WCAG 1.4.12 without breaking layout. */
.login-card .subtitle { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.login-card label { display: block; margin: 0.75rem 0 0.3rem; font-size: 0.85rem; font-weight: 600; }
.required { color: var(--error-ink); }
.login-card input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}
.login-card input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.login-card button { margin-top: 1.25rem; }
/* Live region for client-side form validation (WCAG 4.1.3).
   Collapsed when empty; shown when messages are injected. */
.form-errors:empty { display: none; }
.form-errors {
  margin: 0 0 0.5rem;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  background: var(--error-bg);
  color: var(--error-ink);
  font-size: 0.85rem;
  /* A left bar carries the "this is an error" meaning without relying on colour
     alone (WCAG 1.4.1), which matters for the ~8% of men with red-green CVD. */
  border-left: 4px solid var(--error-ink);
}
/* The error receives focus on load so screen readers announce it (see
   login.html). It is not an interactive control, so it gets no persistent ring —
   but :focus-visible still shows one for keyboard users who Shift+Tab back to
   re-read the message. */
.form-errors:focus { outline: none; }
.form-errors:focus-visible {
  outline: 3px solid var(--error-ink);
  outline-offset: 2px;
}
/* Fade applied 10s after load, just before the box is removed (see login.html).
   Honours reduced-motion by cutting straight to the removal (WCAG 2.3.3). */
.form-errors-dismissing { opacity: 0; transition: opacity 0.4s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .form-errors-dismissing { transition: none; }
}

/* Dashboard / report */
.dashboard-page .content { padding: 0; overflow: hidden; }
.report-head {
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;             /* fixed-height bar, never grows/shrinks */
}
.report-head .page-title { margin: 0; font-size: 1.15rem; }
/* The report fills exactly the remaining space and never overflows, so the
   report's own page-navigation tab row stays inside the viewport (otherwise
   the tabs render below the fold and clicks land outside the frame). */
.report-frame {
  flex: 1 1 auto;
  min-height: 0;             /* allow the flex item to actually shrink */
  width: 100%;
  border: none;
  overflow: hidden;
}
.report-frame iframe { width: 100%; height: 100%; border: none; display: block; }

.report-error {
  margin: 2rem auto;
  max-width: 480px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
}
.report-error h2 { margin-top: 0; }
.report-error p { color: var(--muted); }

/* Multi-report picker (tab bar) */
.report-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem 1rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.report-tab {
  padding: 0.5rem 1rem;
  border-radius: 8px 8px 0 0;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  border: 1px solid transparent;
  border-bottom: none;
}
.report-tab:hover { background: var(--bg, #f3f4f6); color: inherit; }
.report-tab.active {
  color: inherit;
  background: var(--bg, #fff);
  border-color: var(--border);
}
/* When a picker is present, leave room for it (header 57px + picker ~49px). */
.report-picker + .report-frame,
.report-picker ~ .report-frame { min-height: calc(100vh - 106px); }
.report-picker ~ .report-frame iframe { min-height: calc(100vh - 106px); }

/* Reports listing page */
.reports-page .content { padding: 1.5rem; }
.page-title { margin: 0 0 0.25rem; font-size: 1.4rem; }
.page-sub { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.9rem; }
.page-sub code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
}
.reports-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.reports-table th, .reports-table td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  /* Allow cell text to wrap so content is not clipped when users apply the
     WCAG 1.4.12 text-spacing overrides (line-height, letter/word spacing). */
  overflow-wrap: anywhere;
}
/* Keep the ID columns compact but let them wrap rather than overflow. */
.reports-table td.mono { white-space: normal; }
.reports-table thead th {
  color: var(--muted);
  font-weight: 600;
  background: var(--bg);
}
.reports-table tbody tr:last-child td { border-bottom: none; }
.report-row { cursor: pointer; }
.report-row:hover { background: var(--bg); }
.report-name { font-weight: 600; }
.mono { color: var(--muted); font-size: 0.82rem; }
.btn-sm { width: auto; padding: 0.35rem 0.8rem; font-size: 0.82rem; display: inline-block; }

/* Report tiles — the single landing page. One click per report, no drill-down. */
.tile-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1rem;
  /* Reflows from many columns to one without a horizontal scrollbar, so the
     page stays usable at 320px / 400% zoom (WCAG 1.4.10 Reflow). */
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}
.tile { display: flex; }
.tile-link {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
  /* Height grows with content, so nothing clips under the WCAG 1.4.12
     text-spacing overrides. */
  height: auto;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.tile-link:hover {
  border-color: var(--muted);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}
/* WCAG 2.4.7 / 2.4.11: the hover shadow is not a focus indicator. A dark
   outline with an offset stays visible against the card and the page behind it. */
.tile-link:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 2px;
}
.tile-title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  /* Long report names wrap rather than overflow the tile. */
  overflow-wrap: anywhere;
}
.tile-meta { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
/* WCAG 2.3.3: respect a user's reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
  .tile-link { transition: none; }
  .tile-link:hover { transform: none; }
}
/* Site footer navigation (WCAG 2.4.5 Multiple Ways) */
.site-footer {
  flex: 0 0 auto;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
/* The report-embed page fills the viewport with the iframe, so drop the footer
   there to keep the report frame full-height. WCAG 2.4.5 is still met site-wide:
   the topbar nav and the site map are two independent ways to reach every page. */
.dashboard-page .site-footer { display: none; }
.footer-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}
.footer-nav a { color: var(--muted); text-decoration: none; }
.footer-nav a:hover { color: var(--text); text-decoration: underline; }

/* Site map page */
.sitemap-list { line-height: 1.9; }

/* Accessibility: visually-hidden utility — content stays in the accessibility
   tree (screen readers) but is removed from view, and never clips visible text
   when users apply custom text-spacing overrides (WCAG 1.4.12). */
.visually-hidden,
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* Accessibility: skip to main content (WCAG 2.4.1 Bypass Blocks) */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--text);
  color: var(--bg);
  border-radius: 0 0 6px 0;
  text-decoration: none;
}
.skip-link:focus { left: 0; }

/* <main> is focusable only so focus can be moved to it programmatically (skip
   link target, and the post-navigation focus reset). It is not an interactive
   control, so it shows no focus ring — real controls keep theirs. */
#main:focus { outline: none; }

/* Management area: company/user CRUD forms (Phase 2) */
.mgmt-inline-form { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; max-width: 28rem; }
.mgmt-inline-form input { flex: 1; padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; }
/* Explicit placeholder color: this input's real label is sr-only, so the
   placeholder is the only visible instruction sighted users get — it must
   meet the same 4.5:1 contrast (WCAG 1.4.3) as real text, not the browser's
   unstyled default gray. --muted is already verified AA on white/--bg. */
.mgmt-inline-form input::placeholder { color: var(--muted); opacity: 1; }
.mgmt-form { max-width: 28rem; margin-bottom: 1.5rem; }
.mgmt-form label { display: block; margin: 0.75rem 0 0.3rem; font-size: 0.85rem; font-weight: 600; }
.mgmt-form input, .mgmt-form select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.mgmt-form button, .mgmt-form a.btn { margin-top: 1rem; }
.mgmt-checklist { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: 0.5rem; max-width: 28rem; }
.mgmt-checklist label { display: flex; align-items: center; gap: 0.5rem; }
.mgmt-row-actions { display: flex; gap: 0.5rem; align-items: center; white-space: nowrap; }
.mgmt-row-actions form { margin: 0; }
.mgmt-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.mgmt-tab {
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
.mgmt-tab:hover { color: inherit; }
.mgmt-tab.active { color: inherit; border-color: var(--primary); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-head .page-title, .page-head .page-sub { margin-bottom: 0; }
.page-head .btn { flex: 0 0 auto; width: auto; }
