/* ═══════════════════════════════════════════════════════════════════════════
   MING / VALIS Admin Dashboard — Dark Theme
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --admin-bg: #0f1117;
  --admin-surface: #1a1d27;
  --admin-surface-hover: #242836;
  --admin-border: #2a2e3a;
  --admin-text: #e4e4e7;
  --admin-text-muted: #8b8d97;
  --admin-accent: #6366f1;
  --admin-accent-hover: #818cf8;
  --admin-success: #22c55e;
  --admin-warning: #f59e0b;
  --admin-danger: #ef4444;
  --admin-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --admin-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --admin-radius: 8px;
}

/* ── Reset & base ────────────────────────────────────────────────────────── */

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

body {
  font-family: var(--admin-font);
  background: var(--admin-bg);
  color: var(--admin-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

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

.admin-header__title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.admin-header__app-toggle {
  display: flex;
  background: var(--admin-bg);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}

.admin-header__app-btn {
  padding: 6px 20px;
  border: none;
  border-radius: 18px;
  background: transparent;
  color: var(--admin-text-muted);
  font-family: var(--admin-font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.admin-header__app-btn:hover {
  color: var(--admin-text);
}

.admin-header__app-btn--active {
  background: var(--admin-accent);
  color: #fff;
}

.admin-header__status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--admin-text-muted);
}

.admin-header__status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--admin-danger);
  transition: background 0.3s;
}

.admin-header__status-dot--connected {
  background: var(--admin-success);
}

/* ── Auth section ────────────────────────────────────────────────────────── */

.admin-auth {
  max-width: 480px;
  margin: 80px auto 0;
  padding: 32px;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  text-align: center;
}

.admin-auth__inner {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.admin-auth__label {
  font-size: 14px;
  font-weight: 500;
  color: var(--admin-text-muted);
  margin-right: 4px;
}

.admin-auth__input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  background: var(--admin-bg);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  color: var(--admin-text);
  font-family: var(--admin-mono);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.admin-auth__input:focus {
  border-color: var(--admin-accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.admin-auth__note {
  margin-top: 12px;
  font-size: 12px;
  color: var(--admin-text-muted);
}

/* ── Shared inputs ───────────────────────────────────────────────────────── */

.admin-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--admin-bg);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  color: var(--admin-text);
  font-family: var(--admin-font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.admin-input:focus {
  border-color: var(--admin-accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.admin-input[type="number"] {
  font-family: var(--admin-mono);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border: none;
  border-radius: var(--admin-radius);
  font-family: var(--admin-font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  white-space: nowrap;
}

.admin-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.admin-btn--primary {
  background: var(--admin-accent);
  color: #fff;
}

.admin-btn--primary:hover:not(:disabled) {
  background: var(--admin-accent-hover);
}

.admin-btn--danger {
  background: var(--admin-danger);
  color: #fff;
  font-size: 12px;
  padding: 4px 12px;
}

.admin-btn--danger:hover:not(:disabled) {
  background: #dc2626;
}

.admin-btn--ghost {
  background: transparent;
  color: var(--admin-accent);
  border: 1px solid var(--admin-border);
}

.admin-btn--ghost:hover:not(:disabled) {
  background: var(--admin-surface-hover);
  border-color: var(--admin-accent);
}

.admin-btn--icon {
  background: transparent;
  color: var(--admin-text-muted);
  padding: 4px 8px;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: 4px;
}

.admin-btn--icon:hover {
  background: var(--admin-surface-hover);
  color: var(--admin-text);
  border-color: var(--admin-border);
}

.admin-btn--icon--copied {
  color: var(--admin-success);
}

/* Loading state */
.admin-loading {
  position: relative;
  pointer-events: none;
}

.admin-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: inherit;
  animation: admin-pulse 1s ease-in-out infinite;
}

@keyframes admin-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.admin-tabs {
  display: flex;
  gap: 4px;
  padding: 16px 24px 0;
  border-bottom: 1px solid var(--admin-border);
}

.admin-tabs__btn {
  padding: 10px 20px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--admin-text-muted);
  font-family: var(--admin-font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  margin-bottom: -1px;
}

.admin-tabs__btn:hover {
  color: var(--admin-text);
}

.admin-tabs__btn--active {
  color: var(--admin-accent);
  border-bottom-color: var(--admin-accent);
}

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

.admin-main {
  max-width: 960px;
  margin: 0 auto;
  padding-bottom: 60px;
}

.admin-section {
  padding: 24px;
}

.admin-section__title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
}

.admin-section__row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.admin-section__row .admin-input {
  flex: 1;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.admin-form--grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.admin-form__group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-form__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--admin-text-muted);
}

/* ── Cards ────────────────────────────────────────────────────────────────── */

.admin-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 20px;
  margin-top: 16px;
}

.admin-card--empty {
  text-align: center;
  color: var(--admin-text-muted);
  padding: 32px;
}

.admin-card--generated {
  border-color: var(--admin-accent);
  border-width: 2px;
}

.admin-card__field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--admin-border);
}

.admin-card__field:last-of-type {
  border-bottom: none;
}

.admin-card__label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--admin-text-muted);
  min-width: 120px;
  flex-shrink: 0;
}

.admin-card__value {
  font-size: 14px;
  color: var(--admin-text);
  word-break: break-all;
}

.admin-card__value--mono {
  font-family: var(--admin-mono);
  font-size: 13px;
}

.admin-card__value--highlight {
  color: var(--admin-accent);
  font-weight: 600;
  font-size: 15px;
}

.admin-card__actions {
  padding-top: 12px;
  margin-top: 4px;
}

/* ── Subsections ─────────────────────────────────────────────────────────── */

.admin-subsection {
  margin-bottom: 32px;
}

.admin-subsection__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.admin-subsection__title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--admin-text-muted);
}

.admin-subsection__header .admin-subsection__title {
  margin-bottom: 0;
}

/* ── Table ────────────────────────────────────────────────────────────────── */

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.admin-table th {
  background: var(--admin-surface);
  color: var(--admin-text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--admin-border);
  white-space: nowrap;
}

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

.admin-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.admin-table tbody tr:hover {
  background: var(--admin-surface-hover);
}

.admin-table__code {
  font-family: var(--admin-mono);
  font-size: 12px;
  white-space: nowrap;
}

.admin-table__note {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--admin-text-muted);
}

.admin-table__date {
  white-space: nowrap;
  color: var(--admin-text-muted);
  font-size: 12px;
}

/* ── Status badges ───────────────────────────────────────────────────────── */

.admin-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.admin-badge--active {
  background: rgba(34, 197, 94, 0.15);
  color: var(--admin-success);
}

.admin-badge--exhausted {
  background: rgba(245, 158, 11, 0.15);
  color: var(--admin-warning);
}

.admin-badge--revoked {
  background: rgba(239, 68, 68, 0.15);
  color: var(--admin-danger);
}

.admin-badge--expired {
  background: rgba(139, 141, 151, 0.15);
  color: var(--admin-text-muted);
}

/* ── Toast ────────────────────────────────────────────────────────────────── */

.admin-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.admin-toast {
  min-width: 280px;
  max-width: 420px;
  padding: 12px 20px;
  border-radius: var(--admin-radius);
  font-size: 14px;
  font-weight: 500;
  pointer-events: auto;
  animation: admin-toast-in 0.3s ease-out;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.admin-toast--success {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid var(--admin-success);
  color: var(--admin-success);
}

.admin-toast--error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--admin-danger);
  color: var(--admin-danger);
}

.admin-toast--info {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid var(--admin-accent);
  color: var(--admin-accent);
}

.admin-toast--out {
  animation: admin-toast-out 0.3s ease-in forwards;
}

@keyframes admin-toast-in {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes admin-toast-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
  }

  .admin-tabs {
    padding: 12px 16px 0;
    overflow-x: auto;
  }

  .admin-tabs__btn {
    padding: 8px 14px;
    font-size: 13px;
  }

  .admin-section {
    padding: 16px;
  }

  .admin-section__row {
    flex-direction: column;
  }

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

  .admin-card__field {
    flex-wrap: wrap;
  }

  .admin-card__label {
    min-width: 100%;
  }

  .admin-toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .admin-toast {
    min-width: auto;
    max-width: none;
  }
}
