/* Admin area (layouts/admin): a quiet, dense operator UI. Full-width top bar
   and tab bar, a wide content column, flat cards and tables. Built from the
   same tokens as the site, so it follows light and dark. */

.admin-body {
  --admin-max: 1200px;
  --admin-bar: color-mix(in srgb, var(--surface) 92%, var(--paper-2));
  /* Toasts sit below the top bar and tabs. */
  --nav-h: 108px;
  min-height: 100svh;
  font-size: 15px;
  background: var(--paper-2);
  overflow-x: hidden;
}

/* --- Top bar --- */
.admin-top { background: var(--surface); border-bottom: 1px solid var(--hairline); }
.admin-top-inner,
.admin-tabs-inner,
.admin-container {
  max-width: var(--admin-max);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}
.admin-top-inner { height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.admin-wordmark {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.03em;
  color: var(--ink);
  white-space: nowrap;
}
.admin-wordmark:hover { color: var(--ink); }
.admin-wordmark .tld { color: var(--cobalt); }
.admin-wordmark-tag {
  margin-left: 10px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-muted);
}
.admin-top-actions { display: flex; align-items: center; gap: 8px; }
.admin-top-link { color: var(--ink-muted); font-size: 14px; font-weight: 500; padding: 8px 10px; white-space: nowrap; }
.admin-top-link:hover { color: var(--ink); }
.admin-top-link .admin-narrow { display: none; }
.admin-signout-form { margin: 0; }
.admin-signout { padding: 7px 14px; font-size: 13px; }
.admin-theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
}
.admin-theme:hover { color: var(--ink); background: var(--surface-2); }
.admin-theme svg { width: 18px; height: 18px; }
.admin-theme .theme-icon-sun { display: none; }
:root[data-theme="dark"] .admin-theme .theme-icon-sun { display: block; }
:root[data-theme="dark"] .admin-theme .theme-icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .admin-theme .theme-icon-sun { display: block; }
  :root:not([data-theme="light"]) .admin-theme .theme-icon-moon { display: none; }
}

/* --- Tabs: the full-width subnav, active tab underlined --- */
.admin-tabs {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.admin-tabs-inner {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.admin-tabs-inner::-webkit-scrollbar { display: none; }
.admin-tab {
  position: relative;
  flex: none;
  padding: 14px 12px 13px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
  white-space: nowrap;
}
.admin-tab:first-child { margin-left: -12px; }
.admin-tab:hover { color: var(--ink); }
.admin-tab.active { color: var(--cobalt); }
.admin-tab.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--cobalt);
}

/* --- Page --- */
.admin-main { padding: 32px 0 80px; }
.admin-container { min-width: 0; }
.admin-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.admin-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.admin-sub { margin-top: 6px; color: var(--ink-muted); font-size: 14px; max-width: 680px; }
.admin-back { display: inline-block; margin-bottom: 12px; font-size: 14px; color: var(--ink-muted); }
.admin-back:hover { color: var(--ink); }

/* --- Cards --- */
.admin-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  min-width: 0;
}
.admin-card + .admin-card { margin-top: 20px; }
.admin-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline);
}
.admin-card-title { font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.admin-card-head a { font-size: 13px; font-weight: 500; white-space: nowrap; }
.admin-card-body { padding: 16px 20px; }
.admin-card-body > p + p { margin-top: 10px; }
.admin-card-foot { padding: 12px 20px; border-top: 1px solid var(--hairline); font-size: 13px; color: var(--ink-muted); }
.admin-empty { padding: 28px 20px; color: var(--ink-muted); font-size: 14px; text-align: center; }

.admin-grid { display: grid; gap: 20px; margin-top: 20px; align-items: start; }
.admin-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.admin-grid-2 > .admin-card + .admin-card { margin-top: 0; }
.admin-stack > * + * { margin-top: 20px; }
@media (max-width: 900px) {
  .admin-grid-2 { grid-template-columns: minmax(0, 1fr); }
}

/* --- KPI tiles --- */
.admin-tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .admin-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 600px) { .admin-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.admin-tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 16px 18px;
  color: var(--ink);
  min-width: 0;
  transition: border-color var(--t-fast) var(--ease);
}
a.admin-tile:hover { color: var(--ink); border-color: var(--hairline-strong); }
.admin-tile-label { font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.admin-tile-value {
  margin-top: 6px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.admin-tile-sub { margin-top: 4px; font-size: 13px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-tile-sub .up { color: var(--success); font-weight: 500; }
.admin-tile-sub .bad { color: var(--danger); font-weight: 500; }
.admin-tiers { margin-top: 6px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.admin-tier-num { font-family: var(--font-display); font-weight: 500; font-size: 22px; line-height: 1.25; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.admin-tier-name { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.admin-tile-value.is-small { font-size: 20px; }

/* --- Lists (needs attention, activity) --- */
.admin-list { list-style: none; }
.admin-list > li { border-bottom: 1px solid var(--hairline); }
.admin-list > li:last-child { border-bottom: 0; }
.admin-list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  font-size: 14px;
  color: var(--ink);
  min-width: 0;
}
a.admin-list-row:hover { background: var(--surface-2); color: var(--ink); }
.admin-list-main { flex: 1; min-width: 0; }
.admin-list-title { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-list-meta { display: block; margin-top: 1px; font-size: 13px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-list-side { flex: none; font-size: 13px; color: var(--ink-faint); white-space: nowrap; }
.admin-list-chevron { flex: none; width: 16px; height: 16px; color: var(--ink-faint); }
.admin-flag { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.admin-flag-danger { background: var(--danger); }
.admin-flag-info { background: var(--cobalt); }

/* --- Tables --- */
.admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
  background: var(--surface);
}
.admin-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
  color: var(--ink);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.admin-table th:first-child, .admin-table td:first-child { padding-left: 20px; }
.admin-table th:last-child, .admin-table td:last-child { padding-right: 20px; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.admin-table .nowrap { white-space: nowrap; }
.admin-table .actions { text-align: right; white-space: nowrap; }
.admin-table .actions > * + * { margin-left: 6px; }
.admin-table .actions form { display: inline-block; }
.admin-table .muted { color: var(--ink-muted); }
.admin-cell-title { display: block; font-weight: 500; color: var(--ink); }
a.admin-cell-title:hover { color: var(--cobalt); }
.admin-cell-sub { display: block; font-size: 13px; color: var(--ink-muted); }
.admin-cell-wrap { overflow-wrap: anywhere; min-width: 160px; }
.admin-uid { max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Phone width: tables keep their key columns; the rest is a tap away. */
.admin-table .narrow { display: none; }

/* Table cell that is a link across the row's main column. */
.admin-row-link { color: inherit; }
.admin-row-link:hover .admin-cell-title { color: var(--cobalt); }

/* --- Badges --- */
.admin-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: 1px;
  background: var(--surface-2);
  color: var(--ink-muted);
}
.admin-badge-warn { background: color-mix(in srgb, var(--warning) 16%, transparent); color: light-dark(#8a4b00, #F5A742); }
.admin-badge-danger { background: var(--danger-soft); color: var(--danger-ink); }
.admin-badge-ok { background: var(--success-soft); color: var(--success-ink); }
.admin-badge-info { background: var(--cobalt-ghost); color: var(--cobalt); }
.admin-body .tier-chip { padding: 3px 10px; font-size: 11px; gap: 6px; }

/* --- Toolbar: search + filter chips --- */
.admin-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--hairline); }
.admin-search { display: flex; gap: 8px; align-items: center; flex: 1 1 320px; max-width: 460px; min-width: 0; }
.admin-input,
.admin-search input[type="search"],
.admin-select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  padding: 8px 12px;
  height: 38px;
}
.admin-select { width: auto; padding-right: 28px; }
.admin-input:focus, .admin-search input[type="search"]:focus, .admin-select:focus { outline: none; border-color: var(--cobalt); box-shadow: 0 0 0 3px var(--focus-ring); }
.admin-input::placeholder, .admin-search input[type="search"]::placeholder { color: var(--ink-faint); }
.admin-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-chip {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hairline-strong);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  white-space: nowrap;
}
.admin-chip:hover { color: var(--ink); border-color: var(--ink-faint); }
.admin-chip.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.admin-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1 1 auto; }
.admin-filters .admin-input { width: 240px; max-width: 100%; flex: 1 1 200px; }
.admin-count { font-size: 13px; color: var(--ink-muted); white-space: nowrap; }

/* --- Pager --- */
.admin-pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--hairline); }
.admin-pager-page { font-size: 13px; color: var(--ink-muted); }

/* --- Buttons, admin sizes --- */
.admin-body .btn-sm { padding: 7px 14px; font-size: 13px; }
.admin-body .btn:hover { transform: none; }
.admin-body .btn-primary:hover { box-shadow: none; }
.btn-danger { --danger-solid: light-dark(#B42318, #D93025); background: var(--danger-solid); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger-solid) 86%, #000); color: #fff; }
.btn-danger:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-outline-danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-outline-danger:hover { color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.admin-actions form { margin: 0; }

/* --- Person page --- */
.admin-person-head { display: flex; align-items: center; gap: 16px; min-width: 0; }
.admin-avatar {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--cobalt-ghost);
  color: var(--cobalt);
  font-weight: 600;
  font-size: 19px;
}
.admin-person-id { min-width: 0; }
.admin-person-id .admin-title { overflow-wrap: anywhere; }
.admin-person-meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 14px; color: var(--ink-muted); }
.admin-person-meta > span { overflow-wrap: anywhere; }
.admin-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 960px) { .admin-layout { grid-template-columns: minmax(0, 1fr); } }

.admin-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 20px; font-size: 14px; }
.admin-dl dt { color: var(--ink-muted); }
.admin-dl dd { color: var(--ink); overflow-wrap: anywhere; }
.admin-note { font-size: 13px; color: var(--ink-muted); line-height: 1.5; }
.admin-inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.admin-inline-form .admin-input { flex: 1 1 180px; width: auto; }

/* --- Forms (invites, delete confirm) --- */
.admin-form-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
@media (max-width: 900px) { .admin-form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .admin-form-row { grid-template-columns: minmax(0, 1fr); } }
.admin-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.admin-field label { font-size: 13px; font-weight: 600; color: var(--ink); }
.admin-field .hint { font-size: 12px; color: var(--ink-faint); }
.admin-form-stack { display: grid; gap: 16px; max-width: 420px; }

/* Usage bar (invites) */
.admin-uses { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.admin-bar { width: 64px; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; flex: none; }
.admin-bar > span { display: block; height: 100%; border-radius: 3px; background: var(--cobalt); }
.admin-bar.is-high > span { background: var(--warning); }
.admin-bar.is-full > span { background: var(--danger); }

/* Activity details */
.admin-details { font-size: 13px; color: var(--ink-muted); overflow-wrap: anywhere; }
.admin-mono { font-family: var(--font-mono); font-size: 13px; }

/* Delete dialog */
.admin-body .modal { max-width: min(460px, calc(100vw - 32px)); }
.admin-dialog-body { padding: 20px 24px 24px; display: grid; gap: 14px; }
.admin-dialog-body p { font-size: 14px; color: var(--ink-muted); }
.admin-dialog-title { font-size: 18px; font-weight: 600; color: var(--ink); }
.admin-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Old admin views still inside the layout: keep their panels flat. */
.admin-body .panel { box-shadow: none; border-radius: 14px; }

@media (max-width: 600px) {
  .admin-main { padding-top: 24px; }
  .admin-title { font-size: 26px; }
  .admin-top-link { padding: 8px 6px; }
  .admin-top-link .admin-wide { display: none; }
  .admin-top-link .admin-narrow { display: inline; }
  .admin-card-head, .admin-card-body, .admin-list-row, .admin-toolbar, .admin-pager { padding-left: 16px; padding-right: 16px; }
  .admin-table th:first-child, .admin-table td:first-child { padding-left: 16px; }
  .admin-table th:last-child, .admin-table td:last-child { padding-right: 16px; }
  .admin-table .wide { display: none; }
  .admin-table .narrow { display: block; overflow-wrap: anywhere; white-space: normal; }
  .admin-cell-wrap { min-width: 0; }
  .admin-tile { padding: 14px; }
  .admin-tile-value { font-size: 26px; }
}

/* The app registration form (admin_clients/_form) uses the site's .field rows. */
.admin-body .field input[type="text"],
.admin-body .field textarea,
.admin-body .field select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
  min-width: 0;
}
.admin-body .field textarea { resize: vertical; font-family: var(--font-mono); font-size: 13px; }
.admin-body .field textarea:focus, .admin-body .field select:focus { outline: none; border-color: var(--cobalt); box-shadow: 0 0 0 3px var(--focus-ring); }
.admin-body .field label:has(input[type="checkbox"]) { font-weight: 500; display: flex; gap: 8px; align-items: center; }
.admin-form-section { margin: 24px 0 12px; font-size: 13px; font-weight: 600; color: var(--ink-muted); }
.admin-secret { font-family: var(--font-mono); font-size: 13px; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; color: var(--ink); }

/* Dashboard: "Needs attention" is a full-width strip, only when something
   needs you; its rows sit side by side on a wide screen. */
.admin-attention { margin-top: 20px; }
.admin-attention-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.admin-attention-list > li { border-bottom: 0; border-top: 1px solid var(--hairline); }
.admin-attention-list > li:first-child { border-top: 0; }
@media (min-width: 720px) {
  .admin-attention-list > li { border-top: 0; border-right: 1px solid var(--hairline); }
  .admin-attention-list > li:last-child { border-right: 0; }
}
.admin-cell-meta { margin-top: 1px; font-size: 13px; color: var(--ink-muted); }
@media (min-width: 720px) {
  /* One short row: the title on the left, the items beside it. */
  .admin-attention { display: flex; align-items: stretch; }
  .admin-attention > .admin-card-head { flex: none; width: 180px; border-bottom: 0; border-right: 1px solid var(--hairline); }
  .admin-attention > .admin-list { flex: 1; min-width: 0; }
}
