/**
 * BIMFLOW — Sidebar „Rezultate sintetice” (varianta E · Relief invers)
 * Pe aside.sidebar cu clasa .sidebar-results (injectată de design-system-v3.js)
 */

/* Scroll stabil — fără salt când se recalculează conținutul */
html {
  scrollbar-gutter: stable;
}

@supports not (scrollbar-gutter: stable) {
  html {
    overflow-y: scroll;
  }
}

html,
body {
  overflow-anchor: none;
}

aside.sidebar.sidebar-results {
  align-self: start;
  overflow-anchor: none;
  isolation: isolate;
}

aside.sidebar.sidebar-results > section.card:has(.kpi-row),
aside.sidebar.sidebar-results > section.card:has(.bigbox) {
  border-top: none;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  padding: 0;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.25);
}

aside.sidebar.sidebar-results > section.card:has(.kpi-row) .card-head,
aside.sidebar.sidebar-results > section.card:has(.bigbox) .card-head {
  margin-bottom: 0;
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

aside.sidebar.sidebar-results > section.card:has(.kpi-row) .card-head h2,
aside.sidebar.sidebar-results > section.card:has(.bigbox) .card-head h2 {
  color: var(--ink, #f8fafc);
  font-size:var(--text-lg);
}

aside.sidebar.sidebar-results > section.card:has(.kpi-row) .card-body,
aside.sidebar.sidebar-results > section.card:has(.bigbox) .card-body {
  background: transparent;
  margin: 0;
  padding: 14px;
}

aside.sidebar.sidebar-results .kpi-row,
aside.sidebar.sidebar-results .kpi-grid,
aside.sidebar.sidebar-results .card-body > .grid.kpi-row {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 12px;
  align-items: stretch;
}

aside.sidebar.sidebar-results .kpi-row > .bigbox,
aside.sidebar.sidebar-results .kpi-row > .kpi-card,
aside.sidebar.sidebar-results .kpi-grid > .bigbox,
aside.sidebar.sidebar-results .kpi-grid > .kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-width: 0;
  width: 100%;
}

aside.sidebar.sidebar-results .kpi-row .bigbox--spacer,
aside.sidebar.sidebar-results .kpi-grid .bigbox--spacer {
  visibility: hidden;
  border-color: transparent !important;
  background: transparent !important;
  box-shadow: none !important;
  pointer-events: none;
  min-height: 0 !important;
  padding: 0 !important;
  overflow: hidden;
}

aside.sidebar.sidebar-results .kpi-row {
  gap: 12px;
}

aside.sidebar.sidebar-results .bigbox,
aside.sidebar.sidebar-results .kpi-card {
  background: rgba(51, 65, 85, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 14px;
  padding: 14px 10px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: background 0.2s ease, border-color 0.2s ease;
  contain: layout style;
  min-height: 104px;
  box-sizing: border-box;
}

aside.sidebar.sidebar-results .bigbox:hover,
aside.sidebar.sidebar-results .kpi-card:hover {
  background: rgba(71, 85, 105, 0.5);
  border-color: rgba(148, 163, 184, 0.22);
  transform: none;
}

/* Animație casetă KPI — creștere / scădere (fără transform, nu mută layout) */
aside.sidebar.sidebar-results .bigbox.kpi-card-up,
aside.sidebar.sidebar-results .kpi-card.kpi-card-up {
  animation: kpi-card-tint-up 0.5s ease;
}

aside.sidebar.sidebar-results .bigbox.kpi-card-down,
aside.sidebar.sidebar-results .kpi-card.kpi-card-down {
  animation: kpi-card-tint-down 0.5s ease;
}

aside.sidebar.sidebar-results .bigbox.kpi-card-change,
aside.sidebar.sidebar-results .kpi-card.kpi-card-change {
  animation: kpi-card-tint-neutral 0.45s ease;
}

@keyframes kpi-card-tint-up {
  0% {
    background: rgba(51, 65, 85, 0.45);
    border-color: rgba(148, 163, 184, 0.15);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  }
  35% {
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(74, 222, 128, 0.45);
    box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.25);
  }
  100% {
    background: rgba(51, 65, 85, 0.45);
    border-color: rgba(148, 163, 184, 0.15);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  }
}

@keyframes kpi-card-tint-down {
  0% {
    background: rgba(51, 65, 85, 0.45);
    border-color: rgba(148, 163, 184, 0.15);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  }
  35% {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(248, 113, 113, 0.42);
    box-shadow: inset 0 0 0 1px rgba(248, 113, 113, 0.22);
  }
  100% {
    background: rgba(51, 65, 85, 0.45);
    border-color: rgba(148, 163, 184, 0.15);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  }
}

@keyframes kpi-card-tint-neutral {
  0% {
    border-color: rgba(148, 163, 184, 0.15);
  }
  40% {
    border-color: rgba(125, 211, 252, 0.45);
    box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.2);
  }
  100% {
    border-color: rgba(148, 163, 184, 0.15);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  }
}

aside.sidebar.sidebar-results .bigval,
aside.sidebar.sidebar-results .kpi-value {
  color: #f1f5f9;
  font-size:var(--text-xl);
  font-weight: 800;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  line-height: 1.25;
  min-height: 2.4em;
  height: auto;
  max-height: 3.2em;
  width: 100%;
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.35s ease;
  box-sizing: border-box;
}

aside.sidebar.sidebar-results .biglbl,
aside.sidebar.sidebar-results .kpi-label {
  color: #94a3b8;
  font-size:var(--text-micro);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.3;
  max-width: 100%;
  margin-top: 4px;
}

aside.sidebar.sidebar-results .bigval.ok,
aside.sidebar.sidebar-results .kpi-value.ok {
  color: #4ade80;
}

aside.sidebar.sidebar-results .bigval.warn,
aside.sidebar.sidebar-results .kpi-value.warn {
  color: #fbbf24;
}

aside.sidebar.sidebar-results .bigval.bad,
aside.sidebar.sidebar-results .kpi-value.bad {
  color: #f87171;
}

/* Flash discret la actualizare — fără transform (nu mută layout-ul) */
aside.sidebar.sidebar-results .bigval.kpi-flash,
aside.sidebar.sidebar-results .kpi-value.kpi-flash {
  color: #7dd3fc !important;
}

/* Acțiuni rapide */
aside.sidebar.sidebar-results > section.section {
  border-top: none;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 18px 20px !important;
  margin: 0 !important;
}

aside.sidebar.sidebar-results > section.section h3 {
  color: var(--ink, #e2e8f0) !important;
  font-size:var(--text-base) !important;
  margin-bottom: 14px !important;
}

/* Light mode */
body.light-mode aside.sidebar.sidebar-results > section.card:has(.kpi-row),
body.light-mode aside.sidebar.sidebar-results > section.card:has(.bigbox) {
  background: #e2e8f0;
  border-color: #cbd5e1;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.06);
}

body.light-mode aside.sidebar.sidebar-results > section.card:has(.kpi-row) .card-head h2,
body.light-mode aside.sidebar.sidebar-results > section.card:has(.bigbox) .card-head h2 {
  color: #1e293b;
}

body.light-mode aside.sidebar.sidebar-results .bigbox,
body.light-mode aside.sidebar.sidebar-results .kpi-card {
  background: #fff;
  border-color: #cbd5e1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

body.light-mode aside.sidebar.sidebar-results .bigbox:hover,
body.light-mode aside.sidebar.sidebar-results .kpi-card:hover {
  background: #f8fafc;
  transform: none;
}

body.light-mode aside.sidebar.sidebar-results .bigval,
body.light-mode aside.sidebar.sidebar-results .kpi-value {
  color: #0f172a;
}

body.light-mode aside.sidebar.sidebar-results .biglbl,
body.light-mode aside.sidebar.sidebar-results .kpi-label {
  color: #64748b;
}

body.light-mode aside.sidebar.sidebar-results .bigval.kpi-flash,
body.light-mode aside.sidebar.sidebar-results .kpi-value.kpi-flash {
  color: #0d9488 !important;
}

body.light-mode aside.sidebar.sidebar-results > section.section {
  background: #f1f5f9;
  border-color: #e2e8f0;
}

body.light-mode aside.sidebar.sidebar-results > section.section h3 {
  color: #1e293b !important;
}

/* Păstrează chenarul categoriei, fără „aprindere” la hover pe containerele sidebar */
aside.sidebar.sidebar-results > section.card::before,
aside.sidebar.sidebar-results > section.section::before {
  display: none;
}

html[data-cat] aside.sidebar.sidebar-results > section.card:hover,
html[data-cat] aside.sidebar.sidebar-results > section.section:hover,
aside.sidebar.sidebar-results > section.card:hover,
aside.sidebar.sidebar-results > section.section:hover {
  border-color: rgba(255, 255, 255, 0.06) !important;
  border-top-color: var(--calc-accent, var(--accent)) !important;
  border-top-width: 4px !important;
  background: rgba(2, 6, 23, 0.55) !important;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.25) !important;
  transform: none !important;
}

body.light-mode aside.sidebar.sidebar-results > section.card:hover,
body.light-mode aside.sidebar.sidebar-results > section.section:hover {
  background: #e2e8f0 !important;
  border-color: #cbd5e1 !important;
  border-top-color: var(--calc-accent, var(--accent)) !important;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.06) !important;
}

body.light-mode aside.sidebar.sidebar-results .bigbox.kpi-card-up,
body.light-mode aside.sidebar.sidebar-results .kpi-card.kpi-card-up {
  animation: kpi-card-tint-up-light 0.5s ease;
}

body.light-mode aside.sidebar.sidebar-results .bigbox.kpi-card-down,
body.light-mode aside.sidebar.sidebar-results .kpi-card.kpi-card-down {
  animation: kpi-card-tint-down-light 0.5s ease;
}

@keyframes kpi-card-tint-up-light {
  35% {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(22, 163, 74, 0.4);
  }
}

@keyframes kpi-card-tint-down-light {
  35% {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(220, 38, 38, 0.35);
  }
}

/* Reduce scroll jump când se recalculează zona principală */
.calc-container,
.main-calc,
.main-calc .card,
aside.sidebar {
  overflow-anchor: none;
}

/* Zone cu înălțime variabilă la recalcul — rezervă minimă */
.main-calc .out,
.main-calc [id^="out_"],
.main-calc #g_msg,
.main-calc .muted {
  overflow-anchor: none;
}

#out_calc,
#out_results,
#out_pick,
.main-calc [id^="out_"]:not(.tron-count):not(#out_tronsoane_summary) {
  min-height: 9rem;
}

/* Ascunde zonele goale (placeholder) până la primul rezultat */
.main-calc .out:empty,
.main-calc [id^="out_"]:empty {
  min-height: 0;
  padding: 0;
  margin: 0;
  border: none;
  display: none;
}

.main-calc.is-calc-loading .out:not(:empty),
.main-calc.is-calc-loading [id^="out_"]:not(:empty):not(.tron-count):not(#out_tronsoane_summary) {
  min-height: 9rem;
}

/* Sumar tronsoane — text scurt, fără rezervă de înălțime din out_* */
#out_tronsoane_summary,
.main-calc .tron-count {
  min-height: 0 !important;
}

/* Loading server — păstrează conținutul, doar fade discret */
.main-calc.is-calc-loading [id^="out_"],
.calc-container.is-calc-loading [id^="out_"],
.main-calc.is-calc-loading #out_results,
.main-calc.is-calc-loading #out_main,
.main-calc.is-calc-loading .kpi-row {
  opacity: 0.72;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
