/* ============================================================
   Revenue Dashboard — views/BEngine/analytic/Dashboard.php
   Driven by public/BEngine/N/js/revenue-dashboard.js (rd).
   Scoped under .rd so nothing here reaches the other admin pages.
   Every component class is prefixed rd- because Bootstrap 3 already
   owns .btn, .alert, .table and friends.
   Colours, radii and type come from tokens.css; nothing here declares a token.
   ============================================================ */

.rd {
  /* the KPI row and the header actions respond to the page's own width,
     which the left menu changes, not to the window */
  container-type: inline-size;
  padding: 20px 22px 28px;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--slate-50);
}

.rd *, .rd *::before, .rd *::after { box-sizing: border-box; }

/* Bootstrap's [hidden] rule has the same weight as .rd-alert { display:flex }
   and loads first, so it loses. Hidden must always win. */
.rd [hidden] { display: none !important; }

.rd button { font-family: inherit; }

.rd :focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- page header ---------- */

.rd-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--slate-200);
}

.rd .rd-head h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: var(--fs-22);
  font-weight: 700;
  color: var(--navy);
}

.rd-sub {
  max-width: 62ch;
  margin: 4px 0 0;
  font-size: var(--fs-13);
  color: var(--slate-600);
}

.rd-actions { display: flex; gap: 8px; }

.rd-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 13px;
  font-size: var(--fs-13);
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--slate-300);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.rd-btn:hover { border-color: var(--slate-400); background: var(--slate-50); }
.rd-btn:disabled { opacity: .55; cursor: not-allowed; }
.rd-btn svg { width: 15px; height: 15px; flex: 0 0 auto; }

.rd-btn-solid { color: var(--paper); background: var(--blue); border-color: var(--blue); }
.rd-btn-solid:hover { background: var(--blue-600); border-color: var(--blue-600); }

/* ---------- period + grouping toolbar ---------- */

.rd-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.rd-periods { display: flex; flex-wrap: wrap; gap: 6px; }

.rd-chip {
  padding: 6px 13px;
  font-size: var(--fs-13);
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--slate-300);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rd-chip:hover { border-color: var(--slate-400); }
.rd-chip[aria-pressed="true"] { color: var(--paper); background: var(--navy); border-color: var(--navy); }

.rd-seg {
  display: inline-flex;
  padding: 2px;
  background: var(--paper);
  border: 1px solid var(--slate-300);
  border-radius: var(--r);
}
.rd-seg button {
  padding: 5px 13px;
  font-size: var(--fs-13);
  font-weight: 600;
  line-height: 1.3;
  color: var(--slate-600);
  background: transparent;
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.rd-seg button[aria-pressed="true"] { color: var(--blue-600); background: var(--blue-50); }

.rd-custom {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
  margin-top: 12px;
}

.rd-field { display: grid; gap: 5px; }

.rd .rd-field label {
  margin: 0;
  font-size: var(--fs-11);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--slate-600);
}

.rd-field input {
  min-height: 36px;
  padding: 6px 10px;
  font-size: var(--fs-13);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--slate-300);
  border-radius: var(--r);
}
.rd-field input:focus { border-color: var(--blue); }

.rd-range {
  margin: 10px 0 16px;
  font-size: 12.5px;
  color: var(--slate-600);
}
.rd-range b { color: var(--ink); font-weight: 600; }

/* ---------- error banner ---------- */

.rd-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 16px;
  padding: 12px 16px;
  font-size: var(--fs-13);
  color: var(--danger);
  background: var(--danger-50);
  border: 1px solid rgba(192, 57, 43, .28);   /* --danger at 28% */
  border-radius: var(--r-lg);
}
.rd-alert b { display: block; font-size: var(--fs-14); }
.rd-alert span { color: var(--ink); }

/* ---------- the four figures; they are also the chart's metric switch ---------- */

.rd-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.rd-kpi {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  padding: 14px 16px;
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--slate-200);
  border-radius: var(--r-lg);
  box-shadow: var(--e-1);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.rd-kpi:hover { border-color: var(--slate-300); }
.rd-kpi[aria-pressed="true"] { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }

.rd-kpi-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--fs-11);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--slate-600);
}
.rd-kpi-on {
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--blue-600);
  visibility: hidden;
}
.rd-kpi[aria-pressed="true"] .rd-kpi-on { visibility: visible; }

.rd-kpi-value {
  min-height: 32px;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.rd-kpi-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  min-height: 22px;
  font-size: var(--fs-12);
  color: var(--slate-600);
  font-variant-numeric: tabular-nums;
}

.rd-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 8px;
  font-size: var(--fs-12);
  font-weight: 700;
  border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rd-delta.is-up   { color: var(--ok);        background: var(--ok-50); }
.rd-delta.is-down { color: var(--danger);    background: var(--danger-50); }
.rd-delta.is-flat { color: var(--slate-600); background: var(--slate-100); }
.rd-delta-g { font-size: 9px; }

/* ---------- cards ---------- */

.rd-card {
  margin-bottom: 16px;
  background: var(--paper);
  border: 1px solid var(--slate-200);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.rd-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 18px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200);
}

/* beg_responsive.css sizes every .bengine-content h3; this outranks it */
.rd .rd-card-head h4 {
  margin: 0;
  font-family: var(--serif);
  font-size: var(--fs-15);
  font-weight: 700;
  color: var(--navy);
}

.rd-note { font-size: var(--fs-12); color: var(--slate-600); }

.rd-legend { display: flex; align-items: center; gap: 14px; font-size: var(--fs-12); color: var(--slate-600); }
.rd-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.rd-sw-bar  { width: 11px; height: 11px; border-radius: 2px; background: var(--blue); }
.rd-sw-line { width: 18px; height: 0; border-top: 2px dashed var(--slate-400); }

.rd-card-body { padding: 16px 18px 12px; }

.rd-chart { position: relative; height: 300px; }

.rd-chart-sk {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 4px 22px;
}
.rd-chart-sk i { flex: 1 1 0; border-radius: 3px 3px 0 0; }

/* ---------- breakdown table ---------- */

.rd-table-wrap { overflow-x: auto; }

.rd-table {
  width: 100%;
  min-width: 700px;
  margin: 0;
  border-collapse: collapse;
  font-size: var(--fs-13);
  font-variant-numeric: tabular-nums;
}

/* bengine_N.css gives every td a border on all four sides and 10px padding;
   all four sides are reset here, not just the one we want */
.rd .rd-table th,
.rd .rd-table td {
  border: 0;
  border-bottom: 1px solid var(--slate-100);
  font-size: var(--fs-13);
  text-align: right;
  white-space: nowrap;
  vertical-align: middle;
}

.rd .rd-table th {
  padding: 0;
  background: var(--slate-50);
  border-bottom-color: var(--slate-200);
}

.rd .rd-table th:first-child,
.rd .rd-table td:first-child { text-align: left; }

.rd-table th button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  width: 100%;
  padding: 10px 16px;
  font-size: var(--fs-11);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--slate-600);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.rd-table th:not(:first-child) button { justify-content: flex-end; }
.rd-table th button:hover { color: var(--ink); }
.rd-si { width: 8px; font-size: 9px; color: var(--blue-600); }

.rd .rd-table td { padding: 9px 16px; color: var(--ink); }
.rd .rd-table td.rd-ly { color: var(--slate-600); }
.rd .rd-table tbody tr:hover td { background: var(--slate-50); }
.rd .rd-table tr.is-zero td { color: var(--slate-400); }
.rd .rd-table tr.is-zero td:first-child { color: var(--slate-600); }

.rd-tag {
  margin-left: 8px;
  padding: 1px 7px;
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--slate-600);
  background: var(--slate-100);
  border-radius: var(--r-pill);
}

.rd .rd-table tfoot td {
  font-weight: 700;
  background: var(--slate-50);
  border-top: 1px solid var(--slate-200);
  border-bottom: 0;
}

/* ---------- nothing to show ---------- */

.rd-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 46px 20px 50px;
  text-align: center;
}
.rd-empty-ico {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 4px;
  border-radius: 50%;
  color: var(--blue-600);
  background: var(--blue-50);
}
.rd-empty-ico svg { width: 22px; height: 22px; }
.rd .rd-empty h4 { margin: 0; font-family: var(--sans); font-size: var(--fs-15); font-weight: 700; color: var(--ink); }
.rd-empty p { max-width: 46ch; margin: 0 0 8px; font-size: var(--fs-13); color: var(--slate-600); }

/* ---------- loading ---------- */

.rd-sk {
  display: block;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--slate-100) 25%, var(--slate-50) 50%, var(--slate-100) 75%);
  background-size: 200% 100%;
  animation: rd-shimmer 1.2s linear infinite;
}
.rd-sk-v { width: 62%; height: 26px; margin-top: 3px; }
.rd-sk-f { width: 80%; height: 16px; }
.rd-sk-cell { height: 12px; }
@keyframes rd-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- narrow ---------- */

@container (max-width: 760px) {
  .rd-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rd-kpi-value { font-size: 21px; }
}

@container (max-width: 480px) {
  .rd-chart { height: 230px; }
  .rd-actions .rd-btn span { display: none; }
}

@media (max-width: 600px) {
  .rd { padding: 16px 14px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .rd-sk { animation: none; }
  .rd-btn, .rd-chip, .rd-kpi { transition: none; }
}

/* ---------- print: the report, without the admin around it ----------
   inc-css.php loads this file on every admin page, so the rules that hide the admin's own
   header and menu are scoped to the dashboard's <body class="rd-page">: other pages print as
   they always did. */

@media print {
  .rd-page #wrapper .header,
  .rd-page #wrapper .rate-menu,
  .rd-actions,
  .rd-bar,
  .rd-custom { display: none !important; }
  .rd-page #wrapper .rate-content { width: 100%; float: none; }
  .rd { padding: 0; background: #fff; }
  .rd-kpi, .rd-card { box-shadow: none; break-inside: avoid; }
  .rd-table { min-width: 0; }
  .rd-table-wrap { overflow: visible; }
}
