:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --text: #17201d;
  --muted: #5d6865;
  --line: #d9dfdd;
  --brand: #126c57;
  --brand-2: #1d4d8f;
  --danger: #b42318;
  --shadow: 0 16px 34px rgba(18, 32, 29, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #ffffff;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
}

button.secondary {
  background: var(--brand-2);
}

button.danger {
  background: var(--danger);
}

button.ghost {
  background: #e7eceb;
  color: var(--text);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  min-height: 38px;
  padding: 9px 10px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 8px;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 18px 24px;
}

.topbar h1 {
  font-size: 20px;
  line-height: 1.2;
  margin: 0;
}

.topbar p {
  color: var(--muted);
  margin: 5px 0 0;
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - 78px);
}

.sidebar {
  background: #fbfcfc;
  border-right: 1px solid var(--line);
  padding: 20px;
}

.sidebar > button,
.sidebar > select {
  margin-bottom: 12px;
}

.tabs {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.tab {
  background: transparent;
  color: var(--text);
  justify-content: flex-start;
  text-align: left;
}

.tab.active {
  background: var(--surface-2);
  color: var(--brand);
}

.content {
  padding: 24px;
}

.panel {
  display: none;
}

.active-panel {
  display: block;
}

.panel-heading {
  align-items: flex-start;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) minmax(0, 3fr);
  margin-bottom: 16px;
}

.panel-heading h2 {
  font-size: 22px;
  margin: 0;
}

.form-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 20px;
  padding: 16px;
}

.faq-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
}

.span-all,
.form-actions {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  justify-content: stretch;
  min-width: 0;
}

.toolbar input,
.toolbar select {
  max-width: none;
  min-width: 0;
}

.checkbox-row {
  align-items: center;
  color: var(--text);
  display: flex;
  gap: 8px;
  margin: 0;
}

.checkbox-row input {
  height: 16px;
  min-height: 16px;
  width: 16px;
}

.check-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.check-grid label {
  align-items: center;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 9px 10px;
}

.check-grid input {
  height: 16px;
  min-height: 16px;
  width: 16px;
}

.segmented {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
}

.segmented label {
  align-items: center;
  color: var(--text);
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 0;
  padding: 10px;
}

.segmented label + label {
  border-left: 1px solid var(--line);
}

.segmented input {
  height: 16px;
  min-height: 16px;
  width: 16px;
}

.target-box {
  background: #f9fbfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.hidden {
  display: none;
}

.table,
.faq-list,
.log-list,
.messages {
  display: grid;
  gap: 10px;
}

.row,
.faq-item,
.log-item,
.message {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 1fr) auto;
}

.row.is-muted {
  opacity: 0.72;
}

.row-title,
.faq-item h3,
.log-item h3 {
  font-size: 15px;
  margin: 0 0 4px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.faq-item,
.log-item {
  display: grid;
  gap: 10px;
}

.faq-answer,
.log-answer {
  color: #27312e;
  white-space: pre-wrap;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  text-transform: uppercase;
}

.log-faq_hit {
  border-left: 4px solid var(--brand);
}

.log-llm_fallback {
  border-left: 4px solid var(--brand-2);
}

.log-helpline {
  border-left: 4px solid var(--danger);
}

.log-faq_hit .badge {
  background: #def7ec;
  color: var(--brand);
}

.log-llm_fallback .badge {
  background: #dceafe;
  color: var(--brand-2);
}

.log-helpline .badge {
  background: #fee4e2;
  color: var(--danger);
}

.tester {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 16px;
}

.message.user {
  border-left: 4px solid var(--brand-2);
}

.message.bot {
  border-left: 4px solid var(--brand);
}

.modal {
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: min(900px, calc(100vw - 32px));
  padding: 0;
  width: 100%;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-body {
  box-shadow: none;
  margin: 0;
}

.modal-title {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.modal-title h2 {
  margin: 0;
}

.branding-row {
  display: grid;
  gap: 10px;
  grid-template-columns: auto 1fr 1fr auto;
  align-items: end;
}

.branding-row input[type="color"] {
  height: 38px;
  padding: 2px;
  width: 60px;
}

.messages {
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.analytics-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 24px;
}

@media (max-width: 860px) {
  .topbar,
  .layout {
    display: block;
  }

  .topbar-actions,
  .form-grid,
  .segmented,
  .tester,
  .branding-row {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-bottom: 1px solid var(--line);
    border-right: 0;
  }

  .content {
    padding: 16px;
  }
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  visibility: hidden;
  opacity: 0;
  transition: all 0.3s ease;
}

.login-overlay.active {
  visibility: visible;
  opacity: 1;
}

.login-card {
  background: var(--surface);
  padding: 32px;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin-top: 0;
  margin-bottom: 24px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
