:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #5d6d7e;
  --line: #d6dee8;
  --accent: #0b7285;
  --danger: #c92a2a;
  --good: #2b8a3e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #f4f7fb 0%, #eef4f8 50%, #f9fbfd 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}

h1 {
  margin: 0;
  font-size: 22px;
}

.muted {
  color: var(--muted);
  margin: 4px 0 0;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  background: #dfe9f2;
  border: 1px solid #c7d5e4;
  color: #223;
}

.tabs button.active {
  background: #0b7285;
  color: white;
  border-color: #0b7285;
}

main {
  padding: 16px 24px 24px;
}

.tab {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.tab.active {
  display: block;
}

#tab-logs.active {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 190px);
}

button {
  border: 1px solid #cad5e1;
  background: #edf2f7;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.98);
}

button.danger {
  background: #ffe3e3;
  border-color: #ffc9c9;
  color: var(--danger);
}

input,
select,
textarea {
  border: 1px solid #c8d2de;
  border-radius: 8px;
  padding: 8px;
  width: 100%;
  font: inherit;
}

input[type="checkbox"] {
  width: auto;
}

textarea {
  resize: vertical;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.panel-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.multi-entity-options {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
  margin-bottom: 12px;
}

.multi-entity-head {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.multi-entity-grid {
  display: grid;
  grid-template-columns: minmax(210px, 1.4fr) minmax(100px, .7fr) minmax(100px, .7fr) minmax(120px, .8fr);
  gap: 8px;
  align-items: center;
}

.multi-entity-grid-head {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.multi-entity-options label,
.multi-entity-name,
.multi-entity-cache {
  min-width: auto;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.multi-entity-name {
  font-weight: 600;
}

.multi-entity-cache {
  justify-content: flex-start;
}

@media (max-width: 760px) {
  .multi-entity-grid {
    grid-template-columns: 1fr 1fr;
  }

  .multi-entity-grid-head {
    display: none;
  }
}

.progress-box,
.logs-box,
#settings-status,
#prompt-status {
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fbff;
  max-height: 240px;
  overflow: auto;
}

#tab-logs .logs-box {
  max-height: none;
}

.chat-box {
  min-height: 240px;
  max-height: 380px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fbff;
  margin-bottom: 10px;
}

.chat-prompt-preview {
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  padding: 12px;
}

.chat-prompt-preview-head {
  align-items: flex-start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chat-prompt-box {
  background: #fff;
  border: 1px solid #e3ebf3;
  border-radius: 8px;
  margin: 0;
  max-height: 180px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.chat-msg {
  margin: 6px 0;
  padding: 8px;
  border-radius: 8px;
  border-left: 3px solid #99acc2;
  background: #fff;
}

.chat-msg.user {
  border-left-color: #0b7285;
}

.chat-msg.assistant {
  border-left-color: #2b8a3e;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#verify-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#verify-table th,
#verify-table td {
  border-bottom: 1px solid #e7eef6;
  padding: 8px;
  text-align: left;
}

#verify-table th {
  position: sticky;
  top: 0;
  background: #edf3f8;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.settings-actions {
  margin-bottom: 8px;
}

.settings-models-status {
  margin: 2px 0 12px;
}

.model-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.model-picker-info {
  margin-top: -2px;
  min-height: 54px;
  border: 1px solid #e6edf5;
  border-radius: 10px;
  padding: 8px 10px;
  background: #f8fbff;
  font-size: 13px;
  line-height: 1.45;
}

.settings-check-summary {
  margin: 8px 0 12px;
}

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

.settings-check-empty {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 14px;
  color: var(--muted);
  background: #f8fbff;
}

.service-check-card {
  border: 1px solid #dbe5ef;
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,250,253,0.98));
  box-shadow: 0 8px 20px rgba(21, 34, 50, 0.04);
}

.service-check-card.severity-ok {
  border-color: #b7dfc2;
  background: linear-gradient(180deg, #fbfffc, #f3fbf5);
}

.service-check-card.severity-warning {
  border-color: #efd59f;
  background: linear-gradient(180deg, #fffdf8, #fff8ea);
}

.service-check-card.severity-error {
  border-color: #efc0bc;
  background: linear-gradient(180deg, #fffdfd, #fff3f2);
}

.service-check-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.service-check-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.service-check-title strong {
  font-size: 16px;
}

.service-check-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.pill.status-ok {
  background: #daf3e0;
  color: #1d6b33;
}

.pill.status-warning {
  background: #fff0c2;
  color: #8a5b00;
}

.pill.status-error {
  background: #ffe3e3;
  color: #b42318;
}

.pill.status-neutral {
  background: #eef2f7;
  color: #425466;
}

.service-check-main {
  font-weight: 600;
  margin-bottom: 6px;
}

.service-check-detail,
.service-check-limit,
.service-check-action,
.service-check-meta {
  font-size: 13px;
  line-height: 1.5;
  margin-top: 6px;
}

.service-check-detail,
.service-check-limit,
.service-check-action {
  color: #243443;
}

.service-check-meta {
  color: var(--muted);
}

.service-check-limit strong,
.service-check-action strong,
.service-check-meta strong {
  color: var(--ink);
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(560px, 94vw);
  padding: 24px;
}

.auth-divider {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 12px;
  margin: 20px 0 16px;
}

.auth-divider::before,
.auth-divider::after {
  background: var(--line);
  content: "";
  flex: 1;
  height: 1px;
}

.fallback-login {
  background: #f8fbff;
  border: 1px solid #d9e7f5;
  border-radius: 12px;
  margin-bottom: 16px;
  padding: 16px;
}

.auth-label {
  color: var(--ink);
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin: 14px 0 8px;
}

.auth-input {
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  padding: 12px 14px;
  width: 100%;
}

.auth-code-input {
  font-size: 20px;
  letter-spacing: 0.2em;
  text-align: center;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 10px;
}

.auth-button {
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 600;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.auth-button-primary {
  background: #2aabee;
  color: #fff;
}

.auth-button-primary:hover {
  background: #1898d8;
}

.auth-button-secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.auth-button-secondary:hover {
  background: #f5f8fb;
}

.auth-button-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
}

.error { color: var(--danger); }

@media (max-width: 800px) {
  .topbar,
  main,
  .tabs {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* Quick Actions */
.quick-actions {
  gap: 6px;
  flex-wrap: wrap;
}
.quick-actions button {
  font-size: 12px;
  padding: 4px 10px;
  background: #f0f4f8;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.quick-actions button:hover {
  background: #e3eaf0;
}

.results-history {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.results-history-head {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.results-history-head p {
  margin: 4px 0 0;
}

.results-history-wrap {
  max-height: none;
  overflow: auto;
  background: #fff;
}

#verify-history-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  min-width: 860px;
  table-layout: fixed;
  width: 100%;
}

#verify-history-table th,
#verify-history-table td {
  border-bottom: 1px solid #e7eef6;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

#verify-history-table th {
  background: #edf3f8;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
}

#verify-history-table tr:last-child td {
  border-bottom: 0;
}

#verify-history-table th:nth-child(1),
#verify-history-table td:nth-child(1) {
  width: 150px;
}

#verify-history-table th:nth-child(2),
#verify-history-table td:nth-child(2) {
  width: auto;
}

#verify-history-table th:nth-child(3),
#verify-history-table td:nth-child(3) {
  width: 140px;
}

#verify-history-table th:nth-child(4),
#verify-history-table td:nth-child(4) {
  width: 210px;
}

#verify-history-table th:nth-child(5),
#verify-history-table td:nth-child(5) {
  width: 145px;
}

#verify-history-table .history-time {
  white-space: nowrap;
}

#verify-history-table .history-time strong,
#verify-history-table .history-time span {
  display: block;
}

#verify-history-table .history-time span {
  color: var(--muted);
  margin-top: 2px;
}

#verify-history-table .history-check {
  min-width: 0;
}

#verify-history-table .history-check > strong {
  display: block;
  margin-bottom: 6px;
}

.history-entities {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-entity {
  align-items: center;
  color: #405164;
  display: flex;
  gap: 6px;
  line-height: 1.25;
  min-width: 0;
}

.history-entity::before {
  background: #8aa0b7;
  border-radius: 999px;
  content: "";
  flex: 0 0 5px;
  height: 5px;
  margin-top: 1px;
  width: 5px;
}

.history-entity em {
  background: #fff7d6;
  border: 1px solid #f0d88a;
  border-radius: 999px;
  color: #7a5a00;
  font-style: normal;
  padding: 1px 6px;
  white-space: nowrap;
}

.history-status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 6px 9px;
  text-transform: capitalize;
}

.history-status-completed {
  background: #dcfce7;
  color: #166534;
}

.history-status-failed,
.history-status-cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.history-status-running,
.history-status-queued {
  background: #dbeafe;
  color: #1d4ed8;
}

.history-result {
  align-items: flex-start;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.history-metric {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  display: inline-flex;
  flex-direction: column;
  min-width: 62px;
  padding: 6px 8px;
}

.history-metric strong {
  color: #111827;
  font-size: 15px;
  line-height: 1;
}

.history-metric span {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.history-metric-warn {
  background: #fff7ed;
  border-color: #fed7aa;
}

#verify-history-table .history-action-group {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#verify-history-table .history-open,
#verify-history-table .history-delete {
  padding: 6px 12px;
  white-space: nowrap;
}

#verify-history-table .history-delete {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #b42318;
}

#verify-history-table .history-delete:hover:not(:disabled) {
  background: #ffe4e6;
}

#verify-history-table .history-actions {
  text-align: right;
}

/* Settings group (collapsible) */
.settings-group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
}
.settings-group summary {
  cursor: pointer;
  font-weight: 600;
  padding: 4px 0;
}
.settings-group .settings-grid {
  margin-top: 8px;
}

/* Table row coloring */
#verify-table tr td {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Expandable recommendation column ── */
#verify-table tr td:last-child {
  max-width: 400px;
  min-width: 200px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
  cursor: pointer;
}

#verify-table tr td:last-child.collapsed {
  max-width: 400px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#verify-table tr.expanded {
  background: #f0f6ff !important;
}

#verify-table tr.expanded td:last-child {
  max-width: none;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 12px 8px;
  font-size: 13px;
  line-height: 1.5;
}

/* Detail panel under expanded row */
.detail-row td {
  background: #f8fbff;
  padding: 12px 16px !important;
  border-left: 3px solid var(--accent);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap !important;
  word-break: break-word !important;
  max-width: none !important;
}

.logs-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.logs-heading {
  flex: 1 1 320px;
}

.logs-heading h2 {
  margin: 0;
  font-size: 20px;
}

.logs-heading p {
  margin-top: 6px;
}

.logs-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.logs-actions label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.logs-actions input[type="checkbox"] {
  margin: 0;
}

.logs-meta {
  margin-bottom: 10px;
}

.activity-feed {
  flex: 1;
  min-height: calc(100vh - 330px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #f4f8fc 100%);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.activity-empty {
  color: var(--muted);
  border: 1px dashed #cad7e6;
  border-radius: 10px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.85);
}

.activity-entry {
  border: 1px solid #dbe5ef;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.95);
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(21, 34, 50, 0.04);
}

.activity-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.activity-left {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.activity-time {
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 12px;
  color: var(--muted);
}

.activity-kind,
.activity-level {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.activity-kind {
  background: #e7f1fa;
  color: #0f4c81;
}

.activity-level {
  background: #eef2f7;
  color: #425466;
}

.activity-entry.level-warning {
  border-color: #f3d69c;
  background: #fffaf0;
}

.activity-entry.level-warning .activity-level {
  background: #fff0c2;
  color: #8a5b00;
}

.activity-entry.level-error {
  border-color: #f2b8b5;
  background: #fff6f6;
}

.activity-entry.level-error .activity-level {
  background: #ffe3e3;
  color: #b42318;
}

.activity-entry.kind-ai .activity-kind {
  background: #ece8ff;
  color: #5d3ebc;
}

.activity-entry.kind-provider .activity-kind {
  background: #e6f8ee;
  color: #1f7a45;
}

.activity-entry.kind-price .activity-kind {
  background: #fff1e6;
  color: #b3541e;
}

.activity-summary {
  font-weight: 600;
  line-height: 1.5;
}

.activity-detail {
  margin-top: 6px;
  color: #425466;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
