:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-soft: #eef5f2;
  --line: #d9e3de;
  --text: #17211d;
  --muted: #697872;
  --green: #147a5b;
  --green-soft: #e4f5ee;
  --blue: #2f6db5;
  --blue-soft: #e6f0fb;
  --amber: #a36a0a;
  --amber-soft: #fff4d6;
  --red: #b84b40;
  --red-soft: #fdecea;
  --shadow: 0 18px 48px rgba(25, 42, 36, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  background: #12231d;
  color: #eaf5ef;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.brand-mark,
.source-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #0b1813;
  color: #91f0c9;
  font-weight: 800;
}

.brand small,
.sidebar-note span {
  display: block;
  color: #abc3b7;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  color: #d8e8df;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 800;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  line-height: 1.4;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  font-size: 18px;
  margin-bottom: 6px;
}

.top-actions,
.button-row,
.form-row,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-weight: 700;
}

.button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
}

.button.secondary {
  background: var(--surface-soft);
}

.button.danger {
  background: var(--red-soft);
  border-color: #efc3be;
  color: var(--red);
}

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

.app-notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--blue-soft);
  color: #234f7e;
  font-weight: 700;
}

.app-notice.success {
  background: var(--green-soft);
  color: var(--green);
}

.app-notice.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.app-notice.danger {
  background: var(--red-soft);
  color: var(--red);
}

.app-notice[hidden] {
  display: none;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.status-card,
.queue-card,
.api-card,
.source-card,
.queue-table-card,
.detail-panel,
.record-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-card {
  padding: 14px;
}

.status-card small {
  color: var(--muted);
}

.status-card strong {
  display: block;
  margin: 7px 0 3px;
  font-size: 26px;
}

.status-card span {
  color: var(--muted);
  font-size: 13px;
}

.status-card.warning {
  border-left: 5px solid var(--amber);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.segmented button {
  border: 0;
  background: transparent;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 700;
}

.segmented button.is-active {
  color: var(--green);
  background: var(--green-soft);
}

.search-box,
.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-box input,
.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
}

.field textarea {
  resize: vertical;
  min-height: 160px;
}

.field.compact {
  min-width: 160px;
}

.records-layout {
  display: grid;
  grid-template-columns: minmax(280px, 430px) minmax(0, 1fr);
  gap: 14px;
}

.record-list {
  min-height: 520px;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.record-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  display: grid;
  gap: 5px;
  text-align: left;
}

.record-card:hover,
.record-card.is-active {
  border-color: var(--green);
  background: #fbfffd;
}

.record-source,
.pill {
  width: fit-content;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--blue-soft);
  color: #24558f;
  font-size: 12px;
  font-weight: 800;
}

.record-meta,
.muted,
.empty-state span,
.detail-meta {
  color: var(--muted);
}

.record-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.detail-panel {
  min-height: 520px;
  padding: 18px;
  overflow: auto;
}

.empty-state {
  min-height: 480px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 8px;
  align-content: center;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.detail-title {
  margin-bottom: 3px;
  font-size: 24px;
}

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

.field-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.field-box small {
  display: block;
  color: var(--muted);
  margin-bottom: 5px;
}

.link-list,
.prospect-list,
.queue-list,
.rule-list,
.step-list,
.check-list {
  display: grid;
  gap: 8px;
}

.link-list a,
.prospect-row,
.queue-row,
.rule-list span,
.step-list span,
.check-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdfc;
}

.link-list a {
  color: var(--blue);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.prospect-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.prospect-row small {
  display: block;
  color: var(--muted);
}

.queue-layout,
.api-layout,
.source-grid,
.browser-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.source-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.queue-card,
.api-card,
.source-card,
.queue-table-card,
.browser-card {
  padding: 16px;
}

.browser-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.browser-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.browser-toolbar input {
  min-width: min(100%, 320px);
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
}

.browser-live-state {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--blue-soft);
  color: #234f7e;
}

.browser-live-state strong,
.browser-live-state span {
  overflow-wrap: anywhere;
}

.browser-live-state.ok {
  background: var(--green-soft);
  color: var(--green);
}

.browser-live-state.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.browser-live-state.danger {
  background: var(--red-soft);
  color: var(--red);
}

.remote-browser-frame {
  width: 100%;
  aspect-ratio: 1366 / 820;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #101915;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  position: relative;
}

.remote-browser-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  grid-area: 1 / 1;
}

.browser-frame-empty {
  grid-area: 1 / 1;
  align-self: center;
  justify-self: center;
  max-width: 420px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(18, 35, 29, 0.92);
  color: #eaf5ef;
  text-align: center;
  font-weight: 700;
  z-index: 2;
}

.remote-browser-frame.has-image .browser-frame-empty {
  display: none;
}

.remote-browser-frame.is-loading::after {
  content: "Loading hosted browser view...";
  position: absolute;
  right: 12px;
  bottom: 12px;
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.browser-status-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.browser-status-list span,
.transfer-grid span {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdfc;
}

.browser-status-list strong,
.transfer-grid strong {
  overflow-wrap: anywhere;
}

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

.section-title,
.source-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.source-head {
  justify-content: flex-start;
}

.queue-table-card .toolbar {
  margin-bottom: 12px;
}

.queue-row {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr) 160px;
  align-items: center;
  gap: 12px;
}

.queue-row a {
  color: var(--blue);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.status-pill {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.status-pending {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-running {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-done {
  background: var(--green-soft);
  color: var(--green);
}

.status-failed {
  background: var(--red-soft);
  color: var(--red);
}

.endpoint-box {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
  background: #fbfdfc;
}

code,
pre {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

pre {
  white-space: pre-wrap;
  margin: 0;
  color: var(--muted);
}

.check-list {
  padding-left: 0;
  list-style: none;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .status-grid,
  .records-layout,
  .queue-layout,
  .api-layout,
  .source-grid,
  .browser-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .detail-header,
  .queue-row {
    grid-template-columns: 1fr;
    display: grid;
  }

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

  .browser-toolbar input {
    min-width: 0;
  }

  .button,
  .icon-button {
    min-width: 38px;
  }
}
