/* Admin-only styles.
   Keep this file off public bundle pages so admin chrome and forms do not
   block first paint everywhere. Shared primitives (.btn, .text-input,
   .copy-field, flash) live in application.css; this file retunes them for
   a denser console. */

body.admin {
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-rail: #fafafa;
  --color-border: #e7e7ea;
  --color-border-strong: #d4d4d8;
  --color-hover: #f4f4f5;
  --color-text: #18181b;
  --color-muted: #71717a;
  --color-faint: #a1a1aa;
  --color-badge-bg: #f4f4f5;
  --color-protected: #2563eb;
  --color-public: #16a34a;
  --color-off: #a1a1aa;
  --control-height: 34px;
  --radius-md: 6px;
  --radius-lg: 10px;
  font-size: 14px;
  background: var(--color-bg);
}

@media (prefers-color-scheme: dark) {
  body.admin {
    --color-bg: #0c0c0d;
    --color-surface: #0c0c0d;
    --color-rail: #111113;
    --color-border: #232326;
    --color-border-strong: #34343a;
    --color-hover: #18181b;
    --color-text: #ededef;
    --color-muted: #a1a1aa;
    --color-faint: #6b6b73;
    --color-badge-bg: #1c1c1f;
    --color-protected: #60a5fa;
    --color-public: #4ade80;
    --color-off: #52525b;
  }
}

@media (pointer: coarse) {
  body.admin { --control-height: 44px; }
}

/* ── Shell ─────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 16px 12px;
  background: var(--color-rail);
  border-right: 1px solid var(--color-border);
}

.sidebar .brand {
  padding: 4px 8px;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.sidebar .brand:hover { text-decoration: none; }

.sidebar-nav {
  display: grid;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-md);
  color: var(--color-muted);
  white-space: nowrap;
}

.sidebar-nav a:hover {
  color: var(--color-text);
  background: var(--color-hover);
  text-decoration: none;
}

.sidebar-nav a[aria-current="page"] {
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: 0 0 0 1px var(--color-border);
  font-weight: 500;
}

.sidebar-nav svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-account {
  margin-top: auto;
  display: grid;
  gap: 2px;
  padding: 0 8px;
  font-size: 12px;
  color: var(--color-faint);
}

.sidebar-user { overflow-wrap: anywhere; }

.sidebar .sidebar-signout {
  all: unset;
  cursor: pointer;
  color: var(--color-muted);
  font-size: 12px;
}

.sidebar .sidebar-signout:hover { color: var(--color-text); }
.sidebar .sidebar-signout:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.shell-main { min-width: 0; padding: 0; }

.content {
  max-width: 760px;
  padding: 28px 32px 64px;
}

.content.is-wide { max-width: 1080px; }

.admin .flash-stack { position: static; }
.admin .flash { padding: 10px 32px; font-size: 13px; }
.admin .flash .container { max-width: none; padding: 0; }

/* ── Page header ───────────────────────────────────────────── */

.breadcrumb {
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--color-faint);
}

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

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title h1 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.page-title .count {
  all: unset;
  font-size: 14px;
  font-weight: 400;
  color: var(--color-faint);
  font-variant-numeric: tabular-nums;
}

.page-lede {
  margin: -12px 0 24px;
  color: var(--color-muted);
}

.admin h2 {
  font-size: 14px;
  font-weight: 600;
}

/* ── Controls ──────────────────────────────────────────────── */

.admin button,
.admin .btn {
  min-height: var(--control-height);
  padding: 0 12px;
  font-size: 13px;
  border-radius: var(--radius-md);
}

.admin .btn-primary {
  background: var(--color-text);
  color: var(--color-bg);
}

.admin .btn-primary:hover { background: var(--color-text); opacity: 0.86; }

.admin .btn-secondary,
.admin .btn-ghost {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.admin .btn-secondary:hover,
.admin .btn-ghost:hover { background: var(--color-hover); }

.admin .btn-ghost { border-color: transparent; color: var(--color-muted); }
.admin .btn-ghost:hover { color: var(--color-text); }

.admin .btn-danger { background: var(--color-danger); color: #ffffff; }

.btn-small { min-height: 28px; padding: 0 8px; font-size: 12px; }
.admin .btn-small { min-height: 28px; padding: 0 8px; font-size: 12px; }

.btn-github { background: var(--color-text); color: var(--color-bg); }
.btn-github:hover { opacity: 0.88; }

.admin .text-input {
  min-height: var(--control-height);
  padding: 6px 10px;
  font-size: 14px;
  background: var(--color-bg);
  border-color: var(--color-border-strong);
  border-radius: var(--radius-md);
}

.admin .text-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 18%, transparent);
}

.admin select.text-input { padding-right: 28px; }
.admin textarea.text-input { padding: 8px 10px; }

.stack-form { display: grid; gap: 16px; }
.field-group { display: grid; gap: 6px; }
.field-group label,
.admin legend { font-size: 13px; font-weight: 500; }
.admin legend { margin-bottom: 6px; }
.field-note { color: var(--color-muted); font-size: 12px; }
.field-error { color: var(--color-danger); font-size: 12px; }

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.inline-form { display: inline-flex; }

.link-button {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

.admin .link-button { min-height: 0; padding: 0; font-size: inherit; }

.pill-group {
  display: inline-flex;
  flex-wrap: wrap;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  justify-self: start;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: calc(var(--control-height) - 6px);
  padding: 0 12px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--color-muted);
  font-size: 13px;
}

.pill input { margin: 0; accent-color: var(--color-text); }
.pill:has(input:checked) { background: var(--color-hover); color: var(--color-text); font-weight: 500; box-shadow: 0 0 0 1px var(--color-border); }
.pill:focus-within { outline: 2px solid var(--color-accent); outline-offset: 1px; }

/* ── Status dots ───────────────────────────────────────────── */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-muted);
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-off);
}

.status-protected::before { background: var(--color-protected); }
.status-public::before { background: var(--color-public); }
.status-active::before { background: var(--color-public); }
.status-disabled::before,
.status-revoked::before { background: var(--color-off); }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-muted);
  font-size: 12px;
  white-space: nowrap;
}

/* ── Panels ────────────────────────────────────────────────── */

.panel {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.panel + .panel { margin-top: 16px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.panel-body { padding: 16px; }
.panel-body > * + * { margin-top: 12px; }
.panel-body > .stack-form + * { margin-top: 16px; }
.panel-body p { color: var(--color-muted); }
.panel-body .copy-field { margin-top: 0; }

.panel-danger { border-color: color-mix(in srgb, var(--color-danger) 35%, var(--color-border)); }
.panel-danger h2 { color: var(--color-danger); }

.notice-copy {
  margin-bottom: 16px;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-rail);
  color: var(--color-muted);
  font-size: 13px;
}

.notice-copy p { color: inherit; }

.generated-secret {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-accent) 6%, var(--color-bg));
}

.generated-secret .copy-field { margin-top: 0; }

.admin .copy-field label { font-size: 13px; }
.admin .copy-field .mono { font-size: 13px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}

.stats > div { padding: 12px 16px; min-width: 0; }
.stats > div + div { border-left: 1px solid var(--color-border); }

.stat-label {
  color: var(--color-faint);
  font-size: 12px;
}

.stat-value {
  margin-top: 2px;
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: -12px 0 20px;
  color: var(--color-muted);
  font-size: 13px;
}

/* ── Bundle table ──────────────────────────────────────────── */

.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.library-filters .search { flex: 1 1 240px; }
.library-filters select.text-input { width: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  border-spacing: 0;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.data-table th {
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-rail);
  color: var(--color-faint);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.data-table th a { color: inherit; }
.data-table th a:hover { color: var(--color-text); text-decoration: none; }
.data-table th[aria-sort] a { color: var(--color-text); }
.data-table th[aria-sort] a::after { content: " ↓"; }
.data-table th[aria-sort="ascending"] a::after { content: " ↑"; }

.data-table td {
  padding: 10px 12px;
  border-top: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tbody tr:first-child td { border-top: 0; }
.data-table tbody tr:hover { background: var(--color-hover); }
.data-table .num { text-align: right; }
.data-table .muted { color: var(--color-muted); white-space: nowrap; }
.data-table .actions { width: 1%; white-space: nowrap; text-align: right; }

.bundle-title { color: var(--color-text); font-weight: 500; overflow-wrap: anywhere; }
.bundle-title:hover { color: var(--color-accent); text-decoration: none; }
.bundle-slug { color: var(--color-faint); font-size: 12px; overflow-wrap: anywhere; }
.library-row.is-disabled .bundle-title { color: var(--color-faint); }

.row-actions { display: inline-flex; align-items: center; gap: 4px; }
.row-actions [role="status"] { font-size: 12px; color: var(--color-muted); }

@media (hover: hover) {
  .row-actions .btn { opacity: 0; }
  .library-row:hover .row-actions .btn,
  .row-actions:focus-within .btn { opacity: 1; }
}

.empty-state {
  padding: 40px 24px;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
}

.empty-state p { margin: 6px auto 16px; max-width: 420px; color: var(--color-muted); }
.empty-state .button-row { justify-content: center; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: var(--color-muted);
  font-size: 13px;
}

/* ── Token list ────────────────────────────────────────────── */

.token-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.token-form .button-row { padding-top: 25px; }

.token-list { list-style: none; }
.token-list li + li { border-top: 1px solid var(--color-border); }

.token-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
}

.token-heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-weight: 500;
}

.token-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin-top: 2px;
  color: var(--color-muted);
  font-size: 12px;
}

.token-list .empty-state { border: 0; }

/* ── Upload ────────────────────────────────────────────────── */

.drop-zone {
  display: grid;
  gap: 4px;
  place-items: center;
  padding: 36px 16px;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-rail);
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
}

.drop-zone:hover { border-color: var(--color-muted); }
.drop-zone.is-dragover { border-color: var(--color-accent); background: color-mix(in srgb, var(--color-accent) 5%, var(--color-bg)); }

.file-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-rail);
  overflow-wrap: anywhere;
}

.upload-error {
  margin-bottom: 16px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--color-danger) 30%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-danger) 7%, var(--color-bg));
  color: var(--color-danger);
  font-size: 13px;
}

.upload-progress { padding: 24px 0; text-align: center; }
.upload-progress .button-row { justify-content: center; }
.address-preview { overflow-wrap: anywhere; }

.admin details summary { cursor: pointer; }
.admin details p { margin-top: 6px; }

/* ── Sign in and setup ─────────────────────────────────────── */

.admin .page-centered { background: var(--color-rail); }

.admin .centered-card {
  max-width: 360px;
  padding: 32px 28px;
  border-radius: var(--radius-lg);
  box-shadow: none;
}

.admin .centered-card.wide { max-width: 480px; }
.centered-card h1 { font-size: 18px; letter-spacing: -0.01em; }
.centered-card .lede { margin: 2px 0 24px; color: var(--color-muted); }
.centered-card .fine-print { margin-top: 20px; color: var(--color-faint); font-size: 12px; }
.centered-card.is-center { text-align: center; }
.centered-card .actions { display: grid; gap: 8px; }

.checklist { list-style: none; margin-bottom: 16px; }

.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--color-border);
}

.checklist li:first-child { border-top: 0; }
.check-copy p { margin-top: 1px; font-size: 12px; }

.check-icon {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
}

.check-pass { background: color-mix(in srgb, var(--color-success) 15%, transparent); color: var(--color-success); }
.check-fail { background: color-mix(in srgb, var(--color-danger) 15%, transparent); color: var(--color-danger); }
.check-pending { background: var(--color-badge-bg); color: var(--color-muted); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }

/* ── Small screens: the rail becomes a top bar, tables become rows ── */

@media (max-width: 720px) {
  .shell { display: block; }

  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
    padding: 8px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }

  .sidebar .brand { padding: 4px 0; }
  .sidebar-account { margin: 0 0 0 auto; padding: 0; text-align: right; }
  .sidebar-user { display: none; }
  .sidebar .sidebar-signout { min-height: 32px; display: inline-flex; align-items: center; }

  .sidebar-nav {
    order: 3;
    flex-basis: 100%;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    margin: 0 -8px;
  }

  .sidebar-nav a { min-height: 36px; }
  .sidebar-nav svg { display: none; }

  .content { padding: 20px 16px 48px; }
  .admin .flash { padding: 10px 16px; }

  .page-title { align-items: flex-start; }
  .page-title h1 { font-size: 18px; }
  .page-title > .btn { flex-shrink: 0; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats > div:nth-child(3) { border-left: 0; }
  .stats > div:nth-child(n + 3) { border-top: 1px solid var(--color-border); }

  .library-filters .search { flex-basis: 100%; }
  .library-filters select.text-input { flex: 1 1 0; min-width: 0; }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td { display: block; }

  .data-table thead { display: none; }

  .data-table tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 14px;
    padding: 12px 14px;
    border-top: 1px solid var(--color-border);
  }

  .data-table tbody tr:first-child { border-top: 0; }
  .data-table td { padding: 0; border: 0; }
  .data-table td:first-child { flex-basis: 100%; }
  .data-table td:not(:first-child) { font-size: 13px; }
  .data-table .num { text-align: left; }
  .data-table td[data-label]::before { content: attr(data-label) " "; color: var(--color-faint); }
  .data-table .actions { flex-basis: 100%; text-align: left; }
  .row-actions { margin-left: -8px; }
  .row-actions .btn { opacity: 1; }

  .token-form { grid-template-columns: minmax(0, 1fr); }
  .token-form .button-row { padding-top: 0; }
  .token-row { flex-direction: column; align-items: flex-start; }
  .pagination { justify-content: center; }
}
