/* ==========================================================================
   Design tokens & UI system
   ========================================================================== */

:root,
:root[data-theme='light'] {
  --rc-font-sans: 'Inter Variable', 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  --rc-font-display: 'Object Sans', 'Inter Variable', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --rc-font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  color-scheme: light;

  --rc-bg: #f9fafc;
  --rc-surface: #ffffff;
  --rc-surface-subtle: #f9fafc;
  --rc-surface-hover: #f2f3f5;
  --rc-surface-sunken: #f2f3f5;
  --rc-border: #dfe1e6;
  --rc-border-strong: #cbcdd4;
  --rc-border-subtle: #f2f3f5;

  --rc-text-primary: #1d1f25;
  --rc-text-secondary: #505259;
  --rc-text-muted: #75777e;
  --rc-text-faint: #8a8d95;

  --rc-primary: #606dff;
  --rc-primary-hover: #5256fd;
  --rc-primary-soft: #f6f8ff;
  --rc-primary-border: #d0dbff;
  --rc-brand: #f2545b;

  --rc-indigo: #606dff;
  --rc-coral: #de2a39;
  --rc-coral-soft: #fef2f2;
  --rc-coral-border: #fecaca;
  --rc-emerald: #1a8a5a;
  --rc-emerald-soft: #ecfdf5;
  --rc-emerald-border: #a7f3d0;
  --rc-amber: #b9690f;
  --rc-amber-soft: #fffbeb;
  --rc-amber-border: #fde68a;
  --rc-sky: #0284c7;

  --rc-shadow-card: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0.5px 0 rgba(0, 0, 0, 0.05), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
  --rc-shadow-pop: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.1);
  --rc-nav-hover: #f2f3f5;
  --rc-nav-active: #ffffff;
  --rc-scrollbar: #cbcdd4;
  --rc-scrollbar-hover: #a2a4ab;
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --rc-bg: #1d1f25;
  --rc-surface: #14161b;
  --rc-surface-subtle: #181a20;
  --rc-surface-hover: #2d2f35;
  --rc-surface-sunken: #1d1f25;
  --rc-border: #2d2f35;
  --rc-border-strong: #505259;
  --rc-border-subtle: #22252b;

  --rc-text-primary: #f2f3f5;
  --rc-text-secondary: #cbcdd4;
  --rc-text-muted: #a2a4ab;
  --rc-text-faint: #75777e;

  --rc-primary: #778aff;
  --rc-primary-hover: #b4c5fe;
  --rc-primary-soft: #1f1f4f;
  --rc-primary-border: #343794;
  --rc-brand: #f2545b;

  --rc-indigo: #778aff;
  --rc-coral: #feafb2;
  --rc-coral-soft: rgba(254, 175, 178, 0.12);
  --rc-coral-border: rgba(254, 175, 178, 0.3);
  --rc-emerald: #6fd3a0;
  --rc-emerald-soft: rgba(111, 211, 160, 0.12);
  --rc-emerald-border: rgba(111, 211, 160, 0.3);
  --rc-amber: #fad7a2;
  --rc-amber-soft: rgba(250, 215, 162, 0.12);
  --rc-amber-border: rgba(250, 215, 162, 0.3);
  --rc-sky: #38bdf8;

  --rc-shadow-card: 0 0 0 0.5px rgba(255, 255, 255, 0.04);
  --rc-shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.55);
  --rc-nav-hover: rgba(45, 47, 53, 0.35);
  --rc-nav-active: rgba(45, 47, 53, 0.51);
  --rc-scrollbar: #2d2f35;
  --rc-scrollbar-hover: #505259;
}

@media (prefers-contrast: more) {
  :root {
    --rc-border: #94a3b8;
    --rc-border-strong: #64748b;
    --rc-text-muted: #334155;
  }
  :root[data-theme='dark'] {
    --rc-border: #64748b;
    --rc-border-strong: #94a3b8;
    --rc-text-muted: #cbd5e1;
  }
}

@media (forced-colors: active) {
  .rc-card,
  .kpi-card,
  .auth-card,
  .app-panel,
  .rc-dialog {
    border: 1px solid CanvasText;
    box-shadow: none;
  }
}

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

html {
  font-family: var(--rc-font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-padding-top: calc(3.5rem + env(safe-area-inset-top, 0px));
  scroll-padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--rc-bg);
  color: var(--rc-text-primary);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100dvh;
  overflow-wrap: break-word;
  transition: background-color 160ms ease, color 160ms ease;
}

h1, h2, h3, h4 {
  font-family: var(--rc-font-display);
  color: var(--rc-text-primary);
  margin: 0;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

a {
  color: var(--rc-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:where(a, code) {
  overflow-wrap: anywhere;
}

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

.tabular-nums {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

::selection {
  background: var(--rc-primary-soft);
  color: var(--rc-text-primary);
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rc-scrollbar); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--rc-scrollbar-hover); }

/* ==========================================================================
   Brand marks
   ========================================================================== */
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f2545b 0%, #606dff 100%);
  color: #ffffff;
  font-family: var(--rc-font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.brand-mark-lg {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 18px;
  margin: 0 auto 12px;
}

/* ==========================================================================
   Growth App Shell (52px topbar, 212px borderless sidebar, rounded panel)
   ========================================================================== */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--rc-bg);
}

.app-topbar {
  height: 52px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--rc-bg);
  user-select: none;
}

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

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--rc-text-primary);
  font-family: var(--rc-font-display);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  padding: 2px 4px;
  border-radius: 8px;
}

.topbar-brand:hover {
  text-decoration: none;
  opacity: 0.9;
}

.domain-chip {
  display: none;
  font-family: var(--rc-font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--rc-text-muted);
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  border-radius: 6px;
  padding: 2px 7px;
}

@media (min-width: 640px) {
  .domain-chip { display: inline-flex; align-items: center; }
}

.user-pill {
  display: none;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--rc-text-secondary);
  max-width: 240px;
}

@media (min-width: 768px) {
  .user-pill { display: inline-flex; }
}

.user-pill-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-circle {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--rc-primary);
  color: #ffffff;
  font-family: var(--rc-font-display);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
}

.app-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

@media (min-width: 768px) {
  .app-body {
    padding: 0 4px 4px;
  }
}

.app-sidebar {
  display: none;
  width: 212px;
  flex-shrink: 0;
  position: sticky;
  top: 52px;
  height: calc(100dvh - 56px);
  flex-direction: column;
  justify-content: space-between;
  padding: 2px 4px 6px;
  user-select: none;
  transition: width 180ms ease;
}

@media (min-width: 768px) {
  .app-sidebar {
    display: flex;
  }
}

.app-sidebar.collapsed {
  width: 58px;
}

.app-sidebar.collapsed .nav-section-title,
.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .nav-badge {
  display: none;
}

.app-sidebar.collapsed .nav-divider {
  display: block;
}

.app-sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px 8px;
}

.nav-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.nav-divider {
  display: none;
  margin: 6px 10px;
  border-top: 1px solid var(--rc-border);
}

.nav-item {
  position: relative;
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--rc-text-primary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 400;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.nav-item:hover {
  background: var(--rc-nav-hover);
  text-decoration: none;
}

.nav-item-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.nav-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--rc-text-secondary);
  flex-shrink: 0;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item-active,
.nav-item-active:hover {
  background: var(--rc-nav-active);
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 0.5px 0 rgba(0, 0, 0, 0.06), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
}

:root[data-theme='dark'] .nav-item-active,
:root[data-theme='dark'] .nav-item-active:hover {
  box-shadow: 0 0 0 1px var(--rc-border);
}

.nav-item-active .nav-icon {
  color: var(--rc-primary);
}

.app-panel {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--rc-surface);
  border-top: 1px solid var(--rc-border);
  padding: 16px 14px 40px;
}

@media (min-width: 768px) {
  .app-panel {
    border: 1px solid var(--rc-border);
    border-radius: 12px;
    box-shadow: var(--rc-shadow-card);
    height: calc(100dvh - 56px);
    overflow-y: auto;
    padding: 20px 24px 48px;
  }
}

.page-inner {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ==========================================================================
   Page Header & KPI Tiles
   ========================================================================== */
.page-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 640px) {
  .page-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.page-title {
  font-family: var(--rc-font-display);
  font-size: 1.5rem;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--rc-text-primary);
}

.page-subtitle {
  font-size: 0.8125rem;
  color: var(--rc-text-muted);
  margin: 4px 0 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  width: 100%;
}

@media (min-width: 1100px) {
  .kpi-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .kpi-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  border-radius: 8px;
  padding: 14px 16px;
  min-height: 126px;
  text-align: left;
  transition: border-color 140ms ease, background-color 140ms ease;
}

button.kpi-card {
  cursor: pointer;
  font-family: inherit;
}

.kpi-card:hover {
  border-color: var(--rc-primary-border);
  background: var(--rc-surface-subtle);
}

.kpi-card-active {
  border-color: var(--rc-primary);
  box-shadow: inset 0 0 0 1px var(--rc-primary);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi-label {
  font-family: var(--rc-font-display);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--rc-text-muted);
}

.num-display {
  font-family: var(--rc-font-display);
  font-size: 32px;
  line-height: 40px;
  font-weight: 700;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
  margin: 6px 0;
  color: var(--rc-text-primary);
}

.num-display-sm {
  font-size: 24px;
  line-height: 32px;
}

.tone-positive { color: var(--rc-emerald); }
.tone-negative { color: var(--rc-coral); }
.tone-accent { color: var(--rc-primary); }

.kpi-sub {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--rc-text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Cards, Segmented Controls & Toolbars
   ========================================================================== */
.rc-card {
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  border-radius: 10px;
  box-shadow: var(--rc-shadow-card);
  overflow: hidden;
}

.rc-card-subtle {
  background: var(--rc-surface-subtle);
  border: 1px solid var(--rc-border);
  border-radius: 8px;
  padding: 16px;
}

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

.rc-card-title {
  font-family: var(--rc-font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: var(--rc-text-primary);
}

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

.segmented-track {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--rc-surface-sunken);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--rc-border);
  max-width: 100%;
  overflow-x: auto;
}

.segmented-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.35;
  font-weight: 500;
  color: var(--rc-text-muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

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

.segmented-btn-active {
  background: var(--rc-surface);
  color: var(--rc-text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1);
}

:root[data-theme='dark'] .segmented-btn-active {
  background: var(--rc-surface-hover);
  box-shadow: 0 0 0 1px var(--rc-border-strong);
}

.segmented-btn-icon {
  padding: 4px 7px;
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn:hover { text-decoration: none; }
.btn:focus-visible,
.icon-btn:focus-visible,
.nav-item:focus-visible,
.segmented-btn:focus-visible {
  outline: 2px solid var(--rc-primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--rc-primary);
  color: #ffffff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--rc-primary-hover); }

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

.btn-danger {
  background: var(--rc-coral-soft);
  color: var(--rc-coral);
  border-color: var(--rc-coral-border);
}
.btn-danger:hover {
  background: #de2a39;
  border-color: #de2a39;
  color: #ffffff;
}

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 10px 16px; font-size: 14px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--rc-border);
  background: var(--rc-surface);
  color: var(--rc-text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

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

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

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--rc-text-secondary);
  margin-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--rc-border);
  background: var(--rc-surface);
  color: var(--rc-text-primary);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--rc-text-faint);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--rc-primary);
  box-shadow: 0 0 0 3px rgba(96, 109, 255, 0.16);
}

.input-lg {
  padding: 10px 12px;
  font-size: 14px;
}

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

.input-prefix-icon {
  position: absolute;
  left: 11px;
  color: var(--rc-text-faint);
  pointer-events: none;
  display: inline-flex;
}

.input-wrap input.has-prefix { padding-left: 34px; }
.input-wrap input.has-suffix { padding-right: 38px; }

.input-eye-btn {
  position: absolute;
  right: 6px;
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--rc-text-muted);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.input-eye-btn:hover {
  background: var(--rc-surface-hover);
  color: var(--rc-text-primary);
}

.search-input-inline {
  width: 240px;
  max-width: 100%;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--rc-text-secondary);
  cursor: pointer;
  margin-bottom: 8px;
}

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

/* ==========================================================================
   Pills & Alerts
   ========================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.4;
  background: var(--rc-primary-soft);
  color: var(--rc-primary);
  border: 1px solid var(--rc-primary-border);
}

.pill-neutral {
  background: var(--rc-surface-sunken);
  color: var(--rc-text-secondary);
  border-color: var(--rc-border);
}

.pill-green {
  background: var(--rc-emerald-soft);
  color: var(--rc-emerald);
  border-color: var(--rc-emerald-border);
}

.pill-red {
  background: var(--rc-coral-soft);
  color: var(--rc-coral);
  border-color: var(--rc-coral-border);
}

.pill-amber {
  background: var(--rc-amber-soft);
  color: var(--rc-amber);
  border-color: var(--rc-amber-border);
}

.alert-error {
  background: var(--rc-coral-soft);
  border: 1px solid var(--rc-coral-border);
  color: var(--rc-coral);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ==========================================================================
   Login / Auth Shell (mirrors Growth LoginPage.tsx)
   ========================================================================== */
.auth-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--rc-bg);
  position: relative;
}

.auth-theme-bar {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 20;
}

.auth-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--rc-shadow-pop);
}

.auth-header {
  text-align: center;
  margin-bottom: 22px;
}

.auth-footer-note {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--rc-border-subtle);
  text-align: center;
  font-size: 12px;
  color: var(--rc-text-muted);
}

/* ==========================================================================
   Portal App Cards
   ========================================================================== */
.grid-apps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.app-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  border-radius: 10px;
  padding: 16px;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.app-card:hover {
  border-color: var(--rc-primary-border);
  background: var(--rc-surface-subtle);
}

.app-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.app-icon-badge {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--rc-primary-soft);
  border: 1px solid var(--rc-primary-border);
  color: var(--rc-primary);
  font-family: var(--rc-font-display);
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
}

.app-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--rc-border-subtle);
}

/* ==========================================================================
   Responsive Data Tables (Growth rc-table + Modern Web Guidance @container)
   ========================================================================== */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  container-type: inline-size;
  scrollbar-gutter: stable;
  overscroll-behavior-x: contain;
}

.table-wrapper:focus-visible {
  outline: 2px solid var(--rc-primary);
  outline-offset: -2px;
}

.rc-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}

.rc-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
}

.rc-table th {
  background: var(--rc-surface-subtle);
  color: var(--rc-text-muted);
  font-family: var(--rc-font-display);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rc-border);
  white-space: nowrap;
}

.rc-table td {
  padding: 11px 14px;
  font-size: 13.5px;
  color: var(--rc-text-primary);
  border-bottom: 1px solid var(--rc-border-subtle);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

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

.rc-table tbody tr:hover td {
  background: var(--rc-surface-subtle);
}

.truncate-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@container (width < 580px) {
  .rc-table-responsive,
  .rc-table-responsive thead,
  .rc-table-responsive tbody,
  .rc-table-responsive tr,
  .rc-table-responsive th,
  .rc-table-responsive td {
    display: block;
  }

  .rc-table-responsive thead {
    display: none;
  }

  .rc-table-responsive tbody tr {
    border-bottom: 1px solid var(--rc-border);
    padding: 8px 12px;
  }

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

  .rc-table-responsive td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 2px;
    border-bottom: 1px dashed var(--rc-border-subtle);
    text-align: right;
  }

  .rc-table-responsive td:last-child {
    border-bottom: none;
  }

  .rc-table-responsive td[data-label]::before {
    content: attr(data-label);
    font-family: var(--rc-font-display);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--rc-text-muted);
    text-align: left;
    flex-shrink: 0;
  }

  .rc-table-responsive .truncate-cell {
    max-width: 60%;
  }
}

/* ==========================================================================
   Roles & Permissions Matrix
   ========================================================================== */
.rbac-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

@media (min-width: 960px) {
  .rbac-grid {
    grid-template-columns: 1fr 2fr;
  }
}

.rbac-role-card {
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.rbac-role-card:last-child {
  margin-bottom: 0;
}

.perm-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

/* ==========================================================================
   Native <dialog> Modals & Mobile Drawer (Modern Web Guidance)
   ========================================================================== */
dialog.rc-dialog {
  width: min(500px, calc(100vw - 24px));
  max-height: min(90dvh, 720px);
  padding: 0;
  margin: auto;
  border: 1px solid var(--rc-border);
  border-radius: 12px;
  background: var(--rc-surface);
  color: var(--rc-text-primary);
  box-shadow: var(--rc-shadow-pop);
  overflow: hidden;
}

dialog.rc-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}

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

.dialog-header h1 {
  font-family: var(--rc-font-display);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0;
}

.dialog-body {
  padding: 18px;
  overflow-y: auto;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  margin-top: 6px;
  border-top: 1px solid var(--rc-border-subtle);
}

/* Mobile Slide-Out Drawer (<dialog>) */
dialog.rc-drawer {
  width: min(272px, 84vw);
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--rc-border);
  border-radius: 0;
  background: var(--rc-surface);
  color: var(--rc-text-primary);
  box-shadow: var(--rc-shadow-pop);
}

dialog.rc-drawer[open] {
  display: flex;
  flex-direction: column;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rc-border);
}

.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.drawer-foot {
  padding: 12px 14px;
  border-top: 1px solid var(--rc-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  background: var(--rc-surface);
  border: 1px solid var(--rc-border);
  border-left: 3px solid var(--rc-emerald);
  color: var(--rc-text-primary);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--rc-shadow-pop);
  display: none;
  max-width: min(360px, calc(100vw - 32px));
}

.toast.show { display: block; }
.toast.toast-error { border-left-color: var(--rc-coral); }
