:root {
  color-scheme: dark;
  --bg: #0b131f;
  --surface: #111b2c;
  --surface-soft: #152235;
  --card: #16263d;
  --border: rgba(255, 255, 255, 0.08);
  --primary: #3a86ff;
  --primary-dark: #2563eb;
  --accent: #7c5dff;
  --accent-soft: rgba(124, 93, 255, 0.28);
  --muted: #8ea0c2;
  --text: #f4f6fb;
  --danger: #ef476f;
  --success: #4ade80;
  --warning: #fbbf24;
  --font: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body.app-shell {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(circle at top, #16253c, var(--bg));
  color: var(--text);
  min-height: 100vh;
}

.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;
}

/* Header + Navigation */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(8, 12, 20, 0.8);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-mark {
  background: var(--accent);
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

.brand-text {
  font-size: 1rem;
  color: var(--muted);
}

.app-nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.account-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.tenant-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.tenant-switch-form {
  margin: 0;
}

.compact-select {
  min-height: 40px;
  padding-right: 0.35rem;
}

.compact-select select {
  padding: 0.45rem 0;
}

.account-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.9rem;
}

.inline-form {
  margin: 0;
}

.nav-link {
  padding: 0.5rem 1rem;
  border-radius: 0.65rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
  color: #fff;
  background: rgba(58, 134, 255, 0.2);
  box-shadow: 0 8px 20px rgba(58, 134, 255, 0.2);
}

:where(a, button, input, select, textarea, [role="button"], [tabindex]):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.app-main {
  padding: 2rem 1rem 3rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* Generic layout containers */
.layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.page-header h1 {
  margin: 0;
  font-size: 2rem;
}

.page-subtitle {
  margin-top: 0.4rem;
  color: rgba(255, 255, 255, 0.7);
}

/* Filters / inputs */
.filters {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 180px;
}

.filter.grow {
  flex: 1;
}

.filter label {
  font-size: 0.85rem;
  color: var(--muted);
}

.select-wrapper,
.input-wrapper {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.select-wrapper:focus-within,
.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(58, 134, 255, 0.3);
}

.select-wrapper select,
.input-wrapper input {
  background: transparent;
  border: none;
  color: var(--text);
  width: 100%;
  padding: 0.65rem 0;
  outline: none;
  font-size: 0.95rem;
}

.select-wrapper select {
  color-scheme: dark;
}

.select-wrapper select option,
.select-wrapper select optgroup {
  background: var(--surface-soft);
  color: var(--text);
}

.input-icon {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 0.75rem;
  padding: 0.7rem 1.5rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 10px 30px rgba(58, 134, 255, 0.25);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.message-stack {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.alert-banner {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 0.9rem 1rem;
  border-radius: 0.85rem;
}

.alert-banner.danger,
.alert-banner.error {
  border-color: rgba(239, 71, 111, 0.35);
  background: rgba(239, 71, 111, 0.12);
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 430px);
  gap: 1.5rem;
  align-items: stretch;
  min-height: calc(100vh - 12rem);
}

.auth-layout-compact {
  grid-template-columns: minmax(320px, 520px);
  justify-content: center;
  min-height: auto;
}

.auth-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.2rem;
  padding: 2rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
}

.auth-panel-hero {
  position: relative;
  overflow: hidden;
}

.auth-panel-hero::after {
  content: "";
  position: absolute;
  inset: auto -10% -20% auto;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124, 93, 255, 0.3), transparent 68%);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 0.6rem;
  color: var(--warning);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  font-weight: 700;
}

.auth-copy {
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.6;
}

.auth-list {
  margin: 1.2rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  display: grid;
  gap: 0.6rem;
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.auth-field {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
}

.auth-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface-soft);
  color: var(--text);
  padding: 0.85rem 0.95rem;
  font: inherit;
}

.auth-field input:focus {
  border-color: var(--primary);
  outline: 2px solid rgba(58, 134, 255, 0.18);
  outline-offset: 1px;
}

.field-help {
  color: var(--muted);
  line-height: 1.5;
}

.field-error {
  color: #ff8aa3;
}

@media (max-width: 900px) {
  .auth-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .app-header {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .app-nav,
  .account-tools {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 15px 25px rgba(6, 12, 22, 0.5);
}

.btn:active {
  transform: translateY(0);
  opacity: 0.9;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.08);
}

.btn.icon {
  padding: 0.35rem 0.6rem;
  font-size: 1.2rem;
  background: transparent;
  color: var(--muted);
}

.btn.wide {
  width: 100%;
}

/* Cards */
.card {
  background: var(--card);
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 1.5rem;
  box-shadow: 0 20px 35px rgba(7, 11, 17, 0.6);
  position: relative;
  overflow: hidden;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.muted.small {
  font-size: 0.8rem;
}

.badge {
  background: rgba(58, 134, 255, 0.15);
  color: #8fb6ff;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge.accent {
  background: rgba(124, 93, 255, 0.18);
  color: #b3a5ff;
}

.badge.danger {
  background: rgba(239, 71, 111, 0.18);
  color: #ff98b1;
}

.badge.success {
  background: rgba(74, 222, 128, 0.18);
  color: #a6f4c5;
}

/* Tables */
.table-card {
  padding: 1.5rem 0 0;
}

.table-head,
.table-footer {
  padding: 0 1.5rem;
}

.table-wrapper {
  margin-top: 1rem;
  max-height: 520px;
  overflow: auto;
}

.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table-wrapper th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 0.75rem 1.5rem;
  position: sticky;
  top: 0;
  background: rgba(11, 19, 31, 0.95);
  backdrop-filter: blur(4px);
}

.table-wrapper td {
  padding: 0.85rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.table-wrapper tbody tr {
  transition: background 0.2s ease;
}

.table-wrapper tbody tr:hover {
  background: rgba(58, 134, 255, 0.08);
}

.table-wrapper tr.empty td {
  text-align: center;
  color: var(--muted);
}

.table-footer {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1.5rem;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 60;
}

.toast {
  background: rgba(14, 23, 35, 0.95);
  border-radius: 0.8rem;
  padding: 0.8rem 1.1rem;
  min-width: 240px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 20px rgba(3, 7, 15, 0.6);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toast.success {
  border-color: rgba(74, 222, 128, 0.35);
}

.toast.error {
  border-color: rgba(239, 71, 111, 0.35);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 13, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 40;
  backdrop-filter: blur(6px);
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--surface);
  border-radius: 1rem;
  padding: 1.5rem;
  width: min(360px, calc(100% - 2rem));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 25px 55px rgba(6, 10, 18, 0.8);
  transform: translateY(0);
  transition: transform 0.2s ease;
}

.modal-backdrop.hidden .modal {
  transform: translateY(8px);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-input {
  flex-direction: column;
  align-items: flex-start;
  margin: 1rem 0;
}

.modal-input span {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.modal-input input,
.modal-input select {
  width: 100%;
  padding: 0.6rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 1rem;
}

@media (max-width: 720px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .filters {
    flex-direction: column;
  }

  .toast-container {
    right: 0.75rem;
    left: 0.75rem;
    bottom: 0.75rem;
  }

  .toast {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 900px) {
  .table-wrapper {
    max-height: none;
  }

  .table-wrapper table thead {
    display: none;
  }

  .table-wrapper table,
  .table-wrapper tbody,
  .table-wrapper tr,
  .table-wrapper td {
    display: block;
    width: 100%;
  }

  .table-wrapper tbody tr {
    padding: 0.6rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }

  .table-wrapper td {
    display: grid;
    grid-template-columns: minmax(120px, 42%) 1fr;
    gap: 0.75rem;
    align-items: start;
    padding: 0.45rem 0;
    border-top: none;
  }

  .table-wrapper td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04rem;
  }

  .table-wrapper tr.empty td {
    display: block;
    text-align: left;
  }

  .table-wrapper tr.empty td::before {
    content: "";
  }
}
