:root {
  --bg: #f5f7f7;
  --surface: #ffffff;
  --line: #d8e0de;
  --line-strong: #b8c6c3;
  --text: #202725;
  --muted: #66736f;
  --primary: #11695f;
  --primary-dark: #0c4f49;
  --primary-soft: #e0f2ef;
  --blue: #2563eb;
  --cyan: #0891b2;
  --green: #16803c;
  --orange: #b45309;
  --red: #b42318;
  --red-soft: #fee4e2;
  --shadow: 0 12px 32px rgba(29, 41, 57, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

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

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  padding-bottom: 16px;
  margin-bottom: 4px;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.login-panel input {
  width: 100%;
}

.login-error {
  padding: 9px 10px;
  border: 1px solid var(--red-soft);
  border-radius: 8px;
  background: #fff8f7;
  color: var(--red);
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 20px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.drawer h3 {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 20px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

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

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

.topbar h2 {
  font-size: 22px;
  line-height: 1.3;
}

.topbar-actions,
.toolbar,
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn,
.icon-button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}

.btn:hover,
.icon-button:hover {
  border-color: var(--primary);
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.danger {
  border-color: var(--red);
  color: var(--red);
}

.btn.danger:hover {
  background: var(--red-soft);
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  text-align: left;
  cursor: pointer;
}

.metric-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.metric-card strong {
  display: block;
  font-size: 30px;
  margin: 8px 0;
}

.metric-card.danger strong {
  color: var(--red);
}

.metric-label,
.metric-hint,
.summary-line {
  color: var(--muted);
}

.overview-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr);
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 {
  font-size: 15px;
}

.definition-list {
  margin: 0;
  padding: 12px 16px 16px;
}

.definition-list div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #edf1f0;
}

.definition-list div:last-child {
  border-bottom: 0;
}

.definition-list dt {
  color: var(--muted);
}

.definition-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.empty-state {
  padding: 18px 16px;
  color: var(--muted);
}

.toolbar {
  flex-wrap: wrap;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar .grow {
  flex: 1 1 220px;
}

input,
select {
  min-height: 36px;
  min-width: 150px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 10px;
  background: #fff;
  color: var(--text);
}

.grow input {
  width: 100%;
}

.table-panel {
  overflow: hidden;
}

.summary-line {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  border-bottom: 1px solid #edf1f0;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: #f9fbfb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

td.wrap {
  white-space: normal;
  min-width: 220px;
  max-width: 360px;
  overflow-wrap: anywhere;
}

.pager {
  justify-content: flex-end;
  padding: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  background: #eef4ff;
  color: var(--blue);
}

.status-pill.muted {
  background: #f2f4f3;
  color: var(--muted);
}

.status-pill.PROCESSING {
  background: #e0f7fb;
  color: var(--cyan);
}

.status-pill.RETRY {
  background: #fff4e5;
  color: var(--orange);
}

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

.status-pill.SUCCESS,
.status-pill.DONE {
  background: #e7f6ec;
  color: var(--green);
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(760px, 96vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 160ms ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  min-height: 72px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.drawer-body {
  overflow: auto;
  padding: 14px 16px 24px;
}

.detail-section {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.detail-section h4 {
  margin: 0;
  padding: 12px;
  background: #f9fbfb;
  border-bottom: 1px solid var(--line);
}

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

.detail-item {
  padding: 10px 12px;
  border-bottom: 1px solid #edf1f0;
  min-width: 0;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.detail-item strong {
  display: block;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.call-log {
  border-bottom: 1px solid var(--line);
}

.call-log:last-child {
  border-bottom: 0;
}

.call-log-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #fbfcfc;
}

.call-log-header strong,
.call-log-header span {
  display: block;
}

.call-log-header span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.payload-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
}

.payload-grid h5 {
  margin: 0 0 6px;
  font-size: 13px;
}

pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #111b18;
  color: #d8f3ec;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.28);
  z-index: 10;
}

.hidden {
  display: none;
}

.alert {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--red-soft);
  border-radius: 8px;
  background: #fff8f7;
  color: var(--red);
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .nav-item {
    text-align: center;
  }

  .metric-grid,
  .overview-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px 12px 24px;
  }

  .topbar,
  .topbar-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .overview-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  input,
  select {
    min-width: 0;
    width: 100%;
  }
}
