:root {
  --bg:           #f5f6f8;
  --bg-2:         #eef0f3;
  --surface:      #ffffff;
  --surface-2:    #fafbfc;
  --border:       #e1e4e8;
  --border-2:     #d0d4da;
  --text:         #111827;
  --text-2:       #4b5563;
  --text-3:       #6b7280;
  --text-4:       #9ca3af;

  --navy:         #0f223f;
  --navy-2:       #1c3760;
  --primary:      #1d4ed8;
  --primary-2:    #1e40af;

  --danger:       #b91c1c;
  --danger-bg:    #fef2f2;
  --danger-border:#fecaca;
  --warn:         #b45309;
  --warn-bg:      #fffbeb;
  --warn-border:  #fde68a;
  --success:      #047857;
  --success-bg:   #ecfdf5;
  --success-border:#a7f3d0;

  --sans: 'IBM Plex Sans', -apple-system, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', 'Consolas', monospace;

  --shadow-sm: 0 1px 2px rgba(15,34,63,0.04);
  --shadow:    0 1px 3px rgba(15,34,63,0.05), 0 1px 2px rgba(15,34,63,0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* TOPBAR */
.topbar {
  background: var(--navy);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--navy-2);
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-logo {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-logo::before {
  content: '';
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.18);
}
.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-divider {
  width: 1px; height: 18px; background: rgba(255,255,255,0.18); margin: 0 4px;
}
.brand-tag {
  font-family: var(--mono);
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.04em;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 12px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(4, 120, 87, 0.18);
  color: #6ee7b7;
  border-radius: 100px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
}
.status-pill::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,0.6);
  animation: pulse 2s ease-out infinite;
}
.status-pill.error { background: rgba(185,28,28,0.2); color: #fca5a5; }
.status-pill.error::before { background: #ef4444; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
.topbar-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: rgba(255,255,255,0.6);
}

/* LAYOUT */
main {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 24px 60px;
  align-items: start;
}
@media (max-width: 1100px) { main { grid-template-columns: 1fr; padding: 16px; } }

/* PANEL */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}
.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.panel-header .meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}

/* CUSTOMER LIST */
.customer-list { padding: 4px 0; }
.customer-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  column-gap: 12px;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease;
  position: relative;
}
.customer-row:last-child { border-bottom: none; }
.customer-row:hover { background: var(--surface-2); }
.customer-row.active {
  background: #eff6ff;
  border-left: 3px solid var(--primary);
  padding-left: 15px;
}
.customer-row.active::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  width: 6px; height: 6px;
  border-top: 2px solid var(--primary);
  border-right: 2px solid var(--primary);
  transform: translateY(-50%) rotate(45deg);
}
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--bg-2);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}
.customer-row.active .avatar { background: var(--primary); color: #fff; }
.customer-info { min-width: 0; }
.customer-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.customer-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--bg-2);
  color: var(--text-3);
  border: 1px solid var(--border);
}
.badge.low    { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge.medium { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-border); }
.badge.high   { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-border); }
.badge .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* DETAIL */
.detail { display: flex; flex-direction: column; gap: 16px; }
.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.customer-header {
  padding: 22px 26px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
}
.customer-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 6px;
}
.customer-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}
.customer-attrs {
  display: flex;
  gap: 18px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-2);
  flex-wrap: wrap;
}
.customer-attrs .sep { color: var(--text-4); }
.header-score { text-align: right; }
.header-score-num {
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
  font-feature-settings: "tnum";
}
.header-score-meta {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--mono);
  margin-top: 4px;
}
.customer-note {
  padding: 14px 26px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.customer-note::before {
  content: '';
  width: 3px;
  align-self: stretch;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.section { padding: 20px 26px; }
.section + .section { border-top: 1px solid var(--border); }
.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.section-label .sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-4);
  text-transform: none;
  letter-spacing: 0;
}

/* SPEC GRID */
.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px 22px;
}
.spec { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.spec .label { font-size: 11px; color: var(--text-3); }
.spec .value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  font-feature-settings: "tnum";
}
.spec .value.warn   { color: var(--warn); }
.spec .value.danger { color: var(--danger); }

/* SCORES */
.scores-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 720px) { .scores-grid { grid-template-columns: 1fr; } }
.score-box {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 18px 20px;
}
.score-box-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.score-box-title { font-size: 12px; font-weight: 600; color: var(--text); }
.score-box-sub   { font-size: 11px; color: var(--text-4); font-family: var(--mono); }
.score-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.score-num {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
  font-feature-settings: "tnum";
}
.score-denom { font-size: 13px; color: var(--text-3); font-family: var(--mono); }
.score-bar {
  height: 6px;
  background: var(--bg-2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}
.score-bar-fill.low    { background: var(--success); }
.score-bar-fill.medium { background: var(--warn); }
.score-bar-fill.high   { background: var(--danger); }
.score-band-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.score-signals {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.signal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.signal-row .name {
  color: var(--text-2);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.signal-row .w { font-family: var(--mono); font-weight: 600; flex-shrink: 0; }
.signal-row .w.pos { color: var(--danger); }
.signal-row .w.neg { color: var(--success); }

/* ACTIONS */
.actions {
  padding: 16px 26px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 16px;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
  box-shadow: var(--shadow-sm);
}
.btn:disabled {
  background: var(--text-4);
  border-color: var(--text-4);
  cursor: not-allowed;
}
.btn::before {
  content: '';
  width: 6px; height: 6px;
  border-top: 2px solid #fff;
  border-right: 2px solid #fff;
  transform: rotate(45deg);
  margin-left: 2px;
}
.btn.ghost {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border-2);
}
.btn.ghost::before { display: none; }
.btn.ghost:hover { background: var(--bg-2); color: var(--text); }
.actions-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  margin-left: auto;
}

/* ALERT */
.alert {
  display: flex;
  gap: 12px;
  padding: 14px 18px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-left: 3px solid var(--danger);
  border-radius: 6px;
}
.alert-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  color: var(--danger);
  margin-top: 1px;
}
.alert-body { flex: 1; }
.alert-title {
  font-weight: 600;
  color: var(--danger);
  font-size: 13px;
}
.alert-desc {
  font-size: 13px;
  color: #7f1d1d;
  margin-top: 2px;
}

/* RESULT */
.llm-result { display: flex; flex-direction: column; gap: 14px; }
.explanation {
  padding: 14px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}
.pair-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 14px;
}
@media (max-width: 720px) { .pair-row { grid-template-columns: 1fr; } }
.pair-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 18px;
}
.pair-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 6px;
}
.pair-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.pair-rationale {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 6px;
  line-height: 1.55;
}

/* DRAFT */
.draft {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}
.draft-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.draft-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.draft-title-icon {
  width: 14px; height: 14px;
  color: var(--text-3);
}
.draft-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}
.draft-meta.over { color: var(--danger); font-weight: 600; }
.draft-body {
  padding: 14px 18px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.draft-actions {
  padding: 8px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}
.copy-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s;
}
.copy-btn:hover {
  background: var(--bg-2);
  color: var(--text);
  border-color: var(--text-3);
}
.copy-btn.copied {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success-border);
}

/* DEBUG */
details.debug {
  font-size: 12px;
  color: var(--text-3);
}
details.debug summary {
  cursor: pointer;
  padding: 8px 0;
  font-weight: 500;
  color: var(--text-3);
  list-style: none;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
}
details.debug summary::before {
  content: '▸';
  margin-right: 6px;
  display: inline-block;
  transition: transform 0.15s;
}
details.debug[open] summary::before { transform: rotate(90deg); }
details.debug summary::-webkit-details-marker { display: none; }
details.debug summary:hover { color: var(--text); }

pre.text-stream {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 220px;
  overflow-y: auto;
  color: var(--text-2);
  border-radius: 4px;
}
.events {
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}
.event {
  background: var(--bg-2);
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  border-left: 2px solid var(--text-4);
  border-radius: 0 3px 3px 0;
}
.event.tool { border-color: var(--warn); }
.event.err  { border-color: var(--danger); color: var(--danger); }

.json-result {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 12px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 380px;
  overflow: auto;
  color: var(--text-2);
  border-radius: 4px;
  margin-top: 6px;
}

.empty {
  padding: 80px 20px;
  text-align: center;
  color: var(--text-4);
  font-size: 14px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

::selection { background: rgba(29,78,216,0.18); color: var(--text); }
