:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --line: #dde5f0;
  --text: #172033;
  --sub: #667085;
  --muted: #98a2b3;
  --blue: #2f80ed;
  --cyan: #12b5cb;
  --green: #2fb463;
  --orange: #f59e3d;
  --purple: #7c6fe8;
  --red: #e23b4a;
  --navy: #1f2a44;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
  background: var(--bg);
}

.side-nav {
  position: sticky;
  top: 0;
  flex: none;
  display: flex;
  flex-direction: column;
  width: 112px;
  min-height: 100vh;
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding-top: 14px;
  box-shadow: 1px 0 0 rgba(23, 32, 51, 0.02);
}

.side-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px 14px 18px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.side-logo-img {
  width: 100%;
  max-width: 30px;
  height: auto;
  display: none;
}

.side-logo-light {
  display: block;
}

body.dark-mode .side-logo-light {
  display: none;
}

body.dark-mode .side-logo-dark {
  display: block;
}

.side-tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 18px 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--sub);
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease;
}

.side-tab-bar {
  width: 26px;
  height: 4px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--tab-color) 35%, transparent);
  transition: background 0.15s ease, width 0.15s ease;
}

.side-tab-label {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -0.01em;
  text-align: center;
}

.side-tab:hover {
  background: #f5f7fb;
  color: var(--navy);
}

.side-tab.is-active {
  color: var(--tab-color);
  background: color-mix(in srgb, var(--tab-color) 8%, #ffffff);
  box-shadow: inset 3px 0 0 var(--tab-color);
}

.side-tab.is-active .side-tab-bar {
  width: 34px;
  background: var(--tab-color);
}

.page {
  min-width: 1180px;
  padding: 16px 10px 18px;
  zoom: 1.15;
  flex: 1;
}

.header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin: 0 8px 10px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #111827;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.header-subtitle {
  color: var(--sub);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header p {
  margin-top: 8px;
  color: var(--sub);
  font-size: 12px;
}

.header-actions {
  display: grid;
  grid-template-columns: auto auto;
  gap: 6px 12px;
  align-items: center;
  justify-items: end;
  color: #4b5b78;
  font-size: 12px;
}

.date-filter {
  grid-column: 1 / span 2;
  display: flex;
  align-items: center;
  gap: 10px;
}

.button,
select {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: #344054;
  font: inherit;
}

.date-filter select {
  min-width: 210px;
  min-height: 20px;
  padding: 3px 14px;
}

.button {
  padding: 6px 12px;
  cursor: pointer;
}

.csv-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding: 4px 10px;
  font-size: 10px;
  font-weight: 700;
  color: var(--sub);
}

.csv-btn:hover {
  color: var(--blue);
  border-color: var(--blue);
}

.csv-btn svg {
  flex-shrink: 0;
}

.card {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  box-shadow: 0 1px 1px rgb(15 23 42 / 3%);
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.section-title h2,
.card h2 {
  color: var(--navy);
  font-size: 14px;
  font-weight: 800;
}

.section-title span {
  color: var(--sub);
  font-size: 11px;
}

.compact h2 {
  font-size: 13px;
}

.flow-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 8px 12px;
  min-height: 78px;
  margin-top: 10px;
  padding: 7px 10px 6px 14px;
}

.flow-card > .section-title {
  grid-column: 1 / -1;
}

.flow {
  display: flex;
  grid-column: 1;
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}

.flow-step {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 42px;
  padding: 5px 6px 3px;
  border: 1px solid #d9e0ea;
  border-radius: 5px;
  background: #f5f7fa;
}

.flow-step:not(:last-child)::after {
  content: "➜";
  position: absolute;
  right: -12px;
  top: 50%;
  width: auto;
  height: auto;
  display: block;
  color: var(--navy);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  transform: translateY(-50%);
  z-index: 3;
}

.badge {
  display: inline-grid;
  width: 15px;
  height: 15px;
  place-items: center;
  margin-right: 6px;
  border-radius: 999px;
  background: var(--stage-color);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

.flow-step strong {
  color: var(--navy);
  font-size: 11px;
}

.flow-step b {
  display: block;
  margin: 3px 0 2px;
  text-align: center;
  color: var(--navy);
  font-size: 11px;
}

.flow-step small {
  display: block;
  text-align: center;
  color: var(--navy);
  font-size: 9px;
  line-height: 1.3;
}

.flow-step small.total-note {
  margin-top: 3px;
  color: var(--navy);
  font-weight: 700;
  font-size: 10px;
  line-height: 1.5;
}

.flow-step .total-note-title {
  display: block;
  margin: 3px 0 2px;
  text-align: center;
  color: var(--navy);
  font-size: 11px;
}

.flow-color-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 5px;
  color: var(--stage-color);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
}

.flow-color-swatch {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--stage-color);
}

.rule-box {
  grid-column: 2;
  align-self: end;
  margin-bottom: 1px;
  padding: 7px 12px;
  border-radius: 5px;
  background: #f5f6f8;
  color: var(--navy);
  font-size: 10px;
  line-height: 1.5;
}

.rule-box span {
  display: block;
  font-weight: 700;
}

.top-grid {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: 145px 126px 126px 150px 1fr;
  gap: 8px;
  margin-top: 10px;
  isolation: isolate;
}

.kpi-card {
  min-height: 126px;
  padding: 15px 14px;
  text-align: center;
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.kpi-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 8px;
  background: color-mix(in srgb, currentColor, white 88%);
}

.kpi-icon svg {
  width: 16px;
  height: 16px;
}

.kpi-card .label {
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
}

.metric {
  margin-top: 17px;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.metric small {
  margin-left: 5px;
  color: var(--sub);
  font-size: 12px;
  font-weight: 600;
}

.kpi-card p {
  margin-top: 16px;
  color: var(--sub);
  text-align: center;
  font-size: 10px;
}

.danger {
  background: #fffafa;
}

.danger-text,
.red {
  color: var(--red) !important;
}

.blue {
  color: var(--blue);
}

.purple {
  color: var(--purple);
}

.green {
  color: var(--green);
}

.stage-delay-card {
  position: relative;
  z-index: 5;
  padding: 12px 12px 10px;
  overflow: visible;
  display: flex;
  flex-direction: column;
}

.donut-card,
.bar-card {
  position: relative;
  z-index: 1;
  overflow: visible;
}

.stage-delay {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 5px;
  overflow: visible;
  isolation: isolate;
  z-index: 10;
  flex: 1;
  min-height: 0;
}

.stage-delay-item {
  position: relative;
  appearance: none;
  border: 1px solid #f0f2f6;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 9px 8px;
  border-radius: 5px;
  background: #fcfcfe;
  text-align: center;
  cursor: pointer;
  overflow: visible;
  z-index: 1;
  min-height: 0;
}

.stage-delay-item:hover,
.stage-delay-item.is-active {
  border-color: color-mix(in srgb, var(--stage-color), white 30%);
  box-shadow: 0 8px 18px rgb(15 23 42 / 10%);
  z-index: 80;
  isolation: isolate;
}

.stage-delay-item:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--stage-color), white 20%);
  outline-offset: 2px;
}

.stage-delay-item strong {
  display: block;
  color: var(--stage-color);
  font-size: 19px;
}

.stage-delay-item strong .unit {
  margin-left: 2px;
  font-size: 12px;
  font-weight: 600;
}

.stage-delay-item span {
  color: var(--stage-color);
  font-size: 9px;
}

.stage-delay-item small {
  display: block;
  margin-top: 7px;
  color: var(--navy);
  font-size: 8px;
}

.stage-popover {
  position: absolute;
  left: 50%;
  top: calc(100% + 10px);
  width: 220px;
  padding: 10px 10px 9px;
  border: 1px solid #d8e0ea;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 14px 30px rgb(15 23 42 / 16%);
  color: var(--navy);
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  z-index: 90;
  pointer-events: none;
}

/* Original stage-popover always hidden — JS clones it as fixed overlay */
.stage-delay-item:hover .stage-popover,
.stage-delay-item.is-active .stage-popover,
.popover-host:hover .stage-popover,
.popover-host.is-active .stage-popover {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.stage-popover.is-pinned {
  position: fixed !important;
  opacity: 1 !important;
  visibility: visible !important;
  transform: none !important;
  pointer-events: auto !important;
  z-index: 9999 !important;
}

.stage-popover::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 12px;
  height: 12px;
  border-left: 1px solid #d8e0ea;
  border-top: 1px solid #d8e0ea;
  background: #fff;
  transform: translateX(-50%) rotate(45deg);
}

.stage-popover-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
}

.stage-popover-head strong {
  color: var(--stage-color);
  font-size: 12px;
}

.stage-popover-head span {
  color: var(--navy);
  font-size: 10px;
  font-weight: 700;
}

.stage-popover-list {
  display: grid;
  gap: 5px;
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
}

.stage-popover-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  font-size: 10px;
  line-height: 1.35;
  min-width: 0;
}

.svc-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--navy);
}

.svc-delay {
  flex: none;
  color: var(--navy);
  font-weight: 800;
}

.stage-popover .svc-name,
.stage-popover .svc-delay {
  color: #111827 !important;
}

.donut-card,
.bar-card {
  overflow: visible;
}

.donut-slice {
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, stroke-width 0.16s ease, opacity 0.16s ease;
  transform-box: fill-box;
  transform-origin: center;
}

.donut-slice-label {
  font-size: 8px;
  font-weight: 800;
  paint-order: stroke;
  stroke-width: 1.4px;
  stroke-linejoin: round;
  pointer-events: none;
  user-select: none;
}

.donut-slice:hover,
.donut-slice:focus,
.donut-slice.is-active {
  transform: scale(1.03);
  filter: brightness(1.03);
  stroke: #ffffff;
  stroke-width: 2;
  opacity: 0.96;
  outline: none;
}

.stage-popover-empty {
  color: var(--sub);
  font-size: 10px;
}

.middle-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.elapsed-card,
.donut-card,
.bar-card,
.trend-card {
  min-height: 170px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}

.elapsed-summary {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  flex: 1;
}

.leadtime-total {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #eceff4;
  border-radius: 6px;
  background: linear-gradient(180deg, #f6f8ff 0%, #fdfdfe 100%);
}

.leadtime-total-value {
  color: var(--navy);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.leadtime-total-value span {
  margin-left: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--sub);
}

.leadtime-total-label {
  color: var(--navy);
  font-size: 11px;
  font-weight: 700;
}

.leadtime-total-note {
  margin-top: 1px;
  color: var(--sub);
  font-size: 10px;
}

.leadtime-stages {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
}

.leadtime-stage-row {
  display: grid;
  grid-template-columns: 68px 1fr auto auto;
  align-items: center;
  gap: 6px;
}

.leadtime-stage-label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--navy);
  font-size: 10px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leadtime-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.leadtime-stage-bar-track {
  position: relative;
  height: 7px;
  border-radius: 4px;
  background: #eef1f7;
  overflow: hidden;
}

.leadtime-stage-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.leadtime-stage-value {
  color: var(--navy);
  font-size: 11px;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.leadtime-stage-count {
  color: var(--sub);
  font-size: 9px;
  text-align: right;
  white-space: nowrap;
}



.donut-layout {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 16px;
  margin-top: 12px;
  align-items: center;
}

.donut {
  position: relative;
  width: 130px;
  height: 130px;
  display: block;
  border-radius: 50%;
  overflow: visible;
}

.donut-shell {
  position: relative;
  width: 130px;
  height: 130px;
  overflow: visible;
}

.donut-svg {
  display: block;
  width: 130px;
  height: 130px;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin: auto;
  border-radius: 50%;
  background: #fff;
  color: var(--navy);
  text-align: center;
  font-size: 10px;
  line-height: 1.4;
}

.donut-center strong {
  font-size: 18px;
}

.donut-popover {
  position: absolute;
  left: calc(100% + 12px);
  top: 12px;
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  pointer-events: none;
}

.donut-popover.is-active {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  pointer-events: auto;
  z-index: 90;
}

.donut-popover-card {
  width: 230px;
  padding: 10px 10px 9px;
  border: 1px solid #d8e0ea;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 14px 30px rgb(15 23 42 / 16%);
  color: var(--navy);
  text-align: left;
}

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

.popover-host {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
}

.legend-row {
  position: relative;
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 8px;
  align-items: center;
  color: var(--navy);
  font-size: 10px;
  width: 100%;
  padding: 0;
  cursor: default;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--stage-color);
}

.legend-row small {
  color: var(--sub);
}

.trend-chart {
  margin-top: 10px;
}

.trend-chart svg {
  display: block;
}

.trend-value-text {
  font-size: 10px;
  font-weight: 800;
  fill: var(--navy);
}

.trend-label-text {
  font-size: 9px;
  fill: var(--sub);
}

.empty-note {
  margin-top: 24px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.bar-legend {
  display: flex;
  justify-content: flex-end;
  gap: 20px;
  color: var(--sub);
  font-size: 9px;
}

.bar-legend span::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 1px;
  background: #e6e8ed;
}

.bar-legend span:last-child::before {
  background: var(--red);
}

.bars {
  display: grid;
  gap: 10px;
  margin-top: 6px;
  z-index: 1;
}

.bar-row {
  position: relative;
  display: grid;
  grid-template-columns: 94px 1fr 54px;
  gap: 10px;
  align-items: center;
  color: var(--navy);
  font-size: 10px;
  width: 100%;
  padding: 0;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease;
  border-radius: 4px;
}

.bar-row:hover,
.bar-row.is-active {
  transform: translateY(-1px);
  background: #fff8f8;
  z-index: 9999;
}

.bar-row:hover .bar-track,
.bar-row.is-active .bar-track {
  box-shadow: 0 0 0 1px var(--stage-color), 0 8px 18px rgb(15 23 42 / 10%);
}

.bar-row:hover .bar-delay,
.bar-row.is-active .bar-delay {
  filter: brightness(0.95);
}

.bar-track {
  display: flex;
  height: 18px;
  background: #ffffff;
  z-index: 1;
}

.bar-fill {
  display: flex;
  height: 100%;
}

.bar-normal {
  background: #e6e8ed;
  color: var(--navy);
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  line-height: 18px;
}

.bar-delay {
  background: var(--red);
  color: #fff;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  line-height: 18px;
}

.table-card {
  margin-top: 10px;
  padding: 12px 10px 16px;
}

.table-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 7px;
}

.controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

select {
  width: 102px;
  padding: 4px 10px;
  font-size: 10px;
}

.switch {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--navy);
  font-size: 10px;
}

.switch input {
  display: none;
}

.switch span {
  position: relative;
  width: 32px;
  height: 16px;
  border-radius: 999px;
  background: #cbd5e1;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: 0.2s;
}

.switch input:checked + span {
  background: var(--blue);
}

.switch input:checked + span::after {
  transform: translateX(16px);
}

.table-wrap {
  overflow: auto;
  border: 1px solid #edf1f7;
  border-radius: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}

th,
td {
  height: 26px;
  padding: 6px 8px;
  border-bottom: 1px solid #edf1f7;
  color: var(--navy);
  white-space: nowrap;
}

td:nth-child(2),
td:nth-child(4) {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  height: 36px;
  background: #f3f6fa;
  text-align: center;
  font-weight: 800;
}

tbody tr {
  transition: background-color 0.12s ease;
}

tbody tr:hover {
  background-color: #eef3fb;
}

td.num {
  text-align: right;
}

/* Center-align columns: 현재 단계(5) ~ 상태(13) */
th:nth-child(n+5),
td:nth-child(n+5) {
  text-align: center;
}

/* Override .num right-align within centered range */
td:nth-child(n+5).num {
  text-align: center;
}

.status {
  display: inline-block;
  min-width: 36px;
  padding: 3px 8px;
  border-radius: 4px;
  text-align: center;
  font-weight: 800;
}

.status.delay {
  background: #fff1f2;
  color: var(--red);
}

.status.normal {
  background: #eefbf3;
  color: var(--green);
}

.stage-tag {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 2px 8px 2px 7px;
  border-radius: 4px;
  border-left: 3px solid var(--stage-color);
  background: color-mix(in srgb, var(--stage-color), white 90%);
  color: color-mix(in srgb, var(--stage-color), black 15%);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: -0.1px;
  line-height: 1;
  white-space: nowrap;
}

/* Project cell with stage tooltip */
.project-cell {
  position: relative;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  cursor: help;
}

.project-cell:hover .project-name {
  text-decoration: underline;
}

.stage-tooltip-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  width: 420px;
  padding: 8px 10px;
  border: 1px solid #d8e0ea;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 14px 30px rgb(15 23 42 / 16%);
  color: var(--navy);
  font-size: 10px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 9999;
}

.stage-tooltip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 11px;
}

.stage-tooltip-header strong {
  color: var(--navy);
}

.progress-badge {
  background: #eef2ff;
  color: var(--blue);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 9px;
}

.stage-tooltip-progress-track {
  height: 5px;
  background: #edf1f7;
  border-radius: 999px;
  margin-bottom: 8px;
  overflow: hidden;
}

.stage-tooltip-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  border-radius: 999px;
  transition: width 0.2s ease;
}

.stage-tooltip-list {
  display: grid;
  gap: 3px;
}

.stage-tooltip-row {
  display: grid;
  grid-template-columns: 8px 72px 72px 60px 20px 44px;
  gap: 4px;
  align-items: stretch;
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 10px;
  line-height: 1.3;
}

.stage-tooltip-row.current {
  background: #fffbeb;
  font-weight: 700;
}

.stage-tooltip-row.delayed {
  background: #fff1f2;
}

.stage-tooltip-row.legend {
  font-size: 9px;
  font-weight: 700;
  color: var(--sub);
  padding-bottom: 4px;
  margin-bottom: 2px;
  border-bottom: 1px solid #e8ecf0;
}

.stage-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  align-self: center;
}

.stage-tooltip-row .stage-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--navy);
  font-size: 10px;
  line-height: 1.3;
  display: flex;
  align-items: center;
}

.stage-tooltip-row .stage-date {
  color: var(--sub);
  font-size: 10px;
  line-height: 1.3;
  display: flex;
  align-items: center;
}

.stage-tooltip-row .stage-delay {
  color: var(--sub);
  font-size: 10px;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-tooltip-row .stage-delay.has-delay {
  color: var(--red);
  font-weight: 800;
}

.stage-tooltip-row .stage-status {
  text-align: center;
  font-size: 10px;
  line-height: 1.3;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.stage-tooltip-row .stage-reason {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--sub);
  font-size: 10px;
  line-height: 1.3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-tooltip-row.legend .stage-reason {
  color: var(--sub);
}

.reason-trigger {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--red);
  font-weight: 700;
  font-size: 9px;
  cursor: help;
  padding: 1px 5px;
  border-radius: 999px;
  background: #fff1f2;
  white-space: nowrap;
}

.reason-trigger small {
  font-size: 9px;
}

.reason-popover {
  position: fixed;
  padding: 6px 8px;
  border: 1px solid #d8e0ea;
  border-radius: 6px;
  background: #1f2a44;
  color: #fff;
  font-size: 10px;
  line-height: 1.4;
  box-shadow: 0 10px 24px rgb(15 23 42 / 24%);
  z-index: 10000;
  word-break: break-word;
  pointer-events: none;
}

/* Mini progress bar in table */
.mini-progress {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mini-progress-dots {
  display: flex;
  gap: 2px;
  align-items: center;
}

.mini-stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.mini-stage-dot.done {
  opacity: 0.7;
}

.mini-stage-dot.current {
  opacity: 1;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--stage-color, currentColor), white 60%);
}

.mini-stage-dot.pending {
  opacity: 0.4;
}

.mini-progress-pct {
  font-size: 9px;
  font-weight: 800;
  color: var(--navy);
  min-width: 26px;
}

@media (max-width: 900px) {
  .page {
    min-width: 0;
  }

  .header,
  .flow-card,
  .top-grid,
  .middle-grid,
  .table-head {
    display: block;
  }

  .header-actions,
  .flow,
  .stage-delay,
  .elapsed-summary,
  .controls {
    margin-top: 12px;
  }
}

/* ============================================================
   Dark mode (toggled via body.dark-mode)
   ============================================================ */
body.dark-mode {
  --bg: #0b1220;
  --card: #141b2e;
  --line: #2a3550;
  --text: #e5e9f2;
  --sub: #9aa6c3;
  --muted: #6b7794;
  --navy: #e7ebf5;
}

body.dark-mode .side-nav {
  background: var(--card);
  box-shadow: 1px 0 0 rgba(0, 0, 0, 0.2);
}

body.dark-mode .side-tab:hover {
  background: #1c2740;
  color: var(--navy);
}

body.dark-mode .side-tab.is-active {
  background: color-mix(in srgb, var(--tab-color) 16%, var(--card));
}

body.dark-mode h1 {
  color: #f1f4fa;
}

body.dark-mode .header-actions {
  color: #b7c2dd;
}

body.dark-mode .date-filter select,
body.dark-mode .button,
body.dark-mode select {
  background: #1a2236;
  color: var(--text);
  border-color: var(--line);
}

body.dark-mode .flow-step {
  background: #1a2236;
  border-color: var(--line);
}

body.dark-mode .rule-box {
  background: #1a2236;
}

body.dark-mode .danger {
  background: #241a1e;
}

body.dark-mode .kpi-icon {
  background: color-mix(in srgb, currentColor, black 82%);
}

body.dark-mode .stage-delay-item {
  background: #171f33;
  border-color: var(--line);
}

body.dark-mode .stage-popover,
body.dark-mode .donut-popover-card,
body.dark-mode .stage-tooltip-popover {
  background: var(--card);
  border-color: var(--line);
  color: var(--text);
}

body.dark-mode .stage-popover::before {
  background: var(--card);
  border-color: var(--line);
}

body.dark-mode .stage-popover .svc-name,
body.dark-mode .stage-popover .svc-delay {
  color: var(--text) !important;
}

body.dark-mode .leadtime-total {
  background: linear-gradient(180deg, #1b2440 0%, #141b2e 100%);
  border-color: var(--line);
}

body.dark-mode .leadtime-stage-bar-track {
  background: #263049;
}

body.dark-mode .donut-center {
  background: #1a2236;
}

body.dark-mode .bar-track {
  background: #1a2236;
}

body.dark-mode .bar-row:hover,
body.dark-mode .bar-row.is-active {
  background: #201823;
}

body.dark-mode .bar-legend span::before,
body.dark-mode .bar-normal {
  background: #384360;
}

body.dark-mode .table-wrap {
  border-color: var(--line);
}

body.dark-mode th,
body.dark-mode td {
  border-bottom: 1px solid var(--line);
}

body.dark-mode th {
  background: #1a2236;
}

body.dark-mode tbody tr:hover {
  background-color: #1c2740;
}

body.dark-mode .status.delay {
  background: color-mix(in srgb, var(--red), black 75%);
}

body.dark-mode .status.normal {
  background: color-mix(in srgb, var(--green), black 78%);
}

body.dark-mode .stage-tag {
  background: color-mix(in srgb, var(--stage-color), black 75%);
  color: color-mix(in srgb, var(--stage-color), white 25%);
}

body.dark-mode .progress-badge {
  background: color-mix(in srgb, var(--blue), black 75%);
}

body.dark-mode .stage-tooltip-progress-track {
  background: #263049;
}

body.dark-mode .stage-tooltip-row.current {
  background: color-mix(in srgb, var(--orange), black 80%);
}

body.dark-mode .stage-tooltip-row.delayed {
  background: color-mix(in srgb, var(--red), black 78%);
}

body.dark-mode .stage-tooltip-row.legend {
  border-bottom-color: var(--line);
}

body.dark-mode .reason-trigger {
  background: color-mix(in srgb, var(--red), black 75%);
}

body.dark-mode .switch span {
  background: #384360;
}

body.dark-mode .switch span::after {
  background: #e5e9f2;
}
