:root {
  --bg-canvas: #060D1D;
  --bg-surface: #0C152A;
  --bg-surface-hover: #121E3A;
  --bg-input: #081022;
  --border: rgba(90, 96, 128, 0.35);
  --border-strong: rgba(177, 127, 255, 0.45);
  --text-primary: #FFFFFF;
  --text-secondary: #C9CFE2;
  --text-muted: #8E97B3;
  --accent-primary: #A855F7;
  --accent-primary-hover: #B17FFF;
  --accent-primary-soft: rgba(168, 85, 247, 0.16);
  --accent-deep: #7030A0;
  --accent-cyan: #22D3EE;
  --accent-cyan-soft: rgba(34, 211, 238, 0.14);
  --status-success: #34D399;
  --status-success-soft: rgba(52, 211, 153, 0.14);
  --status-warn: #FBBF24;
  --status-warn-soft: rgba(251, 191, 36, 0.14);
  --status-danger: #F472B6;
  --status-danger-soft: rgba(244, 114, 182, 0.15);

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "Fira Code", SFMono-Regular, Menlo, monospace;

  --sidebar-width: 240px;
  --topbar-height: 56px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-modal: 0 24px 64px rgba(2, 6, 18, 0.78);
}

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

[x-cloak] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-canvas);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-cyan);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4 {
  margin: 0;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

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

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

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

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

/* App Shell */

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  height: var(--topbar-height);
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
  text-decoration: none;
}

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

.brand-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-deep));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14) inset;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-section-label {
  padding: 10px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-link-active {
  background: var(--accent-primary-soft);
  color: var(--text-primary);
  border-left-color: var(--accent-primary);
}

.nav-ext {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(6, 13, 29, 0.45);
}

.user-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-meta {
  min-width: 0;
}

.user-name {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-backdrop {
  display: none;
}

/* Main Column & Topbar */

.main-col {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  min-height: var(--topbar-height);
  padding: 10px 32px;
  background: rgba(6, 13, 29, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mobile-menu-btn {
  display: none;
}

.topbar-title-group {
  min-width: 0;
}

.topbar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
}

.topbar-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.page-body {
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding: 24px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

/* Alerts */

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.alert-error {
  background: var(--status-danger-soft);
  border-color: rgba(244, 114, 182, 0.45);
  color: #FCE7F3;
}

.alert-notice {
  background: var(--status-success-soft);
  border-color: rgba(52, 211, 153, 0.4);
  color: #D1FAE5;
}

/* Cards & Stats */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 16px 18px;
}

.card-body-flush {
  padding: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: rgba(12, 21, 42, 0.45);
}

.empty-state-title {
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 4px;
}

/* Tables */

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-secondary);
}

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

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

.table th.num,
.table td.num {
  text-align: right;
  white-space: nowrap;
}

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

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.25;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  text-decoration: none;
}

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

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

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

.btn-primary:active {
  background: var(--accent-deep);
}

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

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: #172647;
}

.btn-danger {
  background: var(--status-danger-soft);
  color: var(--status-danger);
  border-color: rgba(244, 114, 182, 0.35);
}

.btn-danger:hover {
  background: rgba(244, 114, 182, 0.25);
  border-color: rgba(244, 114, 182, 0.6);
}

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

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

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* Badges & Pills */

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-purple {
  background: var(--accent-primary-soft);
  color: #D8B4FE;
  border-color: rgba(168, 85, 247, 0.3);
}

.badge-cyan {
  background: var(--accent-cyan-soft);
  color: var(--accent-cyan);
  border-color: rgba(34, 211, 238, 0.3);
}

.badge-green {
  background: var(--status-success-soft);
  color: var(--status-success);
  border-color: rgba(52, 211, 153, 0.3);
}

.badge-amber {
  background: var(--status-warn-soft);
  color: var(--status-warn);
  border-color: rgba(251, 191, 36, 0.3);
}

.badge-pink {
  background: var(--status-danger-soft);
  color: var(--status-danger);
  border-color: rgba(244, 114, 182, 0.3);
}

.badge-muted {
  background: rgba(142, 151, 179, 0.14);
  color: var(--text-muted);
  border-color: var(--border);
}

.scope-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.scope-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--bg-input);
  color: var(--accent-cyan);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* Tabs */

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 14px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}

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

.tab-active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-primary);
}

/* Forms */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

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

.field-full {
  grid-column: 1 / -1;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

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

.input,
.select,
.textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input.mono,
.textarea.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.18);
}

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

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 6px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.checkbox-row:hover {
  border-color: var(--border-strong);
}

.checkbox-row input[type="checkbox"] {
  accent-color: var(--accent-primary);
  margin: 0;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

/* Breadcrumb & Filter Bar */

.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 9px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

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

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.filter-bar .field {
  flex: 1 1 150px;
  min-width: 130px;
}

.filter-bar .field-compact {
  flex: 0 1 120px;
  min-width: 100px;
}

/* Secret Banner & Code Block */

.secret-banner {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(34, 211, 238, 0.08));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.secret-banner-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.secret-banner-title {
  color: var(--text-primary);
  font-size: 14.5px;
  font-weight: 600;
}

.code-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.code-block pre,
.code-block code {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent-cyan);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Release metadata bar */

.release-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 0 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 7, 18, 0.76);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
}

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

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* HTMX Indicator */

.htmx-indicator {
  display: none;
  font-size: 12px;
  color: var(--accent-cyan);
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Toast Stack */

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 360px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-modal);
}

.toast-success {
  border-color: rgba(52, 211, 153, 0.55);
}

.toast-error {
  border-color: rgba(244, 114, 182, 0.55);
}

.toast-info {
  border-color: rgba(34, 211, 238, 0.55);
}

/* Standalone Login */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(600px 300px at 50% 0%, rgba(168, 85, 247, 0.16), transparent),
    var(--bg-canvas);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-modal);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.login-heading {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.login-copy {
  font-size: 13.5px;
  color: var(--text-muted);
}

/* Responsive */

@media (max-width: 960px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 800px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .sidebar-backdrop.sidebar-open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(3, 7, 18, 0.65);
    z-index: 35;
  }

  .main-col {
    margin-left: 0;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .topbar {
    padding: 10px 16px;
  }

  .page-body {
    padding: 16px 16px 40px;
  }

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

@media (max-width: 520px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }
}
