:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f2;
  color: #17201c;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --surface: #ffffff;
  --surface-muted: #f8faf6;
  --border: #d9dfd7;
  --text-muted: #66716a;
  --text-soft: #89938a;
  --green: #18794e;
  --green-bg: #e8f6ef;
  --red: #bf2f35;
  --red-bg: #fdebec;
  --yellow: #9b6b00;
  --yellow-bg: #fff4cf;
  --blue: #1f68b3;
  --blue-bg: #e9f2ff;
  --shadow: 0 14px 45px rgba(31, 42, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(244, 246, 242, 0.96)),
    #f4f6f2;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.brand-block,
.top-actions,
.status-line,
.metric,
.filter-title,
.receipt-header span,
.search-field span {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #17201c;
  color: #f7fff8;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.status-line {
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.status-line code {
  color: #3b453f;
  background: #eef2ed;
  border: 1px solid #dce3da;
  border-radius: 6px;
  padding: 2px 6px;
  word-break: break-all;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-soft);
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(24, 121, 78, 0.12);
}

.status-dot.reconnecting,
.status-dot.connecting {
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(155, 107, 0, 0.14);
}

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

.metric,
.primary-button,
.secondary-button,
.icon-button {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.metric {
  gap: 7px;
  padding: 0 10px;
  color: var(--text-muted);
  background: var(--surface-muted);
  font-size: 12px;
}

.metric strong {
  color: #17201c;
  font-size: 13px;
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  color: #17201c;
  background: #ffffff;
}

.primary-button {
  color: #ffffff;
  border-color: #17201c;
  background: #17201c;
}

.unread-badge {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  color: #17201c;
  background: #fff3bc;
  font-size: 11px;
  font-weight: 700;
}

.connection-strip {
  padding: 10px 20px 0;
}

.connection-form {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto;
  align-items: center;
  gap: 8px;
  max-width: 860px;
}

.connection-form label,
.filter-bar label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.connection-form input,
.filter-bar input,
.filter-bar select {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  color: #17201c;
  background: #ffffff;
  outline: none;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 430px);
  gap: 16px;
  padding: 16px 20px 20px;
}

.feed-panel,
.receipt-panel {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.feed-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: #fbfcfa;
}

.filter-title {
  align-self: center;
  gap: 6px;
  min-height: 34px;
  color: #28342d;
  font-size: 13px;
  font-weight: 800;
}

.filter-bar label {
  flex: 1 1 142px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.search-field span {
  gap: 7px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
}

.search-field input {
  border: 0;
  padding: 0;
  height: 30px;
}

.search-field {
  flex: 2 1 260px;
}

.icon-button {
  width: 34px;
  padding: 0;
  flex: 0 0 34px;
}

.feed-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 14px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}

.paused-chip {
  color: var(--yellow);
  background: var(--yellow-bg);
  border: 1px solid #f0d985;
  border-radius: 999px;
  padding: 3px 8px;
}

.latency-panel {
  margin: 12px 14px;
  border: 1px solid #123238;
  border-radius: 8px;
  padding: 14px;
  color: #d7efe3;
  background: #071014;
}

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

.latency-panel-header span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #8ecfc2;
  font-size: 12px;
  font-weight: 800;
}

.latency-panel-header h2 {
  margin-top: 4px;
  color: #ecfff8;
  font-size: 16px;
  line-height: 1.2;
}

.latency-panel-header strong {
  flex: 0 0 auto;
  border: 1px solid #1b454a;
  border-radius: 999px;
  padding: 5px 9px;
  color: #b9f4e4;
  background: rgba(17, 74, 78, 0.62);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.latency-empty {
  display: grid;
  place-items: center;
  min-height: 112px;
  border: 1px dashed #1d444a;
  border-radius: 8px;
  color: #7da59f;
  background: rgba(7, 16, 20, 0.64);
  font-size: 13px;
  font-weight: 700;
}

.latency-bars {
  display: grid;
  gap: 9px;
}

.latency-row {
  display: grid;
  grid-template-columns: 64px minmax(80px, 1fr) 44px;
  align-items: center;
  gap: 10px;
}

.latency-label,
.latency-row strong {
  color: #b9cfc9;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.latency-row strong {
  justify-self: end;
  color: #e7fff7;
}

.latency-track {
  height: 12px;
  overflow: hidden;
  border: 1px solid #123238;
  border-radius: 999px;
  background: #0b1d22;
}

.latency-bar {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #14b8a6, #7dd3fc);
  box-shadow: 0 0 18px rgba(20, 184, 166, 0.25);
}

.list-frame {
  flex: 1;
  min-height: 390px;
}

.event-row-shell {
  padding: 4px 10px;
}

.event-row {
  width: 100%;
  height: 70px;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 154px 72px;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
  border-left-width: 4px;
  border-radius: 8px;
  padding: 0 12px 0 10px;
  background: #ffffff;
  color: #17201c;
  text-align: left;
}

.event-row:hover,
.event-row.selected {
  border-color: #cbd5cc;
  background: #f9fbf8;
}

.event-row.selected {
  box-shadow: inset 0 0 0 1px #9cb6a3;
}

.event-time {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 800;
}

.event-main {
  min-width: 0;
}

.event-route {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #26312b;
  font-size: 13px;
}

.event-route strong,
.event-route span,
.event-reason {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-route span {
  color: var(--text-muted);
}

.event-reason {
  display: block;
  margin-top: 5px;
  color: #4d5a52;
  font-size: 12px;
}

.decision-pill,
.latency-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.latency-pill {
  color: #4c584f;
  background: #eef2ed;
}

.decision-allow {
  border-left-color: var(--green);
}

.decision-deny {
  border-left-color: var(--red);
}

.decision-revise {
  border-left-color: var(--blue);
}

.decision-require-approval {
  border-left-color: var(--yellow);
}

.decision-allow .decision-pill,
.decision-pill.decision-allow {
  color: var(--green);
  background: var(--green-bg);
}

.decision-deny .decision-pill,
.decision-pill.decision-deny {
  color: var(--red);
  background: var(--red-bg);
}

.decision-revise .decision-pill,
.decision-pill.decision-revise {
  color: var(--blue);
  background: var(--blue-bg);
}

.decision-require-approval .decision-pill,
.decision-pill.decision-require-approval {
  color: var(--yellow);
  background: var(--yellow-bg);
}

.receipt-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.receipt-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: #fbfcfa;
}

.receipt-header span {
  gap: 7px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.receipt-header h2 {
  margin-top: 5px;
  max-width: 260px;
  overflow-wrap: anywhere;
  color: #17201c;
  font-size: 16px;
  line-height: 1.25;
}

.receipt-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.receipt-facts div {
  min-width: 0;
}

.receipt-facts dt {
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.receipt-facts dd {
  margin: 4px 0 0;
  overflow: hidden;
  color: #2e3831;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-json {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: #d7efe3;
  background: #17201c;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 240px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

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

  .receipt-panel {
    min-height: 540px;
  }

  .filter-title {
    width: 100%;
  }
}

@media (max-width: 780px) {
  .topbar,
  .connection-form {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .brand-block,
  .top-actions {
    width: 100%;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .workspace {
    padding: 12px;
  }

  .connection-strip {
    padding: 10px 12px 0;
  }

  .filter-bar label,
  .search-field {
    flex-basis: 100%;
  }

  .event-row {
    grid-template-columns: 70px minmax(0, 1fr);
    height: 104px;
    align-content: center;
  }

  .decision-pill,
  .latency-pill {
    justify-self: start;
  }

  .receipt-facts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .latency-panel {
    margin: 10px;
    padding: 12px;
  }

  .latency-panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .latency-panel-header strong {
    align-self: flex-start;
  }

  .latency-row {
    grid-template-columns: 58px minmax(0, 1fr) 38px;
    gap: 8px;
  }
}
