* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d8dde3;
  --muted: #667085;
  --text: #182230;
  --accent: #1b6b5f;
  --accent-strong: #124d45;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
}

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

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

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

button.secondary,
.icon-btn {
  background: #fff;
  color: var(--accent);
}

button.secondary:hover,
.icon-btn:hover {
  background: #eef7f5;
}

button.danger-link {
  border-color: #fecdca;
  color: var(--danger);
}

button.danger-link:hover {
  background: #fff5f5;
}

a.button-link {
  display: inline-block;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  text-decoration: none;
}

a.button-link:hover {
  background: var(--accent-strong);
}

a.button-link.secondary-link {
  background: #fff;
  color: var(--accent);
}

a.button-link.secondary-link:hover {
  background: #eef7f5;
}

.shell {
  display: grid;
  grid-template-columns: minmax(320px, 34vw) 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 20px;
}

.topbar span,
.muted,
#docMeta,
#saveState,
#settingsSaveState,
#settingsMeta {
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: 1fr 130px auto;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  min-height: 320px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

textarea.notes {
  min-height: 96px;
  font-family: inherit;
}

textarea.config-text {
  min-height: 72px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.record-list {
  height: calc(100vh - 122px);
  overflow: auto;
}

.record-row {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 12px 16px;
  display: block;
}

.record-row:hover,
.record-row.active {
  background: #eef7f5;
}

.record-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 650;
}

.record-meta,
.record-error {
  margin-top: 4px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.detail {
  min-width: 0;
  padding: 20px;
}

.empty {
  color: var(--muted);
  padding: 20px;
}

.hidden {
  display: none;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.detail-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  align-self: flex-start;
  border: 1px solid var(--line);
  padding: 4px 8px;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}

.pill.processed {
  color: var(--ok);
  border-color: #abefc6;
}

.pill.failed {
  color: var(--danger);
  border-color: #fecdca;
}

.pill.queued,
.pill.processing,
.pill.pending {
  color: var(--warn);
  border-color: #fedf89;
}

.tabs {
  display: flex;
  gap: 0;
  margin-top: 12px;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom: 0;
  padding: 9px 14px;
}

.tab.active {
  background: #fff;
  color: var(--text);
}

.tab-panel {
  display: none;
  background: #fff;
  border: 1px solid var(--line);
  border-top: 0;
  padding: 16px;
}

.tab-panel.active {
  display: block;
}

.form-row {
  max-width: 360px;
  margin-bottom: 12px;
}

label {
  display: block;
  color: var(--muted);
  margin: 0 0 6px;
}

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

.events {
  display: grid;
  gap: 10px;
}

.document-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.document-frame {
  width: 100%;
  height: min(72vh, 860px);
  border: 1px solid var(--line);
  background: #fff;
}

.document-image {
  display: block;
  max-width: 100%;
  max-height: 76vh;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #fff;
}

.event-row {
  border: 1px solid var(--line);
  padding: 10px;
}

.event-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 650;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-box {
  width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--line);
  background: #fff;
  padding: 20px;
}

.login-box h1 {
  margin-bottom: 18px;
}

.login-box button {
  width: 100%;
  margin-top: 12px;
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 28, 0.42);
}

.modal-panel {
  position: relative;
  width: min(820px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  margin: 16px auto;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(12, 18, 28, 0.18);
  padding: 16px;
}

.modal-panel.wide {
  width: min(1180px, calc(100vw - 32px));
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

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

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings-grid label:first-child {
  grid-column: 1 / -1;
}

.modal-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.usage-range-tools {
  grid-template-columns: minmax(150px, 220px) minmax(150px, 220px) auto;
  align-items: end;
}

.usage-range-tools label {
  margin: 0;
}

.kv-grid {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  border: 1px solid var(--line);
  margin-bottom: 16px;
}

.kv-key,
.kv-value {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

.kv-key {
  color: var(--muted);
  background: #f8fafc;
}

.kv-value {
  overflow-wrap: anywhere;
}

.kv-key:nth-last-child(2),
.kv-value:last-child {
  border-bottom: 0;
}

h3 {
  margin: 16px 0 8px;
  font-size: 15px;
}

.chat-row {
  border: 1px solid var(--line);
  padding: 10px;
  margin-bottom: 10px;
  background: #fff;
}

.chat-row.outbound {
  border-left: 4px solid var(--accent);
}

.chat-row.inbound {
  border-left: 4px solid #98a2b3;
}

.chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  margin-bottom: 6px;
}

.chat-meta strong {
  color: var(--text);
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.status-strip.online {
  color: var(--ok);
  border-color: #abefc6;
}

.status-strip.running {
  color: var(--warn);
  border-color: #fedf89;
}

.status-strip.offline {
  color: var(--danger);
  border-color: #fecdca;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.usage-summary,
.posting-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.posting-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.usage-summary > div,
.posting-summary > div {
  border: 1px solid var(--line);
  padding: 10px;
}

.usage-summary strong,
.posting-summary strong {
  display: block;
  font-size: 20px;
}

.usage-summary span,
.posting-summary span {
  color: var(--muted);
}

.kv-grid.compact {
  margin-bottom: 12px;
}

.post-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  padding: 9px 10px;
  margin-bottom: 12px;
  background: #fff;
}

.post-page-info {
  color: var(--muted);
}

.post-page-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.post-page-controls select {
  width: auto;
  min-width: 110px;
}

.post-workspace {
  display: grid;
  gap: 12px;
}

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

.post-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

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

.post-table th {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 650;
}

.post-table-row {
  cursor: pointer;
}

.post-table-row:hover,
.post-table-row.selected {
  background: #eef7f5;
}

.post-status {
  display: inline-block;
  border: 1px solid var(--line);
  padding: 2px 6px;
  font-size: 12px;
  text-transform: uppercase;
}

.post-status.success {
  color: var(--ok);
  border-color: #abefc6;
}

.post-status.failed {
  color: var(--danger);
  border-color: #fecdca;
}

.post-status.pending {
  color: var(--warn);
  border-color: #fedf89;
}

.post-raw-panel {
  border: 1px solid var(--line);
}

.post-raw-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.post-raw-head span {
  color: var(--muted);
  text-align: right;
}

.post-raw-json {
  max-height: 46vh;
  overflow: auto;
  padding: 10px;
}

.usage-table {
  display: grid;
  grid-template-columns: 140px repeat(5, minmax(90px, 1fr));
  border: 1px solid var(--line);
  overflow-x: auto;
}

.usage-table > div {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.usage-head {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 650;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .record-list {
    height: 38vh;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .document-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .modal-tools,
  .kv-grid {
    grid-template-columns: 1fr;
  }

  .usage-summary,
  .posting-summary {
    grid-template-columns: 1fr;
  }

  .usage-table {
    grid-template-columns: repeat(6, minmax(110px, 1fr));
  }

  .post-raw-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .post-raw-head span {
    text-align: left;
  }

  .post-pagination {
    display: grid;
    grid-template-columns: 1fr;
  }

  .post-page-controls {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}
