:root {
  --bg: #10141c;
  --panel: #171d28;
  --line: #2a3344;
  --text: #e8edf5;
  --muted: #8b97ab;
  --accent: #3d8bfd;
  --accent-2: #6ee7b7;
  --danger: #ff7a7a;
  --row-hover: #1e2633;
  --row-selected: #1a2a22;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #0c1017;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 11px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 8px;
  align-items: flex-start;
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.03em;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

#code-select,
#code-input {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}

#code-select {
  min-width: 88px;
}

#code-input {
  width: 150px;
}

.sub {
  margin: 0;
  color: var(--muted);
  max-width: 640px;
  line-height: 1.4;
  font-size: 11px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 8px;
  margin: 0;
}

.stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  min-width: 72px;
}

.stats dt {
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats dd {
  margin: 2px 0 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 20px 10px;
}

.toolbar input[type="search"],
.toolbar input[type="text"] {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}

.toolbar input[type="search"] {
  flex: 1 1 240px;
}

.hide-empty {
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
  font-size: 11px;
}

.toolbar-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 6px 9px;
  font: inherit;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

button:hover { filter: brightness(1.08); }

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

button.warn {
  background: #e3b341;
  color: #1a1404;
}

button.danger {
  background: #8b2e2e;
}

.modal {
  position: fixed;
  inset: 0;
  background: #0008;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  min-width: 280px;
  max-width: 420px;
}

.modal-box p {
  margin: 0 0 14px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

input.invalid {
  border-color: var(--danger);
}

.banner {
  margin: 0 20px 8px;
  padding: 7px 9px;
  border-radius: 8px;
  background: #3a1f24;
  color: var(--danger);
}

.hidden { display: none !important; }

main {
  padding: 0 20px 32px;
}

table {
  width: max-content;
  min-width: 0;
  table-layout: auto;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

th, td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 12px;
  white-space: nowrap;
}

th {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #121826;
  position: sticky;
  top: 0;
  z-index: 5;
}

th.check, td.check {
  width: max-content;
  min-width: 2.4rem;
  text-align: center;
  padding-left: 6px;
  padding-right: 4px;
}

th.iso, td.iso {
  width: max-content;
  padding-right: 8px;
}

th.num, td.num {
  width: max-content;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.timebar {
  padding-top: 0;
}

.window-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.window-label input {
  width: 92px;
}

.quick {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable::after {
  content: "";
  margin-left: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

th.sortable.sort-active[data-dir="asc"]::after { content: "▲"; }
th.sortable.sort-active[data-dir="desc"]::after { content: "▼"; }
th.sortable.sort-active.sort-multi[data-dir="asc"]::after {
  content: attr(data-sort-index) " ▲";
}
th.sortable.sort-active.sort-multi[data-dir="desc"]::after {
  content: attr(data-sort-index) " ▼";
}

.pct-good { color: #3ddc8e; font-weight: 700; }
.pct-mid { color: #f5a524; font-weight: 700; }
.pct-bad { color: #ff6b6b; font-weight: 700; }

.iso-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.iso-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
}

tr.item:hover {
  background: var(--row-hover);
}

tr.item.checked {
  background: var(--row-selected);
}

.flag {
  width: 16px;
  height: 11px;
  object-fit: cover;
  border-radius: 1px;
  box-shadow: 0 0 0 1px #0006;
  flex: 0 0 auto;
}

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

input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
}

@media (max-width: 800px) {
  .top, .toolbar, main { padding-left: 12px; padding-right: 12px; }
  .top { flex-direction: column; }
  .stats { width: 100%; grid-template-columns: repeat(2, 1fr); }
}

.whoami {
  color: var(--muted);
}

.ghost-link {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
}

.auth-card {
  max-width: 360px;
  margin: 12vh auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}

.auth-card label,
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
}

.auth-card input,
.admin-form input,
.admin-form select {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
}

.admin-form {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  padding: 0 20px 32px;
}

.admin-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.admin-panel h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.admin-panel table {
  width: 100%;
}

.admin-panel td.api-key-cell {
  white-space: normal;
  word-break: break-all;
}

.admin-panel code.api-key {
  display: inline-block;
  max-width: 100%;
  user-select: all;
  word-break: break-all;
  white-space: pre-wrap;
}

.key-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.key-row button {
  flex: 0 0 auto;
}

.muted {
  color: var(--muted);
}

.notice {
  margin: 0 20px 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #1e2a1c;
  color: var(--accent-2);
  word-break: break-all;
}
