:root {
  --accent: #5b5bd6;
  --accent-soft: #ececfb;
  --bg: #f5f5f8;
  --panel: #ffffff;
  --border: #e5e5ee;
  --sidebar-bg: #1c1e2b;
  --sidebar-text: #c9cadd;
  --sidebar-text-dim: #8a8ca3;
  --sidebar-hover: #2a2c3d;
  --sidebar-active: #34374d;
  --text: #1f2030;
  --text-dim: #6d6f85;
  --danger: #e5484d;
  --ok: #22a06b;
  --run: #3b82f6;
  --warn: #e2a336;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ============================= Sidebar ============================= */
#sidebar {
  width: 290px;
  flex: 0 0 290px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
}
.brand-logo { display: flex; align-items: center; }
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; color: #fff; }
.brand-sub { font-size: 11px; color: var(--sidebar-text-dim); }

.sidebar-toolbar {
  display: flex;
  gap: 6px;
  padding: 0 12px 12px;
}
#search {
  flex: 1;
  background: var(--sidebar-hover);
  border: 1px solid transparent;
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--sidebar-text-dim); }

.icon-btn, .btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  transition: background 0.12s, opacity 0.12s;
}
.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--sidebar-hover); color: var(--sidebar-text);
}
.icon-btn:hover { background: var(--sidebar-active); color: #fff; }

.run-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}
.run-list::-webkit-scrollbar { width: 8px; }
.run-list::-webkit-scrollbar-thumb { background: #34374d; border-radius: 4px; }

.run-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
}
.run-item:hover { background: var(--sidebar-hover); }
.run-item.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent);
}
.run-item-text { flex: 1; min-width: 0; }
.run-item-name {
  font-size: 13px;
  color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.run-item-sub {
  font-size: 11px;
  color: var(--sidebar-text-dim);
  margin-top: 1px;
  display: flex; gap: 6px; align-items: center;
}

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex: 0 0 auto;
}
.status-dot.finished { background: var(--ok); }
.status-dot.running, .status-dot.finishing { background: var(--run); animation: pulse 1.4s infinite; }
.status-dot.queued { background: var(--warn); }
.status-dot.failed, .status-dot.cancelled { background: var(--danger); }
.status-dot.paused  { background: var(--warn); }
@keyframes pulse { 50% { opacity: 0.35; } }

.sidebar-empty { padding: 24px 18px; font-size: 13px; color: var(--sidebar-text-dim); }
.sidebar-empty code { background: var(--sidebar-hover); padding: 1px 5px; border-radius: 4px; }

.sidebar-footer {
  padding: 10px 14px;
  font-size: 11px;
  color: var(--sidebar-text-dim);
  display: flex; justify-content: space-between;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.sidebar-footer a { color: var(--accent); text-decoration: none; }

/* ============================= Main ============================= */
#main {
  flex: 1;
  overflow-y: auto;
  position: relative;
}
#main::-webkit-scrollbar { width: 10px; }
#main::-webkit-scrollbar-thumb { background: #d8d8e2; border-radius: 5px; }

.welcome {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.welcome-card {
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(30,30,60,0.06);
}
.welcome-card h1 { margin: 0 0 10px; }
.welcome-card p { color: var(--text-dim); margin: 0 0 20px; }

.run-view { max-width: 1080px; margin: 0 auto; padding: 28px 32px 60px; }

.run-header { margin-bottom: 16px; }
.run-title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.run-name {
  font-size: 24px; font-weight: 700;
  border: none; background: transparent;
  color: var(--text); outline: none;
  flex: 1; min-width: 220px;
  border-bottom: 2px solid transparent;
  padding: 2px 4px;
  border-radius: 6px;
}
.run-name:hover { border-bottom-color: var(--border); }
.run-name:focus { border-bottom-color: var(--accent); background: #fff; }

.pill {
  font-size: 11px; font-weight: 600; letter-spacing: 0.4px;
  text-transform: capitalize;
  padding: 2px 9px; border-radius: 999px;
  border: 1px solid transparent;
}
.pill.finished { color: #167a52; background: #e4f6ee; border-color: #bfe9d7; }
.pill.running, .pill.finishing { color: #1d5fa8; background: #e3f0ff; border-color: #c3e0ff; }
.pill.queued, .pill.paused { color: #96700a; background: #fdf3dc; border-color: #f3e0ac; }
.pill.failed, .pill.cancelled { color: #b4232b; background: #fee9ea; border-color: #f6c6c9; }

.run-id { color: var(--text-dim); font-family: var(--mono); font-size: 12px; }
.run-meta { color: var(--text-dim); font-size: 12px; margin: 6px 4px 0; display: flex; gap: 8px; align-items: center; }
.run-meta .dot { color: #c4c4d4; }
.run-actions { display: flex; gap: 8px; margin-top: 12px; }

.btn {
  padding: 7px 14px;
  background: #fff; border: 1px solid var(--border); color: var(--text);
}
.btn:hover { background: var(--accent-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4c4cc8; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #ffe4e5; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* Tabs */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  background: none; border: none; cursor: pointer;
  padding: 10px 14px; font-size: 14px; font-weight: 600;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(30,30,60,0.03);
}
.card-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card-head h2 { font-size: 15px; margin: 0; }
.card-hint { color: var(--text-dim); font-size: 12px; }

/* Summary (latest evaluation) */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}
.stat {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fbfbfe;
}
.stat-key {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}
.stat-key .swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.stat-value {
  font-size: 24px; font-weight: 700; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat-value .unit { font-size: 13px; color: var(--text-dim); font-weight: 500; }

/* Details */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; }
.detail-item { display: flex; flex-direction: column; gap: 4px; }
.detail-item-span { grid-column: 1 / -1; }
.detail-key { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.detail-val {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
  width: 100%;
}
.detail-val:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.detail-val.mono { font-family: var(--mono); background: var(--bg); border-style: dashed; }
select.detail-val { cursor: pointer; }

/* First-class evaluations */
.evaluation-list { display: grid; gap: 12px; }
.eval-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: #fbfbfe;
}
.eval-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.eval-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.eval-metrics .stat { background: #fff; }

.toast {
  display: inline-block;
  margin-top: 12px; padding: 6px 12px;
  background: #e4f6ee; color: #167a52;
  border-radius: 8px; font-size: 12px; font-weight: 600;
  animation: fadein 0.15s;
}
@keyframes fadein { from { opacity: 0; } }

/* Notes */
.notes {
  width: 100%; min-height: 140px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: inherit; font-size: 14px;
  resize: vertical; outline: none;
  background: #fff; color: var(--text);
}
.notes:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.notes-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px;
}
.notes-status { font-size: 12px; color: var(--text-dim); }
.notes-status.saved { color: var(--ok); }

/* Metric toggles */
.metric-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.metric-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer; font-size: 12.5px; font-weight: 600;
  background: #fff; user-select: none;
}
.metric-chip .swatch { width: 10px; height: 10px; border-radius: 3px; }
.metric-chip.off { color: var(--text-dim); background: var(--bg); }
.metric-chip.off .swatch { opacity: 0.3; }

/* Chart */
.chart-wrap { position: relative; }
.chart { width: 100%; height: 420px; }
.tooltip {
  position: absolute; pointer-events: none;
  background: #26283a; color: #fff;
  border-radius: 8px; padding: 8px 12px;
  font-size: 12px; line-height: 1.7;
  box-shadow: 0 6px 20px rgba(20,20,40,0.25);
  z-index: 10; white-space: nowrap;
  transform: translate(-50%, -110%);
}
.tooltip .tt-title { font-weight: 700; margin-bottom: 3px; opacity: 0.9; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .tt-row .tt-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }
.tooltip .tt-val { font-variant-numeric: tabular-nums; }

.chart-empty { padding: 40px; text-align: center; color: var(--text-dim); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,20,35,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff; border-radius: 14px;
  width: 420px; max-width: 92vw;
  padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(20,20,40,0.3);
}
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.modal-field span { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.modal-field input {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 14px; outline: none;
}
.modal-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.hidden { display: none !important; }