:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f7f8fb;
  color: #172033;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button, input, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button.secondary {
  background: #eef2f7;
  color: #172033;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #e8eef8;
}

.login-panel {
  width: min(380px, calc(100vw - 32px));
  padding: 28px;
  background: white;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  display: grid;
  gap: 14px;
  box-shadow: 0 16px 44px rgba(48, 72, 112, 0.12);
}

.brand-mark {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.login-panel h1, .topbar h1 {
  margin: 0;
}

input, textarea, select {
  border: 1px solid #cbd6e4;
  border-radius: 6px;
  padding: 10px 12px;
  background: white;
}

textarea {
  min-height: 240px;
  resize: vertical;
}

button {
  border: 0;
  border-radius: 6px;
  background: #1d4f91;
  color: white;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

button:disabled {
  background: #9aabc0;
  cursor: not-allowed;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: #16243a;
  color: white;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  padding: 10px;
  margin-bottom: 12px;
}

.nav {
  width: 100%;
  background: transparent;
  color: #dbe7f7;
  justify-content: flex-start;
}

.nav.active, .nav:hover {
  background: #244166;
}

.logout {
  margin-top: auto;
}

.content {
  padding: 24px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar p, .muted {
  color: #66758a;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat, .panel {
  background: white;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
}

.stat {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.stat strong {
  font-size: 28px;
}

.panel {
  padding: 18px;
}

.panel-title {
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.split-title {
  justify-content: space-between;
}

.split-title > span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 18px;
  align-items: start;
}

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

.request-row {
  background: #f4f7fb;
  color: #172033;
  border: 1px solid #dbe3ef;
  justify-content: space-between;
  text-align: left;
}

.request-row.active {
  border-color: #1d4f91;
  background: #e8f1ff;
}

.pagination {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  border-top: 1px solid #dbe3ef;
  padding-top: 12px;
  margin-top: 4px;
}

.status {
  color: white;
  background: #66758a;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.status.delivered {
  background: #168255;
}

.status.ocr_failed, .status.llm_failed, .status.delivery_failed {
  background: #b42318;
}

.status.pending_ocr, .status.pending_llm_delivery {
  background: #a35c00;
}

.meta-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 12px;
  margin-bottom: 16px;
}

.json {
  background: #101828;
  color: #e5edf7;
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
  max-height: 360px;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.error {
  background: #fff0ee;
  color: #9f1d12;
  border: 1px solid #ffc9c2;
  border-radius: 6px;
  padding: 10px;
}

.success {
  background: #eefaf4;
  color: #0b6b43;
  border: 1px solid #b9ebcf;
  border-radius: 6px;
  padding: 10px;
}

.form-message {
  margin: 12px 0;
}

.upload-form, .inline-form, .editor {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.editor {
  align-items: stretch;
  flex-direction: column;
  margin-top: 14px;
}

.field-stack {
  display: grid;
  gap: 6px;
  width: min(720px, 100%);
}

.field-stack span {
  font-weight: 700;
}

.table {
  display: grid;
  gap: 6px;
}

.table-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #dbe3ef;
  background: #f8fafc;
  color: #172033;
  border-radius: 6px;
  text-align: left;
}

.user-table-row {
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 1fr) 90px 90px minmax(130px, 1fr) minmax(220px, auto);
}

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

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

.api-key-preview {
  grid-column: 1 / -1;
  padding: 10px;
  background: #eef2f7;
  border: 1px solid #dbe3ef;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.clickable:hover {
  background: #e8f1ff;
}

.live-item {
  border-top: 1px solid #dbe3ef;
  padding-top: 14px;
  margin-top: 14px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.live-panel {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.socket-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.socket-url {
  display: block;
  min-width: 0;
  max-width: 100%;
  padding: 10px;
  background: #eef2f7;
  border: 1px solid #dbe3ef;
  border-radius: 6px;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.socket-pill {
  border-radius: 999px;
  color: white;
  font-size: 12px;
  padding: 5px 9px;
}

.socket-pill.connected {
  background: #168255;
}

.socket-pill.connecting {
  background: #a35c00;
}

.socket-pill.disconnected, .socket-pill.error {
  background: #b42318;
}

.live-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.live-summary .stat strong {
  font-size: 20px;
  overflow-wrap: anywhere;
}

.live-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
  min-width: 0;
}

.live-heading strong, .live-heading span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-direction: row;
    overflow-x: auto;
  }

  .brand {
    margin: 0;
    white-space: nowrap;
  }

  .nav {
    width: auto;
    white-space: nowrap;
  }

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

  .user-table-row {
    grid-template-columns: 1fr;
  }

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

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