:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --line: #d8e0e3;
  --text: #192226;
  --muted: #68767d;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warn: #a15c07;
  --shadow: 0 10px 30px rgba(20, 41, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
}

.status {
  min-width: 88px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
}

.status.ok {
  color: var(--accent-strong);
  border-color: rgba(15, 118, 110, 0.35);
}

.status.error {
  color: #9f1239;
  border-color: rgba(159, 18, 57, 0.35);
}

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

.metric {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1;
}

.filters {
  display: grid;
  grid-template-columns: minmax(160px, 0.9fr) minmax(180px, 1.2fr) minmax(170px, 1fr) minmax(150px, 0.9fr) minmax(170px, 1fr) minmax(140px, 0.8fr) minmax(160px, 0.9fr) auto;
  gap: 12px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.admin-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.new-key-box {
  margin-top: 12px;
  border: 1px solid rgba(15, 118, 110, 0.35);
  border-radius: 6px;
  background: #eefaf8;
  padding: 12px;
  color: var(--accent-strong);
  overflow-wrap: anywhere;
}

.new-key-box code {
  display: block;
  margin-top: 6px;
  color: #102326;
  font-size: 13px;
  line-height: 1.5;
}

.key-list {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.key-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  min-height: 86px;
}

.key-item strong,
.key-item span {
  display: block;
}

.key-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  outline-offset: 1px;
}

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

button {
  height: 38px;
  min-width: 76px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

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

button.secondary:hover {
  background: #eef4f4;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.results-pane,
.detail-pane {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.pager button {
  min-width: 68px;
  height: 32px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 308px);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef4f4;
  color: #344248;
  font-weight: 600;
}

th:nth-child(1),
td:nth-child(1) {
  width: 172px;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5) {
  width: 150px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f1f8f7;
}

tbody tr.selected {
  background: #e4f3f1;
}

td {
  overflow-wrap: anywhere;
}

.empty {
  height: 120px;
  text-align: center;
  color: var(--muted);
}

.detail-pane {
  position: sticky;
  top: 24px;
}

#detail {
  max-height: calc(100vh - 198px);
  overflow: auto;
  padding: 16px;
}

.detail-empty {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.detail-title {
  margin-bottom: 12px;
}

.detail-title strong {
  display: block;
  font-size: 20px;
  line-height: 1.25;
}

.detail-title span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.kv {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  min-height: 64px;
}

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

.kv strong {
  display: block;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.long-section {
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.long-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.long-section p {
  color: #2d393e;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}

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

  .detail-pane {
    position: static;
  }

  .table-wrap,
  #detail {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .section-head,
  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .status,
  button {
    width: 100%;
  }

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