/* License API console — hand-written CSS mirroring the RAG app's /sysadmin
   panel (apps/web: lib/theme/tokens.ts + components/admin/primitives/*).
   Same warm-dark palette, same rail/topbar/card/table geometry, so an operator
   moving between the two panels sees one product.

   The tokens below are copied from lib/theme/tokens.ts. They are duplicated on
   purpose: this service must not depend on the RAG app's build. If the palette
   is ever re-tokenised there, re-copy this block.
   Warm-dark only — no light theme, same as the panel it mirrors. */
:root {
  --canvas: 38 38 36;
  --panel: 31 30 29;
  --surface: 48 48 46;
  --surface-2: 58 58 55;
  --line: 58 58 55;
  --line-soft: 46 46 44;
  --line-strong: 74 74 69;
  --ink: 245 244 236;
  --ink-muted: 184 181 172;
  --ink-faint: 138 135 127;
  --ink-code: 230 227 214;
  --accent: 95 163 223;
  --accent-soft: 142 195 235;
  --code-bg: 26 25 24;
  --success: 76 155 114;
  --success-soft: 154 205 176;
  --warning: 196 148 58;
  --warning-soft: 224 192 130;
  --danger: 217 95 87;
  --danger-soft: 238 170 164;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: rgb(var(--canvas));
  color: rgb(var(--ink));
  font-family: "Helvetica Neue", Helvetica, Arial, ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.tnum {
  font-variant-numeric: tabular-nums;
}
.muted {
  color: rgb(var(--ink-muted));
}
.faint {
  color: rgb(var(--ink-faint));
}
.hidden {
  display: none !important;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid rgb(var(--accent));
  outline-offset: 1px;
}

/* Scrollbars: thin, warm, unobtrusive — same as globals.css. */
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: rgb(var(--line));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgb(var(--line-strong));
  background-clip: content-box;
}
*::-webkit-scrollbar-track {
  background: transparent;
}

/* ── Shell ───────────────────────────────────────────────────────────────── */
.shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.rail {
  display: flex;
  flex-direction: column;
  width: 16rem;
  flex-shrink: 0;
  background: rgb(var(--panel));
  transition: width 0.15s ease;
}
.rail.collapsed {
  width: 3.5rem;
}
.rail-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
}
.rail.collapsed .rail-brand {
  justify-content: center;
  padding: 0.75rem 0;
}
.rail-brand .sunburst {
  color: rgb(var(--accent-soft));
  flex-shrink: 0;
}
.rail-brand-name {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: rgb(var(--ink));
}
.rail-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.5rem;
  scrollbar-width: none;
}
.rail-nav::-webkit-scrollbar {
  display: none;
}
.nav-group + .nav-group {
  margin-top: 1rem;
}
.nav-group-label {
  padding: 0.25rem 0.5rem;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgb(var(--ink-faint));
}
.rail.collapsed .nav-group-label {
  display: none;
}
.rail.collapsed .nav-group-rule {
  display: block;
  margin: 0 0.5rem 0.25rem;
  border-top: 1px solid rgb(var(--line-soft));
}
.nav-group-rule {
  display: none;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.375rem 0.625rem;
  margin-bottom: 0.125rem;
  border-radius: 0.5rem;
  font-size: 13.5px;
  color: rgb(var(--ink-muted));
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}
.rail.collapsed .nav-link {
  justify-content: center;
  padding: 0.5rem 0;
}
.rail.collapsed .nav-link span {
  display: none;
}
.nav-link:hover {
  background: rgb(var(--surface));
  color: rgb(var(--ink));
}
.nav-link.active {
  background: rgb(var(--surface-2));
  color: rgb(var(--ink));
}
.nav-link.active svg {
  color: rgb(var(--accent-soft));
}

.main {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  height: 3.5rem;
  flex-shrink: 0;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid rgb(var(--line));
  background: rgb(var(--canvas) / 0.8);
  backdrop-filter: blur(8px);
  padding: 0 1rem;
}
.crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 13px;
  color: rgb(var(--ink-faint));
}
.crumbs .current {
  color: rgb(var(--ink));
}
.content {
  flex: 1;
  overflow-y: auto;
}
.content-inner {
  margin: 0 auto;
  max-width: 80rem;
  padding: 1.5rem;
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.page-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-header p {
  margin: 0.25rem 0 0;
  max-width: 42rem;
  font-size: 14px;
  color: rgb(var(--ink-muted));
}
.page-header .meta {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.page-header .actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid rgb(var(--line));
  border-radius: 0.5rem;
  background: rgb(var(--surface));
  padding: 1rem;
}
.card + .card,
.card + .table-wrap,
.table-wrap + .card {
  margin-top: 1rem;
}
.card-title {
  margin-bottom: 0.75rem;
  font-size: 14px;
  font-weight: 600;
}
.card.danger-zone {
  border-color: rgb(var(--danger) / 0.35);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
a.btn,
a.rail-brand-name {
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: rgb(var(--accent));
  color: rgb(var(--canvas));
}
.btn-primary:hover:not(:disabled) {
  background: rgb(var(--accent-soft));
}
.btn-secondary {
  background: rgb(var(--surface));
  color: rgb(var(--ink));
  border-color: rgb(var(--line));
}
.btn-secondary:hover:not(:disabled) {
  background: rgb(var(--surface-2));
}
.btn-danger {
  background: rgb(var(--danger) / 0.9);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: rgb(var(--danger));
}
.btn-ghost {
  background: transparent;
  color: rgb(var(--ink-muted));
}
.btn-ghost:hover:not(:disabled) {
  background: rgb(var(--surface));
  color: rgb(var(--ink));
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  padding: 0.375rem;
  color: rgb(var(--ink-muted));
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover {
  background: rgb(var(--surface-2));
  color: rgb(var(--ink));
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.125rem 0.5rem;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-neutral {
  background: rgb(var(--surface-2));
  color: rgb(var(--ink-muted));
}
.badge-green {
  background: rgb(var(--success) / 0.15);
  color: rgb(var(--success-soft));
}
.badge-red {
  background: rgb(var(--danger) / 0.15);
  color: rgb(var(--danger-soft));
}
.badge-amber {
  background: rgb(var(--warning) / 0.15);
  color: rgb(var(--warning-soft));
}
.badge-blue {
  background: rgb(var(--accent) / 0.15);
  color: rgb(var(--accent-soft));
}

/* ── Fields ──────────────────────────────────────────────────────────────── */
.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.25rem;
}
.field > label {
  font-size: 12px;
  font-weight: 500;
  color: rgb(var(--ink-muted));
}
.field .hint {
  font-size: 12px;
  color: rgb(var(--ink-faint));
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  border: 1px solid rgb(var(--line));
  border-radius: 0.375rem;
  background: rgb(var(--surface));
  padding: 0.5rem 0.75rem;
  font-size: 14px;
  font-family: inherit;
  color: rgb(var(--ink));
  outline: none;
  transition: border-color 0.15s, background-color 0.15s;
}
input::placeholder,
textarea::placeholder {
  color: rgb(var(--ink-faint));
}
input:focus,
textarea:focus,
select:focus {
  border-color: rgb(var(--accent));
  background: rgb(var(--surface-2));
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}
.form-actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
/* Checkbox styled as the panel's Switch: a pill that slides. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  font-size: 14px;
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch .track {
  position: relative;
  width: 2.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  border-radius: 999px;
  background: rgb(var(--surface-2));
  transition: background-color 0.15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 0.875rem;
  height: 0.875rem;
  border-radius: 999px;
  background: rgb(var(--ink-faint));
  transition: transform 0.15s, background-color 0.15s;
}
.switch input:checked + .track {
  background: rgb(var(--accent) / 0.4);
}
.switch input:checked + .track::after {
  transform: translateX(1rem);
  background: rgb(var(--accent-soft));
}
.switch input:focus-visible + .track {
  outline: 2px solid rgb(var(--accent));
  outline-offset: 2px;
}

/* ── Key/value list ──────────────────────────────────────────────────────── */
/* Two columns like the panel's DescriptionList, widening to four only where
   there is real room — auto-fit alone stretched eight short values across the
   full 80rem and read as a scattered row. */
.kv-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem 1.5rem;
  margin: 0;
}
@media (min-width: 640px) {
  .kv-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (min-width: 1280px) {
  .kv-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
.kv dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgb(var(--ink-faint));
}
.kv dd {
  margin: 0.125rem 0 0;
  font-size: 14px;
  color: rgb(var(--ink));
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow: hidden;
  border: 1px solid rgb(var(--line));
  border-radius: 0.5rem;
  background: rgb(var(--surface));
}
.table-scroll {
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data thead {
  background: rgb(var(--panel));
}
table.data th {
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgb(var(--ink-faint));
  white-space: nowrap;
}
table.data td {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid rgb(var(--line-soft));
  vertical-align: middle;
}
table.data tbody tr {
  transition: background-color 0.15s;
}
table.data tbody tr.clickable {
  cursor: pointer;
}
table.data tbody tr.clickable:hover {
  background: rgb(var(--surface-2) / 0.6);
}
.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-top: 1px solid rgb(var(--line));
  background: rgb(var(--panel));
  padding: 0.5rem 0.75rem;
  font-size: 12px;
  color: rgb(var(--ink-muted));
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
}
.empty .glyph {
  margin-bottom: 0.75rem;
  border: 1px solid rgb(var(--line-soft));
  border-radius: 999px;
  background: rgb(var(--panel));
  padding: 0.625rem;
  color: rgb(var(--ink-faint));
  line-height: 0;
}
.empty .title {
  font-size: 14px;
  font-weight: 500;
}
.empty .desc {
  margin-top: 0.25rem;
  max-width: 24rem;
  font-size: 12px;
  color: rgb(var(--ink-faint));
}

/* ── Notes ───────────────────────────────────────────────────────────────── */
.error-note {
  border: 1px solid rgb(var(--danger) / 0.3);
  border-radius: 0.375rem;
  background: rgb(var(--danger) / 0.1);
  padding: 0.5rem 0.75rem;
  font-size: 14px;
  color: rgb(var(--danger-soft));
}
pre.code {
  margin: 0;
  border: 1px solid rgb(var(--line-soft));
  border-radius: 0.5rem;
  background: rgb(var(--code-bg));
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: rgb(var(--ink-code));
}

/* The generated key, shown once on issue. */
.key-reveal {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid rgb(var(--accent) / 0.35);
  border-radius: 0.5rem;
  background: rgb(var(--accent) / 0.08);
  padding: 0.625rem 0.75rem;
}
.key-reveal code {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: rgb(var(--ink-code));
}

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-wrap {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-wrap .card {
  width: 100%;
  max-width: 24rem;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.login-brand .sunburst {
  color: rgb(var(--accent-soft));
}
.login-brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(0 0 0 / 0.6);
  padding: 1rem;
  animation: overlay-in 0.15s ease-out;
}
.modal {
  width: 100%;
  max-width: 28rem;
  border: 1px solid rgb(var(--line));
  border-radius: 0.5rem;
  background: rgb(var(--surface));
  padding: 1.25rem;
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.45);
  animation: dialog-in 0.18s ease-out;
}
.modal h2 {
  margin: 0 0 0.75rem;
  font-size: 18px;
  font-weight: 600;
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 70;
  display: flex;
  width: 100%;
  max-width: 24rem;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  border: 1px solid rgb(var(--line));
  border-radius: 0.5rem;
  background: rgb(var(--panel));
  padding: 0.625rem 0.75rem;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.4);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast.success {
  border-color: rgb(var(--success) / 0.35);
  color: rgb(var(--success-soft));
}
.toast.danger {
  border-color: rgb(var(--danger) / 0.35);
  color: rgb(var(--danger-soft));
}
.toast.info {
  color: rgb(var(--accent-soft));
}
.toast .body {
  min-width: 0;
  flex: 1;
}
.toast .t-title {
  font-size: 14px;
  font-weight: 500;
}
.toast .t-desc {
  margin-top: 0.125rem;
  font-size: 12px;
  color: rgb(var(--ink-muted));
}

/* ── Motion ──────────────────────────────────────────────────────────────── */
@keyframes overlay-in {
  from {
    opacity: 0;
  }
}
@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(10px);
  }
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
}
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
.view {
  animation: fade-up 0.25s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .view,
  .toast,
  .modal,
  .modal-backdrop {
    animation: none;
  }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 16rem;
  }
  .rail.mobile-open {
    transform: translateX(0);
  }
  .rail.collapsed {
    width: 16rem;
  }
  .rail.collapsed .nav-link span,
  .rail.collapsed .rail-brand-name,
  .rail.collapsed .nav-group-label {
    display: initial;
  }
  .rail.collapsed .nav-group-rule {
    display: none;
  }
  .scrim {
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgb(0 0 0 / 0.6);
  }
  .content-inner {
    padding: 1rem;
  }
}
@media (min-width: 1024px) {
  .only-mobile {
    display: none !important;
  }
}
