/* ==========================================================================
   bi-dashboard.css  -  NasaOS BI Dashboard  (single-page edition)
   --------------------------------------------------------------------------
   Deploy to:  <project>\files\css\bi-dashboard.css
   Register in uServerModule.CustomFiles:  files/css/bi-dashboard.css

   IMPORTANT: every rule is scoped under .bi-root. This file is injected into
   EVERY page of the application, so an unscoped rule (body, div, h3...) would
   restyle the whole of NasaOS. Do not add a selector outside .bi-root.

   DESIGN NOTES
   ------------
   * One scrolling page, two sections (Sales, Destinations). The section
     headers are sticky, so you always know which block you are looking at
     after scrolling past the fold.
   * Each card carries a 3px top edge in the SAME colour as its series. The
     colour is not decoration - it is the chart's identity colour, declared
     once in uBIDashboard.pas (CLR_USERS, CLR_SUPPLIERS, ...) and mirrored
     here. Change one, change the other.
   * No web fonts, on purpose: NasaOS must render on an offline LAN. All the
     typographic personality therefore comes from scale, weight, letter-
     spacing and tabular figures - never from a downloaded typeface.
   ========================================================================== */

.bi-root {
  /* ---- Design tokens. Retune the whole dashboard from here. ------------- */

  /* Canvas & surfaces */
  --bi-canvas:      #f2f4f7;
  --bi-surface:     #ffffff;
  --bi-surface-alt: #fafbfc;

  /* Lines: hairline for structure, soft for internal dividers */
  --bi-line:        #e4e8ee;
  --bi-line-soft:   #eef1f5;

  /* Ink */
  --bi-ink:         #101828;
  --bi-ink-soft:    #5a6675;
  --bi-ink-faint:   #8b95a3;

  /* Series identity colours - keep in sync with the CLR_* constants. */
  --bi-c-users:     #2f6fb0;
  --bi-c-suppliers: #2e8b57;
  --bi-c-srvtypes:  #6b5b95;
  --bi-c-bclients:  #6b5b95;
  --bi-c-countries: #b24b46;
  --bi-c-areas:     #c98a2b;

  /* Fallback accent, used by any card without a modifier class */
  --bi-accent:      var(--bi-c-users);

  /* Geometry */
  --bi-gap:         18px;
  --bi-radius:      10px;
  --bi-radius-sm:   6px;

  /* Elevation: two very light layers read as paper, one heavy one reads
     as a 2010 web app. */
  --bi-shadow:      0 1px 2px rgba(16, 24, 40, .04),
                    0 1px 3px rgba(16, 24, 40, .06);
  --bi-shadow-lift: 0 2px 4px rgba(16, 24, 40, .04),
                    0 8px 20px rgba(16, 24, 40, .08);

  box-sizing: border-box;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bi-canvas);
  color: var(--bi-ink);

  /* Inherit the host app's font so the dashboard does not look bolted on. */
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.bi-root *,
.bi-root *::before,
.bi-root *::after { box-sizing: inherit; }

/* Centred measure on ultra-wide monitors: past ~1800px the cards would be so
   wide that the eye loses the row it is reading. */
.bi-page {
  max-width: 1800px;
  margin: 0 auto;
  padding: var(--bi-gap) var(--bi-gap) 40px;
}

/* A thin, unobtrusive scrollbar - the page itself is the content. */
.bi-root::-webkit-scrollbar { width: 10px; }
.bi-root::-webkit-scrollbar-track { background: transparent; }
.bi-root::-webkit-scrollbar-thumb {
  background: #cfd6e0;
  border: 3px solid var(--bi-canvas);
  border-radius: 10px;
}
.bi-root::-webkit-scrollbar-thumb:hover { background: #b6c0ce; }

/* ==========================================================================
   Section
   ========================================================================== */

.bi-section + .bi-section { margin-top: 30px; }

/* Sticky, so the block you are scrolled into always names itself.
   The negative top cancels .bi-page's padding, giving a flush stick. */
.bi-section-head {
  position: sticky;
  top: calc(var(--bi-gap) * -1);
  z-index: 3;
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 12px;
  padding: 12px 2px 10px;
  background: var(--bi-canvas);
  border-bottom: 1px solid var(--bi-line);
}

.bi-section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--bi-ink);
}

.bi-section-sub {
  font-size: 12px;
  color: var(--bi-ink-faint);
  /* Drops away first when the window is narrow: it is context, not data. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .bi-section-sub { display: none; }
}

/* ==========================================================================
   Card grid
   ========================================================================== */

.bi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--bi-gap);
  align-items: start;   /* cards size to their own charts; see note below */
}

/* A chart that earns the full width (both destination charts). */
.bi-grid > .bi-card--wide { grid-column: 1 / -1; }

/* Below ~1080px two chart columns stop being readable, so stack them. */
@media (max-width: 1080px) {
  .bi-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   Card
   ========================================================================== */

.bi-card {
  position: relative;
  background: var(--bi-surface);
  border: 1px solid var(--bi-line);
  border-radius: var(--bi-radius);
  box-shadow: var(--bi-shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;               /* lets the chart shrink inside the grid cell */
  transition: box-shadow .16s ease, border-color .16s ease;
}

.bi-card:hover {
  box-shadow: var(--bi-shadow-lift);
  border-color: #d8dee7;
}

/* The signature: a 3px edge in the series colour. It is drawn as a pseudo
   element rather than a border-top so it can be inset to the card radius
   without clipping the card itself (overflow:hidden here used to slice the
   donut whenever its legend made the plot taller than the card). */
.bi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 10px;
  right: 10px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--bi-card-accent, var(--bi-accent));
}

/* Per-card accent. These modifiers are the only place a card knows its own
   colour, so a palette change is a one-line edit. */
.bi-card--users     { --bi-card-accent: var(--bi-c-users); }
.bi-card--suppliers { --bi-card-accent: var(--bi-c-suppliers); }
.bi-card--srvtypes  { --bi-card-accent: var(--bi-c-srvtypes); }
.bi-card--bclients  { --bi-card-accent: var(--bi-c-bclients); }
.bi-card--countries { --bi-card-accent: var(--bi-c-countries); }
.bi-card--areas     { --bi-card-accent: var(--bi-c-areas); }

/* --- Card header --------------------------------------------------------- */

.bi-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 16px 11px;
  border-bottom: 1px solid var(--bi-line-soft);
  background: var(--bi-surface-alt);
  border-radius: var(--bi-radius) var(--bi-radius) 0 0;
}

.bi-card-titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.bi-card-title {
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: -.005em;
  color: var(--bi-ink);
}

/* One line saying what the chart actually counts. Says out loud what the
   reader would otherwise have to guess from the SQL. */
.bi-card-hint {
  font-size: 11.5px;
  color: var(--bi-ink-faint);
  font-weight: 400;
}

/* Right-hand side of the header: total and row count, written by
   setMeta() in bi-dashboard.js. */
.bi-card-meta {
  font-size: 11.5px;
  color: var(--bi-ink-soft);
  white-space: nowrap;
  text-align: right;
  padding-top: 2px;
  /* Figures line up column-wise instead of jittering as values change. */
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* --- Plot area ----------------------------------------------------------- */

/* Charts set their own pixel height (see bi-dashboard.js), so the plot box
   wraps whatever they produce - axis labels included. A fixed height here
   made ApexCharts draw its x-axis labels below the card. */
.bi-plot {
  height: auto;
  min-height: 240px;
  padding: 8px 10px 10px;
  min-width: 0;
}

/* Donut legends can list a dozen service types; the card grows to fit. */
.bi-plot--donut {
  display: flex;
  flex-direction: column;
}

.bi-plot--donut .apexcharts-canvas { margin: 0 auto; }

/* ==========================================================================
   Empty / error state
   Says what happened and what to change - never a bare "No data".
   ========================================================================== */

.bi-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 220px;
  padding: 24px 28px;
  text-align: center;
  color: var(--bi-ink-soft);
  font-size: 12.5px;
  line-height: 1.55;
}

.bi-empty::before {
  content: "";
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px dashed #ccd4de;
  margin-bottom: 2px;
}

.bi-empty--error         { color: #a4342f; }
.bi-empty--error::before { border-color: #e3b4b1; border-style: solid; }

/* ==========================================================================
   ApexCharts overrides
   ========================================================================== */

/* Apex ships its own font stack; pull it back to the host app's. */
.bi-root .apexcharts-text tspan,
.bi-root .apexcharts-tooltip,
.bi-root .apexcharts-legend-text { font-family: inherit !important; }

.bi-root .apexcharts-tooltip {
  border: 1px solid var(--bi-line) !important;
  border-radius: var(--bi-radius-sm) !important;
  box-shadow: var(--bi-shadow-lift) !important;
}

.bi-root .apexcharts-tooltip-title {
  background: var(--bi-surface-alt) !important;
  border-bottom: 1px solid var(--bi-line-soft) !important;
  font-weight: 650 !important;
}

/* The export toolbar is faint until the card is hovered: it is a tool, not
   part of the reading. */
.bi-card .apexcharts-toolbar { opacity: .2; transition: opacity .16s ease; }
.bi-card:hover .apexcharts-toolbar,
.bi-card:focus-within .apexcharts-toolbar { opacity: 1; }

/* ==========================================================================
   Accessibility floor
   ========================================================================== */

.bi-root :focus-visible {
  outline: 2px solid var(--bi-c-users);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .bi-root *,
  .bi-card,
  .bi-card .apexcharts-toolbar { transition: none !important; }
}

/* Printing a dashboard is a real workflow: drop the shadows and let the
   cards break across pages without splitting a chart in half. */
@media print {
  .bi-root { height: auto; overflow: visible; background: #fff; }
  .bi-section-head { position: static; }
  .bi-card { box-shadow: none; break-inside: avoid; page-break-inside: avoid; }
  .bi-card .apexcharts-toolbar { display: none !important; }
}
