/* ==========================================================================
   Seanime Manager V0.1 — Design Tokens & Stylesheet
   Three-layer token architecture (Primitive -> Semantic -> Component)
   Aligned with Seanime's obsidian dark aesthetic (#0c0c0c) + indigo accent.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* 1. Primitive Tokens */
  --p-black-950: #0c0c0c;
  --p-zinc-925: #121215;
  --p-zinc-900: #16161a;
  --p-zinc-850: #1c1c21;
  --p-zinc-800: #24242b;
  --p-zinc-700: #32323c;
  --p-zinc-500: #71717a;
  --p-zinc-400: #a1a1aa;
  --p-zinc-200: #e4e4e7;
  --p-zinc-50: #fafafa;

  --p-indigo-400: #818cf8;
  --p-indigo-500: #6366f1;
  --p-indigo-600: #4f46e5;
  --p-indigo-950: #1e1b4b;

  --p-green-400: #4ade80;
  --p-green-950: #052e16;
  --p-amber-400: #fbbf24;
  --p-amber-950: #451a03;
  --p-red-400: #f87171;
  --p-red-500: #ef4444;
  --p-red-950: #450a0a;

  /* 2. Semantic Tokens */
  --bg-canvas: var(--p-black-950);
  --bg-surface: var(--p-zinc-925);
  --bg-elevated: var(--p-zinc-900);
  --bg-hover: var(--p-zinc-850);
  --bg-input: #0f0f12;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-default: rgba(255, 255, 255, 0.13);
  --border-strong: rgba(255, 255, 255, 0.22);

  --text-primary: var(--p-zinc-50);
  --text-secondary: var(--p-zinc-400);
  --text-muted: var(--p-zinc-500);

  --accent: var(--p-indigo-500);
  --accent-hover: var(--p-indigo-600);
  --accent-soft: rgba(99, 102, 241, 0.14);
  --accent-text: var(--p-indigo-400);
  --focus-ring: #818cf8;

  --status-success-fg: var(--p-green-400);
  --status-success-bg: rgba(34, 197, 94, 0.12);
  --status-warn-fg: var(--p-amber-400);
  --status-warn-bg: rgba(245, 158, 11, 0.12);
  --status-danger-fg: var(--p-red-400);
  --status-danger-bg: rgba(239, 68, 68, 0.12);
  --status-neutral-fg: var(--p-zinc-400);
  --status-neutral-bg: rgba(161, 161, 170, 0.12);

  /* Typography & Scale */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* 3. Component Tokens */
  --btn-height: 40px;
  --btn-height-sm: 32px;
  --input-height: 42px;
  --header-height: 60px;
}

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

html {
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
}

a {
  color: var(--accent-text);
  text-decoration: none;
  transition: color 150ms ease;
}

a:hover {
  color: var(--text-primary);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -48px;
  left: var(--space-4);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.skip-link:focus {
  top: var(--space-3);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
}

/* Brand Mark */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid rgba(99, 102, 241, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-text);
  flex-shrink: 0;
}

.brand-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  padding: 1px 7px;
  border-radius: var(--radius-full);
}

/* ==========================================================================
   Auth Pages Layout (Login, Register, Reset, Status)
   ========================================================================== */

.auth-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  background-image: radial-gradient(
    ellipse 70% 45% at 50% 0%,
    rgba(99, 102, 241, 0.09),
    transparent 70%
  );
}

.auth-shell {
  width: 100%;
  max-width: 420px;
}

.auth-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.auth-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.auth-subtitle {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
  max-width: 38ch;
  text-wrap: pretty;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card-compact {
  padding: var(--space-5);
}

/* Forms */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--p-zinc-200);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.field-error {
  font-size: 0.8rem;
  color: var(--status-danger-fg);
}

.subdomain-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  flex-wrap: wrap;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input,
.select {
  width: 100%;
  height: var(--input-height);
  padding: 0 12px;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: border-color 150ms ease, background-color 150ms ease;
}

.input::placeholder {
  color: var(--text-muted);
}

.input:hover,
.select:hover {
  border-color: var(--border-strong);
}

.input:focus,
.select:focus {
  border-color: var(--accent);
}

.input-with-action {
  padding-right: 44px;
}

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

.password-toggle {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms ease, background-color 150ms ease;
}

.password-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.form-row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-height);
  padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn-full {
  width: 100%;
}

.btn-sm {
  height: var(--btn-height-sm);
  padding: 0 12px;
  font-size: 0.83rem;
  border-radius: var(--radius-sm);
}

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

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

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--status-danger-fg);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.24);
  border-color: rgba(239, 68, 68, 0.5);
}

.divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-5) 0 var(--space-4);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.auth-footer {
  margin-top: var(--space-5);
  text-align: center;
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Alerts & Badges */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
}

.alert:empty,
.hidden {
  display: none !important;
}

.alert-error {
  background: var(--status-danger-bg);
  border-color: rgba(239, 68, 68, 0.32);
  color: #fecaca;
}

.alert-success {
  background: var(--status-success-bg);
  border-color: rgba(34, 197, 94, 0.32);
  color: #bbf7d0;
}

.alert-info {
  background: var(--accent-soft);
  border-color: rgba(99, 102, 241, 0.32);
  color: #c7d2fe;
}

.alert-warn {
  background: var(--status-warn-bg);
  border-color: rgba(245, 158, 11, 0.32);
  color: #fde68a;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: 0.76rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-success {
  background: var(--status-success-bg);
  color: var(--status-success-fg);
}

.badge-warn {
  background: var(--status-warn-bg);
  color: var(--status-warn-fg);
}

.badge-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger-fg);
}

.badge-neutral {
  background: var(--status-neutral-bg);
  color: var(--status-neutral-fg);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* ==========================================================================
   Admin Panel Layout
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-height);
  background: rgba(12, 12, 12, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-inner {
  max-width: 1200px;
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.84rem;
  color: var(--p-zinc-200);
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-10);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.page-head h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

/* Tabs */
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color 150ms ease;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn[aria-selected="true"] {
  color: var(--text-primary);
}

.tab-btn[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

/* Metric Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.metric-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.metric-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Panels & Tables */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-5);
}

.panel-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.panel-subtitle {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.panel-body {
  padding: var(--space-5);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}

.data-table th {
  padding: 11px 16px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.015);
  white-space: nowrap;
}

.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

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

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

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

.inline-form {
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: var(--space-3);
  align-items: end;
}

.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.94rem;
  word-break: break-all;
}

.empty-state {
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.kv-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}

.kv-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.kv-key {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.kv-val {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-word;
}

/* Dialog / Modal */
dialog.modal {
  padding: 0;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  width: min(460px, calc(100vw - 32px));
  overscroll-behavior: contain;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.modal-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
}

.modal-body {
  padding: var(--space-5);
  font-size: 0.9rem;
  color: var(--p-zinc-200);
}

.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* Toast Notification */
.toast-region {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 380px;
}

.toast {
  padding: 12px 15px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 0.88rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}

.toast-success {
  border-color: rgba(34, 197, 94, 0.4);
}

.toast-error {
  border-color: rgba(239, 68, 68, 0.45);
}

/* Utilities (CSP style-src 'self' compliant — zero inline styles) */
.m-0 { margin: 0; }
.mt-4 { margin-top: var(--space-4); }
.mb-0 { margin-bottom: 0; }
.mb-3 { margin-bottom: var(--space-3); }
.mb-5 { margin-bottom: var(--space-5); }
.mt-3 { margin-top: var(--space-3); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--status-success-fg); }
.text-accent { color: var(--accent-text); }
.text-xs { font-size: 0.8rem; }
.text-sm-mono { font-size: 0.82rem; }
.justify-between { justify-content: space-between; }
.auth-shell-wide { max-width: 500px; }
.copy-helper {
  position: fixed;
  opacity: 0;
  pointer-events: none;
}

/* Responsive */
@media (max-width: 720px) {
  .topbar-inner,
  .page-container {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

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

  .user-pill .hide-sm {
    display: none;
  }

  .card {
    padding: var(--space-5);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
