:root {
  /* Light content palette - stat cards, table, body */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-muted: #f1f2f7;
  --border: #e4e6ef;
  --border-strong: #d6d9e5;
  --text: #15172b;
  --text-muted: #6b7086;
  --text-faint: #9598ab;

  /* "Mint Blues" - the dashboard's own brand palette (chrome: header,
     footer, links, active states, avatars). Module tags use their own
     dedicated palette instead - see MODULE_PALETTE in app.js. */
  --accent: #197bbd;
  --accent-strong: #137294;
  --accent-soft: #8cbdde;
  --dev-accent: #5e6e79;
  --success: #0f9d58;
  --error-bg: #fdecec;
  --error-text: #b3261e;
  --error-border: #f6c9c7;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Dark palette - deliberately used for the header/footer "frame" only,
     so the design is a fixed combination of dark + light, not an
     OS-preference toggle between two all-light/all-dark states. */
  --header-bg: #0d3e5f;
  --header-bg-alt: #137294;
  --header-border: rgba(140, 189, 222, 0.25);
  --header-text: #f1f5f9;
  --header-text-muted: #8cbdde;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.75rem;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid var(--header-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--header-text-muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--header-bg-alt);
  border: 1px solid var(--header-border);
  border-radius: var(--radius-pill);
  padding: 0.45rem 0.85rem;
  transition: border-color 0.15s ease;
}

.search-field:focus-within {
  border-color: var(--accent);
}

.search-icon {
  width: 16px;
  height: 16px;
  color: var(--header-text-muted);
  flex-shrink: 0;
}

#search-input {
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--header-text);
  width: 180px;
}

#search-input::placeholder {
  color: var(--header-text-muted);
}

.segmented {
  display: inline-flex;
  background: var(--header-bg-alt);
  border: 1px solid var(--header-border);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.segmented-option {
  border: none;
  background: transparent;
  color: var(--header-text-muted);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented-option:hover {
  color: var(--header-text);
}

.segmented-option.is-active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ---------- Main / stats ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.75rem 2.5rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-value-sm {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ---------- Banner ---------- */

.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.1rem;
  font-size: 0.85rem;
}

.banner-error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

/* ---------- Table ---------- */

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

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 1.1rem 1.5rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border-strong);
}

tbody tr {
  transition: background 0.12s ease;
}

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

tbody tr:hover {
  background: var(--surface-muted);
}

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

/* ---------- Tenant identity (avatar + name/alias) ---------- */

.identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

.identity-text {
  display: flex;
  flex-direction: column;
  line-height: 1.35;
  min-width: 0;
}

.identity-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
}

.identity-alias {
  font-size: 0.78rem;
  color: var(--text-faint);
}

/* ---------- Environment badges ---------- */

.env-badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.env-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--border-strong);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.env-badge:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.env-badge svg {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  opacity: 0.7;
}

.env-badge-dev {
  color: var(--dev-accent);
  background: var(--surface-muted);
  border-color: var(--border-strong);
}

.env-badge-prod {
  color: var(--header-bg);
  background: var(--accent-soft);
  border-color: transparent;
}

/* ---------- Module chips ---------- */

.modules {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.modules-collapsed-view,
.modules-expanded-view {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.modules-expanded-view {
  display: none;
}

.modules.is-expanded .modules-collapsed-view {
  display: none;
}

.modules.is-expanded .modules-expanded-view {
  display: flex;
}

.module-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.module-chip-toggle {
  appearance: none;
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.module-chip-toggle:hover {
  background: var(--surface-muted);
  border-color: var(--text-faint);
  color: var(--text);
}

/* ---------- Skeleton loading ---------- */

.skeleton-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.skeleton-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  background: linear-gradient(90deg, var(--surface-muted) 25%, var(--border) 37%, var(--surface-muted) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}

.skeleton-cell {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-muted) 25%, var(--border) 37%, var(--surface-muted) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state strong {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

/* ---------- Mobile card list ---------- */

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tenant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}

.card-divider {
  height: 1px;
  background: var(--border);
  margin: 0.85rem 0;
}

.tenant-card .field {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.83rem;
}

.tenant-card .field:last-child {
  border-bottom: none;
}

.tenant-card .field-label {
  color: var(--text-faint);
  flex-shrink: 0;
  font-weight: 500;
}

.tenant-card .field-value {
  text-align: right;
  overflow-wrap: anywhere;
}

/* ---------- Footer ---------- */

.footer {
  text-align: center;
  color: var(--header-text-muted);
  font-size: 0.75rem;
  padding: 1.5rem;
  background: var(--header-bg);
  border-top: 1px solid var(--header-border);
}

.footer code {
  background: var(--header-bg-alt);
  color: var(--header-text);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

/* ---------- Responsive ---------- */

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

@media (max-width: 720px) {
  main {
    padding: 1.1rem 1rem 2rem;
  }
  .topbar {
    padding: 0.85rem 1rem;
  }
  #search-input {
    width: 120px;
  }
  .table-card {
    display: none;
  }
  .card-list {
    display: flex;
  }
}

@media (min-width: 721px) {
  .card-list {
    display: none;
  }
}
