:root {
  /* Power BI default palette, used by meaning: blue for volume, green for a
     good outcome, orange for a miss. The number itself stays near-black. */
  --bg: #f3f2f1;
  --panel: #ffffff;
  --text: #252423;
  --muted: #605e5c;
  --line: #edebe9;
  --blue: #118dff;
  --navy: #12239e;
  --green: #1aab40;
  --orange: #e66c37;
  --gold: #d9b300;
  --radius: 4px;
}

* {
  box-sizing: border-box;
}

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

.topbar,
.state-panel,
main {
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 28px 12px;
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

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

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

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

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

.state-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  margin-bottom: 4px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border-left: 3px solid var(--blue);
  background: #eff6fc;
  color: var(--navy);
  font-size: 13px;
}

.state-panel[hidden] {
  display: none;
}

.state-panel.error {
  border-left-color: #a4262c;
  background: #fde7e9;
  color: #a4262c;
}

.state-panel.warn {
  border-left-color: var(--gold);
  background: #fff8e6;
  color: #8a6d00;
}

.state-panel button {
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  padding: 4px 12px;
  cursor: pointer;
  font: inherit;
}

main {
  padding: 12px 28px 40px;
}

section {
  margin-top: 20px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.segmented button.active {
  background: var(--navy);
  color: #fff;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, 248px);
  gap: 12px;
}

.card {
  width: 248px;
  height: 96px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--blue);
  border-radius: var(--radius);
  padding: 10px 14px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.card.selected {
  box-shadow: 0 0 0 2px var(--navy);
}

.card.tone-volume {
  border-top-color: var(--blue);
}

.card.tone-attempt {
  border-top-color: var(--navy);
}

.card.tone-success {
  border-top-color: var(--green);
}

.card.tone-measure {
  border-top-color: var(--gold);
}

.card .label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.card .value {
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.card .note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
}

.bars {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  max-width: 720px;
}

.bar-row {
  display: grid;
  grid-template-columns: 240px 1fr 48px;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.bar-track {
  background: #eef1f5;
  border-radius: 6px;
  height: 14px;
  overflow: hidden;
}

.bar-fill {
  background: var(--orange);
  height: 100%;
  border-radius: 6px;
}

.bar-fill.compose {
  background: var(--blue);
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

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

input[type="search"],
select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 13px;
  min-width: 220px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  background: #f3f2f1;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:nth-child(even) {
  background: #faf9f8;
}

tbody tr:hover {
  background: #eff6fc;
}

.row-open {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--navy);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.row-open:focus-visible,
.card:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef1f5;
  color: var(--muted);
}

.status.connected {
  background: #dff6dd;
  color: #0b6a0b;
}

.status.failed {
  background: #fde7e9;
  color: #a4262c;
}

.empty {
  padding: 20px;
  color: var(--muted);
  text-align: center;
  margin: 0;
}

dialog {
  border: 0;
  border-radius: 12px;
  padding: 0;
  width: min(920px, 96vw);
  max-height: 90vh;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
}

#detail-close {
  border: 0;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
}

#detail-body {
  padding: 16px 18px 20px;
  max-height: calc(90vh - 58px);
  overflow: auto;
}

.status.pending {
  background: #fff4ce;
  color: #8a6d00;
}

.inspector-phone {
  font-size: 22px;
  font-weight: 600;
}

.summary-banner {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  border-left: 3px solid var(--gold);
  background: #fff8e6;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.metric {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.metric-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.section-head h2 {
  margin-bottom: 8px;
}

audio {
  width: 100%;
}

.answers {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.answers p {
  margin: 8px 0;
}

.answers span {
  display: inline-block;
  min-width: 220px;
  color: var(--navy);
  font-weight: 600;
}

.answers em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.route-lead,
.route-buyer {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.route-lead {
  padding: 12px;
}

.route-lead header {
  display: flex;
  gap: 10px;
}

.route-index {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex: none;
}

.route-buyer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
  padding: 10px 12px;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
  font-size: 12px;
}

.checks .ok { color: #0b6a0b; }
.checks .no { color: #a4262c; }

.route-result {
  color: #8a6d00;
  font-weight: 600;
  text-align: right;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  display: grid;
  grid-template-columns: 64px 12px 1fr;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}

.timeline li i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8a8886;
}

.timeline li span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.timeline .dial i { background: var(--gold); }
.timeline .good i { background: var(--green); }
.timeline .bad i { background: #a4262c; }

@media (max-width: 720px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .route-buyer { flex-direction: column; }
  .route-result { text-align: left; }
}

dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 6px 12px;
  margin: 0 0 16px;
}

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

dd {
  margin: 0;
}
.account {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.account[hidden] {
  display: none;
}

.account button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
}

.login-card {
  max-width: 400px;
  margin-top: 12vh;
  padding: 28px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.login-card .state-panel {
  margin: 16px 0 0;
}

.login-button {
  display: inline-block;
  margin-top: 20px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}
