/* FlowNexa Admin & RAG Dashboard Modern Design System */

:root {
  /* ?? Primitive surfaces ?? */
  --bg-dark: #060911;
  --bg-surface: rgba(13, 18, 30, 0.95);
  --bg-card: rgba(18, 26, 43, 0.65);
  --bg-card-hover: rgba(23, 34, 56, 0.85);
  --bg-elevated: #0f172a;
  --border-color: rgba(255, 255, 255, 0.07);
  --border-highlight: rgba(255, 255, 255, 0.14);

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  /* >= 4.5:1 on --bg-elevated (WCAG AA body text); #64748b was ~3.7:1. Guarded by tests/a11y-core.test.js. */
  --text-dim: #7c8ba1;

  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.35);
  --purple: #8b5cf6;
  --purple-glow: rgba(139, 92, 246, 0.35);
  --cyan: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.35);
  --emerald: #10b981;
  --emerald-glow: rgba(16, 185, 129, 0.35);
  --amber: #f59e0b;
  --rose: #f43f5e;
  --brand-orange: #f97316;

  /* Semantic status ? prefer these over ad-hoc colors */
  --status-success: var(--emerald);
  --status-info: var(--cyan);
  --status-warning: var(--amber);
  --status-danger: var(--rose);
  --status-neutral: var(--text-dim);
  --status-accent: var(--purple);

  /* Semantic aliases (design system) */
  --surface-page: var(--bg-dark);
  --surface-card: var(--bg-card);
  --surface-elevated: var(--bg-elevated);
  --surface-subtle: rgba(15, 23, 42, 0.72);
  --surface-input: rgba(13, 20, 36, 0.9);
  --surface-hover: var(--bg-card-hover);
  --surface-interactive: rgba(255, 255, 255, 0.04);

  --border-default: var(--border-color);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-strong: var(--border-highlight);
  --border: var(--border-default);

  --text-primary: var(--text-main);
  --text: var(--text-primary);
  --text-secondary: var(--text-muted);
  --text-disabled: #475569;

  --accent-primary: var(--primary);
  --color-primary: var(--primary);
  --color-success: var(--emerald);
  /* Fill behind white text: #3b82f6 gives 3.7:1, these give >= 4.5:1 (WCAG AA). --primary stays for text/borders. */
  --primary-fill: #2563eb;
  --primary-fill-hover: #1d4ed8;
  --accent-secondary: var(--cyan);
  --danger: var(--status-danger);

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Radius: control/nested 8 ? surface 12 ? rare 16 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;
  --space-9: 40px;

  --control-height-sm: 32px;
  --control-height-md: 36px;
  --control-height-lg: 40px;
  --control-radius: var(--radius-sm);
  --control-padding-x: 12px;
  --icon-size-sm: 14px;
  --icon-size-md: 16px;
  --icon-size-lg: 18px;
  --icon-size-xl: 20px;
  --acc-row-height: 44px;
  --table-row-height: 48px;

  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.6);

  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 1000;
  --z-toast: 1100;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Background Radial Mesh Gradient */
.bg-grid-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(6, 182, 212, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 85% 20%, rgba(139, 92, 246, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 50% 80%, rgba(59, 130, 246, 0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* App Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  position: relative;
  z-index: 1;
}

/* Sidebar Backdrop for Mobile Drawer */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  z-index: 99;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
  display: block;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-mobile-toggle {
  display: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-mobile-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--cyan);
}

/* UX-005: the single flex rule for the header actions (scope badge, tenant selector, last update, refresh) at
   every width. Items wrap instead of overflowing; the selector takes the free space and ellipsizes. */
.top-bar-actions {
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 1vw, 1rem);
  flex-wrap: wrap;
  min-width: 0;
}

.top-bar-actions .tenant-selector-wrap {
  flex: 1 1 16rem;
  min-width: 0;
  max-width: 100%;
}

.top-bar-actions .tenant-select-dropdown {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Main Content - Full Page 100% Width */
.main-content {
  margin-left: 260px;
  width: calc(100% - 260px);
  flex: 1;
  padding: 2rem 2.5rem;
  max-width: none !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

/* Tenant Context Selector Dropdown */
.tenant-selector-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(18, 26, 43, 0.85);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.85rem;
  box-shadow: var(--shadow-sm);
}

.tenant-selector-logo,
.tenant-avatar {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.tenant-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.tenant-cell {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.tenant-cell-text {
  min-width: 0;
}

.tenant-select-dropdown {
  background: transparent;
  border: none;
  color: var(--cyan);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  outline: none;
  cursor: pointer;
  padding-right: 0.5rem;
}

.tenant-select-dropdown option {
  background: #0f172a;
  color: var(--text-main);
  font-weight: 500;
}

/* Table Toolbars */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  max-width: 380px;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  color: var(--text-dim);
}

.search-control {
  padding-left: 2.2rem !important;
}

.filter-pills {
  display: flex;
  gap: 0.35rem;
  background: rgba(13, 20, 36, 0.9);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.filter-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.filter-pill:hover {
  color: var(--text-main);
}

.filter-pill.active {
  background: var(--primary-fill);
  color: white;
}

/* Tenant detail sections (#/tenants/:id/<section>). One card per section, shown by the
   matching nav pill. `.locked` outranks `.active` (same specificity, declared later) so a
   section that needs a saved tenant stays hidden even if it is the requested one.
   Specificity must beat `.page-shell { display: flex }` (same elements also carry page-shell). */
.tenant-section-nav {
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.tenant-section,
.tenant-section.page-shell,
.card.tenant-section {
  display: none;
}

.tenant-section.active,
.tenant-section.page-shell.active,
.card.tenant-section.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: var(--space-5);
}

.tenant-section.locked,
.tenant-section.page-shell.locked,
.card.tenant-section.locked,
.filter-pill.locked {
  display: none;
}

.logo-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(249, 115, 22, 0.1);
  border: 1px solid rgba(249, 115, 22, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px rgba(249, 115, 22, 0.25);
}

.logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(249, 115, 22, 0.4));
}

.brand-name {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: block;
  background: linear-gradient(135deg, #F97316, #FBBF24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub-header {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  display: block;
}

.brand-dashboard-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: rgba(249, 115, 22, 0.12);
  color: #F97316;
  border: 1px solid rgba(249, 115, 22, 0.3);
}

/* User Profile Card & Logout (Bottom of Sidebar) + DB status card */
.sidebar-footer {
  margin-top: auto;
  flex-shrink: 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.user-profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(18, 26, 43, 0.85);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
}

.user-avatar-wrap {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid rgba(249, 115, 22, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.25);
  color: var(--rose);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: rgba(244, 63, 94, 0.25);
  color: #fff;
}

/* Login Page Overlay */
body.login-open {
  overflow: hidden;
}

.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(6, 9, 17, 0.96);
  backdrop-filter: blur(24px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin-bottom: 0.85rem;
}

.login-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
  margin-bottom: 0.3rem;
}

.login-form .form-field > label:not(.login-show-password) {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary, var(--text-muted));
}

.login-submit {
  width: 100%;
  justify-content: center;
  min-height: var(--control-height-md);
  margin-top: var(--space-4);
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.login-error {
  margin: 0.75rem 0 1rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--rose);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: rgba(244, 63, 94, 0.12);
  color: var(--text-main);
  font-size: 0.88rem;
  line-height: 1.45;
  text-align: left;
}

.login-error[hidden] {
  display: none;
}

.login-show-password {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
}

.login-form {
  text-align: left;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 10000; /* above the login overlay (9999): a failed login must be able to say why */
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 420px;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-highlight);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-success {
  border-left: 4px solid var(--emerald);
}

.toast-error {
  border-left: 4px solid var(--rose);
}

/* Background knowledge ingest progress (plan C3) */
.ingest-progress-host {
  position: fixed;
  bottom: 2rem;
  left: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 2000;
  max-width: calc(100vw - 4rem);
}

.ingest-progress-card {
  width: 320px;
  max-width: 100%;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-highlight);
  border-left: 4px solid var(--cyan);
  color: var(--text-main);
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
}

.ingest-progress-card.ingest-progress-failed {
  border-left-color: var(--rose);
}

.ingest-progress-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ingest-progress-track {
  height: 8px;
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.ingest-progress-fill {
  height: 100%;
  background: var(--cyan);
  transition: width 0.4s ease;
}

.ingest-progress-failed .ingest-progress-fill {
  background: var(--rose);
}

.ingest-progress-label {
  margin-top: 0.4rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #f87171;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.25);
}

/* Deprecated color-outline buttons ? alias to canonical outline / danger */
.btn-outline-cyan,
.btn-outline-purple,
.btn-outline-emerald,
.btn-outline-amber {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
.btn-outline-cyan:hover,
.btn-outline-purple:hover,
.btn-outline-emerald:hover,
.btn-outline-amber:hover {
  background: rgba(255, 255, 255, 0.06);
}
.btn-outline-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #f87171;
  border: 1px solid rgba(244, 63, 94, 0.3);
}
.btn-outline-danger:hover {
  background: rgba(244, 63, 94, 0.25);
}

.btn-icon {
  padding: var(--space-2);
  justify-content: center;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.action-buttons-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 0.4rem 0.75rem 0.2rem 0.75rem;
}

.breadcrumb-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}

.breadcrumb-item {
  color: var(--text-muted);
}

a.breadcrumb-item {
  text-decoration: none;
}

a.breadcrumb-item:hover,
a.breadcrumb-item:focus-visible {
  color: var(--text-main);
  text-decoration: underline;
}

.breadcrumb-sep {
  opacity: 0.5;
}

.breadcrumb-current {
  color: var(--cyan);
  font-weight: 600;
}

.last-updated-badge {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.16), rgba(139, 92, 246, 0.16));
  border-color: rgba(59, 130, 246, 0.35);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
  position: relative;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 25%; bottom: 25%;
  width: 3px;
  background: var(--cyan);
  border-radius: 4px;
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.db-status-card {
  background: rgba(13, 20, 36, 0.9);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
}

.db-status-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.35rem;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-indicator.online {
  background: var(--emerald);
  box-shadow: 0 0 10px var(--emerald);
}

.status-indicator.offline {
  background: var(--rose);
  box-shadow: 0 0 10px var(--rose);
}

.status-title {
  font-size: 0.82rem;
  font-weight: 600;
}

.db-details {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.page-title-area h1 {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Single title: keep in-page .page-header; suppress duplicate top-bar H1/subtitle.
   Breadcrumb + global actions stay. */
body:has(.tab-pane.active .page-header .text-page-title) .page-title-area > h1,
body:has(.tab-pane.active .page-header .text-page-title) .page-title-area > .page-subtitle,
body:has(#pane-tenant-detail.active .page-header .text-page-title) .page-title-area > h1,
body:has(#pane-tenant-detail.active .page-header .text-page-title) .page-title-area > .page-subtitle {
  display: none;
}

body:has(.tab-pane.active .page-header .text-page-title) .page-title-area,
body:has(#pane-tenant-detail.active .page-header .text-page-title) .page-title-area {
  padding-bottom: 0;
}

/* Buttons */
.btn {
  padding: 0 1.1rem;
  min-height: var(--control-height-md);
  border-radius: var(--control-radius);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  /* Default = secondary so bare `.btn` / `.btn.btn-sm` never fall back to browser white. */
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-default);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.25;
  box-shadow: none;
}

/* .btn { display: inline-flex } would otherwise override the HTML hidden attribute */
.btn[hidden],
button.btn[hidden] {
  display: none !important;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--border-highlight);
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary-fill);
  color: white;
  border-color: transparent;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-fill-hover);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--border-highlight);
}

/* Quiet tertiary ? for low-emphasis actions (copy, refresh lists, etc.) */
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  box-shadow: none;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-sm {
  padding: 0 0.75rem;
  font-size: 0.78rem;
  min-height: var(--control-height-sm);
}

.btn-md {
  padding: 0 1.1rem;
  font-size: 0.88rem;
  min-height: var(--control-height-md);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-strong);
}

/* Metric Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.metric-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-highlight);
  background: var(--bg-card-hover);
}

.metric-card.glow-cyan::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--primary));
}

.metric-card.glow-purple::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--purple), var(--rose));
}

.metric-card.glow-blue::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--cyan));
}

.metric-card.glow-amber::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--amber), var(--emerald));
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.metric-title {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-cyan { background: rgba(6, 182, 212, 0.12); color: var(--cyan); }
.icon-purple { background: rgba(139, 92, 246, 0.12); color: var(--purple); }
.icon-blue { background: rgba(59, 130, 246, 0.12); color: var(--primary); }
.icon-amber { background: rgba(245, 158, 11, 0.12); color: var(--amber); }

.metric-value {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1;
  margin-top: var(--space-1);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.metric-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Cards & Tables */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.glow-border-cyan {
  border-color: rgba(6, 182, 212, 0.3);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.05);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.card-header h3 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
}

/* minmax(0, 1fr): a plain 1fr track never shrinks below its content's min width, so a wide table in
   one column starved the other (handoff reason column ~10 px at 1440). Children get min-width: 0 for
   the same reason. */
.grid-2col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.grid-crm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.grid-2col > *,
.grid-crm > * {
  min-width: 0;
}

/* Split-table breakpoint (--bp-split, 1500px; media queries cannot read custom properties):
   two data tables side by side need ~1500 px of viewport, so leads/handoffs and RAG
   sources/documents stack below it. */
@media (max-width: 1500px) {
  .grid-2col.rag-split-grid,
  .grid-crm.leads-split-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

#handoffsTable {
  table-layout: fixed;
  width: 100%;
}

#handoffsTable th:nth-child(1),
#handoffsTable td:nth-child(1) {
  width: 26%;
}

#handoffsTable th:nth-child(2),
#handoffsTable td:nth-child(2) {
  width: 38%;
}

#handoffsTable th:nth-child(3),
#handoffsTable td:nth-child(3) {
  width: 18%;
}

#handoffsTable th:nth-child(4),
#handoffsTable td:nth-child(4) {
  width: 18%;
}

#handoffsTable .handoff-reason {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
  max-height: calc(1.35em * 2);
}

/* Stacked (full-width) handoff table: let columns size to content instead of fixed percentages. */
@media (max-width: 1500px) {
  #handoffsTable {
    table-layout: auto;
  }

  #handoffsTable th:nth-child(n),
  #handoffsTable td:nth-child(n) {
    width: auto;
  }
}

@media (max-width: 1280px) {
  .grid-2col, .grid-crm {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* UX-006: page-level lists (tenants, leads, sessions, knowledge) grow with the page and rely on their
   pagination; a capped inner scroller nested a second scrollbar inside the page. Only wide tables scroll (x). */
.table-responsive {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.88rem;
  vertical-align: middle;
}

.data-table select.form-control {
  min-width: 155px;
  width: auto;
  padding: 0.35rem 0.65rem !important;
  font-size: 0.8rem !important;
  font-weight: 600;
  background-color: rgba(15, 23, 42, 0.95) !important;
  color: var(--text-main) !important;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.data-table select.form-control option {
  background-color: #0f172a !important;
  color: #f1f5f9 !important;
  padding: 6px 10px;
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-danger { background: rgba(244, 63, 94, 0.15); color: #f87171; border: 1px solid rgba(244, 63, 94, 0.3); }
.badge-info { background: rgba(6, 182, 212, 0.15); color: #38bdf8; border: 1px solid rgba(6, 182, 212, 0.3); }
.badge-purple { background: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.3); }

/* Tab Panes */
.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Form controls */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  min-height: var(--control-height-md);
  padding: 0.5rem var(--control-padding-x);
  background: var(--surface-input);
  border: 1px solid var(--border-default);
  border-radius: var(--control-radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.2);
}

.form-control:disabled,
.form-control[disabled] {
  opacity: 0.55;
  color: var(--text-disabled);
  cursor: not-allowed;
}

.form-control.is-error,
.form-field.is-error .form-control {
  border-color: var(--status-danger);
}

.form-control.is-error:focus,
.form-field.is-error .form-control:focus {
  box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.2);
}

textarea.form-control {
  min-height: auto;
  padding: var(--space-3) var(--control-padding-x);
  line-height: 1.45;
  resize: vertical;
  overflow: hidden;
  field-sizing: content;
  max-height: 12rem;
}

textarea.form-control:focus {
  overflow: auto;
}

textarea.form-control.textarea-sm { min-height: 4.5rem; }
textarea.form-control.textarea-md { min-height: 7.5rem; }
textarea.form-control.textarea-lg { min-height: 12rem; }

.input-with-button {
  display: flex;
  gap: 0.75rem;
}

/* Chat timeline */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 500px;
  overflow-y: auto;
  padding-right: 0.5rem;
  /* UX-008: visible edge between the thread title and the scrolling transcript */
  border-top: 1px solid var(--border-color);
  padding-top: 0.75rem;
}

.message-bubble {
  max-width: 85%;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  line-height: 1.5;
  font-size: 0.88rem;
}

.message-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white;
  border-bottom-right-radius: 2px;
}

.message-bubble.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-bottom-left-radius: 2px;
}

.citation-box {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(6, 182, 212, 0.1);
  border-left: 3px solid var(--cyan);
  border-radius: 4px;
  font-size: 0.8rem;
  color: #7dd3fc;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--space-4);
  color: var(--text-muted);
}

.empty-state.ui-empty-panel,
.empty-state-inline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
}

.empty-state-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.empty-state-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state-desc,
.empty-state-action {
  margin: 0;
  max-width: 28rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.empty-icon-wrap {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
  color: var(--text-dim);
}

/* DB Info Grid */
.db-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1rem;
}

/* Three columns on wide cards, collapsing on phones; a fixed repeat(3, 1fr)
   clipped uppercase labels at <=390px. */
.db-info-grid--compact {
  grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));
}

/* UX-013: quota alert settings card (was inline styles); thresholds wrap instead of squeezing 3 columns on phones. */
.qa-settings-card {
  grid-column: 1 / -1;
  max-width: 760px;
}

.qa-threshold-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));
  gap: 0.75rem;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.info-val {
  overflow-wrap: anywhere;
}

.info-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
}

.info-val {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--cyan);
  font-weight: 600;
}

.sql-version-banner {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.3);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-md);
  width: 90%;
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 32px minimum hit area for the × close button. */
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.modal-close:hover,
.modal-close:focus-visible {
  color: var(--text-main);
  background: var(--surface-interactive);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.json-code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #38bdf8;
  background: #060911;
  padding: 1rem;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Colors & Helpers */
.text-cyan { color: var(--cyan); }
.text-purple { color: var(--purple); }
.text-blue { color: var(--primary); }
.text-amber { color: var(--amber); }
.text-rose { color: var(--rose); }
.text-emerald { color: var(--emerald); }

.mt-6 { margin-top: 1.5rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* Custom File Upload Component */
.file-upload-dropzone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
  background: rgba(15, 23, 42, 0.7);
  border: 1.5px dashed rgba(99, 102, 241, 0.4);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  transition: all 0.2s ease;
  gap: 12px;
  cursor: pointer;
  margin-top: 6px;
  font: inherit;
  color: inherit;
  text-align: left;
}

.file-upload-dropzone:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
}

.file-info-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-select-file {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #ffffff !important;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-select-file:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.45);
}

/* Responsive Media Queries for Full-Page Fluid UI */
@media (max-width: 1400px) {
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 992px) {
  .btn-mobile-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 500;
    transform: translateX(-100%);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    background: #0d121e;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    padding: 1.25rem 1.25rem;
  }

  .top-bar {
    gap: 1rem;
  }

  .grid-2col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-bar-left {
    width: 100%;
  }

  .top-bar-actions {
    width: 100%;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-input-wrap {
    max-width: 100%;
  }

  .filter-pills {
    overflow-x: auto;
    width: 100%;
  }

  .modal {
    width: 95%;
    max-height: 90vh;
  }

  /* Card-stack transform: a horizontally-scrolling table is unusable for row actions at
     375-414px widths. Every non-colspan .data-table <td> carries a data-label matching its
     column header (cell() in js/lib/ui-states.js; enforced by tests/data-table-labels.test.js),
     surfaced here via ::before. */
  .data-table thead {
    display: none;
  }

  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-card);
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    text-align: right;
    overflow-wrap: anywhere;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  }

  .data-table tr td:last-child {
    border-bottom: none;
  }

  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    text-align: left;
    flex-shrink: 0;
  }

  /* Full-row loading / empty / error cells have no column: no label slot, centred text. */
  .data-table td[colspan] {
    justify-content: center;
    text-align: center;
  }

  .data-table td[colspan]::before {
    content: none;
  }
}

@media (max-width: 420px) {
  .card {
    padding: var(--space-4);
  }

  .card-body {
    padding: var(--space-3);
  }

  .modal {
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .data-table td {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: var(--space-1);
  }
}

/* ?? Tenant Workspace ?? */
.tenant-workspace {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  min-height: 0;
}

/* Inside a customer workspace the platform menu steps aside. Account actions stay in the top bar. */
@media (min-width: 993px) {
  body.tenant-workspace-active .sidebar {
    display: none;
  }

  body.tenant-workspace-active .main-content {
    margin-left: 0;
    width: 100%;
  }

  body.tenant-workspace-active .tenant-selector-wrap {
    display: none !important;
  }
}

.top-bar-user {
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.readonly-banner {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border-highlight);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 650;
}

.nav-item:focus-visible,
.tw-nav-item:focus-visible,
.btn:focus-visible,
.btn-logout:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

a.tw-nav-item {
  text-decoration: none;
}

.tw-sot-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  border: 1px solid rgba(6, 182, 212, 0.28);
  border-radius: 10px;
  background: rgba(6, 182, 212, 0.08);
}

.tw-sot-banner-body {
  min-width: 0;
  flex: 1;
}

.tw-sot-banner-body strong {
  color: var(--cyan);
  font-size: 0.9rem;
}

.tw-sot-banner .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .tw-sot-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .tw-sot-banner .btn {
    width: 100%;
  }
}

.tenant-workspace.is-create-tenant [data-create-hide] {
  display: none !important;
}

.tenant-workspace.is-create-tenant [data-create-only] {
  display: revert;
}

.tenant-workspace:not(.is-create-tenant) [data-create-only] {
  display: none !important;
}

.tenant-workspace.is-create-tenant .tw-create-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  margin-right: 0.35rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--bg-muted, #eef2f7);
  color: var(--text-muted, #64748b);
}

.tenant-workspace.is-create-tenant .tw-nav-item.is-wizard-active .tw-create-step-num,
.tenant-workspace.is-create-tenant .tw-nav-item.active .tw-create-step-num {
  background: var(--color-primary, #0f4c81);
  color: #fff;
}

.create-wizard-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4) var(--space-3);
  border-top: 1px solid var(--border-color);
}

.create-wizard-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.create-wizard-step button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border-color);
  background: var(--bg-card, #fff);
  color: var(--text-muted, #64748b);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.create-wizard-step.is-active button {
  border-color: var(--color-primary, #0f4c81);
  color: var(--color-primary, #0f4c81);
  font-weight: 600;
}

.create-wizard-step.is-done button {
  border-color: color-mix(in srgb, var(--color-success, #16a34a) 45%, var(--border-color));
  color: var(--color-success, #16a34a);
}

.create-wizard-idx {
  font-weight: 700;
}

.create-wizard-hint {
  margin: 0;
  font-size: 0.78rem;
}

.tenant-workspace.is-create-tenant .persona-jump-nav {
  display: none;
}

.tenant-workspace.is-create-tenant .tw-sot-banner {
  margin-bottom: var(--space-3);
}

.tenant-workspace-nav {
  position: sticky;
  top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2);
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  max-height: none;
  overflow: visible;
}

.tw-exit {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.tw-exit a:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.tenant-workspace-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: none;
  width: 100%;
}

.tenant-workspace-header {
  margin-bottom: 0 !important;
}

.tenant-workspace-header .card-header {
  padding-bottom: var(--space-3);
}

.tenant-workspace-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.tw-nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tw-nav-label {
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: var(--space-3) 0 2px;
  padding-left: 0.45rem;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.85;
}

.tw-nav-group:first-child .tw-nav-label {
  margin-top: 0;
}

.tw-nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8125rem;
  line-height: 1.3;
}

.tw-nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.tw-nav-item.active {
  background: rgba(6, 182, 212, 0.12);
  color: var(--cyan);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--cyan);
}

.tw-nav-item.locked {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: auto;
}

.tw-nav-item.locked:hover {
  background: transparent;
  color: var(--text-muted);
}

.tw-header-row {
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.tw-header-identity {
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.tw-header-slug {
  font-size: 0.78rem;
  font-family: var(--font-mono);
}

.tw-header-domain {
  font-size: 0.8rem;
}

.tw-header-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

/* Tenant identity row: the actions drop under the name instead of overflowing on 320px (UX-005). */
.tw-header-row > .tw-header-identity {
  min-width: 0;
  flex: 1 1 16rem;
}

.tw-readiness-pill {
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-main);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  cursor: pointer;
  align-items: center;
  gap: 0.4rem;
}

.tw-readiness-pill:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.tw-readiness-pill.is-low {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
}

.tw-readiness-pill.is-ready {
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(34, 197, 94, 0.1);
  color: #4ade80;
}

.tw-readiness-pill-track {
  display: inline-block;
  width: 2.25rem;
  height: 0.35rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
  vertical-align: middle;
}

.tw-readiness-pill-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--cyan);
  border-radius: inherit;
}

.tw-readiness-pill.is-low .tw-readiness-pill-fill {
  background: #fbbf24;
}

.tw-readiness-pill.is-ready .tw-readiness-pill-fill {
  background: #4ade80;
}

.tw-readiness-bar {
  margin-top: 0.45rem;
  width: 5.5rem;
  height: 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
  margin-left: auto;
}

.tw-readiness-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--cyan);
  border-radius: inherit;
  transition: width 0.25s ease;
}

.tw-readiness-bar-fill.is-low {
  background: #fbbf24;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
}

.tw-readiness-bar-fill.is-ready {
  background: #4ade80;
}

.sticky-tenant-header {
  position: sticky;
  top: var(--space-2);
  z-index: 20;
  margin-bottom: var(--space-2);
}

/* Desktop/laptop: do not pin tenant chrome over the long Widget accordion. */
@media (min-width: 1024px) {
  .sticky-tenant-header.is-widget-section {
    position: static;
    z-index: auto;
  }
}

.tw-section-dirty-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  padding: 0.55rem 1rem 0.75rem;
  border-top: 1px solid var(--border-color);
  background: rgba(245, 158, 11, 0.08);
}

.tw-section-dirty-bar[hidden] {
  display: none !important;
}

.tw-section-dirty-msg {
  font-size: 0.8rem;
  color: var(--text-main);
}

.tw-section-dirty-actions {
  display: flex;
  gap: var(--space-2);
}

/* Status tokens */
.status-token,
.badge.status-token {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}

.status-active { background: rgba(34, 197, 94, 0.18); color: #4ade80; }
.status-draft { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; }
.status-published { background: rgba(6, 182, 212, 0.18); color: #22d3ee; }
.status-processing { background: rgba(59, 130, 246, 0.18); color: #60a5fa; }
.status-warning { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.status-error { background: rgba(239, 68, 68, 0.18); color: #f87171; }
.status-archived,
.status-suspended { background: rgba(100, 116, 139, 0.2); color: #94a3b8; }

.tw-overview-readiness-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.tw-overview-score {
  text-align: right;
}

.tw-overview-score-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
}

.tw-readiness-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.tw-readiness-item {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: start;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.tw-readiness-item.status-ok { border-color: rgba(34, 197, 94, 0.35); }
.tw-readiness-item.status-warning { border-color: rgba(245, 158, 11, 0.35); }
.tw-readiness-item.status-error { border-color: rgba(239, 68, 68, 0.35); }
/* 0.8, not 0.7: dimmed muted text must still reach 4.5:1 on the page background. */
.tw-readiness-item.status-skipped { opacity: 0.8; }

.tw-readiness-icon {
  font-weight: 700;
  line-height: 1.2;
}

.tw-readiness-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.tw-readiness-body strong {
  font-size: 0.78rem;
  text-transform: capitalize;
}

.tw-readiness-body .text-muted {
  font-size: 0.78rem;
}

.tw-overview-cta-row {
  margin-top: var(--space-3);
}

.tw-kv-list {
  margin: 0 0 var(--space-3);
}

.tw-kv-list > div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0.25rem 0;
  font-size: 0.82rem;
}

.tw-kv-list dt {
  color: var(--text-muted);
}

.tw-kv-list dd {
  margin: 0;
  font-weight: 600;
}

.tw-compact-list {
  margin: 0 0 var(--space-3);
  padding-left: 1.1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tw-config-card {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  background: rgba(255, 255, 255, 0.015);
}

.tw-config-card-title {
  margin: 0 0 var(--space-2);
  font-size: 0.92rem;
}

.tw-config-card-hint {
  font-size: 0.78rem;
  margin: 0 0 var(--space-3);
}

.tw-secondary-field label {
  color: var(--text-dim);
  font-size: 0.78rem;
}

.tw-copy-field {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.tw-copy-field .form-control {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tw-locale-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.35rem 0;
  font-size: 0.85rem;
}

.tw-i18n-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: flex-end;
}

.tw-i18n-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-left: auto;
}

.tw-i18n-completeness {
  text-align: right;
  line-height: 1.4;
  font-size: 0.85rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}

.tw-general-layout {
  max-width: none;
  width: 100%;
}

.tenant-section.card,
.tenant-section .card {
  margin-bottom: 0 !important;
}

.tenant-section.active > .card-body,
.tenant-section.active.card .card-body {
  min-height: 220px;
}

.scoped-module-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.8fr);
  gap: var(--space-4);
  align-items: stretch;
  min-height: 200px;
}

.scoped-module-panel .scoped-cta {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  justify-content: center;
}

.widget-management-card .card-body {
  padding-top: var(--space-3);
}

.widget-accordion {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.widget-acc-section {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  overflow: clip;
}

.widget-acc-summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  list-style: none;
  min-height: var(--acc-row-height);
  padding: 0 var(--space-4);
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-main);
  user-select: none;
}

.widget-acc-summary::-webkit-details-marker {
  display: none;
}

.widget-acc-summary::after {
  content: '';
  flex-shrink: 0;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  margin-left: auto;
  background: currentColor;
  opacity: 0.55;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform 0.15s ease;
}

.widget-acc-section[open] > .widget-acc-summary::after {
  transform: rotate(180deg);
}

.widget-acc-body {
  padding: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.widget-acc-body .tw-config-card {
  margin-top: var(--space-3);
}

.widget-acc-body .tw-config-card:first-child {
  margin-top: var(--space-2);
}

.widget-split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 440px);
  gap: var(--space-3);
  align-items: start;
}

.widget-split-preview {
  position: sticky;
  top: var(--space-2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: var(--space-2);
  background: rgba(255, 255, 255, 0.02);
  min-height: 0;
  width: 100%;
  max-width: none;
  justify-self: end;
  overflow: visible;
}

.widget-split-preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 10px;
  background: #dbe4ee;
}

.tw-color-field {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.tw-color-field input[type="color"] {
  width: 42px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: transparent;
}

@media (max-width: 1100px) {
  .widget-split-layout {
    grid-template-columns: 1fr;
  }
  .widget-split-preview {
    position: static;
    width: 100%;
    max-width: 380px;
    justify-self: center;
    min-height: 0;
  }
  .widget-split-preview .widget-preview-sheet-bar {
    display: none;
  }
  .widget-split-preview.is-sheet-open {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1200;
    width: 100%;
    max-width: none;
    min-height: min(88vh, 920px);
    max-height: 94vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    background: var(--bg-elevated, #0f172a);
    padding: var(--space-3);
    box-shadow: none;
    border: 1px solid var(--border-color);
  }
  .widget-split-preview.is-sheet-open .widget-preview-sheet-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }
  body.widget-preview-sheet-active::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    z-index: 1190;
  }
  .widget-split-preview.is-sheet-open .widget-preview-frame-wrap {
    height: min(880px, 70vh);
    margin-inline: auto;
  }
}

/* Phones: the inline preview would sit below the whole accordion; "Xem trước" opens it as a sheet. */
@media (max-width: 640px) {
  .widget-split-preview:not(.is-sheet-open) {
    display: none;
  }
}

/* <fieldset>: drop the UA min-width: min-content so the pills can shrink on narrow screens. */
.tw-preview-viewports {
  flex-basis: 100%;
  margin: 0;
  min-width: 0;
}

.widget-preview-sheet-bar {
  display: none;
}

.domain-env-tag {
  font-size: 0.65rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.tw-i18n-editing-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
  padding: 10px 12px;
  margin-bottom: var(--space-2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.08);
  font-size: 0.9rem;
}

.tw-i18n-status-row.is-active-locale {
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.12);
}

.tw-i18n-missing-list ul {
  margin: 4px 0 0;
}

.tenant-scope-badge {
  margin-left: var(--space-2);
  font-size: 0.72rem;
}

#tenantsTable.hide-plan-col .tenants-plan-col,
#tenantsTable.hide-plan-col td[data-label="Gói"] {
  display: none;
}

.sticky-tenant-header.is-widget-section .tw-readiness-pill {
  opacity: 0.85;
}

.forms-template-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.forms-template-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.forms-summary-line {
  font-size: 0.85rem;
  margin: 0 0 var(--space-2);
}

.forms-summary-table td {
  font-size: 0.82rem;
  vertical-align: top;
}

.forms-summary-warning {
  font-size: 0.75rem;
  margin-top: 2px;
}

.forms-advanced > summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.forms-industry-row {
  margin-bottom: var(--space-3);
}

.forms-industry-apply {
  align-self: end;
}

/* The display rules above would otherwise override the hidden attribute (FRM-002 industry filtering). */
.forms-template-list[hidden],
.forms-template-list label[hidden],
[data-industry-section][hidden],
.widget-industry-toggle[hidden],
.widget-preview-note[hidden] {
  display: none !important;
}

/* <output> is inline by default; the "open form" preview note sits on its own line above the frame. */
.widget-preview-note {
  display: block;
  font-size: 0.78rem;
  margin: 0 0 var(--space-2);
}

.widget-industry-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px dashed var(--border-color, rgba(148, 163, 184, 0.45));
  border-radius: 8px;
  font-size: 0.85rem;
}

.domain-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: none;
}

.domain-chip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: min(100%, 28rem);
}

.domain-chip-host {
  display: inline-block;
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.domain-chip {
  gap: 4px;
  display: inline-flex;
  align-items: center;
  max-width: 24rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.domain-chip-more {
  cursor: help;
}

/* WCAG 2.5.8: remove control is a real button with at least a 24px target. */
.domain-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.75;
  cursor: pointer;
}

.domain-chip-remove:hover,
.domain-chip-remove:focus-visible {
  opacity: 1;
  background: rgba(15, 23, 42, 0.08);
}

.widget-overview-grid {
  margin-bottom: var(--space-3);
}

.widget-overview-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}

.settings-section-title {
  font-size: 0.9rem;
  margin: 0 0 var(--space-2);
  color: var(--text-main);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: var(--space-3);
}

.metric-grid .metric-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--space-3);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: none;
  letter-spacing: 0;
}

.metric-grid .metric-value {
  font-size: 1.05rem;
  font-weight: 650;
  font-family: var(--font-mono);
}

.quota-bar {
  height: 10px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 5px;
  overflow: hidden;
}

.quota-bar.is-empty {
  background: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.14),
    rgba(255, 255, 255, 0.14) 3px,
    rgba(255, 255, 255, 0.05) 3px,
    rgba(255, 255, 255, 0.05) 6px
  );
}

/* Usage page: label + track wrapper */
.quota-bar:has(.quota-bar-track) {
  height: auto;
  background: transparent;
  overflow: visible;
  border-radius: 0;
}

.quota-bar-label {
  font-size: 0.8rem;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.quota-bar-track {
  height: 12px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  overflow: hidden;
}

.quota-bar-fill {
  height: 100%;
  background: var(--cyan);
  min-width: 0;
}

.quota-bar-fill.quota-state-warning,
.quota-state-warning { color: var(--amber); }
.quota-bar-fill.quota-state-warning { background: var(--amber); }
.quota-bar-fill.quota-state-critical,
.quota-state-critical { color: var(--rose); }
.quota-bar-fill.quota-state-critical { background: var(--rose); }
.quota-bar-fill.quota-state-exhausted,
.quota-state-exhausted { color: var(--rose); font-weight: 700; }
.quota-bar-fill.quota-state-exhausted { background: var(--rose); }
.quota-bar-fill.quota-state-over-limit,
.quota-state-over-limit { color: var(--rose); font-weight: 800; text-decoration: underline; }
.quota-bar-fill.quota-state-over-limit { background: var(--rose); box-shadow: 0 0 0 1px var(--rose); }
.quota-state-normal { color: var(--cyan); }

.quota-progress-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.action-menu {
  position: relative;
  display: inline-block;
}

.action-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 160px;
  z-index: 20;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.action-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  text-decoration: none;
}

.action-menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.action-menu-item:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
  background: rgba(255, 255, 255, 0.06);
}

.action-menu-danger {
  color: var(--rose);
  border-top: 1px solid transparent;
}

.action-menu-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.widget-subpanel[hidden],
.persona-locale-pane[hidden] {
  display: none !important;
}

.widget-subpanel.active {
  display: block;
}

.persona-locale-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0 var(--space-2);
}

.persona-mirror {
  display: none;
}

.persona-locale-split {
  margin-top: var(--space-2);
  display: grid;
  grid-template-columns: 1fr;
}

.persona-locale-pane {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
}

.persona-locale-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.persona-locale-col-head .text-section-title {
  margin: 0;
}

.preview-mode-banner {
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid rgba(249, 115, 22, 0.45);
  color: var(--amber);
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  margin-bottom: var(--space-3);
  font-size: 0.8rem;
}

.widget-preview-frame-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #e8eef5;
  height: 640px;
  width: 100%;
  max-width: none;
  margin: 0 auto;
}

.widget-preview-frame-wrap[data-viewport="desktop"] { max-width: none; height: 640px; }
.widget-preview-frame-wrap[data-viewport="tablet"] { max-width: 360px; height: 620px; }
.widget-preview-frame-wrap[data-viewport="mobile"] {
  max-width: 280px;
  height: 560px;
  border: 8px solid #1e293b;
  border-radius: 28px;
}

.widget-preview-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #dbe4ee;
}

.widget-live-preview-swatch {
  margin-top: var(--space-3);
  height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, var(--primary), var(--cyan));
}

.plain-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
}

.badge-secondary {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
}

@media (max-width: 960px) {
  .tenant-workspace {
    grid-template-columns: 1fr;
  }
  .tenant-workspace-nav {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    max-height: none;
  }
  .tw-nav-group {
    display: contents;
  }
  .tw-nav-label {
    width: 100%;
  }
  .tw-nav-item {
    width: auto;
  }
  .scoped-module-panel {
    grid-template-columns: 1fr;
  }
}

/* UX-004: on phones the wrapped menu (~20 items + group labels) filled the first screen; one scrollable row
   keeps the page title and primary action visible. showTenantSection scrolls the active item into view. */
@media (max-width: 640px) {
  .tenant-workspace-nav {
    position: relative;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    padding: var(--space-1);
  }
  .tw-nav-label {
    display: none;
  }
  .tw-nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
    scroll-snap-align: start;
  }
  .tw-nav-item.active {
    box-shadow: inset 0 -2px 0 var(--cyan);
  }
}

/* ===== Phase 1 UX: tenant ops embed + skeletons + save status ===== */
.tenant-ops-embed-hint {
  margin: 0 0 var(--space-3);
  font-size: 0.82rem;
}
.tenant-ops-embed-host {
  min-height: 120px;
}
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops {
  display: block !important;
  margin: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .card {
  border: none;
  background: transparent;
  box-shadow: none;
  margin: 0;
}
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .card > .card-header {
  display: none;
}
/* DS page-shell panes: hide in-pane page-header when embedded (section-scoped already owns the title) */
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .page-shell > .page-header {
  display: none;
}
.tenant-embedded-ops .inbox-operator-hint,
.tenant-embedded-ops .inbox-tenant-col {
  display: none;
}
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .page-shell {
  max-width: none;
  padding: 0;
  margin: 0;
}
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .grid-2col,
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .grid-crm,
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .page-shell .grid-2col,
.tenant-ops-embed-host > .tab-pane.tenant-embedded-ops > .page-shell .grid-crm {
  gap: var(--space-3);
}
.tw-save-status {
  font-size: 0.78rem;
  color: var(--text-muted, #94a3b8);
  padding: 0 0.35rem;
}
.tw-save-status[data-state="dirty"] {
  color: var(--amber, #f59e0b);
}
/* Clean state = "no pending edits", not a success signal (LCH-007): neutral, and dropped on phones. */
.tw-save-status[data-state="saved"] {
  color: var(--text-muted, #94a3b8);
}
@media (max-width: 640px) {
  .tw-save-status[data-state="saved"] {
    display: none;
  }
}
.skeleton-block {
  background: linear-gradient(90deg, rgba(148,163,184,0.12), rgba(148,163,184,0.22), rgba(148,163,184,0.12));
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.metric-value.skeleton,
.skeleton-kpi {
  display: inline-block;
  min-width: 3.5rem;
  height: 1.35rem;
  vertical-align: middle;
}

/* ===== Widget downloadable PDF assets panel ===== */
.widget-docs-panel {
  margin-top: var(--space-4);
}

.widget-docs-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-1);
}

.widget-docs-panel-head .tw-config-card-title {
  margin: 0;
}

.widget-docs-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted, #94a3b8);
  white-space: nowrap;
}

.widget-docs-fields {
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.widget-docs-upload {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.35);
}

.widget-docs-upload-main {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1 1 220px;
}

.widget-docs-upload-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fecaca;
  background: linear-gradient(160deg, rgba(239, 68, 68, 0.28), rgba(127, 29, 29, 0.35));
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.widget-docs-upload-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.widget-docs-upload-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.widget-docs-file {
  max-width: min(100%, 22rem);
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.35rem;
}

.widget-docs-file::file-selector-button {
  margin-right: 0.65rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.widget-docs-file::file-selector-button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-highlight);
}

.widget-docs-upload-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 auto;
}

.widget-docs-list {
  margin-top: var(--space-3);
}

.widget-docs-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
  font-size: 0.78rem;
  color: var(--text-muted, #94a3b8);
}

.widget-docs-empty {
  margin: 0;
  padding: var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-muted, #94a3b8);
  font-size: 0.78rem;
}

.widget-docs-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.widget-docs-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.025);
}

.widget-docs-card:hover {
  border-color: var(--border-highlight);
  background: rgba(255, 255, 255, 0.04);
}

.widget-docs-card-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 8px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #fecaca;
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(248, 113, 113, 0.28);
}

.widget-docs-card-body {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.widget-docs-card-title {
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.widget-docs-card-title:hover {
  color: #93c5fd;
}

.widget-docs-card-meta {
  font-size: 0.72rem;
  color: var(--text-muted, #94a3b8);
  font-family: var(--font-mono);
}

.widget-docs-card-open {
  flex: 0 0 auto;
}

.widget-docs-advanced {
  margin-top: var(--space-3);
  border-top: 1px solid var(--border-color);
  padding-top: var(--space-2);
}

.widget-docs-advanced > summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.78rem;
  color: var(--text-muted, #94a3b8);
  user-select: none;
}

.widget-docs-advanced > summary::-webkit-details-marker {
  display: none;
}

.widget-docs-advanced > summary::before {
  content: none;
}

.widget-docs-advanced[open] > summary::before {
  content: none;
}

.widget-docs-json {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.45;
}

.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;
}

/* ?? Integrations (omnichannel connectors) ??????????????????????????????? */
.integ-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.integ-flag-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.integ-flag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
}

.integ-flag-pill .integ-flag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.integ-flag-pill.is-on {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.1);
  color: #6ee7b7;
}

.integ-flag-pill.is-on .integ-flag-dot {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald-glow);
}

.integ-flag-pill.is-off .integ-flag-dot {
  background: var(--text-dim);
}

.integ-section-head h4 {
  margin: 0 0 var(--space-1);
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.integ-section-head p {
  margin: 0;
  font-size: 0.8rem;
  max-width: 40rem;
}

.integ-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-3);
  list-style: none;
  padding: 0;
  margin: 0;
}

.integ-channel-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
  min-height: 148px;
}

.integ-channel-card:hover {
  border-color: var(--border-highlight);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

.integ-channel-card.avail-planned,
.integ-channel-card.avail-soon {
  opacity: 0.88;
}

.integ-channel-card.glow-cyan::before,
.integ-channel-card.glow-blue::before,
.integ-channel-card.glow-purple::before,
.integ-channel-card.glow-amber::before,
.integ-channel-card.glow-emerald::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}

.integ-channel-card.glow-cyan::before {
  background: linear-gradient(90deg, var(--cyan), var(--primary));
}
.integ-channel-card.glow-blue::before {
  background: linear-gradient(90deg, var(--primary), var(--cyan));
}
.integ-channel-card.glow-purple::before {
  background: linear-gradient(90deg, var(--purple), var(--primary));
}
.integ-channel-card.glow-amber::before {
  background: linear-gradient(90deg, var(--amber), #f97316);
}
.integ-channel-card.glow-emerald::before {
  background: linear-gradient(90deg, var(--emerald), var(--cyan));
}

.integ-channel-card-top {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

.integ-channel-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
}

.integ-channel-icon.accent-cyan { color: var(--cyan); background: rgba(6, 182, 212, 0.12); }
.integ-channel-icon.accent-blue { color: #60a5fa; background: rgba(59, 130, 246, 0.12); }
.integ-channel-icon.accent-purple { color: #a78bfa; background: rgba(139, 92, 246, 0.12); }
.integ-channel-icon.accent-amber { color: #fbbf24; background: rgba(245, 158, 11, 0.12); }
.integ-channel-icon.accent-emerald { color: #34d399; background: rgba(16, 185, 129, 0.12); }

.integ-channel-meta {
  min-width: 0;
  flex: 1;
}

.integ-channel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: 0.25rem;
}

.integ-channel-title-row h5 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
  font-family: var(--font-heading);
}

.integ-channel-meta p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.integ-channel-card-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.integ-channel-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.integ-mini-chip {
  font-size: 0.68rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  color: var(--text-dim);
}

.integ-mini-chip.is-on {
  border-color: rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.1);
}

.integ-accounts-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.18);
}

.integ-accounts-table {
  margin: 0;
  width: 100%;
  font-size: 0.82rem;
}

.integ-accounts-table th,
.integ-accounts-table td {
  padding: 0.85rem 1rem;
  vertical-align: middle;
}

.integ-accounts-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.02);
}

.integ-accounts-table .btn-sm {
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
}

.integ-type-cell {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.1rem 0;
}

.integ-type-cell strong {
  line-height: 1.35;
  font-weight: 600;
}

.integ-type-cell code,
.integ-mono {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--cyan);
  line-height: 1.3;
  letter-spacing: 0.02em;
}

.integ-empty {
  padding: var(--space-5) var(--space-3);
  text-align: center;
}

.integ-empty p {
  margin: 0 0 var(--space-1);
}

.integ-bind-panel {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  overflow: clip;
}

.integ-bind-panel > summary,
.integ-bind-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  user-select: none;
}

.integ-bind-panel > summary::-webkit-details-marker {
  display: none;
}

.integ-bind-summary-left {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.integ-bind-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 7px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  flex: 0 0 auto;
}

#integBindZalo .integ-bind-icon {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.35);
}

#integBindFacebook .integ-bind-icon {
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.16);
  border-color: rgba(139, 92, 246, 0.35);
}

#integIdentityAnalytics .integ-bind-icon {
  color: #67e8f9;
  background: rgba(6, 182, 212, 0.14);
  border-color: rgba(6, 182, 212, 0.32);
}

/* Legacy placeholder "?" removed ? use .integ-bind-icon letters instead */
.integ-bind-summary-left::before {
  content: none;
  display: none;
}

.integ-bind-panel[open] > .integ-bind-summary .integ-bind-summary-left::before,
.integ-bind-panel[open] > summary .integ-bind-summary-left::before {
  content: none;
  display: none;
}

.integ-bind-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.9rem;
}

.integ-summary-pill {
  flex: 0 0 auto;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
}

.integ-summary-pill.is-active {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.12);
  color: #6ee7b7;
}

.integ-summary-pill.is-pending {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
}

.integ-summary-pill.is-error {
  border-color: rgba(244, 63, 94, 0.4);
  background: rgba(244, 63, 94, 0.12);
  color: #fb7185;
}

.integ-bind-body {
  padding: 0 var(--space-4) var(--space-4);
  border-top: 1px solid var(--border-color);
  padding-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.integ-bind-hint {
  font-size: 0.8rem;
  margin: 0;
  max-width: 42rem;
}

.integ-status-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background: rgba(0, 0, 0, 0.2);
}

.integ-status-card.is-active {
  border-color: rgba(16, 185, 129, 0.35);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(0, 0, 0, 0.15));
}

.integ-status-card.is-pending {
  border-color: rgba(245, 158, 11, 0.35);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(0, 0, 0, 0.15));
}

.integ-status-card.is-error {
  border-color: rgba(244, 63, 94, 0.35);
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.08), rgba(0, 0, 0, 0.15));
}

.integ-status-card.is-empty {
  border-style: dashed;
}

.integ-status-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.integ-status-card-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text-main);
}

.integ-status-card-desc {
  margin: 0;
  font-size: 0.78rem;
}

.integ-kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  margin-top: var(--space-2);
  font-size: 0.78rem;
}

.integ-kv dt {
  margin: 0;
  color: var(--text-dim);
}

.integ-kv dd {
  margin: 0;
  color: var(--text-main);
  min-width: 0;
  word-break: break-all;
}

/* In-app confirm dialog (core/dom.js confirmDialog). */
.modal.modal-confirm {
  max-width: 440px;
}

.modal.modal-confirm .modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.modal-confirm-message {
  margin: 0;
  white-space: pre-line;
  line-height: 1.5;
}

.modal-confirm-field {
  margin-top: var(--space-3);
}

/* Shared-app connect card (Kênh › Messenger / Zalo OA): steps, collapsible extras. */
.integ-steps {
  margin: var(--space-2) 0;
  padding-left: 1.2rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.integ-global-connect .integ-bind-actions {
  margin-top: var(--space-3);
}

/* Page / OA picture with the initial underneath (shown when the image is missing or blocked). */
.integ-avatar {
  position: relative;
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.35), rgba(16, 185, 129, 0.3));
  color: var(--text-main);
  font-weight: 650;
  font-size: 0.9rem;
}

.integ-avatar.is-lg {
  width: 3rem;
  height: 3rem;
  font-size: 1.1rem;
}

.integ-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.integ-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.integ-choice-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 22rem;
  overflow-y: auto;
  margin-top: var(--space-2);
}

.integ-choice {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.integ-choice:hover {
  border-color: rgba(59, 130, 246, 0.45);
}

.integ-choice:has(input:checked) {
  border-color: rgba(59, 130, 246, 0.8);
  background: rgba(59, 130, 246, 0.1);
}

.integ-choice.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.integ-choice[hidden] {
  display: none;
}

.integ-choice-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
}

.integ-choice-name {
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.integ-choice-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.integ-choice-meta a {
  color: var(--accent-secondary, var(--primary));
  text-decoration: none;
}

.integ-choice-meta a:hover,
.integ-choice-meta a:focus-visible {
  text-decoration: underline;
}

.integ-choice-search {
  margin-top: var(--space-2);
  max-width: 22rem;
}

.integ-legacy > summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: var(--space-1) 0;
}

.integ-legacy[open] > summary {
  margin-bottom: var(--space-2);
}

.integ-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: var(--space-3);
  margin: 0;
}

.integ-form-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.integ-copy-group {
  margin: 0;
}

.integ-copy-field {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.integ-copy-field .form-control {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.integ-field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.integ-field-hint[hidden] {
  display: none !important;
}

.integ-form-card-image {
  margin-top: var(--space-3);
  display: grid;
  gap: var(--space-2);
}

.integ-form-card-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 2 / 1;
  max-width: 20rem;
  border: 1px dashed var(--border-strong);
  border-radius: 0.5rem;
  overflow: hidden;
  font-size: 0.75rem;
  text-align: center;
  padding: var(--space-2);
}

.integ-form-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.integ-form-card-preview img[hidden],
.integ-form-card-preview span[hidden] {
  display: none;
}

.integ-form-card-preview:has(img:not([hidden])) {
  padding: 0;
  border-style: solid;
}

.integ-form-card-text {
  margin-top: var(--space-3);
  display: grid;
  gap: var(--space-2);
}

.integ-card-text-locale {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  padding: var(--space-2) var(--space-3) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  max-width: 40rem;
}

.integ-card-text-locale legend {
  padding: 0 var(--space-1);
  font-size: 0.8125rem;
  font-weight: 600;
}

.integ-bind-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding-top: 0.25rem;
}

.integ-bind-actions .btn {
  flex: 0 0 auto;
}

.integ-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
}

.integ-switch-end {
  margin-left: auto;
}

.integ-hint-line {
  font-size: 0.78rem;
  margin: 0;
}

.integ-bind-soon {
  opacity: 0.92;
}

.integ-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-color);
}

@media (max-width: 720px) {
  .integ-catalog {
    grid-template-columns: 1fr;
  }

  .integ-switch-end {
    margin-left: 0;
    width: 100%;
  }

  .integ-copy-field {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .widget-docs-upload {
    align-items: stretch;
  }
  .widget-docs-upload-actions {
    width: 100%;
  }
  .widget-docs-upload-actions .btn {
    flex: 1 1 auto;
  }
}

/* --- Dashboard audit Phase 2?11 primitives --- */
.overview-band-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
  text-transform: uppercase;
}

.scope-context-badge {
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: rgba(6, 182, 212, 0.08);
  color: var(--status-info);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scope-context-badge[data-scope="tenant"] {
  background: rgba(139, 92, 246, 0.12);
  color: var(--status-accent);
  border-color: rgba(139, 92, 246, 0.35);
}

.locale-switcher { display: inline-flex; align-items: center; }
.locale-select { min-width: 4.5rem; }

.tenant-usage-dual-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.7rem;
  margin-bottom: 2px;
  color: var(--text-muted);
}

.rag-advanced-diagnostics {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(13, 18, 30, 0.5);
  padding: var(--space-3) var(--space-4);
}

.rag-advanced-summary {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
  color: var(--text-main);
  list-style: none;
}

.rag-advanced-summary::-webkit-details-marker { display: none; }

/* Cap tall ops tables so full-page scrolls stay usable */
#ragSourcesTable,
#ragDocsTable,
#ragChunksTable,
#ragCacheTable,
#leadsTable,
#sessionsTable {
  /* table itself stays normal; scroll on wrapper */
}

#sessionsTable tbody tr.is-selected,
#domainCorpusTable tbody tr.is-selected {
  background: color-mix(in srgb, var(--color-primary, #0f4c81) 8%, transparent);
}

.domain-corpus-pick {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.domain-corpus-pick:hover strong,
.domain-corpus-pick:focus-visible strong {
  color: var(--cyan);
}

.domain-corpus-pick:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.domain-docs-pager {
  justify-content: space-between;
}

#sessionsTable tbody tr.is-empty-session {
  opacity: 0.78;
}

/* The 30-day usage table sits between charts on one screen; it keeps its own scroller. */
#tenantUsageSection .table-responsive {
  max-height: min(55vh, 560px);
  overflow: auto;
}

/* Compact sticky header on non-home sections */
.sticky-tenant-header.is-compact .tw-header-domain,
.sticky-tenant-header.is-compact #tenantWorkspaceEnvBadge,
.sticky-tenant-header.is-compact #tenantWorkspacePlanBadge,
.sticky-tenant-header.is-compact #tenantWorkspaceStatusBadge,
.sticky-tenant-header.is-compact #tenantWorkspaceReadiness {
  display: none !important;
}
.sticky-tenant-header.is-compact #tenantModalTitle {
  font-size: 1.05rem;
}
.sticky-tenant-header.is-compact .tw-header-slug {
  padding: 0;
  font-size: 0.78rem;
}

.security-checklist {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-3);
}

/* UX-018: cards of different text length were centred vertically (from .scoped-module-panel), so titles sat at
   different heights; align to the top and pin the action button to the bottom of each card. */
.security-checklist .scoped-cta {
  padding: var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  justify-content: flex-start;
}

.security-checklist .scoped-cta .text-section-title {
  margin: 0;
  line-height: 1.3;
}

.security-checklist .scoped-cta .form-description {
  margin: 0;
}

.security-checklist .scoped-cta .btn {
  margin-top: auto;
  align-self: flex-start;
}

.security-checklist .security-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  margin-bottom: var(--space-2);
}

.security-checklist .security-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.security-checklist .security-status.is-ok .dot { background: #4ade80; }
.security-checklist .security-status.is-warn .dot { background: var(--amber); }
.security-checklist .security-status.is-bad .dot { background: var(--rose); }

.perf-empty-state {
  display: none;
  padding: var(--space-5) var(--space-4);
  border: 1px solid rgba(125, 211, 252, 0.18);
  border-radius: 12px;
  text-align: left;
  background: linear-gradient(160deg, rgba(14, 165, 233, 0.06), rgba(255, 255, 255, 0.02));
}

.perf-empty-state h4 {
  margin: 0 0 var(--space-2);
  font-size: 1.05rem;
  color: var(--text);
}

.perf-empty-state ol {
  margin: var(--space-3) 0 0;
  padding-left: 1.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

.perf-empty-icon {
  width: 2.25rem;
  height: 2.25rem;
  margin-bottom: var(--space-3);
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.15);
  border: 1px solid rgba(125, 211, 252, 0.35);
}

body.perf-telemetry-unavailable .perf-empty-state {
  display: block;
}

body.perf-telemetry-unavailable .perf-panels-when-unavailable {
  display: none !important;
}

/* ?? Ops tenant panels (Usage / Cost / Performance) ?? */
.ops-section-lead {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
  line-height: 1.45;
}

.ops-section-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.ops-filter-check {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.ops-window-select {
  width: auto;
  min-width: 7rem;
}

.ops-callout {
  font-size: 0.82rem;
  margin-bottom: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

.ops-callout--info {
  border-color: rgba(251, 191, 36, 0.22);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.07), rgba(255, 255, 255, 0.02));
}

.ops-callout-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.ops-callout-list {
  margin: 0.35rem 0 0;
  padding-left: 1.15rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.ops-callout-note {
  margin: 0.55rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.9;
}

.ops-period-banner {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.ops-period-banner strong {
  color: var(--text);
}

.ops-stat-pair,
.ops-stat-quad {
  display: grid;
  gap: var(--space-3);
}

.ops-stat-pair {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ops-stat-quad {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 960px) {
  .ops-stat-quad {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .ops-stat-pair,
  .ops-stat-quad {
    grid-template-columns: 1fr;
  }
}

.ops-stat-pair > .card,
.ops-stat-quad > .card,
.ops-mini-stat {
  padding: var(--space-3);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: none;
}

.ops-mini-stat-value {
  margin-top: 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.ops-table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.ops-table-wrap .data-table {
  margin: 0;
}

.ops-range-toggle {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ops-range-toggle .usage-ts-range.active {
  background: rgba(14, 165, 233, 0.18);
  border-color: rgba(125, 211, 252, 0.45);
  color: var(--text-main);
  box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.12);
}

.ops-forecast {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ops-anomalies {
  margin-top: var(--space-2);
}

.ops-timeseries {
  font-size: 0.85rem;
}

.integ-channel-card.is-selected {
  outline: 1px solid var(--cyan);
  outline-offset: 1px;
}

.integ-channel-card[data-bind-target] {
  cursor: pointer;
}

.tw-readiness-collapsed-summary {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.tw-overview-readiness.is-complete .tw-readiness-list,
.tw-overview-readiness.is-complete .tw-overview-cta-row {
  display: none !important;
}

.tw-overview-readiness.is-complete .tw-readiness-list[hidden],
.tw-readiness-list[hidden] {
  display: none !important;
}

.tw-overview-readiness.is-complete .tw-readiness-collapsed-summary {
  display: flex;
}

.tw-overview-readiness.is-complete.is-expanded .tw-readiness-list {
  display: block !important;
  margin-top: var(--space-3);
}

/* Compact identity when go-live complete: thinner sticky chrome */
.sticky-tenant-header.is-ready-compact .tw-header-full {
  display: none !important;
}

.sticky-tenant-header.is-ready-compact .tw-context-bar {
  display: flex !important;
}

.home-layout {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.home-layout .home-ops-block { order: 2; margin-top: var(--space-4) !important; }
.home-layout .tw-overview-readiness { order: 1; }
.home-layout .tw-overview-panels { order: 3; }
.home-layout .home-shortcuts { order: 4; }

/* When go-live checklist is complete, promote ops summary above it */
.home-layout:has(.tw-overview-readiness.is-complete) .home-ops-block { order: 1; margin-top: 0 !important; }
.home-layout:has(.tw-overview-readiness.is-complete) .tw-overview-readiness { order: 2; margin-top: var(--space-4); }
.home-layout:has(.tw-overview-readiness.is-complete) .home-channel-alerts { order: 0; }

.home-channel-alerts {
  margin-bottom: var(--space-3);
}

.home-channel-alert {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: var(--space-3);
  border-radius: 10px;
  border: 1px solid rgba(244, 63, 94, 0.35);
  background: rgba(244, 63, 94, 0.08);
  font-size: 0.88rem;
  margin-bottom: var(--space-2);
}

.usage-sparkline {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 44px;
  margin-bottom: var(--space-3);
  padding: 4px 0;
}

.usage-spark-bar {
  flex: 1 1 0;
  min-width: 3px;
  max-width: 14px;
  background: rgba(56, 189, 248, 0.45);
  border-radius: 2px 2px 0 0;
}

.usage-spark-bar.is-peak {
  background: var(--cyan, #22d3ee);
}

tr.usage-day-peak td {
  background: rgba(56, 189, 248, 0.08);
}

.inbox-queue-kpis {
  margin-bottom: var(--space-3);
}

#tenantsTable.hide-model-col .tenants-model-col,
#tenantsTable.hide-model-col th[data-col="model"],
#tenantsTable.hide-model-col td[data-label="Model AI"] {
  display: none !important;
}

.persona-cues-details {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  background: rgba(255, 255, 255, 0.02);
}

.persona-cues-details > summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.persona-cues-details > summary::-webkit-details-marker { display: none; }


.ui-state-error td { background: rgba(244, 63, 94, 0.06); }

@media (max-width: 1024px) {
  .scope-context-badge { max-width: 140px; }
}

@media (max-width: 768px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .tenant-usage-cell { min-width: 120px !important; }
  .data-table th, .data-table td { font-size: 0.8rem; }
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.persona-jump-nav {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  margin-bottom: var(--space-4);
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(13, 20, 36, 0.9);
}

.persona-jump-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.persona-jump-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

/* Jump chips reuse .btn.btn-secondary so they never fall back to browser white */
button.persona-jump-link.btn,
.persona-jump-link.btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

button.persona-jump-link.btn.is-active,
.persona-jump-link.btn.is-active {
  background: var(--primary-fill);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.fnx-logo-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: var(--space-3);
  padding: 0.9rem;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.fnx-logo-preview-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #f8fafc;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.fnx-logo-preview {
  width: 72px;
  height: 72px;
  object-fit: contain;
  display: block;
}

.fnx-logo-preview-placeholder {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  /* Sits on the light #f8fafc preview tile: slate-600 keeps >= 4.5:1. */
  color: #475569;
}

.fnx-logo-preview-wrap:has(.fnx-logo-preview:not([hidden])) .fnx-logo-preview-placeholder {
  display: none;
}

.fnx-logo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: center;
}

.fnx-file-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: var(--space-2);
  flex-wrap: wrap;
}

/* Fully hide native file chrome ? open via #btnPickWidgetLogo */
.fnx-file-input,
input[type="file"].fnx-file-input,
#widgetLogoFile {
  display: none !important;
  position: absolute !important;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.fnx-file-name {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fnx-file-name.has-file {
  color: var(--text-main);
}

.form-control.is-secret-saved {
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.message-role-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

.message-bubble.agent {
  border-left: 3px solid var(--amber);
}

.message-bubble.system {
  border-left: 3px solid var(--text-dim);
  opacity: 0.9;
}

/* ========== Design system primitives (ui-refactor) ========== */

/* Typography roles */
.text-page-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;       /* 24px */
  line-height: 2rem;       /* 32px */
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.text-section-title {
  font-size: 1.125rem;     /* 18px */
  line-height: 1.625rem;   /* 26px */
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.text-subsection-title {
  font-size: 0.9375rem;    /* 15px */
  line-height: 1.5rem;     /* 24px */
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.text-card-title {
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.text-body {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--text-primary);
}

.text-label {
  font-size: 0.8125rem;    /* 13px */
  line-height: 1.125rem;   /* 18px */
  font-weight: 500;
  color: var(--text-secondary);
}

.text-helper {
  font-size: 0.75rem;
  line-height: 1.125rem;
  color: var(--text-muted);
  margin: var(--space-1) 0 0;
}

.text-meta {
  font-size: 0.75rem;
  line-height: 1rem;
  color: var(--text-muted);
}

.text-table-header {
  font-size: 0.75rem;
  line-height: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Content widths */
.content-sm { max-width: 720px; width: 100%; }
.content-md { max-width: 900px; width: 100%; } /* opt-in narrow forms only */
.content-lg { max-width: 1100px; width: 100%; }
.content-full { max-width: none; width: 100%; }

/* Page shell — full width by default (Playground was the example; site-wide). */
.page-shell {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  width: 100%;
  max-width: none;
}

/* Re-assert after .page-shell: inactive tenant panes must stay hidden. */
.tenant-section:not(.active),
.tenant-section.locked {
  display: none;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.page-header-text {
  min-width: 0;
  flex: 1 1 16rem;
}

.page-breadcrumb {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.page-description {
  margin: var(--space-1) 0 0;
  color: #cbd5e1;
  font-size: 0.8125rem;
  line-height: 1.35;
  max-width: 42rem;
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.page-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Form field structure */
.form-field {
  margin-bottom: var(--space-4);
}

.form-field .form-label,
.form-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 0.8125rem;
  line-height: 1.125rem;
  color: var(--text-secondary);
}

.form-description {
  margin: var(--space-1) 0 0;
  font-size: 0.75rem;
  line-height: 1.125rem;
  color: #cbd5e1;
}

.form-error {
  margin: var(--space-1) 0 0;
  font-size: 0.75rem;
  line-height: 1rem;
  color: var(--status-danger);
}

.form-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-6);
}

.form-grid-full,
.form-grid > .form-field-full,
.form-grid > .form-group-full,
.form-field-full {
  grid-column: 1 / -1;
}

/* UX-003: a bare 1fr track grows to its widest child's min-content (a <select> with long options, a fieldset,
   which defaults to min-width:min-content) and pushed Products to 576px on a 390px screen. */
.form-grid > *,
.form-grid-3 > *,
.settings-grid > *,
.grant-create-row > * {
  min-width: 0;
}

select.form-control {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

@media (max-width: 768px) {
  .form-grid,
  .settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Section (borderless grouping) */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.section-header-text {
  min-width: 0;
  flex: 1;
}

.section-divider {
  height: 0;
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: var(--space-2) 0;
}

/* Surface (bordered container ? prefer over nested cards) */
.surface {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  padding: var(--space-5);
}

.surface-subtle {
  background: var(--surface-subtle);
  border-color: var(--border-subtle);
}

.surface-flush {
  padding: 0;
  overflow: hidden;
}

.action-bar,
.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

/* Status badge (canonical) */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  border: 1px solid transparent;
  line-height: 1.2;
}

/* Toggled badges (e.g. #widgetUnpublishedBadge): display above would override the hidden attribute. */
.status-badge[hidden] {
  display: none !important;
}

.status-badge--success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
}

.status-badge--info {
  background: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
  border-color: rgba(6, 182, 212, 0.3);
}

.status-badge--warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

.status-badge--danger {
  background: rgba(244, 63, 94, 0.15);
  color: #f87171;
  border-color: rgba(244, 63, 94, 0.3);
}

.status-badge--neutral {
  background: rgba(100, 116, 139, 0.2);
  color: #94a3b8;
  border-color: rgba(100, 116, 139, 0.35);
}

/* Align legacy badge + status-token colors to status tokens */
.badge-success,
.status-active {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-info,
.status-published,
.status-processing {
  background: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.badge-warning,
.status-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger,
.status-error {
  background: rgba(244, 63, 94, 0.15);
  color: #f87171;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.status-draft,
.status-archived,
.status-suspended,
.badge-secondary {
  background: rgba(100, 116, 139, 0.2);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.35);
}

/* Color field */
.color-field,
.tw-color-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.color-field input[type="color"],
.tw-color-field input[type="color"] {
  width: 42px;
  height: var(--control-height-md);
  padding: 2px;
  border: 1px solid var(--border-default);
  border-radius: var(--control-radius);
  background: var(--surface-input);
  cursor: pointer;
  flex-shrink: 0;
}

.color-field .form-control,
.tw-color-field .form-control {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* Accordion primitive */
.acc-section,
.widget-acc-section {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  margin-bottom: var(--space-2);
  overflow: clip;
}

.acc-summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--acc-row-height);
  padding: 0 var(--space-4);
  cursor: pointer;
  list-style: none;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-primary);
  user-select: none;
}

.acc-summary::-webkit-details-marker { display: none; }

.acc-summary::after {
  content: '';
  flex-shrink: 0;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  margin-left: auto;
  background: currentColor;
  opacity: 0.55;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform 0.15s ease;
}

.acc-section[open] > .acc-summary::after {
  transform: rotate(180deg);
}

.acc-title { flex: 1; min-width: 0; }
.acc-meta {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.acc-body {
  padding: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* Help tooltip */
.help-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.help-tooltip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: help;
}

.help-tooltip-btn:hover,
.help-tooltip-btn:focus-visible {
  color: var(--text-secondary);
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.help-tooltip-panel {
  position: absolute;
  z-index: var(--z-dropdown);
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  min-width: 12rem;
  max-width: 18rem;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.35;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
}

.help-tooltip.is-open .help-tooltip-panel,
.help-tooltip:hover .help-tooltip-panel,
.help-tooltip:focus-within .help-tooltip-panel {
  opacity: 1;
  visibility: visible;
}

/* File upload (canonical states) */
.file-upload {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-interactive);
}

.file-upload.is-dragover {
  border-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
}

.file-upload.is-error {
  border-color: var(--status-danger);
  border-style: solid;
}

.file-upload-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}

.file-upload-preview {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: #f8fafc;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.file-upload-preview img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  display: block;
}

.file-upload-preview-icon {
  color: var(--text-dim);
  width: var(--icon-size-xl);
  height: var(--icon-size-xl);
}

.file-upload-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.file-upload-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-upload-name.is-empty {
  color: var(--text-muted);
  font-weight: 500;
}

.file-upload-hint,
.file-upload-size,
.file-upload-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-upload-status.is-error {
  color: var(--status-danger);
}

.file-upload-status.is-success {
  color: var(--status-success);
}

.file-upload-progress {
  height: 4px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-top: var(--space-1);
}

.file-upload-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent-primary);
  transition: width 0.2s ease;
}

.file-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.file-upload .fnx-file-input {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Compact tenant context bar */
.tenant-context-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  min-height: 40px;
}

.tenant-context-identity {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-width: 0;
}

.tenant-context-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.tenant-context-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tenant-context-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.tenant-context-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

/* Data table density */
.data-table tbody tr {
  height: auto;
  min-height: var(--table-row-height);
}

/* Long source paths stay on one line; the full value is in title. */
.cell-url {
  max-width: 28rem;
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow-wrap: anywhere;
  word-break: normal;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.cell-url a {
  color: inherit;
  text-decoration: none;
}

.cell-url a:hover {
  text-decoration: underline;
}

.data-table th,
.data-table td {
  padding: var(--space-2) var(--space-3);
  vertical-align: middle;
}

/* Image upload card */
.image-upload {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
}

.image-upload-preview {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  border: 1px solid var(--border-default);
  background: #f8fafc;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.image-upload-preview img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  display: block;
}

.image-upload-preview-placeholder {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #475569;
}

.image-upload-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.image-upload-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-upload-name.is-empty {
  color: var(--text-muted);
  font-weight: 500;
}

.image-upload-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.image-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Align logo upload to horizontal card layout */
.fnx-logo-upload.image-upload {
  flex-direction: row;
  align-items: flex-start;
  justify-content: flex-start;
  margin-top: var(--space-2);
}

.fnx-logo-upload.image-upload .fnx-logo-actions {
  justify-content: flex-start;
}

/* Advanced disclosure */
.advanced-block {
  margin-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-3);
}

.advanced-block > summary {
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
}

.advanced-block > summary::-webkit-details-marker { display: none; }

.advanced-block[open] > summary {
  margin-bottom: var(--space-3);
  color: var(--text-secondary);
}

/* Draft preview label */
.preview-draft-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--status-warning);
  margin-bottom: var(--space-2);
}

/* Widget status summary strip */
.status-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.status-summary-item {
  padding: var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  min-width: 0;
}

.status-summary-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.status-summary-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 1.5rem;
}

.status-summary-value code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
}

.widget-status-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: var(--space-4);
}

@media (max-width: 900px) {
  .widget-status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Channel card (simplified) */
.channel-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-card);
}

.channel-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.channel-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.channel-card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.channel-card-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: auto;
}

/* ===== Tenant workspace UX refactor (layout system) ===== */

.tw-tenant-name {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-main);
}

.tw-context-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  padding: 0.45rem 0.85rem;
  min-height: 2.5rem;
}

.tw-context-bar[hidden] {
  display: none !important;
}

.tw-context-bar-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  min-width: 0;
}

.tw-context-bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.tw-context-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tw-context-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.tw-context-sep {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.tw-context-domain {
  font-size: 0.78rem;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sticky-tenant-header.is-compact {
  margin-bottom: var(--space-3);
}

.sticky-tenant-header.is-compact .tw-header-full {
  display: none !important;
}

/* Page title rhythm ? section job beats tenant chrome */
.tenant-section > .card-header.page-header,
.tenant-section > .page-header,
.tenant-section.home-layout > .page-header {
  margin-bottom: var(--space-1);
}

/* Home: keep readiness/ops reorder when wrapped in page-content */
.home-layout > .page-content {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.home-shortcuts-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tenant-domains-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-3);
}

.domain-add-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  max-width: none;
}

.playground-example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
  border: none;
  padding: 0;
  min-inline-size: 0;
}

.playground-example-chips .btn {
  font-size: 0.78rem;
}

.search-results-area {
  min-height: 0;
}

.search-results-area.is-empty {
  min-height: 8rem;
  max-height: 14rem;
}

.search-results-area .empty-state {
  padding: var(--space-4) var(--space-3);
}

.form-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 768px) {
  .domain-add-row {
    flex-direction: column;
    align-items: stretch;
  }
  .domain-add-row .btn {
    width: 100%;
  }
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}

.grant-create-row {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.7fr) minmax(0, 1fr) auto;
  align-items: end;
}

/* UX-009: stacking must come after the base rule (equal specificity); it used to sit in the block above, so the
   four columns always won and phones got ~50px inputs. */
@media (max-width: 768px) {
  .grant-create-row {
    grid-template-columns: minmax(0, 1fr);
  }
  .grant-create-action .btn {
    width: 100%;
  }
}

.grant-create-action {
  display: flex;
  align-items: flex-end;
}

.quota-grants-list {
  margin-bottom: var(--space-3);
  font-size: 0.8rem;
}

/* Avoid double chevrons when ops-advanced + acc-summary coexist */
.ops-advanced-details > summary.acc-summary::before,
.page-advanced-details > summary.acc-summary::before {
  content: none;
}

.tenant-section .text-page-title,
.page-header .text-page-title {
  margin: 0;
  font-size: 1.375rem !important;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main) !important;
  line-height: 1.25;
}

.tenant-section .page-description {
  margin-top: var(--space-2);
  max-width: 40rem;
}

/* Content width & form density — workspace fills remaining main area */
.tenant-section .form-control:not(textarea):not(select[multiple]),
.tenant-section .form-field input.form-control,
.tenant-section .form-field select.form-control {
  max-width: none;
}

.tenant-section textarea.form-control {
  max-width: none;
}

.domain-add-row .form-field {
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
}

.domain-add-row .form-control,
.domain-add-row .btn {
  height: var(--control-height-md);
  min-height: var(--control-height-md);
}

.domain-add-row .form-control {
  width: 100%;
  max-width: none;
}

.form-section {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-color);
}

.form-section:last-child {
  border-bottom: none;
}

.form-section .text-section-title {
  margin: 0 0 var(--space-3);
}

.ops-advanced-details,
.page-advanced-details {
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.015);
}

.ops-advanced-details > summary,
.page-advanced-details > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-secondary);
  list-style: none;
}

.ops-advanced-details > summary::-webkit-details-marker,
.page-advanced-details > summary::-webkit-details-marker {
  display: none;
}

.ops-advanced-details > summary::before,
.page-advanced-details > summary::before {
  content: none;
}

.ops-advanced-details[open] > summary::before,
.page-advanced-details[open] > summary::before {
  content: none;
}

/* Scoped embed pages ? drop redundant outer chrome noise */
.tenant-ops-embed-host .page-header .text-page-title {
  font-size: 1.05rem !important;
}

.tenant-section[data-tenant-section='knowledge'] > .card-header .tenant-scope-badge,
.tenant-section[data-tenant-section='leads'] > .card-header .tenant-scope-badge,
.tenant-section[data-tenant-section='conversations'] > .card-header .tenant-scope-badge,
.tenant-section[data-tenant-section='inbox'] > .card-header .tenant-scope-badge,
.tenant-section[data-tenant-section='audit'] > .card-header .tenant-scope-badge {
  display: none;
}

.persona-form-section {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-color);
  scroll-margin-top: 5rem;
}

.persona-form-section:last-child {
  border-bottom: none;
}

.persona-form-section .text-section-title {
  margin-top: 0;
}

/* Narrow sidebar only while the menu is still a column; at <=960px it becomes a full-width row (see above) and a
   fixed width here squeezed it to ~184px on phones and tablets. */
@media (min-width: 961px) and (max-width: 1280px) {
  .tenant-workspace-nav {
    width: 11.5rem;
    min-width: 11.5rem;
  }
}

@media (max-width: 1280px) {
  .tw-nav-item {
    font-size: 0.78rem;
    padding: 0.3rem 0.45rem;
  }
}

@media (max-width: 1024px) {
  .tenant-workspace-main {
    max-width: none;
  }

  .tenant-section .form-control:not(textarea),
  .tenant-section textarea.form-control {
    max-width: none;
  }
}

/* ---------------------------------------------------------------------------
 * Product Discovery section (scoped to [data-tenant-section="products"]).
 * ------------------------------------------------------------------------- */
[data-tenant-section="products"] .section { margin-bottom: 28px; }
[data-tenant-section="products"] .inline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
[data-tenant-section="products"] .inline-actions .form-control { width: auto; min-width: min(180px, 100%); max-width: 100%; flex: 0 1 auto; }
[data-tenant-section="products"] .form-check { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
[data-tenant-section="products"] .form-hint { font-size: 12px; color: var(--text-muted, #64748b); margin: 4px 0 8px; }
[data-tenant-section="products"] .code-textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.45; }
[data-tenant-section="products"] .form-errors { margin: 10px 0; padding: 10px 14px 10px 28px; border-radius: 8px; background: rgba(220, 38, 38, 0.08); color: #f87171; font-size: 12.5px; }
[data-tenant-section="products"] .table-wrap { overflow-x: auto; margin: 8px 0; }
[data-tenant-section="products"] .clickable-row { cursor: pointer; }
[data-tenant-section="products"] .clickable-row:hover td { background: rgba(37, 99, 235, 0.06); }
[data-tenant-section="products"] .code-block { white-space: pre-wrap; font-size: 12px; padding: 10px; border-radius: 8px; background: var(--surface-subtle); max-height: 260px; overflow: auto; }
[data-tenant-section="products"] .badge-neutral { background: rgba(100, 116, 139, 0.14); color: #94a3b8; }
[data-tenant-section="products"] .btn-xs { padding: 2px 8px; font-size: 11.5px; }
[data-tenant-section="products"] fieldset.form-group { border: none; padding: 0; margin: 0; }
[data-tenant-section="products"] .pd-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
[data-tenant-section="products"] .pd-stat { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border-color, rgba(148,163,184,0.3)); }
[data-tenant-section="products"] .pd-stat-value { font-size: 22px; font-weight: 800; }
[data-tenant-section="products"] .pd-stat-label { font-size: 12px; color: var(--text-muted, #64748b); }
[data-tenant-section="products"] .pd-stat-sub { font-size: 11.5px; margin-top: 2px; }

/* Card-stack tables on a phone (max-width 640px, rules above): the fixed row height of the density rule
   ".data-table tbody tr" made every stacked card the height of one row, so the cards overlapped. */
@media (max-width: 640px) {
  .data-table tbody tr {
    height: auto;
  }
}

.tenant-link { color: inherit; text-decoration: none; }
.tenant-link:hover strong { text-decoration: underline; }

/* Quota visibility (UI review): rose metric card, overview band header and the open-alerts badge in the sidebar */
.metric-card.glow-rose::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--rose), var(--amber));
}

.overview-band-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.overview-band-head .overview-band-title {
  margin: 0;
}

.nav-badge {
  margin-left: auto;
  min-width: 1.35rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--rose);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.35rem;
  text-align: center;
}

.nav-badge[hidden] {
  display: none;
}

/* Daily usage chart (UI review): SVG with axes, replaces the unlabeled spark bars */
.usage-chart {
  display: block;
  width: 100%;
  max-width: 900px;
  height: auto;
  margin: var(--space-2) 0;
}

.usage-chart-grid { stroke: rgba(148, 163, 184, 0.25); stroke-width: 1; }
.usage-chart-tick { fill: var(--text-muted); font-size: 11px; }
.usage-chart-note { fill: var(--text-muted); font-size: 11px; }
.usage-chart-bar { fill: var(--cyan); opacity: 0.85; }
.usage-chart-bar:hover { opacity: 1; }
.usage-chart-bar.is-unknown { fill: var(--text-muted); opacity: 0.5; }
.usage-chart-line { fill: none; stroke: var(--cyan); stroke-width: 2; }
.usage-chart-dot { fill: var(--cyan); }
.usage-chart-average { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 5 4; }
.usage-chart-limit { stroke: var(--rose); stroke-width: 1.5; stroke-dasharray: 6 4; }
.usage-chart-pace { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 3 4; }
.usage-chart-metric.active { border-color: var(--cyan); color: var(--cyan); }
.usage-chart-bar.is-partial { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 3 2; }

/* Read-only role (viewer / read_only): inspect configuration without mutating fields */
body.is-read-only-role #tenantForm input:not([type="search"]),
body.is-read-only-role #tenantForm select:not(#widgetPreviewLocaleSticky):not(#widgetPreviewScenario):not(#widgetI18nPreviewLocale):not(#usageChannelFilter):not(#perfWindowSelect):not(#pdStatusFilter),
body.is-read-only-role #tenantForm textarea {
  pointer-events: none;
  opacity: 0.78;
}

/* Tenant Workspace Audit (#/tenants/:id/audit): show single-column business audit log; platform workflow errors stay in #/logs */
#tenantEmbedAudit #logsErrorsSurface {
  display: none !important;
}

#tenantEmbedAudit #pane-logs .form-grid {
  grid-template-columns: 1fr;
}

/* Users who ask the OS for less motion get no animations, transitions or smooth scrolling. */
.queue-tabs {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  overflow-x: auto;
  max-width: 100%;
}

.queue-tab {
  flex: 0 0 auto;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-main);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}

.queue-tab.is-current {
  background: var(--bg-card);
  border-color: var(--text-main);
  font-weight: 600;
}

.widget-accordion:not(.is-show-more) .widget-secondary {
  display: none;
}

.widget-more-toggle {
  margin-bottom: var(--space-3);
}

.create-wizard-step.is-later {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px dashed var(--border-color);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
  color: var(--text-muted, #64748b);
  opacity: 0.7;
}

@media (max-width: 640px) {
  .form-control,
  .form-field input,
  .form-field select,
  .form-field textarea {
    max-width: 100%;
  }

  .page-header-actions,
  .action-bar {
    width: 100%;
    flex-wrap: wrap;
  }

  .modal-confirm {
    width: min(100% - 24px, 420px);
  }

  .last-updated-badge,
  .user-name,
  #topBarUserName {
    display: none;
  }

  body.tenant-workspace-active .tenant-selector-wrap {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.queue-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  padding: 0;
  border: 0;
  min-inline-size: 0;
}

.queue-filters-legend {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.queue-filters .btn.is-active {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.queue-job {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.queue-job-status {
  font-size: 0.78rem;
}

.tenant-queue-detail {
  margin-top: 1rem;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 2000;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.tw-admin-fold {
  margin-top: 0.35rem;
  border: 0;
  padding: 0;
}

.tw-admin-fold > .tw-admin-fold-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.tw-admin-fold > .tw-admin-fold-summary::-webkit-details-marker {
  display: none;
}

.tw-admin-fold[open] > .tw-admin-fold-summary {
  color: var(--text-muted);
}

.admin-advanced-fold {
  margin-top: var(--space-5);
  padding: var(--space-3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.35);
}

.admin-advanced-fold > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}

.admin-advanced-fold[open] > summary {
  margin-bottom: var(--space-3);
  color: var(--text-main);
}

.home-admin-fold {
  margin-top: var(--space-3);
  width: 100%;
}

.session-back {
  display: none;
}

.page-shell:has(.ui-state-loading) #purgeOldSessionsBtn,
.page-shell:has(.ui-state-loading) #btnClearAuditLogs,
.page-shell:has(.ui-state-loading) #clearAllCacheBtn {
  display: none;
}

@media (max-width: 640px) {
  #pane-sessions .session-thread:not(.is-thread-open) {
    display: none;
  }

  #pane-sessions .session-thread.is-thread-open .session-back {
    display: inline-flex;
  }

  #pane-sessions .grid-2col:has(.session-thread.is-thread-open) > .surface:first-child {
    display: none;
  }

  .page-content:has(#tenantQueueDetail.is-open) > .table-responsive,
  .page-content:has(#tenantQueueDetail.is-open) > .queue-filters,
  .page-content:has(#tenantQueueDetail.is-open) > #tenantQueueStatus {
    display: none;
  }

  #tenantQueueTable [data-action="queue-take"],
  #tenantQueueTable [data-action="queue-resume"] {
    display: none;
  }
}
