:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #5a5a5a;
  --border: #d8d8d8;
  --panel: #f7f7f8;
  --accent: #2453ff;
  --risk-low: #0a7d3a;
  --risk-medium: #a15c00;
  --risk-high: #b3221e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --fg: #eaeaea;
    --muted: #a3a3a3;
    --border: #33343a;
    --panel: #1d1e24;
    --accent: #7c9bff;
    --risk-low: #4ad07f;
    --risk-medium: #e0a340;
    --risk-high: #ff6b66;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.app-header h1 { font-size: 1.25rem; margin: 0; }
.identity { color: var(--muted); font-size: 0.85rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
}

.panel.sources, .panel.workflow-status, .panel.data-status {
  grid-column: 1 / -1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

.panel h2 { margin-top: 0; font-size: 1rem; }

form label, .panel label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}

form input, form select, .panel input, .panel select {
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 0.95rem;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  width: 100%;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 1rem;
  line-height: 1.4;
}

.status { font-size: 0.9rem; color: var(--muted); margin-bottom: 1rem; }
.status.error { color: var(--risk-high); }

.candidate {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.candidate-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.candidate-header .time { font-weight: 600; }

.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.risk-badge.low { color: var(--risk-low); }
.risk-badge.medium { color: var(--risk-medium); }
.risk-badge.high { color: var(--risk-high); }

.risk-bar-track {
  height: 8px;
  border-radius: 4px;
  background: color-mix(in srgb, currentColor 15%, transparent);
  margin: 0.5rem 0;
  overflow: hidden;
}
.risk-bar-fill { height: 100%; border-radius: 4px; background: currentColor; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem 1rem;
  font-size: 0.85rem;
  margin: 0.75rem 0;
}
.meta-grid dt { color: var(--muted); }
.meta-grid dd { margin: 0; font-weight: 600; }

.explanation { font-size: 0.9rem; line-height: 1.45; }
.warnings { color: var(--risk-medium); font-size: 0.82rem; margin-top: 0.5rem; }

.customer-list { font-size: 0.82rem; color: var(--muted); margin-top: 0.5rem; }

.sources-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0.75rem 0;
}
.sources-table th, .sources-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.sources-table th { color: var(--muted); font-weight: 600; }
.sources-table button { width: auto; padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.sources-table td.actions { display: flex; gap: 0.4rem; }

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}
.checkbox-label input { width: auto; }

.workflow-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  margin-bottom: 0.75rem;
}
.workflow-status-badge.ok { color: var(--risk-low); }
.workflow-status-badge.pending { color: var(--risk-medium); }
.workflow-status-badge.bad { color: var(--risk-high); }

.workflow-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
}
