:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #667085;
  --accent: #2456d6;
  --good: #137a4b;
  --good-bg: #e3f5ec;
  --bad: #b3261e;
  --bad-bg: #fde8e6;
  --pending: #8a5a00;
  --pending-bg: #fdf1d7;
  --code-bg: #f1f3f6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --surface: #1a1f27;
    --border: #2c3440;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --accent: #7aa2ff;
    --good: #5fd39a;
    --good-bg: #153527;
    --bad: #ff8f87;
    --bad-bg: #41201d;
    --pending: #f2c260;
    --pending-bg: #3a2e12;
    --code-bg: #10141a;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.45 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
}

a {
  color: var(--accent);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
}

h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}

h4 {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}

/* ---------------------------------------------------------------- top bar */

.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
  flex-wrap: wrap;
}

.top nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.top nav a {
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}

.top nav a.current {
  background: var(--accent);
  color: #fff;
}

.spacer {
  flex: 1;
}

main {
  padding: 18px;
  max-width: 1500px;
}

/* ---------------------------------------------------------------- controls */

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

input,
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

button {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}

button.quiet {
  background: transparent;
  color: var(--accent);
  border-color: var(--border);
}

button.danger {
  background: var(--bad);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
}

label.toggle {
  flex-direction: row;
  align-items: center;
  font-size: 14px;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.toolbar input[type='search'] {
  min-width: 300px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin: 8px 0;
}

.inline-form .wide {
  flex: 1;
  min-width: 200px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 640px;
  align-items: flex-start;
}

.stack label,
.stack input {
  width: 100%;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 8px 0;
}

td .actions {
  margin: 0;
  flex-wrap: nowrap;
  gap: 4px;
}

td button {
  padding: 2px 8px;
}

.popover {
  position: relative;
}

.popover > summary {
  cursor: pointer;
  color: var(--accent);
  list-style: none;
}

.popover[open] > form {
  position: absolute;
  right: 0;
  top: 28px;
  z-index: 3;
  width: 520px;
  max-width: 90vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}

/* ---------------------------------------------------------------- tables */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover {
  background: var(--code-bg);
}

.nowrap {
  white-space: nowrap;
}

.clip {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.empty {
  color: var(--muted);
  padding: 24px 0;
}

.results {
  overflow-x: auto;
}

.results > button {
  margin-top: 12px;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.good {
  color: var(--good);
  background: var(--good-bg);
}

.badge.bad {
  color: var(--bad);
  background: var(--bad-bg);
}

.badge.pending {
  color: var(--pending);
  background: var(--pending-bg);
}

.problem {
  color: var(--bad);
}

.notice {
  background: var(--pending-bg);
  color: var(--pending);
  padding: 10px 14px;
  border-radius: 8px;
}

/* ---------------------------------------------------------------- overview */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  color: inherit;
  text-decoration: none;
}

.card .total {
  font-size: 28px;
  font-weight: 600;
  margin: 2px 0 8px;
}

.card ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 70px;
}

.bar {
  flex: 1;
  background: var(--accent);
  min-height: 1px;
  border-radius: 1px 1px 0 0;
}

/* ---------------------------------------------------------------- detail panel */

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(760px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgb(0 0 0 / 0.18);
  z-index: 5;
  display: flex;
  flex-direction: column;
}

.panel > header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel > header h2 {
  flex: 1;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-body {
  padding: 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.fields {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0;
}

.fields dt {
  color: var(--muted);
}

.fields dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.message,
.code {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 10px;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code {
  font:
    12px/1.5 ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
  max-height: 420px;
  overflow: auto;
}

.history,
.callbacks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history li {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
}

.history .at {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.callbacks summary {
  cursor: pointer;
  overflow-wrap: anywhere;
}

kbd {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font: inherit;
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.email-body iframe,
.fax-file iframe {
  width: 100%;
  height: 520px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

/* ---------------------------------------------------------------- settings and sign-in */

.settings {
  display: flex;
  flex-direction: column;
  gap: 26px;
  max-width: 900px;
}

.editor {
  width: 100%;
  font:
    12px/1.5 ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
}

.sign-in {
  max-width: 320px;
  margin: 12vh auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
