/**
 * Procurement Intelligence Dashboard — Responsive CSS
 *
 * Color palette: red (#d92027), yellow (#f5b800), ink (#171717)
 * Layout: fixed 260px sidebar + fluid content grid
 * Responsive: fluid grids with mode-change breakpoints at 1360 / 1100 / 760 / 480
 *
 * Font "Inter" is loaded via external_stylesheets in app.py, not @import.
 */

/* ========================================================================== */
/* ROOT VARIABLES & RESET                                                     */
/* ========================================================================== */

:root {
  --red: #d92027;
  --red-dark: #b8171d;
  --yellow: #f5b800;
  --yellow-ink: #b07d00;
  --green: #15966f;
  --ink: #171717;
  --ink-2: #2b2b2b;
  --ink-line: #393939;
  --ink-soft: #a8a8a8;
  --muted: #5f5f5f;
  --paper: #f4f1eb;
  --white: #fff;
  --line: #dedbd5;
  --input-line: #ddd;
  --radius: 6px;
  --radius-sm: 4px;
  --sidebar-w: 260px;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ========================================================================== */
/* SHELL / LAYOUT                                                             */
/* ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.content {
  grid-column: 2;
  padding: 0 32px 50px;
  min-width: 0;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

/* ========================================================================== */
/* SIDEBAR                                                                    */
/* ========================================================================== */

.sidebar {
  background: var(--ink);
  color: var(--white);
  padding: 27px 18px;
  position: fixed;
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  z-index: 3;
}

.brand {
  display: flex;
  gap: 13px;
  align-items: center;
  padding: 0 8px 28px;
  border-bottom: 1px solid var(--ink-line);
}

.mark {
  background: var(--red);
  width: 45px;
  height: 45px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 18px;
  color: var(--white);
  flex-shrink: 0;
}

.brand h1 {
  font-size: 14px;
  margin: 0;
}

.brand p {
  font-size: 10px;
  color: var(--ink-soft);
  margin: 5px 0 0;
}

nav {
  padding-top: 28px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
  padding: 13px 14px;
  margin: 4px 0;
  border-radius: 7px;
  font: 600 13px Inter, Arial, sans-serif;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav span:first-child {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

.nav:hover,
.nav.active {
  background: var(--ink-2);
  color: var(--white);
}

.nav.active {
  box-shadow: inset 3px 0 var(--red);
}

/* ========================================================================== */
/* SIDEBAR FOOTER — LIVE badge + developer credit                             */
/* ========================================================================== */

.source {
  margin-top: auto;
  padding: 16px 6px 4px;
  border-top: 1px solid var(--ink-line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* --- LIVE badge ---------------------------------------------------------- */

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 9px;
  border-radius: 999px;
  background: rgba(82, 211, 151, 0.08);
  border: 1px solid rgba(82, 211, 151, 0.22);
  align-self: flex-start;
  user-select: none;
}

.live-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #52d397;
  box-shadow: 0 0 0 0 rgba(82, 211, 151, 0.55);
  animation: live-pulse 2s ease-out infinite;
  flex-shrink: 0;
}

.live-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.6px;
  color: #52d397;
  text-transform: uppercase;
  line-height: 1;
}

@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(82, 211, 151, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(82, 211, 151, 0);   }
  100% { box-shadow: 0 0 0 0 rgba(82, 211, 151, 0);     }
}

/* --- Developer credit ---------------------------------------------------- */

.credit {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.3px;
  line-height: 1.4;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 2px 0;
  border: 0;
  transition: color 0.15s ease;
}

.credit:hover,
.credit:focus-visible {
  color: var(--white);
}

.credit-arrow {
  display: inline-block;
  font-size: 10px;
  color: var(--ink-soft);
  transition: color 0.15s ease, transform 0.15s ease;
}

.credit:hover .credit-arrow,
.credit:focus-visible .credit-arrow {
  color: var(--red);
  transform: translate(1px, -1px);
}

/* ========================================================================== */
/* TOPBAR & LANGUAGE SWITCHER                                                 */
/* ========================================================================== */

.topbar {
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 0;
}

.eyebrow {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--red);
  margin: 0 0 7px;
}

.topbar h2 {
  font-size: 25px;
  margin: 0;
}

.language {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 4px;
  border-radius: 7px;
  display: inline-flex;
  flex-shrink: 0;
}

.lang {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  color: #888;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}

.lang.active {
  background: var(--ink);
  color: var(--white);
}

/* ========================================================================== */
/* FILTERS PANEL                                                              */
/* ========================================================================== */

.filters-panel {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 18px 20px;
  margin-bottom: 20px;
  min-width: 0;
}

.filter-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 13px;
  gap: 12px;
}

.filter-heading h3 {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 0;
}

.reset {
  border: 0;
  background: none;
  color: var(--red);
  font-weight: 700;
  cursor: pointer;
  transition: color 0.15s ease;
  flex-shrink: 0;
}

.reset:hover {
  color: var(--red-dark);
}

/* Fluid filter grid — reflows automatically without media queries. */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
}

.filter,
.filter-grid > * {
  min-width: 0;
}

.filter label,
.forecast-control label {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 6px;
}

/* Dropdown — react-select v1 + v2 + dash wrappers */
.Select-control,
.Select__control,
.dash-dropdown .Select-control,
.dash-dropdown .Select__control {
  border-color: var(--input-line) !important;
  min-width: 0;
}

/* ========================================================================== */
/* DATE RANGE — single fluid control (start ▸ end, no stacking, no overflow)  */
/* ========================================================================== */

.date {
  min-width: 0;
}

/* Outer wrappers must be allowed to shrink. */
.date .DateRangePicker,
.date .dash-datepicker,
.date .dash-datepicker-input-wrapper {
  width: 100%;
  min-width: 0;
}

/* The outer wrapper becomes the single visible control. */
.date .DateRangePickerInput,
.date .DateRangePickerInput_1,
.date .dash-datepicker-input-wrapper {
  display: flex;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  padding: 0;
  background: var(--white);
  border: 1px solid var(--input-line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Each date segment flexes equally — no more 100%-width table cells. */
.date .DateInput,
.date .DateInput_1,
.date .dash-datepicker-input {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: none;
  display: flex;
  align-items: center;
  background: transparent;
  border: 0;
}

/* The actual text input fills its segment quietly. */
.date .DateInput_input,
.date .DateInput_input_1 {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 0 !important;
  background: transparent;
  font: 500 13px Inter, Arial, sans-serif;
  color: var(--ink);
  line-height: 1.2;
}

/* Divider + arrow between the two dates: small, fixed, centred. */
.date .DateRangePickerInput_arrow,
.date .DateRangePickerInput_arrow_svg,
.date .dash-datepicker-input-wrapper .dash-datepicker-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  color: var(--muted);
  background: transparent;
  flex: 0 0 auto;
}

/* Match the dropdowns' focus ring for a consistent look. */
.date .DateRangePickerInput:focus-within,
.date .dash-datepicker-input-wrapper:focus-within {
  outline: 2px solid var(--red);
  outline-offset: 1px;
  border-color: var(--red);
}

/* Suppress any stray outlines react-dates puts on its inner inputs. */
.date input:focus,
.date input:focus-visible,
.DateInput_input:focus,
.DateInput_input:focus-visible,
.dash-datepicker-input:focus,
.dash-datepicker-input:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

/* ========================================================================== */
/* KPI CARDS                                                                  */
/* ========================================================================== */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 18px;
  min-height: 112px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.kpi:after {
  content: "";
  position: absolute;
  height: 3px;
  width: 34px;
  background: var(--red);
  left: 18px;
  bottom: 0;
}

.kpi-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 700;
  color: var(--muted);
}

.tone.red    { color: var(--red); }
.tone.yellow { color: var(--yellow); }
.tone.green  { color: var(--green); }

.kpi strong {
  display: block;
  font-size: 27px;
  margin: 14px 0 7px;
  letter-spacing: -1px;
  overflow-wrap: anywhere;
}

.kpi small {
  color: var(--muted);
  font-size: 10px;
}

.kpi .delta.up   { color: var(--green); }
.kpi .delta.down { color: var(--red); }

/* ========================================================================== */
/* GRID & PANELS                                                              */
/* ========================================================================== */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 20px;
}

.grid > * {
  min-width: 0;
}

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 18px;
  margin-bottom: 20px;
  min-width: 0;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel h3 {
  font-size: 12px;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* Chart wrappers must allow shrinking. */
.panel .dash-graph,
.panel .js-plotly-plot,
.panel .plot-container {
  width: 100% !important;
  min-width: 0;
}

/* ========================================================================== */
/* FORECAST CONTROLS & OUTPUT                                                 */
/* ========================================================================== */

.forecast-bar {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 20px;
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 24px;
  margin-bottom: 20px;
}

.forecast-control {
  flex: 1 1 220px;
  min-width: 0;
}

.forecast-control label {
  font-size: 10px;
}

.forecast-control .form-check,
.forecast-control .dash-radio-items label {
  margin-right: 16px;
}

.run {
  border: 0;
  background: var(--red);
  color: var(--white);
  padding: 13px 20px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.8px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  flex-shrink: 0;
}

.run:hover  { background: var(--red-dark); }
.run:active { transform: translateY(1px); }
.run:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--red-dark);
}

.forecast-empty {
  min-height: 330px;
  background: var(--white);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.forecast-empty span {
  font-size: 46px;
  color: var(--red);
}

.forecast-empty h3 {
  color: var(--ink);
  margin: 12px;
}

.empty-state {
  background: var(--white);
  padding: 60px;
  text-align: center;
  border: 1px solid var(--line);
  color: var(--muted);
}

/* ========================================================================== */
/* PAGE HELP PANEL (<details> collapsible)                                    */
/* ========================================================================== */

.page-help {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 14px 18px;
  margin-bottom: 16px;
}

.page-help summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 11px;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

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

.page-help summary::before {
  content: "▸";
  font-size: 12px;
  color: var(--red);
  transition: transform 0.15s ease;
  display: inline-block;
}

.page-help[open] summary::before {
  transform: rotate(90deg);
}

.page-help[open] summary {
  margin-bottom: 12px;
}

.page-help .help-body {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

.page-help .help-body strong {
  color: var(--ink);
  font-weight: 700;
}

.page-help .help-body p  { margin: 0 0 10px; }
.page-help .help-body p:last-child { margin-bottom: 0; }
.page-help .help-body ul { padding-left: 20px; margin: 6px 0 10px; }
.page-help .help-body li { margin-bottom: 4px; }

/* ========================================================================== */
/* ACCESSIBILITY                                                              */
/* ========================================================================== */

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Native interactive controls keep the ring. `input` is intentionally
   NOT in this list — react-select embeds a 1px hidden input inside every
   dropdown, and outlining it renders as two thin vertical bars inside the
   control. Dropdowns get their own focus affordance below. */
button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* Suppress the focus outline on react-select's inner search input
   (react-select v1 uses `.Select-input > input`, v2 uses `.Select__input input`,
   and `.dash-dropdown input` catches any other variant). */
.Select-input > input:focus,
.Select-input > input:focus-visible,
.Select__input input:focus,
.Select__input input:focus-visible,
.dash-dropdown input:focus,
.dash-dropdown input:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border: 0 !important;
}

/* Replacement focus ring drawn around the visible control instead. */
.Select-control:focus-within,
.Select__control--is-focused,
.dash-dropdown:focus-within .Select-control,
.dash-dropdown:focus-within .Select__control {
  outline: 2px solid var(--red);
  outline-offset: 1px;
  border-color: var(--red) !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================================================== */
/* RESPONSIVE                                                                 */
/* ========================================================================== */

/* Laptop: stack the two-column chart grid before it gets cramped. */
@media (max-width: 1360px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 1100px) {
  .kpis {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
}

@media (max-width: 760px) {
  .shell {
    display: block;
  }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
  }

  .sidebar nav {
    display: flex;
    overflow-x: auto;
    padding-top: 12px;
    scrollbar-width: none;
  }

  .sidebar nav::-webkit-scrollbar {
    display: none;
  }

  .nav { min-width: 135px; }

  /* Footer stays visible on mobile as a horizontal row. */
  .source {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 4px 0;
    margin-top: 14px;
  }

  .content {
    padding: 0 14px 35px;
  }

  .forecast-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 18px;
  }

  .topbar {
    min-height: 90px;
  }
}

@media (max-width: 480px) {
  .brand   { padding-bottom: 15px; }
  .content { padding: 0 9px 30px; }

  .empty-state    { padding: 32px 16px; }
  .forecast-empty { min-height: 240px; }
}

/* ========================================================================== */
/* ACTIVE-STATE HARDENING                                                     */
/* Must come last so it beats any earlier rule with equal specificity.        */
/* ========================================================================== */

.nav.active {
  background: #2b2b2b !important;
  color: #fff !important;
  box-shadow: inset 3px 0 var(--red) !important;
}

.lang.active {
  background: #171717 !important;
  color: #fff !important;
}