:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: rgba(17, 24, 39, 0.92);
  --control: rgba(31, 41, 55, 0.95);
  --border: rgba(255, 255, 255, 0.1);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(203, 213, 225, 0.72);
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

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

.card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  margin: 12vh auto 0;
}

h1,
h2 {
  margin: 0 0 14px;
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
}

.form,
.create-row {
  display: grid;
  gap: 12px;
}

.create-row {
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) 120px auto auto;
  align-items: end;
}

.code-row {
  grid-template-columns: 110px 160px minmax(240px, 1fr) auto;
}

.duration-wrap {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.duration-wrap[hidden] {
  display: none !important;
}

.duration-wrap input {
  width: 130px;
}

.duration-wrap select {
  width: 120px;
}

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

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

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
}

input,
select,
button {
  height: 38px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--control);
  color: var(--text);
  padding: 0 10px;
  font: inherit;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(55, 65, 81, 0.95);
}

.primary {
  border-color: rgba(34, 211, 238, 0.4);
  background: var(--primary);
}

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

.danger {
  background: rgba(127, 29, 29, 0.45);
  border-color: rgba(248, 113, 113, 0.28);
}

.admin {
  display: grid;
  gap: 16px;
}

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

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

.stat-card {
  display: grid;
  gap: 10px;
  min-height: 120px;
  align-content: center;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  font-size: 36px;
  line-height: 1;
  font-weight: 700;
  color: var(--text);
}

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

.error {
  min-height: 18px;
  margin: 0;
  color: #fca5a5;
  font-size: 13px;
}

.codes-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.code-search {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: center;
}

.batch-input {
  width: 100%;
  min-height: 120px;
  margin-bottom: 10px;
  resize: vertical;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--control);
  color: var(--text);
  padding: 10px;
  font: inherit;
}

.code-filters {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(180px, 1fr) 140px 160px auto auto;
  gap: 10px;
  align-items: center;
}

.batch-actions {
  display: grid;
  grid-template-columns: 150px minmax(220px, 320px) auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.code-filters input,
.code-filters select,
.batch-actions select,
.batch-actions input {
  width: 100%;
}

.user-list {
  display: grid;
  gap: 8px;
}

.code-list {
  display: grid;
  gap: 8px;
  min-width: 1320px;
}

.code-list-panel {
  margin-top: 10px;
  max-height: 420px;
  overflow: auto;
  padding-right: 6px;
}

.code-list-panel::-webkit-scrollbar {
  width: 10px;
}

.code-list-panel::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 999px;
}

.created-codes {
  width: 100%;
  min-height: 130px;
  margin-top: 10px;
  resize: vertical;
  white-space: pre;
  overflow: auto;
  font-family: Consolas, "SFMono-Regular", monospace;
}
.code-value,
.created-codes {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-radius: 6px;
  background: rgba(34, 211, 238, 0.1);
  color: #a5f3fc;
  padding: 4px 8px;
}

.user-row {
  display: grid;
  grid-template-columns: 1.2fr 110px 110px minmax(160px, 1fr) minmax(160px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(31, 41, 55, 0.55);
}

.code-item {
  display: grid;
  grid-template-columns: 72px 220px 160px 180px 300px 90px 224px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(31, 41, 55, 0.55);
  white-space: nowrap;
}

.code-select {
  padding-bottom: 0;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.code-actions button {
  flex: 0 0 108px;
}

.used,
.binding,
.period,
.invite {
  color: var(--muted);
  font-size: 13px;
}

.code-value,
.binding,
.type,
.period {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.username {
  font-weight: 700;
}

@media (max-width: 900px) {
  .stats-grid,
  .create-row,
  .code-search,
  .batch-actions,
  .code-filters,
  .user-row {
    grid-template-columns: 1fr;
  }
}
