:root{
  --bg: #0f1218;
  --panel: #141a22;
  --text: #e5eef8;
  --muted: #94a3b8;
  --accent: #5b9cff;
  --accent-2: #9b59b6;
  --bar: #2b87ff;
  --bar-hover: #5aa3ff;
  --border: #263241;
  --danger: #ff6b6b;
  --btn-h: 34px;
  --hover-bg: #1c2430;
}

body.light{
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --bar: #3b82f6;
  --bar-hover: #60a5fa;
  --border: #e2e8f0;
  --danger: #ef4444;
  --hover-bg: #f1f5f9;
}

*{ box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; }
body{
  margin:0; font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg);
}

#app{ height: 100%; position: relative; }
main#main{ padding: 12px 16px 16px 16px; height: 100%; display:flex; flex-direction: column; }

h1{ font-size: 18px; margin: 0 0 12px; }
.control-group{ margin-bottom: 14px; }
.control-group.compact{ display: flex; gap: 8px; }
.row{ display:flex; align-items:center; gap:10px; }
.row.space-between{ justify-content: space-between; }

label{ font-weight: 600; font-size: 12px; color: var(--muted); display:block; margin-bottom:4px; }
label.radio{ font-weight: 500; display:flex; align-items:center; gap:6px; margin-right: 12px; }

select, input[type="text"]{
  width:100%; background: var(--bg); color:var(--text); border:1px solid var(--border); border-radius:8px; padding:8px 10px; outline:none;
}
select:focus, input[type="text"]:focus{ border-color: var(--accent); }

.stage-list{ border:1px solid var(--border); border-radius:8px; background: var(--bg); max-height: none; overflow:auto; padding:6px; flex: 1 1 auto; }
.stage-item{ display:flex; align-items:center; justify-content: space-between; padding:6px 8px; border-radius:6px; cursor: pointer; user-select: none; }
.stage-item:hover{ background: var(--hover-bg); }
.stage-item .left{ display:flex; align-items:center; gap:8px; }
.stage-item input{ display:none; }
.stage-item .marker{ width: 10px; height: 10px; border-radius: 50%; border:1px solid var(--border); display:inline-block; }
.stage-item.selected .marker{ background: var(--accent); border-color: var(--accent); }
.stage-value{ color: var(--muted); font-size: 12px; }
#stagePanel.collapsed{ display:none; }

.btn{ background: var(--accent); color:white; border:none; border-radius:8px; padding:8px 10px; cursor:pointer; font-weight:600; }
.btn.secondary{ background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn:disabled{ opacity:.6; cursor:not-allowed; }

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

#chartHeader{ margin-bottom: 8px; height: var(--btn-h); display:flex; align-items:center; justify-content: space-between; position: relative; }
#chartHeader .panel-wrap{ position: relative; }
.text-btn{ background: transparent; border:1px solid var(--border); color: var(--text); padding: 0 10px; border-radius: 8px; cursor:pointer; font-weight:600; display:inline-flex; align-items:center; height: var(--btn-h); }
.text-btn .chev{ display:inline-flex; margin-left: 6px; color: var(--muted); }
.text-btn .chev svg{ display:block; width: 12px; height: 6px; transition: transform .16s ease, color .16s ease; }
.text-btn[aria-expanded="true"]{ color: var(--accent); border-color: var(--accent); }
.text-btn[aria-expanded="true"] .chev{ color: var(--accent); }
.text-btn[aria-expanded="true"] .chev svg{ transform: rotate(180deg); }
.dropdown-panel{ position: absolute; top: calc(100% + 6px); right: 0; left: auto; width: 320px; max-height: 70vh; background: var(--panel); border:1px solid var(--border); border-radius: 10px; padding: 10px; box-shadow: 0 10px 20px rgba(0,0,0,.35); z-index: 1000; opacity: 0; transform: translateY(-4px); visibility: hidden; pointer-events: none; transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s; display:flex; flex-direction: column; }
.dropdown-panel.open{ opacity: 1; transform: translateY(0); visibility: visible; pointer-events: auto; transition: opacity .16s ease, transform .16s ease; }
#chart{ flex:1 1 auto; min-height:0; overflow:hidden; padding: 12px 6px 12px 6px; }
.chart-vertical{ display:flex; flex-direction: row; align-items: flex-end; gap:12px; }
.chart-horizontal{ display:block; }
/* Horizontal grid: three columns shared across rows */
#chart.chart-horizontal{ display:flex; flex-direction: column; gap: 12px; }

/* Conversion arrows strip */
.conv-strip{ margin-top: 6px; }
.conv-strip.hidden{ display:none; }
.conv-strip{ display: grid; grid-template-columns: repeat(var(--pairs, 1), 1fr); column-gap: 12px; align-items: center; }
.conv-item{ position: relative; height: 14px; }
.conv-item .line{ position:absolute; left:0; right:0; top:50%; height: 2px; background: var(--border); transform: translateY(-50%); }
.conv-item .line::after{ content: ""; position:absolute; right:0; top:50%; transform: translateY(-50%); border-left:6px solid var(--border); border-top:4px solid transparent; border-bottom:4px solid transparent; }
.conv-item .pct{ position:absolute; top:-10px; left:50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); background: transparent; padding: 0 4px; white-space: nowrap; }

/* Header icon button */
.icon-btn{ display:inline-flex; align-items:center; justify-content:center; gap:6px; width: var(--btn-h); height: var(--btn-h); padding: 0; border-radius:8px; border:1px solid var(--border); background: var(--panel); color: var(--text); cursor:pointer; margin-right: 0; }
.icon-btn:hover{ border-color: var(--accent); color: var(--accent); }
.icon-btn img{ width: 20px; height: 20px; object-fit: contain; display:block; }

/* Vertical bars layout */
.bar-col{
  display:flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
  flex: 1 1 0;
  min-width: 0;
}
.bar-col.drag-over{ outline:1px dashed var(--accent-2); }
.bar-outer{
  width: 100%;
  height: 100%;
  display:flex;
  align-items: flex-end;
  justify-content: center;
  background: transparent;
  padding: 0;
}
.bar{
  width: 100%;
  min-height: 6px;
  background: linear-gradient(180deg, var(--bar), var(--bar-hover));
  border-radius: 4px;
  transition: height .15s ease;
}
.col-value{ font-size: 12px; color: var(--text); text-align: center; width: 100%; font-weight: 700; }
.col-value .col-pct{ color: #B4B4B4; display:block; margin-top: 2px; }
.col-label{
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-sub{ font-size: 11px; color: var(--muted); }

/* removed labels tilt */

/* Horizontal bars layout (mirrors vertical with axes swapped) */
.hbar-col{ display:grid; grid-template-columns: var(--labelw, max-content) 1fr; align-items:center; gap:10px; padding:4px 2px; }
.hbar-col.drag-over{ outline:1px dashed var(--accent-2); }
.bar-outer-h{ width: 100%; height: 34px; background: transparent; position: relative; }
.bar-h{ height: 100%; background: linear-gradient(90deg, var(--bar), var(--bar-hover)); border-radius: 4px; transition: width .15s ease; width: 0%; }
.row-value{ position:absolute; top:50%; transform: translateY(-50%); white-space: nowrap; font-size: 12px; color: var(--text); font-weight: 700; padding-right: 8px; }
.row-value .sep{ color: var(--muted); margin: 0; }
.row-value .pct{ color: #B4B4B4; }
.row-label{ color: var(--text); font-size: 12px; white-space: nowrap; text-align: left; }

.tooltip{ position: fixed; z-index: 9999; background: var(--panel); border:1px solid var(--border); color: var(--text); padding:8px 10px; border-radius:8px; box-shadow: 0 10px 20px rgba(0,0,0,.15); max-width: 320px; }
.tooltip .stage{ font-weight: 600; margin-bottom: 2px; }
.tooltip .row2{ display:flex; align-items: baseline; gap: 6px; }
.tooltip .row2 .num{ font-weight: 700; }
.tooltip .row2 .sep{ color: var(--muted); }
.tooltip .row2 .pct{ color: var(--muted); }

#status{ margin-top: 8px; font-size: 12px; }
.col-sub{ font-size: 11px; color: var(--muted); }

/* removed labels tilt */

/* legacy horizontal styles (no longer used) */

.tooltip{ position: fixed; z-index: 9999; background: var(--panel); border:1px solid var(--border); color: var(--text); padding:8px 10px; border-radius:8px; box-shadow: 0 10px 20px rgba(0,0,0,.15); max-width: 320px; }
.tooltip .stage{ font-weight: 600; margin-bottom: 2px; }
.tooltip .row2{ display:flex; align-items: baseline; gap: 6px; }
.tooltip .row2 .num{ font-weight: 700; }
.tooltip .row2 .sep{ color: var(--muted); }
.tooltip .row2 .pct{ color: var(--muted); }

#status{ margin-top: 8px; font-size: 12px; }
