/*
 * FMCG P&L Dashboard.
 *
 * The palette is defined here and nowhere else. Chart modules read these
 * custom properties at render time rather than carrying hex values of their
 * own, so the scenarios stay consistent across every chart and a theme change
 * is a CSS edit, not a hunt through JavaScript.
 */

:root {
  color-scheme: light;

  /* --- scenario palette ------------------------------------------------
   * Actual is the hero and carries the darkest, most saturated tone.
   * Forecast is the same teal family one step lighter, and is always drawn
   * dashed: it has to read as "not yet real" even in greyscale.
   * Budget is ochre, the one warm tone, so plan and actual never blur.
   * Last year is neutral grey: context, never the subject.
   */
  --scenario-actual: #0b5563;
  --scenario-forecast: #3e97a8;
  --scenario-budget: #c98a2e;
  --scenario-ly: #98a2ae;

  /* --- variance palette -------------------------------------------------
   * Separate from the scenarios, because favourable and adverse are a
   * different axis of meaning. Deliberately not the reflex red and green:
   * these are muted enough to sit next to the teal without shouting, and
   * they differ in lightness as well as hue. Colour is never the only
   * encoding - the direction of the bar and the sign on the number both
   * repeat it.
   */
  --variance-favourable: #2e7d5b;
  --variance-adverse: #b4552d;

  /* --- surfaces and text ---------------------------------------------- */
  --page: #f3f6f8;
  --surface: #ffffff;
  --raised: #ffffff;
  --ink: #16202a;
  --ink-soft: #5b6874;
  --ink-faint: #8b97a3;
  --line: #e2e7ec;
  --line-strong: #cdd6de;
  --open-period: rgba(11, 85, 99, 0.045);
  --hover: rgba(11, 85, 99, 0.05);

  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 32, 42, 0.06),
    0 8px 24px rgba(22, 32, 42, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    /* Lifted for contrast against a dark ground; the roles are unchanged. */
    --scenario-actual: #4bb8cc;
    --scenario-forecast: #2c7d8c;
    --scenario-budget: #e0a44a;
    --scenario-ly: #7d8894;

    --variance-favourable: #4fae82;
    --variance-adverse: #d97a4e;

    --page: #0e1419;
    --surface: #161e26;
    --raised: #1b242d;
    --ink: #e8edf2;
    --ink-soft: #9aa8b5;
    --ink-faint: #6f7d8a;
    --line: #26313b;
    --line-strong: #33404c;
    --open-period: rgba(75, 184, 204, 0.06);
    --hover: rgba(75, 184, 204, 0.08);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 "Segoe UI", system-ui, -apple-system, "Helvetica Neue",
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Tabular figures wherever digits are compared, so columns line up and a
   changing value does not shift the text beside it. */
.kpi-value,
.kpi-delta,
.pnl td,
.period {
  font-variant-numeric: tabular-nums;
}

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

.page-header {
  padding: 26px 0 20px;
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.period {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
}

/* --- control bar -------------------------------------------------------- */

.control-bar {
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 6px rgba(22, 32, 42, 0.04);
}

/*
 * Sticky only when the screen is tall enough to spare it. On a short
 * viewport the slicers wrap into three rows and pin roughly 300px to the top,
 * which on a 384px window leaves no dashboard underneath. Below the
 * threshold the bar simply scrolls away like any other content.
 */
@media (min-height: 680px) {
  .control-bar {
    position: sticky;
    top: 0;
  }
}

.slicer-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  align-items: flex-end;
  padding: 12px 0 11px;
}

.slicer {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slicer-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.segmented {
  display: flex;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  overflow: hidden;
}

.segment {
  padding: 5px 11px;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line-strong);
  font-size: 13px;
  cursor: pointer;
}

.segment:last-child {
  border-right: 0;
}

.segment:hover {
  background: var(--hover);
}

.segment[aria-pressed="true"] {
  background: var(--scenario-actual);
  color: #fff;
  font-weight: 600;
}

/* --- multi-select picker ------------------------------------------------ */

.picker {
  position: relative;
}

.picker-summary {
  padding: 5px 11px;
  min-width: 96px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.picker-summary::-webkit-details-marker {
  display: none;
}

.picker-summary::after {
  content: " ▾";
  color: var(--ink-faint);
}

.picker-summary:hover {
  background: var(--hover);
}

.picker-summary.is-active {
  border-color: var(--scenario-actual);
  color: var(--scenario-actual);
  font-weight: 600;
}

.picker-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 5px);
  left: 0;
  /* Never wider than the screen it opens on: a fixed min-width pushed the
     panel past the viewport edge on a phone and took the page with it. */
  min-width: min(190px, calc(100vw - 40px));
  max-width: calc(100vw - 28px);
  max-height: 300px;
  overflow-y: auto;
  padding: 7px;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.picker-option {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 5px 7px;
  border-radius: 5px;
  font-size: 13.5px;
  cursor: pointer;
}

.picker-option:hover {
  background: var(--hover);
}

.picker-clear {
  width: 100%;
  margin-top: 5px;
  padding: 5px;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
}

.slicer-reset {
  padding: 5px 13px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
}

.slicer-reset:hover {
  background: var(--hover);
  color: var(--ink);
}

/* --- breadcrumb and reading line ---------------------------------------- */

.context-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  align-items: baseline;
  padding: 0 0 11px;
}

.trail {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
}

.crumb {
  padding: 2px 7px;
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-size: 13px;
  color: var(--scenario-actual);
  cursor: pointer;
}

.crumb:hover:not(:disabled) {
  background: var(--hover);
}

.crumb:disabled {
  color: var(--ink-soft);
  cursor: default;
}

.crumb.is-current {
  font-weight: 650;
  color: var(--ink);
}

.crumb-sep {
  color: var(--ink-faint);
}

.reading {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
}

.reading-note {
  flex-basis: 100%;
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-faint);
}

/* --- view switcher ------------------------------------------------------ */

.views {
  display: flex;
  /* Wraps rather than pushing the page sideways: three tabs plus their
     badges do not fit on a phone in one row. */
  flex-wrap: wrap;
  gap: 4px;
  padding: 18px 0 0;
}

.view-tab {
  display: flex;
  gap: 7px;
  align-items: center;
  padding: 7px 15px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}

.view-tab:hover {
  color: var(--ink);
}

.view-tab[aria-pressed="true"] {
  font-weight: 650;
  color: var(--ink);
  border-bottom-color: var(--scenario-actual);
}

.view-badge {
  padding: 1px 6px;
  background: var(--page);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* --- KPI strip ---------------------------------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-top: 22px;
}

.kpi {
  padding: 13px 15px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.kpi-label {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.kpi-value {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.kpi-delta {
  margin: 2px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-faint);
}

.kpi.is-unavailable .kpi-value {
  color: var(--ink-faint);
  font-weight: 500;
}

.is-favourable {
  color: var(--variance-favourable);
}

.is-adverse {
  color: var(--variance-adverse);
}

.is-flat {
  color: var(--ink-faint);
}

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

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.card {
  margin-top: 18px;
  padding: 20px 22px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.grid-2 .card {
  margin-top: 18px;
  min-width: 0;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.card-header p {
  margin: 5px 0 0;
  max-width: 76ch;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.chart-frame {
  position: relative;
  height: 330px;
  margin-top: 16px;
}

.chart-frame.is-short {
  height: 250px;
}

.inline-key {
  display: inline-block;
  min-width: 15px;
  padding: 0 3px;
  background: var(--page);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 11px;
  text-align: center;
}

/* --- P&L table ---------------------------------------------------------- */

.table-frame {
  margin-top: 14px;
  overflow-x: auto;
}

.pnl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.pnl th,
.pnl td {
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

.pnl thead th {
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line-strong);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.pnl .num {
  text-align: right;
}

.pnl .col-line {
  width: 30%;
  font-weight: 400;
}

.pnl-row.is-strong {
  font-weight: 650;
}

.pnl-row.is-strong th,
.pnl-row.is-strong td {
  border-top: 1px solid var(--line);
}

.pnl-row.is-normal .col-line {
  padding-left: 22px;
  color: var(--ink-soft);
}

.pnl-row.is-detail {
  font-size: 12.5px;
  color: var(--ink-soft);
}

.pnl-row.is-detail .col-line {
  padding-left: 46px;
  font-weight: 400;
}

.pnl-row.is-unavailable {
  color: var(--ink-faint);
}

.pnl-row:hover td,
.pnl-row:hover th {
  background: var(--hover);
}

.disclose {
  width: 17px;
  height: 17px;
  margin-right: 7px;
  padding: 0;
  background: var(--page);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
}

.disclose:hover {
  border-color: var(--scenario-actual);
  color: var(--scenario-actual);
}

/* --- roadmap views ------------------------------------------------------ */

.roadmap {
  margin-top: 22px;
  padding: 26px 28px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.roadmap h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 650;
}

.roadmap p {
  margin: 0 0 14px;
  max-width: 74ch;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.roadmap ul {
  margin: 0;
  padding-left: 20px;
  max-width: 78ch;
}

.roadmap li {
  margin-bottom: 9px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}

.roadmap strong {
  color: var(--ink);
}

/* --- status and footer -------------------------------------------------- */

.status {
  margin: 26px 0 0;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--ink-soft);
}

.status code {
  padding: 1px 5px;
  background: var(--page);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 12.5px;
}

.page-footer {
  margin: 34px 0 0;
  padding: 18px 0 40px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-faint);
}

.page-footer a {
  margin-left: 8px;
  color: var(--ink-soft);
}

/* --- responsive --------------------------------------------------------- */

@media (max-width: 1080px) {
  .kpis {
    grid-template-columns: repeat(3, 1fr);
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 0 14px;
  }
  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }
  .chart-frame {
    height: 280px;
  }
  .slicer-bar {
    gap: 10px 14px;
  }
  h1 {
    font-size: 21px;
  }
  .pnl .col-line {
    width: auto;
  }
  .view-tab {
    padding: 7px 11px;
  }
}
