:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f6;
  --text: #172033;
  --muted: #637083;
  --border: #d7dee7;
  --primary: #1f7a8c;
  --success: #16815a;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 34px;
  padding: 0 11px;
  color: #fff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 7px;
  cursor: pointer;
}

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

button.danger {
  color: var(--danger);
  background: #fff;
  border-color: rgb(180 35 24 / 38%);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

input,
select {
  height: 34px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
}

.admin-shell {
  width: min(1440px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.topbar,
.panel,
.detail-panel,
.notice-panel,
.login-gate-panel,
.metrics-grid article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 18px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 1.55rem;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.auth-box {
  display: grid;
  gap: 10px;
  width: min(100%, 620px);
}

.session-box {
  display: grid;
  gap: 10px;
  width: min(100%, 620px);
}

.auth-box label,
.login-grid label,
.token-row label {
  color: var(--muted);
  font-size: 0.86rem;
}

.login-grid,
.token-row {
  display: grid;
  gap: 8px;
  align-items: center;
}

.login-grid {
  grid-template-columns: auto 130px auto 150px auto auto;
}

.token-row {
  grid-template-columns: auto minmax(280px, 1fr) auto auto;
}

.token-row input {
  min-width: 0;
}

.login-gate-panel {
  margin-top: 14px;
  padding: 28px;
}

.login-gate-panel h2 {
  margin-bottom: 8px;
}

.login-gate-panel p {
  margin-bottom: 0;
  color: var(--muted);
}

.admin-workspace {
  display: grid;
  gap: 14px;
}

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

.metrics-grid article {
  padding: 14px;
}

.metrics-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.metrics-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 1.5rem;
}

.notice-panel {
  margin-bottom: 14px;
  padding: 12px 14px;
  color: #2d3b50;
  font-size: 0.9rem;
  line-height: 1.6;
  background: #fff8eb;
  border-color: #f0c36d;
}

.workspace {
  display: grid;
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.filters {
  display: flex;
  gap: 8px;
}

.filters input {
  width: 220px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

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

th {
  color: #2d3b50;
  font-size: 0.82rem;
  background: var(--surface-soft);
}

td {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

td strong {
  display: block;
  color: var(--text);
}

.original-preview {
  display: inline-grid;
  gap: 4px;
  max-width: 100%;
  cursor: help;
  outline: none;
}

.original-preview:focus-visible {
  border-radius: 6px;
  box-shadow: 0 0 0 3px rgb(31 122 140 / 20%);
}

.original-preview span {
  overflow-wrap: anywhere;
}

.original-tooltip {
  position: fixed;
  z-index: 30;
  width: min(420px, calc(100vw - 24px));
  max-height: min(320px, calc(100vh - 24px));
  padding: 12px 14px;
  overflow: auto;
  color: #172033;
  font-size: 0.86rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  pointer-events: none;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 46px rgb(23 32 51 / 18%);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  color: var(--primary);
  background: rgb(31 122 140 / 10%);
  border-radius: 999px;
}

.status-pill.success {
  color: var(--success);
  background: rgb(22 129 90 / 10%);
}

.status-pill.failed,
.status-pill.rejected,
.status-pill.unauthorized {
  color: var(--danger);
  background: rgb(180 35 24 / 10%);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-panel {
  display: none;
  margin-top: 14px;
  padding: 14px;
}

.detail-panel.is-open {
  display: block;
}

.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

pre {
  max-height: 520px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  color: #243246;
  line-height: 1.55;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.message-line {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
}

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

.message-line.is-success {
  color: var(--success);
}

.hidden {
  display: none;
}

@media (max-width: 980px) {
  .admin-shell {
    padding-top: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-box,
  .session-box {
    width: 100%;
  }

  .login-grid {
    grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .login-grid button {
    grid-column: span 2;
  }

  .token-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .token-row button {
    justify-self: start;
  }

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

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

  .filters {
    width: 100%;
  }

  .filters select,
  .filters input {
    flex: 1 1 0;
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .table-wrap {
    overflow: visible;
    border: 0;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table {
    border-collapse: separate;
    border-spacing: 0;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
  }

  td {
    display: grid;
    grid-template-columns: minmax(84px, 0.38fr) minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
    overflow-wrap: anywhere;
    border-bottom: 1px solid var(--border);
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    color: #2d3b50;
    font-size: 0.78rem;
    font-weight: 800;
    content: attr(data-label);
  }

  .empty-row td {
    display: block;
    color: var(--muted);
  }

  .empty-row td::before {
    display: block;
    margin-bottom: 6px;
  }
}

@media (max-width: 640px) {
  .admin-shell {
    width: min(100% - 20px, 480px);
    padding: 12px 0 24px;
  }

  .topbar,
  .panel,
  .login-gate-panel,
  .detail-panel {
    padding: 14px;
  }

  h1 {
    font-size: 1.3rem;
  }

  .login-grid,
  .token-row,
  .filters {
    display: grid;
    grid-template-columns: 1fr;
  }

  .login-grid button,
  .token-row button,
  .filters input,
  .filters select {
    grid-column: auto;
    justify-self: stretch;
    width: 100%;
  }

  input,
  select,
  button {
    width: 100%;
  }

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

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

  .action-row button {
    min-width: 0;
  }

  td {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  pre {
    max-height: 420px;
    font-size: 0.82rem;
  }
}
