:root {
  color-scheme: dark;
  --bg: #0f1013;
  --surface: #17191f;
  --surface-2: #1d2027;
  --surface-3: #232731;
  --fg: #f3f4f8;
  --muted: #9aa0ad;
  --muted-2: #737987;
  --border: #2a2e38;
  --border-strong: #3a4050;
  --accent: #8b9cff;
  --accent-strong: #a7b4ff;
  --danger: #ff7b8a;
  --success: #71d69a;
  --warning: #f2c66d;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-panel: 0 22px 70px rgba(0, 0, 0, 0.34);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -20%, rgba(139, 156, 255, 0.12), transparent 34rem),
    linear-gradient(180deg, #111218 0%, var(--bg) 42%);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

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

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

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

.launcher-shell {
  display: grid;
  gap: 18px;
  width: min(860px, 100%);
}

.launcher-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 24px;
}

.launcher-hero h1 {
  margin: 10px 0 0;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1;
  letter-spacing: -0.03em;
}

.launcher-hero p {
  max-width: 56ch;
  margin: 10px 0 0;
  color: var(--muted);
}

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

.screen-card {
  display: grid;
  gap: 18px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  padding: 18px;
  text-decoration: none;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.screen-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  transform: translateY(-1px);
}

.screen-card:focus-visible {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 156, 255, 0.18);
}

.screen-card strong {
  display: block;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.screen-card span {
  color: var(--muted);
}

.screen-title {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.login-shell {
  width: min(430px, 100%);
  min-width: 0;
}

.login-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in oklch, var(--surface), #111218 18%);
  padding: 28px;
  box-shadow: var(--shadow-panel);
}

.brand-mark {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  color: var(--accent-strong);
  font-weight: 720;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.screen-title h1,
.panel-title h2,
.section-title h2 {
  margin: 0;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.screen-title p,
.panel-title p,
.section-title p {
  margin: 8px 0 0;
  color: var(--muted);
}

.card-header {
  margin-bottom: 24px;
}

.card-header h2 {
  margin: 16px 0 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

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

.form-stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: 0;
  background: #111319;
  color: var(--fg);
  padding: 0 11px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.field input::placeholder {
  color: #565d6c;
}

.field input:focus,
.field select:focus {
  border-color: color-mix(in oklch, var(--accent), white 10%);
  box-shadow: 0 0 0 3px rgba(139, 156, 255, 0.16);
  background: #131722;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--fg);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 156, 255, 0.18);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.btn:disabled:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.btn-primary,
#submit {
  border-color: color-mix(in oklch, var(--accent), #000 26%);
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #10121a;
}

.btn-danger {
  color: var(--danger);
}

.btn-full {
  width: 100%;
  min-height: 40px;
}

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

.status.error {
  color: var(--danger);
}

.dashboard-page .status {
  margin: 0 2px;
}

.enroll-panel {
  display: grid;
  gap: 13px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.025);
}

.qr-frame {
  display: grid;
  min-height: 160px;
  place-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: #101218;
}

.qr-frame img,
#totp-qr {
  max-width: 142px;
  max-height: 142px;
}

.dashboard-page {
  min-height: 100vh;
  background: var(--bg);
}

body.dashboard-page {
  overflow: hidden;
  background: var(--bg);
}

.admin-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 16, 19, 0.92);
  padding: 12px clamp(14px, 3vw, 28px);
}

.identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.identity-copy {
  min-width: 0;
}

.identity strong {
  display: block;
  overflow: hidden;
  color: var(--fg);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity span {
  display: block;
  overflow: hidden;
  color: var(--muted-2);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-main {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 16px;
  width: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 16px clamp(14px, 3vw, 28px) 28px;
}

.admin-main-focused {
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.sidebar,
.content {
  min-width: 0;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 12px;
}

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

.content-primary {
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.support-title {
  align-items: flex-end;
  padding: 4px 2px 0;
}

.support-title h1 {
  max-width: 18ch;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 0.98;
}

.support-title p {
  max-width: 72ch;
}

.support-toolbar {
  padding-bottom: 2px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.panel-inner {
  padding: 14px;
}

.panel-title,
.section-title {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 14px 0;
}

.panel-title h2,
.section-title h2 {
  font-size: 14px;
}

.panel-title p,
.section-title p {
  font-size: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.admin-tabs {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #12141a;
  padding: 3px;
}

.tab-button {
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  padding: 0 13px;
  font-size: 12px;
  font-weight: 650;
  transition: background 160ms ease, color 160ms ease;
}

.tab-button:hover {
  color: var(--fg);
}

.tab-button:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(139, 156, 255, 0.16);
}

.tab-button.is-active {
  background: var(--surface-3);
  color: var(--fg);
}

.tab-panel {
  min-width: 0;
  min-height: 0;
}

.tab-panel-codes:not([hidden]) {
  display: grid;
}

.tab-panel-operations:not([hidden]) {
  display: grid;
  gap: 14px;
  overflow: auto;
  padding-right: 2px;
}

.codes-workbench {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.codes-command-bar {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 16px 0;
}

.codes-command-bar h2 {
  margin: 0;
  color: var(--fg);
  font-size: 15px;
  letter-spacing: -0.02em;
}

.codes-command-bar p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.codes-count {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

.codes-count strong {
  color: var(--fg);
  font-weight: 650;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1.15fr) minmax(220px, 1fr) auto;
  gap: 10px;
  margin: 14px 16px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #12141a;
}

.search-field label {
  color: #c8ccd6;
}

.search-field input {
  height: 42px;
  border-color: var(--border-strong);
  background: #0d0f14;
  font-family: var(--font-mono);
}

.search-submit {
  align-self: end;
  min-height: 42px;
}

.filter-row {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 2px;
}

.filter-chip {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 11px;
  font-size: 12px;
  font-weight: 650;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.filter-chip:hover {
  border-color: var(--border-strong);
  color: var(--fg);
}

.filter-chip:focus-visible {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 156, 255, 0.16);
}

.filter-chip.is-active {
  border-color: color-mix(in oklch, var(--accent), #000 42%);
  background: rgba(139, 156, 255, 0.12);
  color: var(--accent-strong);
}

.secondary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.supporting-tables {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}

.supporting-tables .table-section:first-child {
  grid-row: span 2;
}

.compact-panel {
  background: color-mix(in oklch, var(--surface), #000 8%);
}

.compact-form .btn {
  justify-self: start;
}

.grid-form {
  display: grid;
  gap: 10px;
}

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

.table-section {
  min-width: 0;
  overflow: hidden;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  padding: 12px 14px 14px;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 12px;
}

.codes-table-wrap {
  min-height: 240px;
  overflow: auto;
  padding: 10px 16px 16px;
}

.codes-table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1240px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 9px 8px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 650;
}

.data-table td {
  color: #d8dbe4;
}

.muted-cell {
  color: var(--muted-2) !important;
}

.code-guid {
  color: #f0f2f8;
  font-weight: 650;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.codes-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border);
}

.codes-table th:last-child,
.codes-table td:last-child {
  position: sticky;
  right: 0;
  min-width: 218px;
  background: linear-gradient(90deg, rgba(23, 25, 31, 0.88), var(--surface) 18%);
  box-shadow: -18px 0 24px rgba(15, 16, 19, 0.62);
}

.codes-table th:last-child {
  z-index: 5;
}

.codes-table td:last-child {
  z-index: 2;
}

.codes-table td:last-child:has(.reset-confirm[open]) {
  z-index: 4;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.pill-ok {
  border-color: rgba(113, 214, 154, 0.28);
  color: var(--success);
}

.pill-warn {
  border-color: rgba(242, 198, 109, 0.28);
  color: var(--warning);
}

.pill-danger {
  border-color: rgba(255, 123, 138, 0.28);
  color: var(--danger);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.row-actions .btn {
  min-height: 28px;
  padding: 0 9px;
}

.code-actions {
  position: relative;
}

.reset-confirm {
  position: relative;
}

.reset-confirm summary {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 123, 138, 0.26);
  border-radius: var(--radius-sm);
  background: rgba(255, 123, 138, 0.035);
  color: var(--danger);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 650;
  list-style: none;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.reset-confirm summary::-webkit-details-marker {
  display: none;
}

.reset-confirm summary:hover {
  border-color: rgba(255, 123, 138, 0.44);
  background: rgba(255, 123, 138, 0.075);
}

.reset-confirm summary:focus-visible {
  outline: 0;
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 123, 138, 0.14);
}

.reset-confirm[open] {
  z-index: 5;
}

.reset-popover {
  position: absolute;
  top: 36px;
  right: 0;
  display: grid;
  width: 280px;
  gap: 10px;
  border: 1px solid rgba(255, 123, 138, 0.3);
  border-radius: var(--radius-md);
  background: #111319;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  padding: 12px;
  white-space: normal;
}

.reset-popover p {
  margin: 0;
  color: #e7e9ef;
  font-size: 12px;
  line-height: 1.45;
}

.btn-danger-soft {
  border-color: rgba(255, 123, 138, 0.34);
  background: rgba(255, 123, 138, 0.07);
  color: var(--danger);
}

.btn-danger-soft:hover {
  border-color: rgba(255, 123, 138, 0.55);
  background: rgba(255, 123, 138, 0.1);
}

.detail-dialog {
  width: min(640px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--fg);
  padding: 0;
  box-shadow: var(--shadow-panel);
}

.detail-dialog::backdrop {
  background: rgba(0, 0, 0, 0.52);
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(110px, 150px) minmax(0, 1fr);
  gap: 0;
  margin: 0;
  padding: 12px 14px 16px;
}

.detail-list dt,
.detail-list dd {
  min-width: 0;
  border-bottom: 1px solid var(--border);
  margin: 0;
  padding: 9px 0;
  font-size: 12px;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 650;
}

.detail-list dd {
  color: #d8dbe4;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .admin-main {
    grid-template-columns: 1fr;
  }

  .supporting-tables,
  .secondary-grid {
    grid-template-columns: 1fr;
  }

  .supporting-tables .table-section:first-child {
    grid-row: auto;
  }

  .search-panel {
    grid-template-columns: 1fr;
  }

  .search-submit {
    justify-self: start;
  }
}

@media (max-width: 520px) {
  body {
    background: var(--bg);
  }

  body.dashboard-page {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .admin-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .login-page {
    display: block;
    padding: 12px;
  }

  .login-shell {
    width: 100%;
  }

  .login-card {
    border-radius: var(--radius-md);
    padding: 18px;
  }

  .launcher-page {
    display: block;
    padding: 12px;
  }

  .launcher-hero {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

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

  .admin-header {
    align-items: flex-start;
  }

  .admin-main {
    overflow: visible;
    padding: 12px 10px 24px;
  }

  .screen-title,
  .section-title,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .support-title h1 {
    font-size: 28px;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .codes-command-bar {
    flex-direction: column;
    padding: 14px 12px 0;
  }

  .codes-count {
    justify-content: flex-start;
  }

  .search-panel {
    margin: 12px 12px 0;
    padding: 10px;
  }

  .filter-row {
    padding: 10px 12px 2px;
  }

  .filter-chip {
    max-width: 100%;
  }

  .codes-table-wrap {
    max-height: 62vh;
    padding: 10px 12px 12px;
  }

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

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

  .detail-list dt {
    border-bottom: 0;
    padding-bottom: 2px;
  }

  .detail-list dd {
    padding-top: 0;
  }

  .btn {
    min-width: 0;
  }
}
