:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --line: #d9d8d0;
  --text: #202124;
  --muted: #666a70;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #1f7a3f;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  align-items: center;
  background: #263238;
  color: #fff;
  display: flex;
  gap: 28px;
  min-height: 56px;
  padding: 0 28px;
}

.brand {
  font-size: 16px;
  font-weight: 700;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.nav a {
  color: #eef4f3;
  font-weight: 600;
}

.container {
  margin: 0 auto;
  max-width: 1320px;
  padding: 28px;
}

.page-head {
  align-items: end;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  margin: 0;
}

h2 {
  font-size: 18px;
  margin: 28px 0 12px;
}

.muted {
  color: var(--muted);
}

.message,
.warning {
  border: 1px solid var(--line);
  margin: 0 0 14px;
  padding: 10px 12px;
}

.message {
  background: #edf8f4;
  border-color: #b9ded3;
}

.warning {
  background: #fff5e7;
  border-color: #efc47e;
}

.toolbar,
.filters {
  align-items: end;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px 0;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 160px;
}

.field.wide {
  min-width: 260px;
}

.field.extra-wide {
  min-width: min(100%, 520px);
}

label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #bfc4c7;
  border-radius: 4px;
  color: var(--text);
  min-height: 34px;
  padding: 6px 8px;
}

textarea {
  font: inherit;
}

button,
.button {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 700;
  justify-content: center;
  min-height: 34px;
  padding: 6px 11px;
  text-decoration: none;
  white-space: nowrap;
}

button.secondary,
.button.secondary {
  background: #fff;
  border-color: #aeb6b8;
  color: var(--text);
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

table {
  background: var(--surface);
  border-collapse: collapse;
  width: 100%;
}

.table-scroll {
  overflow-x: auto;
  width: 100%;
}

.narrow-table {
  max-width: 520px;
}

.analytics-manager-table {
  min-width: 1180px;
}

.manager-name-cell {
  min-width: 190px;
  white-space: nowrap;
}

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

th {
  background: #ecefeb;
  color: #3f4548;
  font-size: 11px;
  text-transform: uppercase;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
}

.status.QUEUED,
.status.NEW {
  background: #e5f0ff;
  color: #174ea6;
}

.status.RUNNING,
.status.DOWNLOADING,
.status.DOWNLOADED,
.status.TRANSCRIBING,
.status.CLASSIFYING,
.status.EVALUATING {
  background: #fff3cd;
  color: var(--warning);
}

.status.WAITING_PROVIDER {
  background: #eef4ff;
  color: #315a9f;
}

.status.DONE,
.status.TRANSCRIBED,
.status.TRANSCRIPTION_DONE,
.status.CLASSIFIED {
  background: #e8f5e9;
  color: var(--ok);
}

.status.FAILED {
  background: #fdecea;
  color: var(--danger);
}

.status.SKIPPED {
  background: #eef1f3;
  color: #3f4548;
}

.status.CONNECTED {
  background: #e8f5e9;
  color: var(--ok);
}

.status.ERROR {
  background: #fdecea;
  color: var(--danger);
}

.status.OK {
  background: #e8f5e9;
  color: var(--ok);
}

.status.NOT_CONNECTED,
.status.NOT_CHECKED {
  background: #eef1f3;
  color: #3f4548;
}

.stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  margin-bottom: 18px;
}

.queue-stage {
  margin-top: 26px;
}

.section-head {
  align-items: end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0 0 4px;
}

.compact-stats {
  margin-top: 6px;
}

.stat {
  background: var(--surface);
  border-top: 3px solid var(--accent);
  padding: 12px;
}

.stat strong {
  display: block;
  font-size: 22px;
}

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

.bulk-actions {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 0;
}

.select-cell {
  text-align: center;
  width: 44px;
}

.select-cell input {
  min-height: auto;
}

.error-cell {
  color: var(--danger);
  max-width: 220px;
  overflow-wrap: anywhere;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 18px;
}

.classification-panel {
  margin-top: 18px;
}

.evaluation-panel {
  margin-top: 18px;
}

.classification-head h2 {
  margin-bottom: 4px;
}

.evaluation-head h2 {
  margin-bottom: 4px;
}

.classification-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.classification-chip {
  background: #edf8f4;
  border: 1px solid #b9ded3;
  border-radius: 999px;
  color: #0b5f59;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  padding: 5px 9px;
}

.classification-confidence {
  font-weight: 700;
  margin-top: 12px;
}

.classification-reason {
  color: #3f4548;
  line-height: 1.5;
  margin: 8px 0 0;
  max-width: 860px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.classification-error {
  color: var(--danger);
  line-height: 1.45;
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.classification-date,
.classification-note {
  margin-top: 10px;
}

.evaluation-note,
.evaluation-date {
  margin-top: 10px;
}

.evaluation-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  margin-top: 16px;
}

.evaluation-text-block {
  margin-top: 16px;
}

.evaluation-text-block h3,
.evaluation-panel h3 {
  font-size: 15px;
  margin: 16px 0 8px;
}

.evaluation-text-block p {
  line-height: 1.5;
  margin: 0;
  max-width: 900px;
}

.evaluation-list {
  display: grid;
  gap: 8px;
  line-height: 1.45;
  margin: 8px 0 0;
  padding-left: 20px;
}

.evaluation-details {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 12px;
}

.evaluation-details summary {
  cursor: pointer;
  font-weight: 700;
}

.nightly-summary {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  margin-top: 16px;
}

.nightly-summary div {
  background: #f6f8f8;
  border-left: 3px solid var(--accent);
  padding: 10px 12px;
}

.nightly-summary span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.nightly-summary strong {
  display: block;
  font-size: 20px;
  margin-top: 2px;
}

.nightly-queues {
  margin-top: 18px;
}

.nightly-dry-run {
  margin-top: 16px;
}

.compact-table {
  font-size: 12px;
}

.calls-table {
  min-width: 1040px;
}

.compact-text {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-cell {
  font-weight: 700;
  white-space: nowrap;
}

.pagination {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin: 14px 0 0;
}

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

.settings-section {
  margin-top: 18px;
}

.prompts-list {
  display: grid;
  gap: 14px;
}

.prompt-panel {
  padding: 0;
}

.prompt-summary {
  cursor: pointer;
  display: grid;
  gap: 5px;
  grid-template-columns: minmax(220px, max-content) minmax(260px, 1fr) auto;
  list-style-position: outside;
  padding: 18px;
}

.prompt-title {
  font-size: 17px;
  font-weight: 700;
}

.prompt-description {
  color: var(--muted);
  line-height: 1.4;
}

.prompt-form {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding: 18px;
}

.prompt-textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-height: 500px;
  resize: vertical;
  white-space: pre-wrap;
  width: 100%;
}

.panel-head {
  align-items: flex-start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.panel-head h2 {
  margin-top: 0;
}

.integration-grid {
  margin-top: 14px;
}

.check-result {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 4px;
}

.check-action {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.monospace {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.probe-table {
  margin-top: 14px;
}

.json-preview {
  background: #f6f8f8;
  border: 1px solid var(--line);
  color: #2e3436;
  font-size: 11px;
  line-height: 1.45;
  max-height: 280px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.department-tree {
  border: 1px solid var(--line);
  margin: 10px 0 14px;
  max-height: 420px;
  overflow: auto;
  padding: 8px;
}

.department-row,
.checkbox-line {
  align-items: center;
  display: flex;
  gap: 8px;
  min-height: 30px;
  text-transform: none;
}

.audited-users {
  background: #fff;
  border: 1px solid var(--line);
  margin: 10px 0 0;
  max-height: 420px;
  overflow: auto;
  padding: 12px 12px 12px 28px;
}

.audited-users li {
  margin-bottom: 6px;
}

.scope-warning {
  margin-top: 14px;
}

.audit-scope-card {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  max-width: 860px;
}

.scope-field {
  display: grid;
  gap: 6px;
}

.scope-select {
  position: relative;
}

.scope-select > summary {
  align-items: center;
  background: #fff;
  border: 1px solid #bfc4c7;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  list-style: none;
  min-height: 40px;
  padding: 7px 10px;
}

.scope-select > summary::-webkit-details-marker,
.employee-details > summary::-webkit-details-marker {
  display: none;
}

.scope-popover {
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 12px 28px rgba(32, 33, 36, 0.16);
  left: 0;
  margin-top: 6px;
  padding: 10px;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 10;
}

.scope-include-children {
  margin-bottom: 8px;
}

.scope-search {
  width: 100%;
}

.compact-tree {
  margin-bottom: 10px;
  max-height: 280px;
}

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

.scope-chips {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.chip {
  background: #eef6f4;
  border: 1px solid #c8e0dc;
  border-radius: 999px;
  color: #24413e;
  display: inline-flex;
  font-size: 13px;
  line-height: 1.2;
  max-width: 220px;
  min-height: 26px;
  overflow: hidden;
  padding: 5px 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted-chip {
  background: #f3f4f4;
  border-color: var(--line);
  color: var(--muted);
}

.audited-preview {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.audited-preview h2 {
  font-size: 16px;
  margin: 0 0 8px;
}

.employee-chips {
  align-items: flex-start;
}

.employee-details {
  display: inline-block;
  position: relative;
}

.employee-details > summary {
  cursor: pointer;
  list-style: none;
}

.employee-panel {
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 12px 28px rgba(32, 33, 36, 0.14);
  margin-top: 8px;
  max-height: 260px;
  min-width: 280px;
  overflow: auto;
  padding: 8px 10px;
  position: absolute;
  right: 0;
  z-index: 9;
}

.employee-row {
  align-items: baseline;
  border-bottom: 1px solid #ecefeb;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 7px 0;
}

.employee-row:last-child {
  border-bottom: 0;
}

.scope-save {
  justify-self: start;
}

.detail-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.detail-item {
  background: var(--surface);
  border-left: 3px solid var(--line);
  padding: 10px 12px;
}

.transcript {
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.55;
  overflow-x: auto;
  padding: 16px;
  white-space: pre-wrap;
}

.inline-form {
  display: inline;
}

/* ── Stats grid with auto-fill (used for wider stat blocks like ai-costs) ── */
.stats-wrap {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

/* ── Settings accordion ── */
.settings-accordion {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.accordion-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.accordion-summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  list-style: none;
  padding: 14px 18px;
  user-select: none;
}

.accordion-summary::-webkit-details-marker {
  display: none;
}

.accordion-item[open] > .accordion-summary {
  border-bottom: 1px solid var(--line);
}

.accordion-summary:hover {
  background: #f9faf9;
}

.accordion-title {
  font-size: 15px;
  font-weight: 700;
}

.accordion-desc {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.accordion-summary-left {
  flex: 1;
  min-width: 0;
}

.accordion-summary-right {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: 10px;
}

.accordion-chevron {
  color: var(--muted);
  display: inline-block;
  font-size: 14px;
  transition: transform 0.15s ease;
}

.accordion-item[open] .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-badge {
  background: #eef1f3;
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
}

.accordion-body {
  padding: 18px;
}

/* ── Diagnostic section (legacy, kept for non-accordion details) ── */
.diagnostic-section > summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 0 4px;
  user-select: none;
}

/* ── Extra filters (collapsible in calls list) ── */
.extra-filters {
  width: 100%;
}

.extra-filters-toggle {
  align-items: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 12px;
  font-weight: 600;
  gap: 5px;
  list-style: none;
  padding: 5px 10px;
  user-select: none;
}

.extra-filters-toggle::-webkit-details-marker {
  display: none;
}

.extra-filters[open] .extra-filters-toggle {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.extra-filters-body {
  align-items: flex-end;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
}

/* ── Checkbox grid for data mirror entity selection ── */
.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 10px;
}

.checkbox-inline {
  align-items: center;
  display: flex;
  gap: 6px;
  text-transform: none;
}

@media (max-width: 780px) {
  body {
    font-size: 14px;
  }

  .topbar,
  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .container {
    padding: 18px;
  }

  .stats,
  .nightly-summary,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .accordion-badge {
    display: none;
  }

  .scope-select > summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .prompt-summary {
    grid-template-columns: 1fr;
  }

  .scope-popover {
    left: 0;
    position: fixed;
    right: 0;
    top: auto;
    bottom: 0;
    margin: 0;
    max-height: 82vh;
    overflow: auto;
  }

  .employee-details {
    position: static;
  }

  .employee-panel {
    left: 0;
    min-width: 0;
    position: absolute;
    right: 0;
  }

  table {
    font-size: 12px;
  }
}
