:root {
  color-scheme: light;
  --page: #161616;
  --app: #f5f5f5;
  --sidebar: #ebebeb;
  --surface: #ffffff;
  --surface-soft: #f5f5f5;
  --surface-warm: #efe9dd;
  --text: #151515;
  --text-soft: #3a3a36;
  --muted: #888888;
  --line: #e1e1e1;
  --line-strong: #d5ccbc;
  --accent: #f70628;
  --accent-dark: #c80521;
  --accent-soft: #ffe8ec;
  --accent-pale: #fff3f5;
  --dark: #414353;
  --ok: #248b65;
  --warning: #b7791f;
  --danger: #f70628;
  --shadow-soft: 0 22px 52px rgba(23, 23, 23, 0.08);
  --shadow-card: 0 14px 34px rgba(23, 23, 23, 0.07);
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  padding-bottom: 122px;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease,
    color 180ms ease,
    border-color 180ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(247, 6, 40, 0.18);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  width: min(100%, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  overflow: hidden;
  border-radius: 28px;
  background: var(--app);
  box-shadow: 0 34px 92px rgba(0, 0, 0, 0.42);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 950;
  box-shadow: 0 14px 24px rgba(247, 6, 40, 0.22);
}

.brand strong {
  display: block;
  color: var(--text);
  font-size: 17px;
  line-height: 1.15;
}

.brand small {
  color: var(--muted);
}

.brand small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
  padding: 0 16px;
  font-weight: 750;
  font-size: 14px;
}

.tab::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 10px;
  border-radius: 50%;
  background: #d7d0c3;
  vertical-align: 1px;
  transition: background 180ms ease;
}

.tab.active,
.tab:hover {
  background: var(--dark);
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(23, 23, 23, 0.12);
}

.tab.active::before,
.tab:hover::before {
  background: var(--accent);
}

.guide-button {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  width: 100%;
  min-height: 74px;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  box-shadow: 0 12px 24px rgba(23, 23, 23, 0.06);
}

.guide-button .icon {
  grid-row: span 2;
  align-self: center;
}

.guide-button span {
  font-size: 14px;
  font-weight: 950;
}

.guide-button small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.guide-button:hover {
  border-color: rgba(247, 6, 40, 0.22);
  background: var(--accent-pale);
  box-shadow: 0 15px 28px rgba(247, 6, 40, 0.08);
}

.sidebar-collapse-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  flex: 0 0 auto;
  margin-left: auto;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-soft);
  box-shadow: 0 10px 22px rgba(23, 23, 23, 0.06);
}

.sidebar-collapse-button:hover {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 14px 26px rgba(247, 6, 40, 0.2);
}

.workspace {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  padding: 26px;
  animation: fadeUp 420ms ease both;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.topbar > div:first-child {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 0;
  color: var(--text);
  font-size: clamp(28px, 3.2vw, 44px);
  line-height: 1.04;
  letter-spacing: -0.01em;
}

h2 {
  margin-bottom: 16px;
  color: var(--text);
  font-size: 22px;
  line-height: 1.15;
}

h3 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 17px;
}

p {
  color: var(--muted);
  line-height: 1.48;
}

.feedback-banner {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 34px;
  margin-top: 16px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  transition:
    background 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

.feedback-banner.saved {
  border-color: rgba(36, 139, 101, 0.22);
  background: rgba(36, 139, 101, 0.12);
  color: var(--ok);
  box-shadow: 0 12px 26px rgba(36, 139, 101, 0.08);
  transform: translateY(-1px);
}

.feedback-banner.active {
  border-color: rgba(247, 6, 40, 0.2);
  background: var(--accent-soft);
  color: var(--accent-dark);
  box-shadow: 0 12px 26px rgba(247, 6, 40, 0.08);
}

.feedback-banner.saving {
  border-color: rgba(247, 6, 40, 0.2);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.feedback-banner.error {
  border-color: rgba(184, 42, 42, 0.24);
  background: rgba(184, 42, 42, 0.11);
  color: var(--danger);
}

.actions,
.panel-heading,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.language-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 10px 22px rgba(23, 23, 23, 0.05);
}

.lang-option {
  min-width: 42px;
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
}

.lang-option.active,
.lang-option:hover {
  background: var(--dark);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(23, 23, 23, 0.12);
}

.section-head {
  margin-bottom: 16px;
  padding: 0 2px;
}

.section-head > *,
.panel-heading > * {
  min-width: 0;
}

.primary-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  min-height: 42px;
}

.primary-button {
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 900;
  box-shadow: 0 14px 24px rgba(247, 6, 40, 0.2);
}

.primary-button:hover {
  background: var(--accent-dark);
  box-shadow: 0 16px 28px rgba(247, 6, 40, 0.28);
}

.primary-button.is-saved {
  cursor: default;
  background: #ded8cd;
  color: #7f7a72;
  box-shadow: none;
}

.ghost-button {
  padding: 0 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 850;
}

.ghost-button:hover {
  border-color: #c8bead;
  background: #ffffff;
  box-shadow: var(--shadow-card);
}

.icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 900;
}

.icon-button:hover {
  background: var(--accent);
  color: #ffffff;
}

.icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}

.metric {
  position: relative;
  min-height: 158px;
  overflow: hidden;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition:
    transform 220ms ease,
    box-shadow 220ms ease,
    border-color 220ms ease;
}

.metric:first-child {
  border-color: transparent;
  background: var(--accent);
  color: #ffffff;
}

.metric:first-child span,
.metric:first-child small {
  color: rgba(255, 255, 255, 0.76);
}

.metric::after {
  content: "";
  position: absolute;
  right: -34px;
  top: -34px;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(247, 6, 40, 0.08);
}

.metric:first-child::after {
  background: rgba(255, 255, 255, 0.18);
}

.metric:hover {
  transform: translateY(-4px);
  border-color: rgba(247, 6, 40, 0.22);
  box-shadow: 0 20px 42px rgba(23, 23, 23, 0.12);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 18px;
  color: inherit;
  font-size: clamp(31px, 3vw, 44px);
  line-height: 0.95;
}

.metric small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.layout {
  display: grid;
  gap: 20px;
  margin-bottom: 20px;
  min-width: 0;
  max-width: 100%;
}

.two-col {
  grid-template-columns: minmax(0, 1.38fr) minmax(330px, 0.82fr);
}

.panel,
.table-wrap,
.logic-note {
  min-width: 0;
  max-width: 100%;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.table-wrap,
.logic-note {
  border: 1px solid var(--line);
}

.panel {
  overflow: hidden;
  padding: 24px;
  margin-bottom: 20px;
  transition:
    transform 220ms ease,
    box-shadow 220ms ease;
}

.panel:hover {
  transform: translateY(-3px);
  box-shadow: 0 22px 48px rgba(23, 23, 23, 0.11);
}

.rule-panel {
  overflow: visible;
}

.rule-group-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.rule-group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 7px 10px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.rule-group-off {
  border-color: rgba(23, 23, 23, 0.08);
  background: rgba(248, 248, 248, 0.8);
}

.rule-group-off .table-wrap {
  opacity: 0.58;
}

.dashboard-logic-card {
  position: relative;
  overflow: hidden;
  padding: 28px;
}

.dashboard-logic-card::before {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(247, 6, 40, 0.085), transparent 38%),
    radial-gradient(circle at 86% 14%, rgba(69, 196, 138, 0.13), transparent 28%);
  content: "";
  pointer-events: none;
}

.dashboard-logic-head,
.logic-step-chart {
  position: relative;
  z-index: 1;
}

.dashboard-logic-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.dashboard-logic-head h2 {
  margin: 3px 0 8px;
}

.dashboard-logic-head p:not(.eyebrow) {
  max-width: 680px;
  color: var(--muted);
  line-height: 1.55;
}

.dashboard-logic-final {
  display: grid;
  gap: 4px;
  min-width: 170px;
  padding: 14px 16px;
  border: 1px solid rgba(247, 6, 40, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  text-align: right;
}

.dashboard-logic-final span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.dashboard-logic-final strong {
  color: var(--accent);
  font-size: 34px;
  line-height: 1;
}

.logic-step-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(142px, 1fr));
  gap: 10px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 2px 2px 12px;
  scrollbar-color: rgba(247, 6, 40, 0.36) transparent;
}

.logic-step {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  min-width: 0;
  animation: logicStepIn 420ms ease both;
  animation-delay: calc(var(--step-index) * 70ms);
}

.logic-step-marker {
  display: flex;
  align-items: center;
  min-height: 30px;
}

.logic-step-marker span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--dark);
  color: #ffffff;
  font-size: 12px;
  font-weight: 950;
}

.logic-step-body {
  min-width: 0;
  min-height: 138px;
  padding: 12px 12px 11px;
  border: 1px solid rgba(18, 18, 18, 0.075);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 14px 28px rgba(20, 20, 20, 0.055);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.logic-step-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
}

.logic-step-top h3 {
  min-width: 0;
  font-size: 13px;
  line-height: 1.18;
}

.logic-step-top span {
  display: inline-flex;
  flex: 0 0 auto;
  min-height: 24px;
  padding: 0 8px;
  align-items: center;
  border-radius: 999px;
  background: rgba(69, 196, 138, 0.13);
  color: #17874f;
  font-size: 10px;
  font-weight: 950;
}

.logic-step-body > strong {
  display: grid;
  gap: 4px;
  margin: 9px 0 9px;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.logic-step-body > strong span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.logic-step-meta {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  line-height: 1.35;
}

.logic-step-meta span {
  color: var(--accent);
}

.logic-step:hover .logic-step-body {
  transform: translateY(-5px);
  border-color: rgba(247, 6, 40, 0.28);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 20px 38px rgba(20, 20, 20, 0.11), 0 0 0 1px rgba(247, 6, 40, 0.06);
}

.logic-step:hover .logic-step-marker span {
  transform: scale(1.06);
  box-shadow: 0 10px 20px rgba(247, 6, 40, 0.2);
}

.logic-step.skipped .logic-step-body {
  background: rgba(246, 246, 246, 0.74);
}

.logic-step.skipped .logic-step-top span,
.logic-step.skipped .logic-step-meta span {
  background: rgba(161, 152, 138, 0.12);
  color: var(--muted);
}

.logic-step.final .logic-step-marker span,
.logic-step.peer-impact .logic-step-marker span {
  background: #f70628;
  color: #ffffff;
}

.logic-step.peer-impact .logic-step-body,
.logic-step.final:not(.skipped) .logic-step-body {
  border-color: rgba(247, 6, 40, 0.16);
  background: linear-gradient(180deg, rgba(247, 6, 40, 0.075), rgba(255, 255, 255, 0.86));
}

.logic-step.peer-impact .logic-step-top span,
.logic-step.final:not(.skipped) .logic-step-top span {
  background: rgba(247, 6, 40, 0.12);
  color: var(--accent);
}

.logic-step-arrow {
  position: absolute;
  top: 15px;
  left: 36px;
  right: -7px;
  height: 2px;
  overflow: hidden;
  background: rgba(247, 6, 40, 0.16);
}

.logic-step-arrow::after {
  position: absolute;
  inset: 0;
  width: 44%;
  background: linear-gradient(90deg, transparent, rgba(247, 6, 40, 0.72), transparent);
  content: "";
  animation: logicArrowMove 1500ms ease-in-out infinite;
}

.bonus-formula-strip {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(180px, 0.32fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 22px;
  padding: 16px;
  border: 1px solid rgba(18, 18, 18, 0.07);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.74);
}

.bonus-formula-strip > div:first-child {
  display: grid;
  align-content: center;
  gap: 6px;
}

.bonus-formula-strip span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 950;
}

.bonus-formula-strip p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.bonus-formula-chain {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.bonus-formula-chain code {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  max-width: 380px;
  min-height: 62px;
  padding: 9px 10px;
  border: 1px solid rgba(247, 6, 40, 0.1);
  border-radius: 12px;
  background: rgba(247, 6, 40, 0.055);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.35;
  white-space: normal;
}

.bonus-formula-chain code strong {
  color: var(--accent);
  font-weight: 950;
  white-space: nowrap;
}

.bonus-formula-chain code span {
  color: var(--muted);
  font-weight: 950;
}

.bonus-formula-chain code em {
  min-width: 0;
  color: var(--text);
  font-style: normal;
}

.bonus-formula-chain > span {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 950;
}

.chart {
  position: relative;
  display: block;
  min-height: 308px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-color: rgba(247, 6, 40, 0.45) rgba(228, 222, 210, 0.7);
  scrollbar-width: thin;
}

.chart::-webkit-scrollbar {
  height: 8px;
}

.chart::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(228, 222, 210, 0.7);
}

.chart::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(247, 6, 40, 0.48);
}

.chart svg {
  display: block;
  width: max(100%, 760px);
  min-width: 760px;
  height: 330px;
}

.chart svg rect {
  transform-box: fill-box;
  transform-origin: center bottom;
  transition:
    opacity 180ms ease,
    filter 180ms ease,
    transform 180ms ease;
}

.chart svg rect:hover {
  filter: brightness(0.94);
  opacity: 0.92;
  transform: scaleY(1.018);
}

.bar-label {
  fill: #7f7a72;
  font-size: 11px;
  font-weight: 700;
}


.bar-value-label {
  font-size: 10px;
  font-weight: 800;
}

.axis {
  stroke: #ded6c8;
  stroke-width: 1;
}

.bar-main {
  fill: var(--accent);
}

.bar-alt {
  fill: var(--dark);
}

.bar-muted {
  fill: #c8c0b2;
}

.bar-danger {
  fill: #f28f9c;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  position: static;
  flex-direction: row;
}


.legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.legend span:nth-child(2)::before {
  background: var(--dark);
}

.legend span:nth-child(3)::before {
  background: #c8c0b2;
}

.legend span:nth-child(4)::before {
  background: #f28f9c;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
}

.table-wrap.wide table {
  min-width: 1280px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

tbody tr {
  transition: background 160ms ease;
}

tbody tr:hover {
  background: var(--accent-pale);
}

td input,
td select,
.form-grid input,
.form-grid select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf7;
  color: var(--text);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

td input:focus,
td select:focus,
.form-grid input:focus,
.form-grid select:focus {
  border-color: rgba(247, 6, 40, 0.44);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(247, 6, 40, 0.08);
}

select option {
  background: #ffffff;
  color: var(--text);
}

.c-level-select {
  min-width: 116px;
}

.calculated-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgb(159 159 159 / 18%);
  border-radius: 999px;
  background: var(--accent-soft);
  color: #939393;
  font-weight: 900;
  white-space: nowrap;
}

.calculated-value.success {
  border-color: rgba(36, 139, 101, 0.22);
  background: rgba(36, 139, 101, 0.1);
  color: var(--ok);
}

.calculated-value.warn {
  border-color: rgba(183, 121, 31, 0.22);
  background: rgba(183, 121, 31, 0.1);
  color: var(--warning);
}

.calculated-value.danger {
  border-color: rgba(247, 6, 40, 0.18);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status-line {
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  color: var(--text-soft);
}

.status-line.warning {
  border-color: rgba(247, 6, 40, 0.2);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.logic-note {
  margin: 18px 0 20px;
  padding: 20px;
}

.logic-note-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.logic-note-head h3 {
  margin-bottom: 6px;
}

.logic-note-head p {
  max-width: 760px;
  color: var(--muted);
  line-height: 1.55;
}

.formula-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(69, 196, 138, 0.22);
  border-radius: 999px;
  background: rgba(69, 196, 138, 0.12);
  color: #17874f;
  font-size: 12px;
  font-weight: 950;
  white-space: nowrap;
}

.logic-note.gate-skipped .formula-status {
  border-color: rgba(161, 152, 138, 0.22);
  background: rgba(161, 152, 138, 0.12);
  color: var(--muted);
}

.formula-equation {
  display: inline-flex;
  max-width: 100%;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(247, 6, 40, 0.12);
  border-radius: 12px;
  background: rgba(247, 6, 40, 0.055);
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.4;
}

.formula-flow {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px;
}

.formula-step {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
  font-weight: 950;
  white-space: nowrap;
}

.formula-step.active {
  border-color: rgba(69, 196, 138, 0.24);
  background: rgba(69, 196, 138, 0.13);
  color: #17874f;
}

.formula-step.skipped {
  border-style: dashed;
  color: var(--muted);
  text-decoration: line-through;
}

.formula-arrow {
  color: var(--muted);
  font-weight: 950;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 46px;
  height: 26px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #c8c0b2;
  transition: 0.16s ease;
}

.slider::before {
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  content: "";
  transition: 0.16s ease;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.score-stack {
  display: grid;
  gap: 0;
}

.score-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  border-radius: 10px;
}

.score-row:last-child {
  border-bottom: 0;
}

.score-row span {
  color: var(--muted);
  font-size: 13px;
}

.score-row strong {
  font-variant-numeric: tabular-nums;
}

.score-row.changed.negative {
  background: rgba(247, 6, 40, 0.055);
}

.score-row.changed.positive {
  background: rgba(36, 139, 101, 0.07);
}

.score-row.changed::before {
  position: absolute;
  left: -4px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  content: "";
}

.score-row.changed.negative::before {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(247, 6, 40, 0.08);
}

.score-row.changed.positive::before {
  background: var(--ok);
  box-shadow: 0 0 0 5px rgba(36, 139, 101, 0.1);
}

.breakdown-space {
  height: 14px;
}

.breakdown-list-title {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 13px;
}

.breakdown-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.breakdown-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.breakdown-list li.changed.negative {
  border-color: rgba(247, 6, 40, 0.18);
  background: linear-gradient(90deg, rgba(247, 6, 40, 0.085), rgba(247, 6, 40, 0.025));
}

.breakdown-list li.changed.positive {
  border-color: rgba(36, 139, 101, 0.2);
  background: linear-gradient(90deg, rgba(36, 139, 101, 0.09), rgba(36, 139, 101, 0.025));
}

.breakdown-marker {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #c9c9c9;
}

.breakdown-list li.changed.negative .breakdown-marker {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(247, 6, 40, 0.08);
}

.breakdown-list li.changed.positive .breakdown-marker {
  background: var(--ok);
  box-shadow: 0 0 0 5px rgba(36, 139, 101, 0.1);
}

.breakdown-list small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

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

.info-box summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 22px;
  color: var(--text);
  font-weight: 950;
  cursor: pointer;
  list-style: none;
}

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

.info-box summary small {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 18px;
  line-height: 1;
}

.info-box[open] summary small {
  transform: rotate(45deg);
}

.info-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 0 18px 18px;
}

.info-content article {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}

.info-content h3 {
  margin-bottom: 8px;
  color: var(--accent-dark);
  font-size: 13px;
}

.info-content p {
  margin-bottom: 0;
  font-size: 13px;
}

.dynamic-result-card {
  position: fixed;
  right: 24px;
  bottom: 18px;
  left: 24px;
  z-index: 8500;
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  width: min(1040px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 16px 18px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 70px rgba(23, 23, 23, 0.24);
  backdrop-filter: blur(18px);
}

.dynamic-result-card > div:first-child span,
.dynamic-result-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.dynamic-result-card > div:first-child strong {
  display: block;
  margin-top: 4px;
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
}

.dynamic-result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.dynamic-result-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}

.dynamic-result-grid strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clean-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.75;
}

.summary-list {
  display: grid;
  gap: 10px;
}
.summary-list-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}


.summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}

.summary-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.summary-item strong {
  color: var(--text);
  font-size: 16px;
}

.sheet-open {
  overflow: hidden;
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  justify-content: flex-end;
  padding: 18px;
  background: rgba(0, 0, 0, 0.48);
}

.sheet-overlay.active {
  display: flex;
}

.sheet-panel {
  width: min(920px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 24px 74px rgba(0, 0, 0, 0.28);
  animation: slideIn 220ms ease both;
}

.sheet-handle {
  width: 46px;
  height: 5px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: var(--line-strong);
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.sheet-close {
  flex: 0 0 auto;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.guide-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
}

.guide-card.featured {
  border-color: rgba(247, 6, 40, 0.24);
  background: var(--accent-pale);
}

.guide-card span {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--dark);
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.guide-card h3 {
  margin-top: 12px;
}

.guide-card p {
  margin-bottom: 12px;
}

.guide-example {
  padding: 12px;
  border-radius: 14px;
  background: #ffffff;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.45;
}

.toast-host {
  position: fixed;
  top: 22px;
  left: 50%;
  z-index: 9500;
  display: grid;
  gap: 10px;
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
}

.toast {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 14px 14px 14px 16px;
  border: 1px solid rgba(247, 6, 40, 0.18);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.14);
  animation: fadeUp 180ms ease both;
}

.toast.warning {
  border-color: rgba(183, 121, 31, 0.24);
}

.toast.leaving {
  opacity: 0;
  transform: translateY(-8px);
}

.toast strong {
  display: block;
  margin-bottom: 4px;
}

.toast p {
  margin: 0;
  font-size: 13px;
}

.toast button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 900;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes logicStepIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes logicArrowMove {
  from {
    transform: translateX(-115%);
  }

  to {
    transform: translateX(245%);
  }
}

@keyframes logicArrowMoveVertical {
  from {
    transform: translateY(-115%);
  }

  to {
    transform: translateY(245%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .logic-step,
  .logic-step-arrow::after {
    animation: none;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .app-shell.sidebar-collapsed .sidebar {
    align-items: stretch;
    padding: 24px 18px;
  }

  .app-shell.sidebar-collapsed .brand {
    display: flex;
    justify-items: initial;
  }

  .app-shell.sidebar-collapsed .brand-copy,
  .app-shell.sidebar-collapsed .tab span,
  .app-shell.sidebar-collapsed .about-button span,
  .app-shell.sidebar-collapsed .about-button small {
    display: initial;
  }

  .app-shell.sidebar-collapsed .tabs {
    width: auto;
  }

  .app-shell.sidebar-collapsed .tab {
    display: block;
    width: 100%;
    min-height: 43px;
    padding: 0 15px;
    margin: 0;
  }

  .app-shell.sidebar-collapsed .tab::before {
    width: 8px;
    height: 8px;
    margin-right: 10px;
  }

  .app-shell.sidebar-collapsed .guide-button {
    display: grid;
    width: 100%;
    min-height: 72px;
    place-items: initial;
    grid-template-columns: auto 1fr;
    padding: 15px 17px;
  }

  .app-shell.sidebar-collapsed .guide-button .icon {
    grid-row: span 2;
  }

  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tab {
    text-align: center;
  }

  .metric-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-logic-head {
    display: grid;
  }

  .dashboard-logic-final {
    text-align: left;
  }

  .logic-step-chart {
    grid-template-columns: repeat(7, minmax(150px, 1fr));
  }

  .bonus-formula-strip {
    grid-template-columns: 1fr;
  }

  .logic-step-body {
    min-height: 132px;
  }

  .logic-step-arrow {
    top: 15px;
    right: -7px;
    bottom: auto;
    left: 36px;
    width: auto;
    height: 2px;
  }

  .logic-step-arrow::after {
    width: 44%;
    height: 100%;
    animation-name: logicArrowMove;
  }

  .two-col {
    grid-template-columns: 1fr;
  }
}


@media (max-width: 820px) {
  body {
    padding-bottom: 192px;
  }

  .app-shell {
    width: min(100%, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    min-height: calc(100vh - 16px);
    margin: 8px auto;
    border-radius: 22px;
  }

  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .section-head,
  .panel-heading,
  .sheet-header {
    display: grid;
    gap: 14px;
  }

  .actions {
    justify-content: flex-start;
  }

  .rule-group-actions {
    justify-content: flex-start;
  }

  .logic-note-head {
    display: grid;
  }

  h1 {
    font-size: 36px;
  }

  .tabs,
  .metric-grid,
  .form-grid,
  .logic-step-chart,
  .info-content,
  .guide-grid,
  .summary-list-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-logic-card {
    padding: 22px;
  }

  .metric {
    min-height: 132px;
  }

  .chart svg {
    width: 680px;
    min-width: 680px;
    height: 292px;
  }

  .sheet-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .sheet-panel {
    width: 100%;
    max-height: 88vh;
    margin: 0;
    padding: 14px 16px 20px;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 24px 24px 0 0;
  }

  .toast-host {
    top: 16px;
    left: 50%;
    right: auto;
  }

  .dynamic-result-card {
    right: 8px;
    bottom: 8px;
    left: 8px;
    grid-template-columns: 1fr;
    width: auto;
    gap: 12px;
    padding: 14px;
    border-radius: 20px;
  }

  .dynamic-result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dynamic-result-card > div:first-child strong {
    font-size: 26px;
  }
}

/* Requested update: Managers table gets dedicated scroll behavior for larger manager/KPI sets. */
.managers-scroll {
  max-height: 560px;
  overflow: auto;
}

.managers-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
}

button:disabled {
  cursor: default;
}

button:disabled:hover {
  transform: none;
}

/* Dashboard score distribution panel. */
.distribution-heading {
  align-items: flex-start;
}

.distribution-heading > div:first-child {
  min-width: 0;
}

.distribution-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(270px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.distribution-side {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.segmented-toggle {
  display: flex;
  flex-wrap: nowrap;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  scrollbar-width: thin;
  scrollbar-color: rgba(247, 6, 40, 0.42) transparent;
}

.segmented-toggle::-webkit-scrollbar {
  height: 6px;
}

.segmented-toggle::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(247, 6, 40, 0.42);
}

.segmented-option {
  flex: 1 0 max-content;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.segmented-option.active,
.segmented-option:hover {
  background: var(--dark);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(23, 23, 23, 0.12);
}

.distribution-list {
  display: grid;
  gap: 8px;
}

.distribution-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.distribution-row span {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 900;
}

.distribution-row strong {
  color: var(--accent-dark);
  font-size: 16px;
}

.distribution-row small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  .distribution-layout {
    grid-template-columns: 1fr;
  }
}


@media (max-width: 820px) {
  .segmented-toggle {
    border-radius: 999px;
  }
}

/* About This App detailed explanation sheet. */
.about-button {
  margin-top: -14px;
}

.about-sheet-panel {
  width: min(1100px, 100%);
}

.about-header h2 {
  margin-bottom: 10px;
  font-size: clamp(28px, 3.5vw, 42px);
  line-height: 1;
}

.about-flow-card {
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface-soft);
}

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

.about-section-heading span {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 950;
  text-transform: uppercase;
}

.about-flow {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.about-step {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
}

.about-step > strong {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 999px;
  background: var(--dark);
  color: #ffffff;
  font-size: 12px;
  font-weight: 950;
}

.about-step h3 {
  margin-bottom: 5px;
  color: var(--text);
  font-size: 14px;
}

.about-step p {
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.42;
}

.about-section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.about-section {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 10px 24px rgba(23, 23, 23, 0.05);
}

.about-section.featured {
  border-color: rgba(247, 6, 40, 0.24);
  background: var(--accent-pale);
}

.about-section h3 {
  margin-bottom: 10px;
  color: var(--accent-dark);
  font-size: 16px;
}

.about-section ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--text-soft);
}

.about-section li {
  line-height: 1.45;
}

.about-formula {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
}

.about-formula span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}

.about-formula code {
  display: block;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: normal;
}

@media (max-width: 1180px) {
  .about-flow {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}


@media (max-width: 820px) {
  .about-button {
    margin-top: 0;
  }

  .about-flow,
  .about-section-grid {
    grid-template-columns: 1fr;
  }

  .about-flow-card,
  .about-section {
    padding: 14px;
  }
}


/* Mobile navigation, theme mode, centered sheets, and autosave UX updates. */
.mobile-menu-button,
.mobile-sidebar-backdrop,
.sidebar-mobile-actions {
  display: none;
}

.topbar-title-row,
.topbar-copy {
  min-width: 0;
}

.theme-toggle-button {
  white-space: nowrap;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #050506;
  --app: #101114;
  --sidebar: #16171a;
  --surface: #1a1b1f;
  --surface-soft: #202126;
  --surface-warm: #252228;
  --text: #f4f0e8;
  --text-soft: #d5d0c8;
  --muted: #a7a098;
  --line: #343238;
  --line-strong: #4a4650;
  --accent-soft: rgba(247, 6, 40, 0.18);
  --accent-pale: rgba(247, 6, 40, 0.12);
  --dark: #050506;
  --shadow-soft: 0 22px 52px rgba(0, 0, 0, 0.3);
  --shadow-card: 0 14px 34px rgba(0, 0, 0, 0.28);
}

:root[data-theme="dark"] body {
  background: var(--page);
}

:root[data-theme="dark"] .app-shell {
  box-shadow: 0 34px 92px rgba(0, 0, 0, 0.62);
}

:root[data-theme="dark"] .feedback-banner,
:root[data-theme="dark"] .status-line,
:root[data-theme="dark"] .guide-example,
:root[data-theme="dark"] .about-step,
:root[data-theme="dark"] .about-formula,
:root[data-theme="dark"] .toast {
  background: var(--surface);
}

:root[data-theme="dark"] td input,
:root[data-theme="dark"] td select,
:root[data-theme="dark"] .form-grid input,
:root[data-theme="dark"] .form-grid select {
  border-color: var(--line);
  background: #15161a;
  color: var(--text);
}

:root[data-theme="dark"] td input:focus,
:root[data-theme="dark"] td select:focus,
:root[data-theme="dark"] .form-grid input:focus,
:root[data-theme="dark"] .form-grid select:focus {
  background: #18191e;
}

:root[data-theme="dark"] select option {
  background: #18191e;
  color: var(--text);
}

:root[data-theme="dark"] .feedback-banner.saved {
  border-color: rgba(69, 196, 138, 0.24);
  background: rgba(69, 196, 138, 0.13);
  color: #65d69c;
}

:root[data-theme="dark"] .feedback-banner.error {
  border-color: rgba(255, 107, 107, 0.28);
  background: rgba(255, 107, 107, 0.12);
  color: #ff8b8b;
}

:root[data-theme="dark"] .feedback-banner.active {
  border-color: rgba(247, 6, 40, 0.26);
  background: rgba(247, 6, 40, 0.16);
  color: #ff6f84;
}

:root[data-theme="dark"] .metric:first-child {
  color: #ffffff;
}

:root[data-theme="dark"] .sheet-overlay,
:root[data-theme="dark"] .mobile-sidebar-backdrop {
  background: rgba(0, 0, 0, 0.62);
}

:root[data-theme="dark"] .dynamic-result-card {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(26, 27, 31, 0.94);
}

.sheet-overlay {
  align-items: center;
  justify-content: center;
}

.sheet-panel {
  animation: fadeUp 220ms ease both;
}


@media (max-width: 820px) {
  body {
    padding-bottom: 24px;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .app-shell {
    overflow: visible;
  }

  .mobile-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-weight: 900;
    box-shadow: 0 10px 22px rgba(23, 23, 23, 0.06);
  }

  .topbar-title-row {
    display: grid;
    gap: 12px;
  }

  .topbar-copy {
    width: 100%;
  }

  .feedback-banner {
    width: fit-content;
    max-width: 100%;
    min-height: 38px;
    padding: 8px 12px;
    white-space: normal;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 9300;
    display: flex;
    align-items: stretch;
    width: min(334px, calc(100vw - 44px));
    max-width: calc(100vw - 44px);
    height: 100vh;
    overflow-y: auto;
    padding: 20px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 0 24px 24px 0;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
    transform: translateX(-110%);
    transition: transform 220ms ease;
  }

  .topbar-actions {
    display: none;
  }

  .sidebar .tabs {
    grid-template-columns: 1fr;
  }

  .sidebar .tab {
    text-align: left;
  }

  .sidebar-mobile-actions {
    display: grid;
    gap: 10px;
    margin-top: 4px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
  }

  .sidebar-mobile-actions .language-toggle {
    justify-self: start;
  }

  .sidebar-mobile-actions .ghost-button,
  .sidebar-mobile-actions .primary-button {
    width: 100%;
    justify-content: flex-start;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9200;
    display: block;
    background: rgba(0, 0, 0, 0.48);
  }

  .dynamic-result-card {
    display: none;
  }

  .sheet-overlay {
    align-items: center;
    justify-content: center;
    padding: 12px;
  }

  .sheet-panel {
    width: min(100%, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    margin: 0;
    padding: 14px 16px 20px;
    border: 1px solid var(--line);
    border-radius: 24px;
  }

  .toast-host {
    top: 16px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

/* Dark mode UI polish and topbar cleanup. */
:root[data-theme="dark"] .ghost-button:hover,
:root[data-theme="dark"] .mobile-menu-button:hover {
  border-color: rgba(247, 6, 40, 0.38);
  background: var(--surface-soft);
  color: var(--text);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.34);
}

:root[data-theme="dark"] .language-toggle {
  border-color: var(--line);
  background: var(--surface);
}

:root[data-theme="dark"] .lang-option:hover,
:root[data-theme="dark"] .lang-option.active {
  background: rgba(247, 6, 40, 0.22);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(247, 6, 40, 0.36);
}

:root[data-theme="dark"] .tab.active {
  background: rgba(247, 6, 40, 0.22);
  color: #ffffff;
  box-shadow:
    inset 0 0 0 1px rgba(247, 6, 40, 0.42),
    0 12px 24px rgba(0, 0, 0, 0.22);
}

:root[data-theme="dark"] .tab:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

:root[data-theme="dark"] .tab.active::before,
:root[data-theme="dark"] .tab:hover::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(247, 6, 40, 0.14);
}

:root[data-theme="dark"] .tab.active:hover {
  background: rgba(247, 6, 40, 0.28);
  color: #ffffff;
  box-shadow:
    inset 0 0 0 1px rgba(247, 6, 40, 0.5),
    0 12px 24px rgba(0, 0, 0, 0.24);
}

:root[data-theme="dark"] .primary-button.is-saved {
  background: var(--surface-soft);
  color: var(--muted);
  box-shadow: none;
}

.verdict-card {
  position: relative;
}

.verdict-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.verdict-kicker {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.verdict-head p {
  max-width: 860px;
  margin-bottom: 0;
}

.verdict-status {
  display: inline-flex;
  flex: 0 0 auto;
  min-height: 34px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 950;
  white-space: nowrap;
}

.verdict-status.good {
  border-color: rgba(36, 139, 101, 0.28);
  background: rgba(36, 139, 101, 0.1);
  color: var(--ok);
}

.verdict-status.satisfactory {
  border-color: rgba(123, 159, 42, 0.28);
  background: rgba(123, 159, 42, 0.1);
  color: #5f7f1f;
}

.verdict-status.neutral {
  border-color: rgba(111, 134, 166, 0.28);
  background: rgba(111, 134, 166, 0.1);
  color: #526b8c;
}

.verdict-status.bad {
  border-color: rgba(183, 121, 31, 0.28);
  background: rgba(183, 121, 31, 0.1);
  color: var(--warning);
}

.verdict-status.very-bad {
  border-color: rgba(247, 6, 40, 0.22);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.verdict-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.verdict-metrics div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}

.verdict-metrics span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.verdict-metrics strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.verdict-body {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 14px;
}

.verdict-body article {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
}

.verdict-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 18px;
  color: var(--text-soft);
  line-height: 1.55;
}

.verdict-list.compact {
  gap: 8px;
}

:root[data-theme="dark"] .verdict-card,
:root[data-theme="dark"] .verdict-metrics div,
:root[data-theme="dark"] .verdict-body article {
  background: var(--surface-soft);
}

:root[data-theme="dark"] .verdict-status.satisfactory {
  color: #b6d66c;
}

:root[data-theme="dark"] .verdict-status.neutral {
  color: #a8bddb;
}

@media (max-width: 980px) {
  .verdict-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .verdict-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .verdict-head {
    display: grid;
  }

  .verdict-metrics {
    grid-template-columns: 1fr;
  }
}

/* Summary compact verdict layout update */
.verdict-metrics div:first-child {
  border-color: transparent;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 18px 38px rgba(247, 6, 40, 0.16);
}

.verdict-metrics div:first-child span,
.verdict-metrics div:first-child strong {
  color: #ffffff;
}

.verdict-metrics div:first-child strong {
  font-size: clamp(24px, 2.4vw, 34px);
  line-height: 1;
}

:root[data-theme="dark"] .verdict-metrics div:first-child {
  background: var(--accent);
  color: #ffffff;
}

:root[data-theme="dark"] .verdict-metrics div:first-child span,
:root[data-theme="dark"] .verdict-metrics div:first-child strong {
  color: #ffffff;
}


/* Summary verdict hero metrics layout */
.verdict-card {
  border-color: rgba(247, 6, 40, 0.16);
  background: var(--surface);
}

.verdict-metrics {
  gap: 10px;
  margin: 18px 0 18px;
  padding: 16px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.18), transparent 32%),
    linear-gradient(135deg, var(--accent) 0%, #f70628 54%, #e00020 100%);
  box-shadow: 0 18px 42px rgba(247, 6, 40, 0.18);
}

.verdict-metrics div,
.verdict-metrics div:first-child {
  min-height: 74px;
  padding: 13px 15px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  box-shadow: none;
  backdrop-filter: blur(10px);
}

.verdict-metrics div:first-child {
  background: rgba(255, 255, 255, 0.19);
}

.verdict-metrics span,
.verdict-metrics strong,
.verdict-metrics div:first-child span,
.verdict-metrics div:first-child strong {
  color: #ffffff;
}

.verdict-metrics span {
  opacity: 0.88;
}

.verdict-metrics strong {
  font-size: clamp(18px, 1.75vw, 24px);
  line-height: 1.05;
}

.verdict-metrics div:first-child strong {
  font-size: clamp(28px, 3vw, 42px);
}

:root[data-theme="dark"] .verdict-card {
  border-color: rgba(247, 6, 40, 0.24);
  background: var(--surface);
}

:root[data-theme="dark"] .verdict-metrics,
:root[data-theme="dark"] .verdict-metrics div,
:root[data-theme="dark"] .verdict-metrics div:first-child {
  color: #ffffff;
}

:root[data-theme="dark"] .verdict-metrics div,
:root[data-theme="dark"] .verdict-metrics div:first-child {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
}

:root[data-theme="dark"] .verdict-metrics div:first-child {
  background: rgba(255, 255, 255, 0.18);
}

@media (max-width: 980px) {
  .verdict-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .verdict-metrics {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}


.rule-preview-panel {
  width: min(1080px, 100%);
}

.rule-preview-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-bottom: 16px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
}

.rule-preview-status span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.rule-preview-status strong {
  color: var(--text);
  font-size: 13px;
}

.rule-preview-status.active {
  border-color: rgba(36, 139, 101, 0.24);
  background: rgba(36, 139, 101, 0.1);
}

.rule-preview-status.active strong {
  color: var(--ok);
}

.rule-preview-status.inactive {
  border-color: rgba(183, 121, 31, 0.24);
  background: rgba(183, 121, 31, 0.1);
}

.rule-preview-status.inactive strong {
  color: var(--warning);
}

.rule-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.rule-preview-card {
  min-width: 0;
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
}

.rule-preview-card h3 {
  margin-bottom: 12px;
}

.rule-preview-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rule-preview-facts div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.rule-preview-facts span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.rule-preview-facts strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  text-overflow: ellipsis;
}

.rule-preview-table {
  margin-bottom: 0;
  background: var(--surface);
}

.rule-preview-table tbody tr.affected {
  background: var(--accent-pale);
}

.match-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.match-pill.yes {
  background: rgba(36, 139, 101, 0.12);
  color: var(--ok);
}

.match-pill.no {
  background: rgba(143, 138, 130, 0.14);
  color: var(--muted);
}

.rule-preview-notes {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--text-soft);
  line-height: 1.5;
}


:root[data-theme="dark"] .rule-preview-card,
:root[data-theme="dark"] .rule-preview-status,
:root[data-theme="dark"] .rule-preview-facts div,
:root[data-theme="dark"] .rule-preview-table {
  border-color: var(--line);
  background: var(--surface);
}

:root[data-theme="dark"] .rule-preview-table tbody tr.affected {
  background: rgba(247, 6, 40, 0.12);
}

:root[data-theme="dark"] .score-row.changed.negative {
  background: rgba(247, 6, 40, 0.11);
}

:root[data-theme="dark"] .score-row.changed.positive {
  background: rgba(36, 139, 101, 0.13);
}

:root[data-theme="dark"] .breakdown-list li.changed.negative {
  border-color: rgba(247, 6, 40, 0.28);
  background: linear-gradient(90deg, rgba(247, 6, 40, 0.15), rgba(255, 255, 255, 0.035));
}

:root[data-theme="dark"] .breakdown-list li.changed.positive {
  border-color: rgba(36, 139, 101, 0.28);
  background: linear-gradient(90deg, rgba(36, 139, 101, 0.17), rgba(255, 255, 255, 0.035));
}

:root[data-theme="dark"] .breakdown-marker {
  background: rgba(255, 255, 255, 0.22);
}


@media (max-width: 820px) {
  .rule-preview-grid,
  .rule-preview-facts {
    grid-template-columns: 1fr;
  }

  .rule-preview-card {
    padding: 14px;
  }
}


/* Scenario Builder */
.scenario-card-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.scenario-card {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

.scenario-card strong {
  font-size: 14px;
  line-height: 1.25;
}

.scenario-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.scenario-card.active,
.scenario-card:hover {
  border-color: rgba(247, 6, 40, 0.3);
  background: var(--accent-pale);
  box-shadow: 0 14px 30px rgba(247, 6, 40, 0.08);
}

.scenario-layout {
  grid-template-columns: minmax(0, 1.1fr) minmax(330px, 0.9fr);
}

.scenario-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.scenario-form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.scenario-form-grid select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf7;
  color: var(--text);
}

.scenario-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.scenario-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.scenario-preview-grid div,
.scenario-summary-list div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}

.scenario-preview-grid span,
.scenario-summary-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.scenario-preview-grid strong,
.scenario-summary-list strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.scenario-preview-grid small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.scenario-summary-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

:root[data-theme="dark"] .scenario-card,
:root[data-theme="dark"] .scenario-preview-grid div,
:root[data-theme="dark"] .scenario-summary-list div {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

:root[data-theme="dark"] .scenario-card.active,
:root[data-theme="dark"] .scenario-card:hover {
  border-color: rgba(247, 6, 40, 0.5);
  background: rgba(247, 6, 40, 0.12);
}

:root[data-theme="dark"] .scenario-form-grid select {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

@media (max-width: 1180px) {
  .scenario-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .scenario-layout {
    grid-template-columns: 1fr;
  }
}


@media (max-width: 820px) {
  .scenario-card-grid,
  .scenario-form-grid,
  .scenario-preview-grid {
    grid-template-columns: 1fr;
  }
}

/* Scenario preset editing */
.scenario-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.scenario-card-main {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 84px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  box-shadow: none;
}

.scenario-card-main:hover {
  transform: none;
}

.scenario-edit-button {
  align-self: start;
  flex: 0 0 auto;
}

.scenario-edit-panel {
  width: min(760px, 100%);
}

.scenario-edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.scenario-edit-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.scenario-edit-form label.full {
  grid-column: 1 / -1;
}

.scenario-edit-form input,
.scenario-edit-form textarea,
.scenario-edit-form select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf7;
  color: var(--text);
  resize: vertical;
}

.scenario-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

:root[data-theme="dark"] .scenario-edit-form input,
:root[data-theme="dark"] .scenario-edit-form textarea,
:root[data-theme="dark"] .scenario-edit-form select {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text);
}


@media (max-width: 820px) {
  .scenario-edit-form {
    grid-template-columns: 1fr;
  }
}

/* Dashboard reference refinement: light, calm card system from the supplied server mockup. */
:root {
  --font-latin: "Montserrat", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-georgian: "Noto Sans Georgian", "Montserrat", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font: var(--font-latin);
  --page: #121212;
  --app: #f2f2f2;
  --sidebar: #e8e8e8;
  --surface: #ffffff;
  --surface-soft: #f6f6f6;
  --text: #151515;
  --text-soft: #3d3d3d;
  --muted: #8d8d8d;
  --line: rgba(18, 18, 18, 0.07);
  --dark: #363848;
  --shadow-card: 0 18px 42px rgba(16, 16, 16, 0.07);
  --shadow-soft: 0 24px 60px rgba(16, 16, 16, 0.08);
}

html:lang(ka) {
  --font: var(--font-georgian);
}

html:lang(en) {
  --font: var(--font-latin);
}

body {
  font-family: var(--font);
}

.app-shell {
  grid-template-columns: 300px minmax(0, 1fr);
  width: min(100%, calc(100vw - 32px));
  max-width: 100%;
  min-height: calc(100vh - 18px);
  margin: 9px auto;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 22px;
  background: var(--app);
  box-shadow: 0 30px 88px rgba(0, 0, 0, 0.48);
}

.sidebar {
  gap: 24px;
  padding: 24px 18px;
  background: linear-gradient(180deg, #ffffff 0%, #e2e2e2 100%);
  border-right: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 28px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  box-shadow: 0 13px 24px rgba(247, 6, 40, 0.20);
}

.brand strong {
  font-size: 16px;
  font-weight: 900;
}

.brand small {
  color: #9a9a9a;
  font-size: 11px;
}

.tabs {
  gap: 9px;
}

.tab {
  min-height: 43px;
  padding: 0 15px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 850;
}

.tab.active,
.tab:hover {
  background: #333545;
  box-shadow: 0 12px 24px rgba(29, 31, 40, 0.18);
}

.guide-button {
  min-height: 72px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 14px 30px rgba(17, 17, 17, 0.08);
}

.workspace {
  padding: 26px 28px 28px;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 88px minmax(0, 1fr);
}

.app-shell.sidebar-collapsed .sidebar {
  align-items: center;
  padding: 22px 12px;
}

.app-shell.sidebar-collapsed .brand {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .tab span,
.app-shell.sidebar-collapsed .about-button span,
.app-shell.sidebar-collapsed .about-button small {
  display: none;
}

.app-shell.sidebar-collapsed .brand-mark {
  width: 46px;
  height: 46px;
  font-size: 12px;
}

.app-shell.sidebar-collapsed .sidebar-collapse-button {
  margin-left: 0;
}

.app-shell.sidebar-collapsed .tabs {
  width: 100%;
  gap: 10px;
}

.app-shell.sidebar-collapsed .tab {
  display: grid;
  width: 48px;
  min-height: 48px;
  place-items: center;
  padding: 0;
  margin: 0 auto;
}

.app-shell.sidebar-collapsed .tab::before {
  width: 10px;
  height: 10px;
  margin: 0;
  vertical-align: 0;
}

.app-shell.sidebar-collapsed .guide-button {
  display: grid;
  width: 48px;
  min-height: 48px;
  place-items: center;
  grid-template-columns: 1fr;
  padding: 0;
}

.app-shell.sidebar-collapsed .guide-button .icon {
  grid-row: auto;
  align-self: center;
}

.topbar {
  align-items: center;
  margin-bottom: 20px;
}

h1 {
  font-size: clamp(30px, 2.2vw, 42px);
  letter-spacing: -0.04em;
}

.status-line {
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 20px rgba(20, 20, 20, 0.04);
}

.actions,
.language-toggle {
  gap: 7px;
}

.language-toggle,
.ghost-button,
.primary-button,
.icon-button {
  box-shadow: 0 10px 22px rgba(18, 18, 18, 0.05);
}

.metric-grid {
  gap: 18px;
  margin-bottom: 20px;
}

.metric {
  min-height: 146px;
  padding: 21px 22px 19px;
  border: none;
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 20px 44px rgba(20, 20, 20, 0.065);
}

.metric:first-child {
  color: var(--text);
  border-color: rgba(18, 18, 18, 0.055);
  background: #ffffff;
}

.metric:first-child span,
.metric:first-child small {
  color: var(--muted);
}

.metric::after {
  right: -42px;
  top: auto;
  bottom: -54px;
  width: 150px;
  height: 86px;
  border-radius: 999px;
  background: radial-gradient(circle at 25% 45%, rgba(247, 6, 40, 0.28), rgba(247, 6, 40, 0.06) 42%, transparent 72%);
  filter: blur(20px);
}

.metric:first-child::after {
  background: radial-gradient(circle at 25% 45%, rgba(247, 6, 40, 0.28), rgba(247, 6, 40, 0.06) 42%, transparent 72%);
}

.metric-top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.metric-icon {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  background: #fff0f3;
  color: var(--accent)!important;
  padding: 9px;
}

.metric-icon .icon {
  width: 16px;
  height: 16px;
}

.metric-icon-img {
  display: block;
  width: 16px;
  height: 16px;
}

.metric span {
  color: #999999;
  font-size: 11px;
  letter-spacing: 0.02em;
}

.metric strong {
  position: relative;
  z-index: 2;
  margin-top: 14px;
  font-size: clamp(31px, 2.45vw, 43px);
  letter-spacing: -0.045em;
}

.metric small {
  position: relative;
  z-index: 2;
  margin-top: 8px;
  font-size: 12px;
  color: #9b9b9b;
}

.metric-sparkline {
  position: absolute;
  right: -2px;
  bottom: -1px;
  width: 140px;
  height: 41px;
  z-index: 1;
  overflow: visible;
  pointer-events: none;
}

.layout {
  gap: 20px;
}

.two-col {
  grid-template-columns: minmax(0, 1.42fr) minmax(360px, 0.78fr);
}

.table-wrap,
.logic-note,
.info-box {
  border-color: rgba(18, 18, 18, 0.055);
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 22px 46px rgba(20, 20, 20, 0.066);
}

.panel {
  border: 0;
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 22px 46px rgba(20, 20, 20, 0.066);
  padding: 26px;
}

.panel-heading h2,
.section-head h2 {
  margin-bottom: 8px;
  letter-spacing: -0.035em;
}

.panel-heading p,
.section-head p {
  color: #999999;
  line-height: 1.55;
}

.chart {
  min-height: 318px;
  scrollbar-color: rgba(247, 6, 40, 0.28) rgba(245, 245, 245, 0.8);
}

.chart svg {
  height: 324px;
}

.axis {
  stroke: rgba(18, 18, 18, 0.10);
}

.bar-main {
  fill: var(--accent);
  filter: drop-shadow(0 8px 9px rgba(247, 6, 40, 0.22));
}

.bar-alt {
  fill: #333545;
}

.bar-muted {
  fill: #d4d5d7;
}

.bar-danger {
  fill: #f397a7;
}

.bar-label {
  fill: #9a9a9a;
  font-size: 10px;
  font-weight: 700;
}

.bar-value-label {
  fill: #7e7e7e;
  font-size: 10px;
  font-weight: 800;
}

.legend {
  position: static;
  justify-content: center;
  margin-top: 12px;
  gap: 18px;
}

.distribution-panel {
  padding-bottom: 28px;
}

.distribution-layout {
  grid-template-columns: minmax(0, 1.55fr) minmax(330px, 0.78fr);
  gap: 24px;
}

.segmented-toggle {
  padding: 4px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(18, 18, 18, 0.07);
}

.segmented-option.active {
  background: #333545;
}

.distribution-row {
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(247, 6, 40, 0.055), rgba(247, 6, 40, 0.025));
  border-color: rgba(247, 6, 40, 0.08);
}

:root[data-theme="dark"] {
  --page: #050506;
  --app: #101114;
  --sidebar: #16171a;
  --surface: #1a1b1f;
  --surface-soft: #202126;
  --text: #f4f0e8;
  --text-soft: #d5d0c8;
  --muted: #a7a098;
  --line: rgba(255, 255, 255, 0.095);
  --shadow-card: 0 18px 40px rgba(0, 0, 0, 0.28);
}

:root[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #17181b 0%, #121316 100%);
}

:root[data-theme="dark"] .sidebar-collapse-button {
  background: rgba(255, 255, 255, 0.065);
  color: var(--text-soft);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.24);
}

:root[data-theme="dark"] .sidebar-collapse-button:hover {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 16px 30px rgba(247, 6, 40, 0.28);
}

:root[data-theme="dark"] .metric,
:root[data-theme="dark"] .metric:first-child,
:root[data-theme="dark"] .table-wrap,
:root[data-theme="dark"] .logic-note,
:root[data-theme="dark"] .info-box,
:root[data-theme="dark"] .guide-button,
:root[data-theme="dark"] .segmented-toggle {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.09);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.03));
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.26);
}

:root[data-theme="dark"] .panel {
  color: var(--text);
  border: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.03));
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.26);
}

:root[data-theme="dark"] .metric:first-child span,
:root[data-theme="dark"] .metric:first-child small {
  color: var(--muted);
}

:root[data-theme="dark"] .status-line,
:root[data-theme="dark"] .language-toggle,
:root[data-theme="dark"] .ghost-button {
  background: rgba(255, 255, 255, 0.055);
  border-color: rgba(255, 255, 255, 0.09);
}

:root[data-theme="dark"] .rule-group-toggle {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.055);
}

:root[data-theme="dark"] .rule-group-off {
  background: rgba(255, 255, 255, 0.025);
}

:root[data-theme="dark"] .formula-equation {
  border-color: rgba(247, 6, 40, 0.2);
  background: rgba(247, 6, 40, 0.12);
}

:root[data-theme="dark"] .formula-step {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.055);
}

:root[data-theme="dark"] .formula-step.active,
:root[data-theme="dark"] .formula-status {
  border-color: rgba(69, 196, 138, 0.28);
  background: rgba(69, 196, 138, 0.15);
  color: #65d69c;
}

:root[data-theme="dark"] .logic-note.gate-skipped .formula-status {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted);
}

:root[data-theme="dark"] .dashboard-logic-card::before {
  background:
    linear-gradient(135deg, rgba(247, 6, 40, 0.12), transparent 42%),
    radial-gradient(circle at 86% 14%, rgba(69, 196, 138, 0.12), transparent 30%);
}

:root[data-theme="dark"] .dashboard-logic-final,
:root[data-theme="dark"] .logic-step-body,
:root[data-theme="dark"] .bonus-formula-strip {
  border-color: rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.055);
}

:root[data-theme="dark"] .bonus-formula-chain code {
  border-color: rgba(247, 6, 40, 0.2);
  background: rgba(247, 6, 40, 0.13);
}

:root[data-theme="dark"] .logic-step.skipped .logic-step-body {
  background: rgba(255, 255, 255, 0.032);
}

:root[data-theme="dark"] .logic-step.peer-impact .logic-step-body,
:root[data-theme="dark"] .logic-step.final:not(.skipped) .logic-step-body {
  border-color: rgba(247, 6, 40, 0.24);
  background: linear-gradient(180deg, rgba(247, 6, 40, 0.16), rgba(255, 255, 255, 0.045));
}

:root[data-theme="dark"] .logic-step:hover .logic-step-body {
  border-color: rgba(247, 6, 40, 0.34);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.042));
  box-shadow: 0 22px 42px rgba(0, 0, 0, 0.32), 0 0 0 1px rgba(247, 6, 40, 0.08);
}

:root[data-theme="dark"] .logic-step-marker span {
  background: rgba(255, 255, 255, 0.12);
}

:root[data-theme="dark"] .metric-icon {
  background: rgba(247, 6, 40, 0.14);
}

:root[data-theme="dark"] .axis {
  stroke: rgba(255, 255, 255, 0.11);
}

:root[data-theme="dark"] .bar-label,
:root[data-theme="dark"] .bar-value-label {
  fill: #aaa6a1;
}

:root[data-theme="dark"] .distribution-row {
  background: rgba(247, 6, 40, 0.08);
  border-color: rgba(247, 6, 40, 0.14);
}

@media (max-width: 1180px) {
  .two-col,
  .distribution-layout {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed .sidebar {
    align-items: stretch;
    padding: 24px 18px;
  }

  .app-shell.sidebar-collapsed .brand {
    display: flex;
    justify-items: initial;
  }

  .app-shell.sidebar-collapsed .brand-copy,
  .app-shell.sidebar-collapsed .tab span,
  .app-shell.sidebar-collapsed .about-button span,
  .app-shell.sidebar-collapsed .about-button small {
    display: initial;
  }

  .app-shell.sidebar-collapsed .brand-mark {
    width: 42px;
    height: 42px;
    font-size: inherit;
  }

  .app-shell.sidebar-collapsed .sidebar-collapse-button {
    margin-left: auto;
  }

  .app-shell.sidebar-collapsed .tabs {
    width: auto;
  }

  .app-shell.sidebar-collapsed .tab {
    display: block;
    width: 100%;
    min-height: 43px;
    padding: 0 15px;
    margin: 0;
  }

  .app-shell.sidebar-collapsed .tab::before {
    width: 8px;
    height: 8px;
    margin-right: 10px;
  }

  .app-shell.sidebar-collapsed .guide-button {
    display: grid;
    width: 100%;
    min-height: 72px;
    place-items: initial;
    grid-template-columns: auto 1fr;
    padding: 15px 17px;
  }

  .app-shell.sidebar-collapsed .guide-button .icon {
    grid-row: span 2;
  }

  .tab {
    text-align: left;
  }
}


@media (max-width: 820px) {
  .app-shell {
    width: min(100%, calc(100vw - 12px));
    max-width: calc(100vw - 12px);
    margin: 6px auto;
    border-radius: 20px;
  }

  .workspace,
  .sidebar {
    padding: 18px;
  }

  .metric {
    min-height: 138px;
  }

  .panel {
    padding: 20px;
  }
}


/* Mobile viewport containment fix: keep dashboard content inside the visible width. */
@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    background: var(--app);
  }

  .app-shell {
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    margin: 0;
    border-radius: 0;
    overflow: hidden;
  }

  .workspace {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    padding: 18px;
  }

  .topbar,
  .topbar-title-row,
  .topbar-copy,
  .metric-grid,
  .layout,
  .two-col,
  .distribution-layout,
  .panel,
  .table-wrap,
  .info-box,
  .logic-note,
  .section-head,
  .panel-heading {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .metric-grid,
  .two-col,
  .distribution-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .metric {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .mobile-menu-button,
  .feedback-banner {
    width: 100%;
  }

  .feedback-banner {
    justify-content: flex-start;
    border-radius: 18px;
  }
}

/* Targeted dashboard refinements: dark segmented state and larger score distribution chart. */
:root[data-theme="dark"] .segmented-option:hover,
:root[data-theme="dark"] .segmented-option.active {
  background: rgba(247, 6, 40, 0.22);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(247, 6, 40, 0.36);
}

.distribution-panel .chart {
  min-height: 360px;
}

.distribution-panel .chart svg {
  height: 340px;
}

@media (max-width: 820px) {
  .distribution-panel .chart {
    min-height: 328px;
  }

  .distribution-panel .chart svg {
    height: 308px;
  }
}

/* Score distribution donut chart. */
.donut-chart {
  display: grid;
  place-items: center;
  min-height: 496px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: radial-gradient(circle at 50% 50%, rgba(247, 6, 40, 0.08), transparent 54%), #f6f6f600;
  overflow: hidden;
}

.donut-svg {
  width: min(100%, 360px);
  height: auto;
  overflow: visible;
}

.donut-slice {
  stroke: var(--card);
  stroke-width: 4;
  transition: transform 180ms ease, opacity 180ms ease;
  transform-origin: 50% 50%;
}

.donut-slice:hover {
  transform: scale(1.018);
  opacity: 0.9;
}

.donut-slice-0,
.donut-key-0 { fill: #171717; background: #171717; }
.donut-slice-1,
.donut-key-1 { fill: #5a5f68; background: #5a5f68; }
.donut-slice-2,
.donut-key-2 { fill: #f70628; background: #f70628; }
.donut-slice-3,
.donut-key-3 { fill: #ff6b80; background: #ff6b80; }
.donut-slice-4,
.donut-key-4 { fill: #ffb0ba; background: #ffb0ba; }
.donut-slice-5,
.donut-key-5 { fill: #ffd6dc; background: #ffd6dc; }

.donut-empty-ring {
  stroke: var(--line);
}

.donut-hole {
  fill: #f7062800;
  filter: drop-shadow(0 12px 24px rgba(23, 23, 23, 0.08));
}

.donut-label {
  fill: #ffffff;
  font-size: 13px;
  font-weight: 950;
  pointer-events: none;
}

.donut-center-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.donut-center-value {
  fill: var(--text);
  font-size: 32px;
  font-weight: 950;
}

.donut-center-subtitle {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.donut-key {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.26);
}

.distribution-row span {
  display: inline-flex;
  align-items: center;
}

:root[data-theme="dark"] .donut-chart {
  background: radial-gradient(circle at 50% 50%, rgba(247, 6, 40, 0.13), transparent 54%), #20212600;
}

:root[data-theme="dark"] .donut-hole {
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.28));
}

@media (max-width: 820px) {
  .donut-chart {
    min-height: 328px;
  }

  .donut-svg {
    width: min(100%, 320px);
  }
}
