/* /opt/dashboard/public/css/app_orders.css */

/* =========================
 * ROOT BLOCK
 * ========================= */

.orders-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 10px;
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.35),
    0 0 0 0.5px rgba(255, 255, 255, 0.02) inset;
  width: 310px;
  max-width: 310px;
  flex: 0 0 310px;

  /* ✅ allow stretch */
  height: 100%;
  min-height: 250px;
  box-sizing: border-box;
}

/* =========================
 * HEADER
 * ========================= */

.orders-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
  flex: 0 0 auto;
}

.orders-mode-switch {
  margin-left: auto;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0;
  width: 220px;
  height: 24px;
  padding: 2px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  overflow: hidden;
}

.orders-mode-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc((100% - 4px) / var(--seg-count, 3));
  height: calc(100% - 4px);
  border-radius: 8px;
  background: rgba(245, 245, 247, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(255, 255, 255, 0.55) inset;
  transform: translateX(calc(var(--seg-index, 0) * 100%));
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.orders-mode-btn {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  border: 0;
  background: transparent;
  font-size: 11px;
  line-height: 1;
  font-weight: 560;
  color: rgba(229, 231, 235, 0.78);
  cursor: pointer;
  user-select: none;
  transition: color 140ms ease, transform 80ms ease;
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  padding: 0 8px;
  white-space: nowrap;
}

.orders-mode-btn:hover {
  color: rgba(245, 245, 247, 0.92);
}

.orders-mode-btn:active {
  transform: scale(0.98);
}

.orders-mode-btn.is-active {
  color: rgba(17, 24, 39, 0.95);
  font-weight: 650;
}

/* =========================
 * BODY
 * ========================= */

.orders-body {
  display: flex;
  gap: 12px;

  /* ✅ stretch so bars can fill height */
  align-items: stretch;

  min-width: 0;
  width: 100%;
  max-width: none;

  flex: 1 1 auto;
  min-height: 0;
}

/* =========================
 * KPI COLUMN
 * ========================= */

.orders-kpi {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0;
  border: none;
  background: transparent;
  align-self: flex-start;
}

.orders-kpi-card {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: var(--bg-elevated);
  box-shadow:
    0 10px 18px rgba(0, 0, 0, 0.22),
    0 0 0 0.5px rgba(255, 255, 255, 0.03) inset;
  text-align: center;
}

.orders-kpi-label {
  display: block;
  margin-bottom: 6px;
  user-select: none;
}

.orders-kpi-label-top {
  font-size: 11px;
  opacity: 0.82;
  line-height: 1.1;
  white-space: nowrap;
}

.orders-kpi-label-sub {
  font-size: 10px;
  opacity: 0.62;
  line-height: 1.1;
  margin-top: 2px;
  white-space: nowrap;
}

.orders-kpi-value {
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.05;
}

.orders-kpi-value--plan { color: rgba(245, 245, 247, 0.92); }
.orders-kpi-value--avg  { color: rgba(245, 245, 247, 0.86); }

.orders-block .orders-funnel-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-flow: row;
  gap: 5px;
  row-gap: 4px;
  flex: 0 0 auto;
  max-width: 100%;
  overflow: visible;
  overflow-x: visible;
  overflow-y: visible;
  -webkit-overflow-scrolling: auto;
  scrollbar-width: auto;
  align-items: stretch;
}

.orders-block .orders-funnel-metrics .funnel-metric {
  flex: initial;
  width: auto;
  min-width: 0;
  max-width: none;
}

.orders-funnel-separator {
  height: 1px;
  margin-top: auto;
  margin-bottom: 2px;
  background: rgba(255, 255, 255, 0.09);
  flex: 0 0 auto;
  transform: translateY(-28px);
}


/* =========================
 * ORDER TEMPO
 * ========================= */

.orders-tempo {
  --orders-tempo-fill-pct: 0%;
  --orders-tempo-mark-pct: 66.67%;
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  margin-top: 0px;
  margin-bottom: 2px;
  padding: 0px;
  box-sizing: border-box;
}

.orders-tempo__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.orders-tempo__title {
  font-size: 12px;
  line-height: 1;
  font-weight: 400;
  color: rgba(245, 245, 247, 0.84);
  white-space: nowrap;
}

.orders-tempo__value {
  font-size: 16px;
  line-height: 1;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: rgba(245, 245, 247, 0.96);
  white-space: nowrap;
}

.orders-tempo__bar-wrap {
  position: relative;
  padding-top: 9px;
}

.orders-tempo__bar {
  position: relative;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

.orders-tempo__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--orders-tempo-fill-pct);
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(34, 135, 255, 0.78), rgba(71, 166, 255, 0.96));
  box-shadow: 0 0 12px rgba(37, 126, 255, 0.28);
}

.orders-tempo__mark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: var(--orders-tempo-mark-pct);
  width: 2px;
  border-radius: 999px;
  background: rgba(245, 245, 247, 0.82);
  transform: translateX(-50%);
}

.orders-tempo__mark-label {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transform: translateY(-2px);
  height: 10px;
  font-size: 9px;
  line-height: 1;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: rgba(245, 245, 247, 0.66);
  white-space: nowrap;
  pointer-events: none;
}


.orders-tempo__mark-title {
  position: absolute;
  top: 0;
  left: 0;
  color: rgba(245, 245, 247, 0.76);
}

.orders-tempo__mark-title::after {
  content: " · ";
}

.orders-tempo__mark-mid {
  position: absolute;
  top: 0;
  left: var(--orders-tempo-mark-pct);
  transform: translateX(-50%);
  color: rgba(245, 245, 247, 0.64);
}


.orders-tempo__mark-value {
  position: absolute;
  top: 0;
  left: 56px;
  color: rgba(245, 245, 247, 0.86);
}

.orders-tempo__meta {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  font-size: 10px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: rgba(245, 245, 247, 0.68);
}

.orders-tempo__meta-expected {
  position: absolute;
  left: var(--orders-tempo-mark-pct);
  transform: translateX(-50%);
  white-space: nowrap;
}

/* =========================
 * GRAPH CONTAINER
 * ========================= */

.orders-bars {
  --bar-w: 15px;
  --bar-gap: 10px;

  --mid-h: 26px;
  --col-gap: 6px;
  --top-pad: 14px;
  --bottom-pad: 8px;

  --band-inset: 6px;
  --band-bg: rgba(255, 255, 255, 0.055);
  --band-border: rgba(255, 255, 255, 0.08);

  --legend-pill-min-w: 150px;

  width: auto;
  max-width: 100%;

  flex: 1 1 auto;
  height: 140px;
  min-height: 140px;
  align-self: flex-start;

  margin-top: 0px;

  padding: 28px 8px 8px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: var(--bg-elevated);
  box-shadow:
    0 10px 18px rgba(0, 0, 0, 0.22),
    0 0 0 0.5px rgba(255, 255, 255, 0.03) inset;
  position: relative;

  min-width: 0;

  display: flex;
  flex-direction: column;
}

.orders-bars--single { --bar-w: 32px; }

/* =========================
 * LEGEND
 * ========================= */

.orders-legend {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  min-width: 0;
  min-height: 18px;
  padding: 2px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.075);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  user-select: none;
  width: fit-content;
  max-width: calc(100% - 16px);
  color: rgba(245, 245, 247, 0.92);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.orders-source-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 18px;
  height: 18px;
  color: rgba(245, 245, 247, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.orders-source-icon svg {
  width: 12px;
  height: 12px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.orders-source-icon--funnel svg {
  fill: currentColor;
  stroke: none;
}

/* =========================
 * VIEWPORT
 * ========================= */

.orders-bars-viewport {
  margin-top: 2px;
  margin-bottom: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  border-radius: 5px;
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  display: block;

  flex: 0 0 auto;
  height: 108px;
  min-height: 0;
}

.orders-bars-viewport::-webkit-scrollbar {
  display: none;
}

/* =========================
 * TRACK
 * ========================= */

.orders-bars-track {
  display: flex;
  align-items: stretch;
  gap: var(--bar-gap);
  position: relative;
  padding-top: var(--top-pad);
  padding-bottom: var(--bottom-pad);
  padding-left: calc(var(--bar-gap) / 2);
  padding-right: calc(var(--bar-gap) / 2);
  overflow: hidden;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);

  height: 100%;
  width: max-content;
  min-width: max-content;
  box-sizing: border-box;

  --y-mid-top: calc(100% - var(--mid-h) - var(--bottom-pad));
  --y-mid-bot: calc(var(--y-mid-top) + var(--mid-h));
}

.orders-dateband {
  position: absolute;
  left: calc(var(--band-inset) - (var(--bar-gap) / 2));
  right: calc(var(--band-inset) - (var(--bar-gap) / 2));
  top: var(--y-mid-top);
  height: var(--mid-h);
  background: var(--band-bg);
  box-shadow:
    2px 0 5px 0 var(--band-border) inset,
    0 10px 18px rgba(0, 0, 0, 0.16);

  pointer-events: none;
  z-index: 0;
}

.orders-bars-track::before,
.orders-bars-track::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
  z-index: 1;
}

.orders-bars-track::before { top: var(--y-mid-top); }
.orders-bars-track::after  { top: var(--y-mid-bot); }

/* =========================
 * COLUMN
 * ========================= */

.orders-bar-col {
  width: var(--bar-w);
  height: 100%;

  display: grid;
  grid-template-rows: 1fr var(--mid-h);
  align-items: stretch;
  justify-items: stretch;

  gap: var(--col-gap);
  position: relative;
  isolation: isolate;
  z-index: 2;
}

.orders-bar-col::after {
  content: "";
  position: absolute;
  top: calc(-1 * var(--top-pad));
  bottom: calc(-1 * var(--bottom-pad) + 15px);
  left: 0;
  right: 0;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow:
    -3px 0 0 rgba(255, 255, 255, 0.035),
    3px 0 0 rgba(255, 255, 255, 0.035);
  opacity: 0;
  transform: scaleY(0.985);
  transition:
    opacity 140ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
  z-index: 0;
  pointer-events: none;
}

.orders-bar-col.is-selected::after {
  opacity: 1;
  transform: scaleY(1);
}

.orders-bar-col:hover::after {
  opacity: 1;
  transform: scaleY(1);
  box-shadow:
    -3px 0 0 rgba(255, 255, 255, 0.04),
    3px 0 0 rgba(255, 255, 255, 0.04);
}

/* hover sync */
.orders-bar-col:hover .orders-bar-rod--up,
.orders-bar-col:hover .orders-bar-rod--down {
  filter: brightness(1.2) saturate(0.9);
  transform: translateY(-2px) scaleY(1);
}
.orders-bar-col:hover .orders-bar-value--up { color: rgb(255, 255, 255); }
.orders-bar-col:hover .orders-bar-value--down { color: rgba(245, 245, 247, 1); }
.orders-bar-col:hover .orders-bar-midlabels { filter: brightness(1.08); }

.orders-bar-col > * {
  position: relative;
  z-index: 1;
}

/* month start marker */
.orders-bar-col--month-start::before {
  content: "";
  position: absolute;
  top: calc(-1 * var(--top-pad));
  bottom: var(--bottom-pad);
  left: calc(-1 * (var(--bar-gap) / 2));
  width: 1px;
  background: linear-gradient(
    to top,
    rgba(255, 255, 255, 0.30) 0%,
    rgba(255, 255, 255, 0.22) 72%,
    transparent 100%
  );
  opacity: 1;
  z-index: 2;
  pointer-events: none;
}

/* =========================
 * HALVES
 * ========================= */

.orders-bar-half {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: visible;
}

.orders-bar-half--down {
  display: none;
}

/* =========================
 * RODS
 * ========================= */

.orders-bar-rod {
  width: 100%;
  border-radius: 0;
  opacity: 0;
  transform: scaleY(0.65);
  transition:
    transform 520ms cubic-bezier(0.2, 0.9, 0.2, 1),
    opacity 360ms ease,
    filter 160ms ease;
  transition-delay: 0ms;
  position: absolute;
}

.orders-bars--ready .orders-bar-rod {
  transform: scaleY(1);
  opacity: 1;
}

.orders-bar-rod--up {
  left: 0;
  right: 0;
  bottom: 0;
  transform-origin: bottom;
  border-radius: 5px 5px 0 0;
}

.orders-bar-rod--down {
  background: #F6292B;
  left: 0;
  right: 0;
  top: 0;
  transform-origin: top;
}

.orders-bar-rod--orders { background: var(--accent); }
.orders-bar-rod--cancels { background: #F6292B; }
.orders-bar-rod--sales { background: #22C55E; }

/* =========================
 * VALUES
 * ========================= */

.orders-bar-value {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  line-height: 1;
  user-select: none;
  opacity: 0.92;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  transition: color 140ms ease;
}

.orders-bar-value--up {
  color: rgba(245, 245, 247, 0.92);
  top: -12px;
}

.orders-bar-value--down {
  color: rgba(245, 245, 247, 0.92);
  bottom: -12px;
}

/* =========================
 * MID LABELS
 * ========================= */

.orders-bar-midlabels {
  width: 100%;
  height: var(--mid-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 2px 2px;
  background: transparent;
  border: none;
  box-shadow: none;
  user-select: none;
  position: relative;
  transition: filter 160ms ease;
  justify-content: top;
}

.orders-bar-label-day {
  font-size: 10px;
  line-height: 1;
  color: rgba(245, 245, 247, 0.92);
  opacity: 0.95;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* ✅ month label like before: absolute, not affecting column width */
.orders-bar-label-month {
  position: absolute;
  left: 50%;
  bottom: 1px;
  transform: translateX(-50%);
  font-size: 10px;
  line-height: 1;
  color: rgba(245, 245, 247, 0.62);
  opacity: 1;
  white-space: nowrap;
  pointer-events: none;
}

/* =========================================================
 * FIXES
 * ========================================================= */

/* ✅ remove month pill */
.orders-bar-col--month-start .orders-bar-midlabels::before {
  content: none !important;
  display: none !important;
}

.orders-day-popover {
  position: absolute;
  z-index: 5;
  min-width: 132px;
  padding: 8px 9px;
  border-radius: 9px;
  background: rgb(80, 80, 83);
  border: 1px solid rgba(255, 255, 255, 0.075);
  box-shadow:
    0 14px 30px rgba(0, 0, 0, 0.34),
    0 0 0 0.5px rgba(255, 255, 255, 0.04) inset;
  color: rgba(245, 245, 247, 0.94);
  pointer-events: auto;
}

.orders-day-popover[hidden] {
  display: none;
}

.orders-day-popover__date {
  margin-bottom: 7px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(245, 245, 247, 0.96);
  font-size: 10px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}

.orders-day-popover__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
  font-size: 10px;
  line-height: 1.45;
}

.orders-day-popover__row span {
  color: rgba(245, 245, 247, 0.68);
  white-space: nowrap;
}

.orders-day-popover__row b {
  color: rgba(245, 245, 247, 0.96);
  font-size: 11px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.orders-day-popover__sep {
  height: 1px;
  margin: 6px 0 7px;
  background: rgba(255, 255, 255, 0.14);
}
