:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d8dee9;
  --text: #18202f;
  --muted: #687386;
  --accent: #1769aa;
  --accent-strong: #0f4f82;
  --danger: #a52121;
  --success: #187046;
  --warning: #9a6400;
  --shadow: 0 8px 24px rgba(24, 32, 47, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 0 12px;
  cursor: pointer;
}

button.secondary {
  background: white;
  color: var(--accent);
}

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

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 0 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: white;
}

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

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

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

.top-actions a {
  color: var(--accent);
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
}

.auth-panel {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 84px);
  padding: 18px;
}

.auth-form {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 20px;
  box-shadow: var(--shadow);
}

.auth-form h2 {
  margin: 0;
  font-size: 18px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-title h2 {
  margin: 0;
  font-size: 16px;
}

.tenant-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  align-items: end;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

td.actions {
  white-space: nowrap;
}

td.actions button {
  margin-right: 6px;
  margin-bottom: 6px;
}

.jobs {
  display: grid;
  gap: 8px;
  padding: 12px 16px;
}

.job {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(120px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #edf2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.status.succeeded {
  background: #e5f6ee;
  color: var(--success);
}

.status.failed {
  background: #fae7e7;
  color: var(--danger);
}

.status.completed_with_errors {
  background: #fff3d6;
  color: var(--warning);
}

.status.running {
  background: #fff3d6;
  color: var(--warning);
}

.status.compliant {
  background: #e5f6ee;
  color: var(--success);
}

.status.needs_review {
  background: #fff3d6;
  color: var(--warning);
}

.status.non_compliant {
  background: #fae7e7;
  color: var(--danger);
}

.note-filter {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 150px 150px auto;
  gap: 10px;
  align-items: center;
}

.notes-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.8fr) minmax(360px, 1.2fr);
  min-height: 420px;
}

.note-detail {
  min-width: 0;
  border-left: 1px solid var(--line);
  padding: 16px;
}

.demo-output {
  border-left: 0;
  min-height: 420px;
}

.note-detail h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.note-detail pre {
  overflow: auto;
  max-height: 520px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.analysis-card {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.analysis-head {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.analysis-head p,
.criterion p {
  margin: 4px 0 0;
  color: var(--muted);
}

.review-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.review-metric {
  display: grid;
  gap: 3px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  padding: 9px 10px;
}

.review-metric span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.review-metric strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.review-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.score {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
}

.score.compliant {
  border-color: #98d8b8;
  color: var(--success);
}

.score.needs_review {
  border-color: #f0c36a;
  color: var(--warning);
}

.score.non_compliant {
  border-color: #efb3b3;
  color: var(--danger);
}

.analysis-section h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

.analysis-section ul {
  margin: 0;
  padding-left: 18px;
}

.analysis-section li {
  margin: 4px 0;
}

.raw-note {
  margin-top: 10px;
}

.raw-note summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
}

.raw-note pre {
  margin-top: 10px;
}

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

.criterion {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 10px;
}

.criterion span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.criterion span.pass {
  color: var(--success);
}

.criterion span.fail {
  color: var(--danger);
}

.note-row {
  cursor: pointer;
}

.note-row:hover {
  background: #f2f7fc;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--text);
  color: white;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .topbar,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .tenant-form,
  .note-filter,
  .notes-grid {
    grid-template-columns: 1fr;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .note-detail {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .review-metrics {
    grid-template-columns: 1fr;
  }
}
