/* ===== Design tokens — light theme only ===== */
:root {
  --bg: #F7F7F5; --card: #FFFFFF;
  --border: #E6E4E0; --border-light: #F0EEEA;
  --text: #1C1C1A; --text-mid: #5C5C58; --text-light: #9C9C96;
  --blue: #4A6FA5; --blue-light: #4A6FA510; --blue-border: #4A6FA525;
  --orange: #B8703E; --orange-light: #B8703E10; --orange-border: #B8703E25;
  --green: #3D8B7A; --green-light: #3D8B7A10; --green-border: #3D8B7A25;
  --red: #A85C5C; --red-light: #A85C5C10; --red-border: #A85C5C25;
  --purple: #7B6FA5; --purple-light: #7B6FA510; --purple-border: #7B6FA525;
  --fh: 'Outfit', sans-serif;
  --fb: 'DM Sans', sans-serif;
  --fm: 'JetBrains Mono', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset + Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--fb); background: var(--bg); color: var(--text);
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}
#app { min-height: 100dvh; max-width: 430px; margin: 0 auto; }
button, select, input, textarea {
  font-family: inherit; font-size: inherit; color: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); padding: 10px 14px;
}
button { cursor: pointer; border: none; background: none; padding: 0; }
a { color: var(--blue); text-decoration: none; }

/* ===== Section card ===== */
.section {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 8px;
}
.section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; margin-bottom: 10px;
}

/* ===== Pill ===== */
.pill {
  display: inline-block; font-size: 10px; font-weight: 600;
  letter-spacing: 0.3px; padding: 2px 8px; border-radius: 4px;
}

/* ===== Expand button ===== */
.expand-btn {
  width: 100%; padding: 13px 16px; background: var(--card);
  border: 1px solid var(--border); color: var(--text-mid);
  font-size: 13px; cursor: pointer; display: flex;
  justify-content: space-between; align-items: center; font-weight: 600;
  border-radius: 12px; font-family: var(--fb);
}
.expand-btn.open {
  border-bottom: none; border-bottom-left-radius: 0;
  border-bottom-right-radius: 0; margin-bottom: 0;
}
.expand-btn:not(.open) { margin-bottom: 8px; }
.expand-content {
  background: var(--card); border: 1px solid var(--border);
  border-top: none; border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px; padding: 12px 16px; margin-bottom: 8px;
}
.expand-chevron {
  font-size: 14px; color: var(--text-light);
  transition: transform 0.2s;
}
.expand-chevron.open { transform: rotate(180deg); }

/* ===== Sticky header ===== */
.sticky-header {
  padding: 12px 16px; display: flex;
  justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}

/* ===== Filter pills ===== */
.filter-pill {
  padding: 5px 14px; border-radius: 20px; font-size: 11px;
  font-weight: 600; cursor: pointer; font-family: var(--fb);
  border: 1px solid var(--border); background: transparent;
  color: var(--text-light);
}
.filter-pill.active {
  border-color: #4A6FA550; background: var(--blue-light); color: var(--blue);
}

/* ===== Login ===== */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center;
  justify-content: center; padding: 16px;
}
.login-form {
  width: 100%; max-width: 320px; display: flex;
  flex-direction: column; gap: 12px;
}
.login-form h1 {
  font-family: var(--fh); font-size: 22px; font-weight: 700;
  text-align: center; margin-bottom: 8px;
}
.login-form input {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; font-size: 14px; background: var(--card);
}
.login-btn {
  background: var(--blue); color: white; border: none;
  border-radius: 8px; padding: 12px; font-size: 14px;
  font-weight: 600; cursor: pointer; font-family: var(--fb);
}
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error {
  font-size: 12px; color: var(--red); text-align: center; min-height: 18px;
}

/* ===== Skeleton loading ===== */
.skeleton {
  background: linear-gradient(90deg, var(--border-light) 25%, var(--card) 50%, var(--border-light) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
  border-radius: 12px;
}
.skeleton-card { height: 140px; margin-bottom: 8px; }
.skeleton-tile { height: 72px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 20px;
  border-radius: 100px; font-size: 12px; z-index: 999;
  opacity: 0; transition: opacity 0.2s;
}

/* ===== Chat bubbles ===== */
.bubble-user {
  background: var(--blue-light); border: 1px solid var(--blue-border);
  border-radius: 14px; border-bottom-right-radius: 4px;
}
.bubble-agent {
  background: var(--bg); border: 1px solid var(--border-light);
  border-radius: 14px; border-bottom-left-radius: 4px;
}

/* ===== Export menu ===== */
.export-menu {
  position: absolute; bottom: 100%; left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 4px; margin-bottom: 6px; z-index: 20;
}
.export-menu button {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; border: none; background: none;
  font-size: 13px; font-weight: 500; color: var(--text-mid);
  border-radius: 8px; cursor: pointer; font-family: var(--fb);
}
.export-menu button:hover { background: var(--bg); color: var(--text); }
.export-menu button:focus-visible {
  outline: 2px solid var(--blue); outline-offset: -2px;
}
.export-menu hr {
  border: none; border-top: 1px solid var(--border-light);
  margin: 2px 0;
}

/* ===== Utility ===== */
.mono { font-family: var(--fm); }
.heading { font-family: var(--fh); }

/* ===== Admin Tools Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 100; display: flex; align-items: center; justify-content: center;
}
.modal-panel {
  background: var(--bg); border-radius: 16px; width: 100%;
  max-width: 430px; max-height: 90dvh; overflow-y: auto; margin: 16px;
}
.modal-header {
  padding: 16px; display: flex; justify-content: space-between;
  align-items: center; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); border-radius: 16px 16px 0 0;
  z-index: 1;
}
.modal-body {
  padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 8px;
}
.tool-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.tool-card-title {
  font-family: var(--fh); font-size: 14px; font-weight: 600;
  margin-bottom: 2px;
}
.tool-card-desc {
  font-size: 12px; color: var(--text-mid); margin-bottom: 10px;
}
.tool-btn {
  background: var(--blue); color: white; border: none;
  border-radius: 8px; padding: 8px 16px; font-size: 12px;
  font-weight: 600; cursor: pointer; font-family: var(--fb);
}
.tool-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tool-btn--outline {
  background: transparent; color: var(--blue);
  border: 1px solid var(--blue); border-radius: 8px;
  padding: 8px 16px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: var(--fb);
}
.tool-btn--outline:disabled { opacity: 0.5; cursor: not-allowed; }
.tool-result {
  font-size: 12px; padding: 8px 10px; border-radius: 6px;
  margin-top: 8px;
}
.tool-result--success { background: var(--green-light); color: var(--green); border: 1px solid var(--green-border); }
.tool-result--info { background: var(--blue-light); color: var(--blue); border: 1px solid var(--blue-border); }
.tool-result--error { background: var(--red-light); color: var(--red); border: 1px solid var(--red-border); }
.orphan-list {
  font-size: 11px; color: var(--text-mid); margin-top: 8px;
  max-height: 150px; overflow-y: auto;
}
.orphan-row {
  display: flex; justify-content: space-between; padding: 4px 0;
  border-bottom: 1px solid var(--border-light); font-family: var(--fm);
}
.orphan-row:last-child { border-bottom: none; }

/* ===== Bulk select (pipeline) ===== */
.bulk-action-bar {
  position: sticky; top: 0; z-index: 5;
  margin: 0 16px 12px; padding: 10px 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}
.row-checkbox {
  /* Reset the global input styling so native checkbox renders. */
  appearance: auto; -webkit-appearance: auto;
  width: 18px; height: 18px;
  padding: 0; margin: 0; border: none; background: transparent;
  border-radius: 0; flex-shrink: 0; cursor: pointer;
  accent-color: var(--blue);
}
.row-checkbox:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}

/* ===== Conversation module (Section G) ===== */
.conv-panel { font-family: var(--fb); }
.conv-list { display: flex; flex-direction: column; gap: 8px; }
.conv-bubble {
  border-radius: 14px; padding: 10px 14px; max-width: 85%;
  align-self: flex-start; position: relative; cursor: pointer;
}
.conv-bubble--user {
  background: var(--blue-light); border: 1px solid var(--blue-border);
  border-bottom-right-radius: 4px; align-self: flex-end;
}
.conv-bubble--agent {
  background: var(--bg); border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
}
.conv-bubble-head {
  display: flex; align-items: baseline; gap: 6px; margin-bottom: 2px;
}
.conv-bubble-role {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.conv-bubble-time { font-size: 9px; color: var(--text-light); }
.conv-bubble-body {
  font-size: 13px; color: var(--text-mid); line-height: 1.5;
  white-space: pre-wrap; margin: 4px 0 0;
}
.conv-bubble-body p { margin: 0 0 0.5em; }
.conv-bubble-body p:last-child { margin-bottom: 0; }
.conv-bubble-body code {
  font-family: var(--fm); font-size: 12px;
  background: var(--border-light); padding: 1px 4px; border-radius: 3px;
}
.conv-bubble-body a { color: var(--blue); text-decoration: underline; }
.conv-bubble[data-collapsible="true"] .conv-bubble-body {
  position: relative;
}
.conv-bubble[data-collapsible="true"][data-collapsed="true"] .conv-bubble-body::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0;
  height: 2em; pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--card) 80%);
}
.conv-bubble--user[data-collapsible="true"][data-collapsed="true"] .conv-bubble-body::after {
  background: linear-gradient(to bottom, transparent, var(--blue-light) 80%);
}
.conv-show-more {
  display: block; margin-top: 6px; font-size: 11px;
  font-weight: 600; color: var(--blue);
  background: transparent; border: none; cursor: pointer;
  font-family: var(--fb); padding: 0;
}
.conv-show-more:hover { text-decoration: underline; }
.conv-announcer {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.conv-copy-toast {
  position: absolute; top: 6px; right: 8px;
  background: var(--text); color: var(--card);
  padding: 2px 8px; border-radius: 10px; font-size: 10px;
  font-weight: 600; letter-spacing: 0.3px;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none;
}
.conv-copy-toast--visible { opacity: 1; }
.conv-bubble:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}
.conv-chiprow {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px;
}
.conv-chip {
  display: inline-flex; align-items: baseline;
  font-size: 10px; font-weight: 600; letter-spacing: 0.2px;
  padding: 2px 8px; border-radius: 100px;
  border: 1px solid transparent; line-height: 1.4;
  font-family: var(--fb);
}
.conv-chip-dim { font-family: var(--fm); font-weight: 700; }
.conv-chip-arrow { font-weight: 700; }
.conv-chip-conf { font-weight: 500; opacity: 0.75; }
.conv-chip--revision { border-style: dashed; }
.conv-chip--complete {
  background: var(--green-light); border-color: var(--green-border);
  color: var(--green);
}
.conv-toolbar { margin-bottom: 10px; }
.conv-toolbar-primary {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.conv-search-slot, .conv-jump-slot {
  display: flex; align-items: center;
}
.conv-role-chips {
  display: inline-flex; gap: 0;
  border: 1px solid var(--border); border-radius: 100px;
  overflow: hidden; background: var(--card);
}
.conv-role-chip {
  padding: 4px 12px; font-size: 11px; font-weight: 600;
  background: transparent; color: var(--text-light);
  border: none; border-radius: 0; cursor: pointer; font-family: var(--fb);
}
.conv-role-chip + .conv-role-chip { border-left: 1px solid var(--border); }
.conv-role-chip--active { background: var(--blue); color: #fff; }
.conv-view-wrap { position: relative; margin-left: auto; }
.conv-view-btn {
  padding: 5px 10px; font-size: 11px; font-weight: 600;
  color: var(--text-mid); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-family: var(--fb);
}
.conv-view-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  min-width: 180px; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  padding: 4px; z-index: 30;
  display: flex; flex-direction: column; gap: 2px;
}
.conv-view-menu[hidden] { display: none; }
.conv-search {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 8px; border: 1px solid var(--border);
  border-radius: 100px; background: var(--card);
}
.conv-search-input {
  border: none; outline: none; background: transparent;
  font-size: 12px; padding: 2px 4px; min-width: 0; width: 110px;
}
.conv-search-counter {
  font-size: 10px; color: var(--text-light); font-family: var(--fm);
  min-width: 28px; text-align: right;
}
.conv-search-nav {
  padding: 2px 6px; font-size: 11px; color: var(--text-mid);
  background: transparent; border: none; cursor: pointer;
  font-family: var(--fb); border-radius: 6px;
}
.conv-search-nav:hover { background: var(--bg); }
.conv-search-nav:disabled { opacity: 0.4; cursor: not-allowed; }
.conv-mark {
  background: var(--orange-light); border-radius: 2px; padding: 0 2px;
}
.conv-mark--active {
  background: var(--orange); color: #fff; font-weight: 600;
}
.conv-menu-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; width: 100%; text-align: left;
  background: transparent; border: none; cursor: pointer;
  font-size: 12px; color: var(--text-mid); font-family: var(--fb);
  border-radius: 6px;
}
.conv-menu-item:hover { background: var(--bg); color: var(--text); }
.conv-menu-item:focus-visible {
  outline: 2px solid var(--blue); outline-offset: -2px;
}
.conv-menu-check {
  display: inline-block; width: 14px; height: 14px;
  border: 1px solid var(--border); border-radius: 3px;
  font-size: 11px; line-height: 12px; text-align: center;
  color: var(--blue); flex-shrink: 0;
}
.conv-menu-icon {
  display: inline-block; width: 14px; text-align: center;
  color: var(--text-light); flex-shrink: 0;
}
.conv-event-row {
  display: flex; align-items: flex-start; flex-wrap: wrap;
  margin: 4px 0 4px 12px; padding: 2px 6px;
  font-family: var(--fm); font-size: 10px;
  color: var(--text-light); line-height: 1.4;
  border-left: 2px solid var(--border-light);
}
.conv-event-kind { color: var(--text-light); flex-shrink: 0; }
.conv-event-name { color: var(--text-mid); }
.conv-event-payload {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-event-caret {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-light); font-size: 10px; padding: 0 2px;
}
.conv-event-caret:hover { color: var(--text-mid); }
.conv-event-full {
  flex-basis: 100%; margin-top: 4px; padding: 6px 8px;
  background: var(--bg); border-radius: 4px;
  font-size: 10px; color: var(--text-mid);
  white-space: pre-wrap; word-break: break-word;
  max-height: 240px; overflow-y: auto;
}
.conv-event-full[hidden] { display: none; }
.conv-latency {
  font-size: 10px; color: var(--text-light);
  font-family: var(--fm); margin: 2px 0;
}
.conv-jump { position: relative; display: inline-block; }
.conv-jump-btn {
  padding: 5px 10px; font-size: 11px; font-weight: 600;
  color: var(--text-mid); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-family: var(--fb);
}
.conv-jump-list {
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 160px; max-height: 260px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  padding: 4px; z-index: 30;
}
.conv-jump-list[hidden] { display: none; }
.conv-jump-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; width: 100%; padding: 6px 10px;
  background: transparent; border: none; cursor: pointer;
  font-size: 12px; color: var(--text-mid); font-family: var(--fb);
  border-radius: 6px; text-align: left;
}
.conv-jump-item:hover { background: var(--bg); color: var(--text); }
.conv-jump-item--active { background: var(--blue-light); color: var(--blue); font-weight: 700; }
.conv-jump-dot { color: var(--orange); font-size: 14px; line-height: 1; }
.conv-score-trace {
  margin-bottom: 10px;
  border: 1px solid var(--border-light); border-radius: 10px;
  overflow: hidden;
}
.conv-score-trace-btn {
  width: 100%; padding: 8px 12px; text-align: left;
  background: var(--bg); border: none; cursor: pointer;
  font-size: 11px; font-weight: 600; color: var(--text-mid);
  font-family: var(--fb);
}
.conv-score-trace-content {
  padding: 8px 12px; background: var(--card);
  border-top: 1px solid var(--border-light);
  display: flex; flex-direction: column; gap: 8px;
}
.conv-score-trace-content[hidden] { display: none; }
.conv-score-trace-row {
  display: flex; flex-direction: column; gap: 4px;
  padding-bottom: 6px; border-bottom: 1px dashed var(--border-light);
}
.conv-score-trace-row:last-child { border-bottom: none; padding-bottom: 0; }
.conv-score-trace-label {
  font-size: 10px; font-weight: 700; color: var(--text-mid);
  font-family: var(--fm);
}
.conv-score-trace-track {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
}
.conv-score-trace-entry {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 100px;
  border: 1px solid transparent; font-family: var(--fm);
}
.conv-score-trace-arrow {
  font-size: 11px; font-weight: 700;
}
