/* File: assets/css/account-mgmt.css
 * ----------------------------------------------------------------------------
 * Account Management view-specific styles.
 *
 * Design notes:
 *   * The shell is a CSS Grid: blade column (240px) + main column (1fr) on
 *     viewports >= 992px (Bootstrap's lg). Below that the blade collapses
 *     into a Bootstrap offcanvas and the grid degenerates to a single column.
 *   * We do NOT override Bootstrap's design tokens; we only layer on top.
 *   * Page-wide assumptions inherited from main.css:
 *       --accent-color: #0076d4
 *       --heading-color: #273d4e
 *     ...are used for active-link highlight and the brand strip.
 *   * The layout uses position: sticky for the blade so long views in the
 *     main pane scroll while the nav stays visible. Top offset matches
 *     the portal's fixed-top header height (~ 90px).
 *   * On lg+ we widen the .container that hosts #arc-acct-root so the blade
 *     hugs the left side of a wider viewport and the dashboard widgets get
 *     enough horizontal room for their charts and table columns. The
 *     override is scoped strictly to body.arc-acct-page so no other page
 *     in the portal is affected, and it leaves the fixed-top header and
 *     footer untouched.
 * ---------------------------------------------------------------------------- */

:root {
  --arc-acct-blade-width: 240px;
  --arc-acct-header-offset: 90px; /* portal #header is fixed-top, ~ 90px tall */
  --arc-acct-content-max: 1640px; /* widened cap for the account-mgmt page */
}

#arc-acct-root {
  /* The host now lives inside <section class="starter-section section
     light-background"><div class="container">. The section provides the
     light backdrop and the page-title above it provides the dark spacer
     under the fixed-top header, so #arc-acct-root no longer paints its
     own background. */
}

/* ----- Container width override (account-mgmt page only) ---------------
 * Bootstrap's .container caps at 1320px on xxl, which leaves the
 * dashboard's blade nav, charts, and table fighting for horizontal room.
 * On lg+ we raise that cap so the blade can shift left and the main
 * pane has room for full-width charts and a non-scrolling table.
 * The header (#header) and footer (#footer) are not selected here, so
 * their layout is unaffected.
 * ---------------------------------------------------------------------- */
@media (min-width: 992px) {
  body.arc-acct-page #account-management.starter-section > .container {
    max-width: var(--arc-acct-content-max);
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }
}

/* ----- Sticky-blade authed shell ---------------------------------------
 * The shell sits inside the (now widened) .container so the blade can
 * hug the left edge while the main content has room to breathe.
 * ---------------------------------------------------------------------- */

.arc-acct-shell {
  position: relative;
}

/* ----- Unauthed entry panels (key, TOTP enroll, TOTP verify) -----------
 * The page wraps #arc-acct-root in <section.starter-section><div.container>
 * (matching index.html / gettingStarted.html), so the panel itself no
 * longer needs flex-centering or its own container; it just renders
 * inline into the section. The class hook is kept in case any
 * descendant rule wants to scope styles, but layout is handled by the
 * portal-wide .section / .container chrome.
 * ---------------------------------------------------------------------- */
.arc-acct-panel {
  /* Intentionally empty; see comment block above. */
}

.arc-acct-grid {
  display: grid;
  grid-template-columns: 1fr;
  /* Section padding provides clearance; the grid does not need to fill
     the whole viewport here. */
  min-height: 60vh;
}

@media (min-width: 992px) {
  .arc-acct-grid {
    grid-template-columns: var(--arc-acct-blade-width) 1fr;
    column-gap: 1.25rem;
  }
}

/* ----- Sticky left blade ---------------------------------------------- */
.arc-acct-blade {
  background: #ffffff;
  border-right: 1px solid #e6e8ee;
  position: sticky;
  top: var(--arc-acct-header-offset);
  height: calc(100vh - var(--arc-acct-header-offset));
  align-self: start;
}

.arc-acct-blade-brand {
  border-bottom: 1px solid #e6e8ee;
  font-family: "Raleway", sans-serif;
  letter-spacing: 0.02em;
}

.arc-acct-blade-nav .nav-link.arc-acct-nav-link {
  color: var(--heading-color, #273d4e);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.15rem;
  transition: background-color 120ms ease, color 120ms ease;
}

.arc-acct-blade-nav .nav-link.arc-acct-nav-link:hover,
.arc-acct-blade-nav .nav-link.arc-acct-nav-link:focus-visible {
  background-color: #eef4fb;
  color: var(--accent-color, #0076d4);
}

.arc-acct-blade-nav .nav-link.arc-acct-nav-link.active {
  background-color: var(--accent-color, #0076d4);
  color: #ffffff;
}

/* Offcanvas mirror: same visual language as the desktop blade */
.offcanvas .nav-link.arc-acct-nav-link {
  color: var(--heading-color, #273d4e);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
}

.offcanvas .nav-link.arc-acct-nav-link.active {
  background-color: var(--accent-color, #0076d4);
  color: #ffffff;
}

/* ----- Main pane ------------------------------------------------------ */
.arc-acct-main {
  min-width: 0; /* allow children to shrink in grid */
}

.arc-acct-main .card {
  border-radius: 10px;
}

.arc-acct-main .card .card-body h2.h5,
.arc-acct-main .card .card-body h2.h6 {
  color: var(--heading-color, #273d4e);
}

/* ----- Dashboard chart wrappers --------------------------------------- *
 * Each Chart.js canvas is initialised with maintainAspectRatio:false so
 * it fills its parent. These wrappers give the parent a defined size so
 * the chart has room to render labels and lines without overflowing the
 * card or being squashed when the viewport is narrow.
 *
 * The dashboard places all three charts in a single row (col-lg-4 each)
 * on lg+, so each card is ~540px wide on a 1640px container. The line
 * and radar wrappers below give each chart enough vertical room at that
 * width without forcing the cards to be unevenly tall.
 * ---------------------------------------------------------------------- */
.arc-acct-line-wrap {
  position: relative;
  height: 260px;
  min-height: 220px;
}

.arc-acct-radar-wrap {
  position: relative;
  height: 320px;
  min-height: 260px;
}

@media (min-width: 1200px) {
  .arc-acct-line-wrap {
    height: 280px;
  }
  .arc-acct-radar-wrap {
    height: 340px;
  }
}

/* ----- Chart card extras --------------------------------------------- *
 * Each chart card gets a small Expand button in the top-right corner.
 * The button uses Bootstrap's btn-outline-secondary so it stays muted
 * relative to the card title.
 * ---------------------------------------------------------------------- */
.arc-acct-chart-card .arc-acct-chart-expand {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ----- Fullscreen chart modal ---------------------------------------- *
 * The modal renders an expanded copy of whichever chart was clicked.
 * The body is a flex column so the canvas wrapper fills available space
 * vertically while keeping a sensible max-width for radar charts (which
 * look stretched on ultrawide displays).
 * ---------------------------------------------------------------------- */
.arc-acct-chart-modal .modal-body {
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: #ffffff;
}

.arc-acct-chart-modal-wrap {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  /* Cap horizontal stretch on very wide screens so the radar polygon
     stays roughly square and the line charts do not become a thin
     horizon-line. Centred via auto margins. */
  max-width: 1400px;
  margin: 0 auto;
  /* The modal-fullscreen modal-body has flex:1 1 auto on us, but
     Chart.js needs an explicit height target as well. Set a generous
     min-height; the flex parent supplies the actual height. */
  min-height: 60vh;
}

.arc-acct-chart-modal-wrap > canvas {
  max-width: 100%;
  height: 100% !important;
  width: 100% !important;
}

/* ----- Recent reports table ------------------------------------------- *
 * Column min-widths so the seven columns each get enough room to render
 * their header text and values without the table forcing a horizontal
 * scrollbar on standard desktop widths. On narrower viewports the
 * .table-responsive wrapper still allows horizontal scroll as a fallback.
 * ---------------------------------------------------------------------- */
.arc-acct-reports-wrap {
  /* Reserve a sensible minimum height so the empty-state row and a
     short list of reports do not make the card collapse to almost
     nothing on screens with little content. */
  min-height: 220px;
}

.arc-acct-reports-wrap > table {
  min-width: 880px; /* sum of per-column min-widths below, with margin */
}

.arc-acct-reports-wrap > table th,
.arc-acct-reports-wrap > table td {
  vertical-align: middle;
}

.arc-acct-reports-wrap > table th:nth-child(1),
.arc-acct-reports-wrap > table td:nth-child(1) { min-width: 200px; } /* Target Domain */
.arc-acct-reports-wrap > table th:nth-child(2),
.arc-acct-reports-wrap > table td:nth-child(2) { min-width: 170px; } /* Completed At */
.arc-acct-reports-wrap > table th:nth-child(3),
.arc-acct-reports-wrap > table td:nth-child(3) { min-width: 90px;  } /* Score % */
.arc-acct-reports-wrap > table th:nth-child(4),
.arc-acct-reports-wrap > table td:nth-child(4) { min-width: 70px;  } /* Pass */
.arc-acct-reports-wrap > table th:nth-child(5),
.arc-acct-reports-wrap > table td:nth-child(5) { min-width: 80px;  } /* Failure */
.arc-acct-reports-wrap > table th:nth-child(6),
.arc-acct-reports-wrap > table td:nth-child(6) { min-width: 110px; } /* Unavailable */
.arc-acct-reports-wrap > table th:nth-child(7),
.arc-acct-reports-wrap > table td:nth-child(7) { min-width: 110px; } /* View button */

/* ----- Key Management: billing-period scans table -------------------- *
 * Lighter footprint than the dashboard's Recent reports table since it
 * has fewer columns. Min-widths sized to the actual columns
 * (Target Domain, Executed, Checks Run, View).
 * ---------------------------------------------------------------------- */
.arc-acct-km-period-table > table {
  min-width: 640px;
}
.arc-acct-km-period-table > table th,
.arc-acct-km-period-table > table td {
  vertical-align: middle;
}
.arc-acct-km-period-table > table th:nth-child(1),
.arc-acct-km-period-table > table td:nth-child(1) { min-width: 220px; } /* Target Domain */
.arc-acct-km-period-table > table th:nth-child(2),
.arc-acct-km-period-table > table td:nth-child(2) { min-width: 200px; } /* Executed */
.arc-acct-km-period-table > table th:nth-child(3),
.arc-acct-km-period-table > table td:nth-child(3) { min-width: 110px; } /* Checks Run */
.arc-acct-km-period-table > table th:nth-child(4),
.arc-acct-km-period-table > table td:nth-child(4) { min-width: 110px; } /* View */

/* ----- Sortable header indicators ------------------------------------- */
.arc-acct-main th.arc-sort {
  user-select: none;
  white-space: nowrap;
}

.arc-acct-main th.arc-sort:hover {
  color: var(--accent-color, #0076d4);
}

.arc-acct-main th.arc-sort.active {
  color: var(--accent-color, #0076d4);
}

/* ----- Empty state for charts (no scans yet) -------------------------- */
.arc-acct-main canvas {
  max-width: 100%;
}

/* ----- Forms / inputs ------------------------------------------------- */
.arc-acct-main .form-label.fw-semibold {
  color: var(--heading-color, #273d4e);
}

.arc-acct-main code.form-control {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
  overflow-x: auto;
}

/* ----- Mobile toggle bar --------------------------------------------- */
.arc-acct-mobile-bar {
  z-index: 1010; /* below Bootstrap's modal (1055) but above page content */
}

/* ----- Honour reduced-motion preferences ----------------------------- */
@media (prefers-reduced-motion: reduce) {
  .arc-acct-blade-nav .nav-link.arc-acct-nav-link {
    transition: none;
  }
}

/* ----- Sticky-footer behaviour (account management page only) ---------
 * Scoped strictly to `body.arc-acct-page` so this rule cannot affect
 * any other page in the portal.
 *
 * Strategy: classic flexbox sticky footer.
 *   - body becomes a vertical flex column at least 100vh tall
 *   - <main> (which holds the page-title + section) flex-grows to fill
 *     the space between the header and footer
 *   - Inside <main>, the section flex-grows to take all the space the
 *     page-title strip leaves behind
 *
 * Net effect: the footer always sits at the bottom of the viewport
 * when content is short, with no manual min-height calc that has to
 * guess the footer's actual height. When content is taller than the
 * viewport (TOTP enrol with the QR + secret), everything just grows
 * naturally and the footer scrolls below the fold the normal way.
 *
 * Why not put this on the body of every page?
 * Because the home page already has plenty of content and switching
 * its layout to flex could subtly affect AOS triggers and section
 * spacing on pages that work fine today. Restricting to .arc-acct-page
 * limits the blast radius to this drop-in.
 * ---------------------------------------------------------------------- */
body.arc-acct-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body.arc-acct-page > main.main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

body.arc-acct-page > footer {
  flex-shrink: 0;
}

body.arc-acct-page #account-management.starter-section {
  /* Take whatever vertical space the page-title above us leaves over.
     The dashboard now has multiple stacked rows, so we no longer
     vertically centre the contents; we let them flow from the top so
     the table at the bottom does not float off-screen on tall viewports. */
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

body.arc-acct-page #account-management.starter-section > .container {
  /* Flex item: without an explicit width Bootstrap's .container would
     shrink to its content. */
  width: 100%;
}
