:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #18202b;
  --muted: #647084;
  --accent: #1769aa;
  --accent-dark: #0f4f86;
  --ok: #0f766e;
  --warn: #b45309;
}

* {
  box-sizing: border-box;
}

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

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
  min-width: 330px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

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

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 16px;
}

.searchbar {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  margin: 22px 0 12px;
}

input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  font-size: 16px;
  background: #fff;
}

input:focus {
  outline: 2px solid rgba(23, 105, 170, 0.18);
  border-color: var(--accent);
}

input[readonly] {
  background: #f3f6fa;
  color: #475467;
}

td input,
td select {
  height: 34px;
  min-width: 150px;
  font-size: 14px;
}

button {
  height: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

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

.inline-form {
  display: inline-flex;
  margin: 0 0 0 6px;
}

.small-button {
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.danger-button {
  background: #b42318;
}

.danger-button:hover {
  background: #8a1f16;
}

.link-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  background: #e8f3ff;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.link-button:hover,
.download-button:hover {
  background: #d7eafe;
}

select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 14px;
  background: #fff;
}

.status {
  min-height: 24px;
  color: var(--muted);
  font-size: 14px;
}

.summary-grid,
.results {
  display: grid;
  gap: 16px;
  margin-top: 12px;
}

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

.empty,
.note {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  color: var(--muted);
}

.note {
  color: var(--warn);
  border-color: #f3d19c;
  background: #fff8eb;
}

.success {
  background: #ecfdf5;
  border: 1px solid #99f6e4;
  border-radius: 6px;
  padding: 12px;
  color: #0f766e;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.section h2 {
  margin: 0;
  padding: 12px 14px;
  font-size: 16px;
  border-bottom: 1px solid var(--line);
  background: #f9fafc;
}

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

.batch-detail {
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid #edf0f5;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

.text-left {
  text-align: left;
}

th {
  color: var(--muted);
  background: #fbfcfe;
  font-weight: 700;
}

tfoot td {
  font-weight: 700;
  background: #f9fafc;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #e8f3ff;
  color: var(--accent-dark);
}

.badge.pending {
  background: #fff2cc;
  color: #92400e;
}

.kv {
  display: grid;
  grid-template-columns: 170px 1fr;
  border-bottom: 1px solid #edf0f5;
  min-height: 36px;
}

.kv:last-child {
  border-bottom: 0;
}

.key {
  padding: 9px 12px;
  color: var(--muted);
  background: #fbfcfe;
  border-right: 1px solid #edf0f5;
}

.value {
  padding: 9px 12px;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.missing {
  color: #98a2b3;
  font-family: inherit;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
}

.auth-form,
.admin-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.admin-form {
  grid-template-columns: 1fr 1fr 120px 120px;
  align-items: center;
}

.admin-form .note,
.admin-form .success {
  grid-column: 1 / -1;
}

@media (max-width: 820px) {
  .topbar {
    flex-direction: column;
  }

  .stats {
    min-width: 0;
    width: 100%;
  }

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

  .admin-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .app {
    padding: 16px;
  }

  .topbar,
  .grid,
  .summary-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
    min-width: 0;
  }

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

  .kv {
    grid-template-columns: 120px 1fr;
  }
}
