/**
 * NEXT INNOVATION - Enterprise Cloud Suite & SSO Hub
 * Design System & Component Stylesheet (portal.css)
 * Material Design 3 / Google Stitch Specification Compliant
 * 
 * Rules Enforced:
 * - Rule 68: Zero Tailwind CDN! 100% Pure Custom CSS Variables & Tokens
 * - Rule 57: Font 'Lato', 'M PLUS 1', sans-serif, tabular-nums for numeric/IDs
 * - Rule 58: Floating Grid Card Selector Modal for ALL selections (Zero <select>)
 * - Rule 21: Custom M3 Modals & Drawers (Escape & backdrop close, zero native dialogs)
 * - Rule 50: Optical vertical alignment, shrink-0 whitespace-nowrap, scroll lock
 */

/* ==========================================================================
 * 1. CSS Custom Properties / Design Tokens
 * ========================================================================== */
:root {
  /* Brand Primary & Accents (Google Stitch & M3 Specification) */
  --primary: #181B39;                /* Midnight Navy */
  --primary-rgb: 24, 27, 57;
  --primary-light: #2C3259;
  --primary-container: #E0E2FF;
  --on-primary: #FFFFFF;
  --on-primary-container: #00105C;

  --secondary: #4F46E5;              /* Indigo Accent */
  --secondary-light: #EEF2FF;
  --secondary-dark: #3730A3;

  --tertiary: #D81B60;               /* Deep Ruby */
  --tertiary-container: #FFD8E4;

  /* Surfaces & Backgrounds - Clean & Flat High Contrast */
  --bg-body: #F8F9FA;
  --surface: #FFFFFF;
  --surface-subtle: #F1F5F9;
  --surface-hover: #F8FAFC;
  --surface-card: #FFFFFF;
  --surface-overlay: rgba(15, 23, 42, 0.65);

  /* Borders & Outlines */
  --border-subtle: #E2E8F0;
  --border-medium: #CBD5E1;
  --border-strong: #94A3B8;

  /* Typography Colors */
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --text-disabled: #94A3B8;
  --text-inverse: #FFFFFF;

  /* Status Colors */
  --status-success: #10B981;
  --status-success-bg: #ECFDF5;
  --status-success-border: #A7F3D0;
  --status-success-text: #065F46;

  --status-warning: #F59E0B;
  --status-warning-bg: #FFFBEB;
  --status-warning-border: #FDE68A;
  --status-warning-text: #92400E;

  --status-danger: #EF4444;
  --status-danger-bg: #FEF2F2;
  --status-danger-border: #FECACA;
  --status-danger-text: #991B1B;

  --status-info: #0288D1;
  --status-info-bg: #E1F5FE;
  --status-info-border: #81D4FA;
  --status-info-text: #01579B;

  /* Elevations & Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.08);

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Layout */
  --header-height: 72px;
  --max-content-width: 1400px;
}

/* Dark Mode Tokens */
[data-theme="dark"] {
  --primary: #9AA0A6;
  --primary-light: #2A324B;
  --primary-container: #23284A;
  --on-primary: #0F1420;
  --on-primary-container: #DDE2FF;

  --secondary: #818CF8;
  --secondary-light: #1E2342;
  --secondary-dark: #6366F1;

  --bg-body: #0B0F19;
  --surface: #131927;
  --surface-subtle: #1A2234;
  --surface-hover: #1F2A40;
  --surface-card: #131927;
  --surface-overlay: rgba(3, 7, 18, 0.8);

  --border-subtle: #243048;
  --border-medium: #334466;
  --border-strong: #4B638F;

  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-muted: #7E90AA;
  --text-disabled: #4B5A72;
  --text-inverse: #0B0F19;

  --status-success: #34D399;
  --status-success-bg: rgba(16, 185, 129, 0.15);
  --status-success-border: rgba(16, 185, 129, 0.35);
  --status-success-text: #6EE7B7;

  --status-warning: #FBBF24;
  --status-warning-bg: rgba(245, 158, 11, 0.15);
  --status-warning-border: rgba(245, 158, 11, 0.35);
  --status-warning-text: #FCD34D;

  --status-danger: #F87171;
  --status-danger-bg: rgba(239, 68, 68, 0.15);
  --status-danger-border: rgba(239, 68, 68, 0.35);
  --status-danger-text: #FCA5A5;

  --status-info: #38BDF8;
  --status-info-bg: rgba(2, 136, 209, 0.15);
  --status-info-border: rgba(2, 136, 209, 0.35);
  --status-info-text: #7DD3FC;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 20px 30px rgba(0, 0, 0, 0.7);
}

/* ==========================================================================
 * 2. Reset & Base Typography (Rule 57)
 * ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: 'Lato', 'M PLUS 1', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-body);
  color: var(--text-primary);
}

body.modal-open {
  overflow: hidden !important;
}

/* Tabular Numbers for all IDs, metrics, currency */
.tabular-nums, .num, .metric-value, .currency, .price-display, .badge-count {
  font-family: 'Lato', sans-serif;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* Links & Buttons Reset */
a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  cursor: pointer;
  outline: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease-in-out;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Material Symbols optical alignment (Rule 50) */
.material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  user-select: none;
}

/* ==========================================================================
 * 3. Header & Navigation (Rule 50)
 * ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xs);
  transition: background-color 0.2s, border-color 0.2s;
}

.header-inner {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 0 20px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-shrink: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-mark {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #181B39 0%, #2A337A 50%, #4F46E5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(24, 27, 57, 0.25);
}

.brand-text-wrap {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background-color: var(--secondary-light);
  color: var(--secondary);
  border: 1px solid var(--border-subtle);
  text-transform: uppercase;
}

.brand-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Nav Pill Switcher (3 Main Views) */
.header-nav {
  display: flex;
  align-items: center;
  background-color: var(--surface-subtle);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.nav-pill {
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.nav-pill:hover {
  color: var(--text-primary);
  background-color: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .nav-pill:hover {
  background-color: rgba(255, 255, 255, 0.06);
}

.nav-pill.active {
  background-color: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

.nav-pill.admin-pill {
  color: #B45309;
}
[data-theme="dark"] .nav-pill.admin-pill {
  color: #FCD34D;
}
.nav-pill.admin-pill.active {
  color: #B45309;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Impersonation Sticky Warning Bar */
.impersonation-bar {
  background: linear-gradient(90deg, #B45309 0%, #D97706 100%);
  color: #FFFFFF;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(180, 83, 9, 0.25);
  animation: slideDown 0.2s ease-out;
}

.impersonation-btn-reset {
  background: #FFFFFF;
  color: #B45309;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 800;
  box-shadow: var(--shadow-xs);
}
.impersonation-btn-reset:hover {
  background: #FEF3C7;
}

/* Quick SSO Demo Bar (Subheader) */
.sso-demo-bar {
  background-color: var(--surface-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 6px 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow-x: auto;
}

.sso-demo-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.sso-demo-btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.sso-demo-chip {
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background-color: var(--surface);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.sso-demo-chip:hover {
  border-color: var(--secondary);
  color: var(--secondary);
}

.sso-demo-chip.active {
  background-color: var(--secondary);
  color: #FFFFFF;
  border-color: var(--secondary);
}

/* ==========================================================================
 * 4. Main App Layout & Grid Containers
 * ========================================================================== */
.app-container {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 28px 20px 80px;
  width: 100%;
  flex: 1;
}

.view-section {
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.view-section.active {
  display: block;
}

/* Hero Section (Catalog) */
.hero-banner {
  background: linear-gradient(135deg, #181B39 0%, #1F2758 60%, #2A367D 100%);
  border-radius: var(--radius-xl);
  padding: 44px 40px;
  color: #FFFFFF;
  margin-bottom: 36px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.hero-banner::after {
  content: '';
  position: absolute;
  top: -60px;
  right: -60px;
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.3) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.hero-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 4px 14px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 16px;
  backdrop-filter: blur(8px);
}

.hero-title {
  font-size: 32px;
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.hero-desc {
  font-size: 15px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.85);
  max-width: 720px;
  margin-bottom: 24px;
}

.hero-kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding-top: 20px;
}

.hero-kpi-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.08);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.hero-kpi-val {
  font-size: 18px;
  font-weight: 900;
  color: #FFFFFF;
}

.hero-kpi-lbl {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
}

/* Featured Apps Section (FS & PleasureMapPrice) */
.section-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.section-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.featured-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(540px, 1fr));
  gap: 28px;
  margin-bottom: 48px;
}

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

.featured-card {
  background-color: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.featured-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-medium);
}

/* Real Screen Browser Frame in Card */
.browser-frame {
  background-color: var(--surface-subtle);
  border-bottom: 1px solid var(--border-subtle);
  overflow: hidden;
  position: relative;
}

.browser-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
}

.browser-dots {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.browser-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot-red { background-color: #EF4444; }
.dot-yellow { background-color: #F59E0B; }
.dot-green { background-color: #10B981; }

.browser-url-pill {
  flex: 1;
  max-width: 380px;
  margin: 0 12px;
  background-color: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 2px 12px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browser-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9.5;
  background-color: #0F172A;
  overflow: hidden;
  cursor: pointer;
}

.browser-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 0.3s ease;
}

.browser-image-wrap:hover img {
  transform: scale(1.02);
}

.browser-zoom-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  color: #FFFFFF;
  font-weight: 700;
  gap: 6px;
  font-size: 13px;
}

.browser-image-wrap:hover .browser-zoom-overlay {
  opacity: 1;
}

/* Card Content Area */
.featured-card-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-top-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-category-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background-color: var(--surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.card-pricing-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.card-desc {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 20px;
  flex: 1;
}

.card-features-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.card-feature-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background-color: var(--surface-subtle);
  color: var(--text-muted);
}

.card-actions-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

/* Primary, Secondary, Ghost Buttons */
.btn-primary {
  background-color: var(--primary);
  color: var(--on-primary);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background-color: var(--primary-light);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background-color: var(--surface-subtle);
  border-color: var(--border-medium);
}

.btn-accent {
  background: linear-gradient(135deg, #4F46E5 0%, #3730A3 100%);
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.btn-accent:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* ==========================================================================
 * 5. High Density Data Tables (Admin & Tenant)
 * ========================================================================== */
.table-card {
  background-color: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  margin-bottom: 24px;
}

.table-toolbar {
  padding: 16px 20px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 320px;
  width: 100%;
}

.search-input-wrap .material-symbols-outlined {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 18px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--surface-subtle);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: all 0.15s;
}
.search-input:focus {
  border-color: var(--secondary);
  background-color: var(--surface);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background-color: var(--surface-subtle);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  user-select: none;
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background-color 0.1s ease;
}

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

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

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-success {
  background-color: var(--status-success-bg);
  border: 1px solid var(--status-success-border);
  color: var(--status-success-text);
}

.badge-warning {
  background-color: var(--status-warning-bg);
  border: 1px solid var(--status-warning-border);
  color: var(--status-warning-text);
}

.badge-danger {
  background-color: var(--status-danger-bg);
  border: 1px solid var(--status-danger-border);
  color: var(--status-danger-text);
}

.badge-info {
  background-color: var(--status-info-bg);
  border: 1px solid var(--status-info-border);
  color: var(--status-info-text);
}

.badge-neutral {
  background-color: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

/* Role Badges (Rule 40 English Only) */
.role-badge {
  font-family: 'Lato', sans-serif;
  font-weight: 800;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
}

.role-superadmin { background: #181B39; color: #FFFFFF; }
.role-oo { background: #4338CA; color: #FFFFFF; }
.role-om { background: #0284C7; color: #FFFFFF; }
.role-oc { background: #0D9488; color: #FFFFFF; }
.role-rgm { background: #059669; color: #FFFFFF; }
.role-1st { background: #D97706; color: #FFFFFF; }
.role-2nd { background: #EA580C; color: #FFFFFF; }
.role-crew { background: #64748B; color: #FFFFFF; }

/* 2-Tier Permission Toggle Switcher Pill */
.perm-pill-group {
  display: inline-flex;
  background-color: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 2px;
  gap: 2px;
}

.perm-pill-btn {
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.perm-pill-btn.active-on {
  background-color: var(--status-success-bg);
  color: var(--status-success-text);
  border: 1px solid var(--status-success-border);
  box-shadow: var(--shadow-xs);
}

.perm-pill-btn.active-admin {
  background-color: #181B39;
  color: #FFFFFF;
  box-shadow: var(--shadow-xs);
}

.perm-pill-btn.active-off {
  background-color: var(--status-danger-bg);
  color: var(--status-danger-text);
  border: 1px solid var(--status-danger-border);
  box-shadow: var(--shadow-xs);
}

/* ==========================================================================
 * 6. Rule 58: Floating Grid Card Selector Modal
 * ========================================================================== */
.grid-selector-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background-color: var(--surface-overlay);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease-out;
}

.grid-selector-card {
  background-color: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 580px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: scaleUp 0.18s ease-out;
}

.grid-selector-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.grid-selector-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.grid-selector-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.grid-selector-item {
  background-color: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  transition: all 0.15s ease;
  text-align: left;
}

.grid-selector-item:hover {
  border-color: var(--secondary);
  background-color: var(--surface);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.grid-selector-item.selected {
  border-color: var(--secondary);
  background-color: var(--secondary-light);
  box-shadow: 0 0 0 2px var(--secondary);
}

[data-theme="dark"] .grid-selector-item.selected {
  background-color: rgba(79, 70, 229, 0.2);
}

.grid-selector-item-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
}

.grid-selector-item-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ==========================================================================
 * 7. Rule 21: Custom M3 Modals & Drawers
 * ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background-color: var(--surface-overlay);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease-out;
}

.modal-dialog {
  background-color: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: scaleUp 0.18s ease-out;
}

.modal-dialog.modal-lg {
  max-width: 900px;
}

.modal-dialog.modal-xl {
  max-width: 1200px;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--surface-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

/* Right Slide-over Drawer (SuperAdmin Quick Edit) */
.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 950;
  background-color: var(--surface-overlay);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: flex-end;
  animation: fadeIn 0.15s ease-out;
}

.drawer-panel {
  width: 100%;
  max-width: 480px;
  height: 100%;
  background-color: var(--surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: slideLeft 0.22s ease-out;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
  min-width: 280px;
  max-width: 420px;
  animation: toastIn 0.25s ease-out;
  border: 1px solid transparent;
}

.toast-success {
  background-color: var(--status-success-bg);
  border-color: var(--status-success-border);
  color: var(--status-success-text);
}

.toast-error {
  background-color: var(--status-danger-bg);
  border-color: var(--status-danger-border);
  color: var(--status-danger-text);
}

.toast-info {
  background-color: var(--status-info-bg);
  border-color: var(--status-info-border);
  color: var(--status-info-text);
}

/* ==========================================================================
 * 8. Screenshots Showcase & Lightbox UI (Rule: Real Screenshots)
 * ========================================================================== */
.showcase-container {
  background-color: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  margin-bottom: 32px;
}

.showcase-tabs-bar {
  display: flex;
  align-items: center;
  background-color: var(--surface-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 6px 12px;
  gap: 6px;
  overflow-x: auto;
}

.showcase-tab {
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.showcase-tab:hover {
  color: var(--text-primary);
  background-color: rgba(0, 0, 0, 0.04);
}

.showcase-tab.active {
  background-color: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

.showcase-viewport {
  position: relative;
  background-color: #0F172A;
  aspect-ratio: 16 / 9.5;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
}

.showcase-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.25s ease;
}

.showcase-viewport:hover .showcase-img {
  transform: scale(1.015);
}

.showcase-caption {
  padding: 16px 20px;
  background-color: var(--surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.showcase-caption-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Fullscreen Lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background-color: rgba(3, 7, 18, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  padding: 20px;
  animation: fadeIn 0.15s ease-out;
}

.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #FFFFFF;
  padding-bottom: 12px;
}

.lightbox-title {
  font-size: 16px;
  font-weight: 800;
}

.lightbox-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lightbox-img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

/* ==========================================================================
 * 9. Pricing Simulator & Contract Form
 * ========================================================================== */
.pricing-sim-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-subtle) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 32px;
  margin-bottom: 40px;
  box-shadow: var(--shadow-sm);
}

.pricing-sim-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 32px;
  align-items: center;
}

@media (max-width: 860px) {
  .pricing-sim-grid {
    grid-template-columns: 1fr;
  }
}

.pricing-calc-box {
  background-color: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.pricing-total-amount {
  font-size: 36px;
  font-weight: 900;
  color: var(--primary);
  margin: 12px 0 4px;
}
[data-theme="dark"] .pricing-total-amount {
  color: #818CF8;
}

.pricing-slider-wrap {
  margin: 20px 0;
}

.pricing-slider {
  width: 100%;
  accent-color: var(--secondary);
  height: 6px;
  cursor: pointer;
}

.pricing-exclusion-notice {
  background-color: var(--status-success-bg);
  border: 1px solid var(--status-success-border);
  color: var(--status-success-text);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
}

/* Form Controls (Strict M3 styling, zero standard select) */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--surface);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: all 0.15s;
}

.form-input:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.selector-trigger-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--surface);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all 0.15s;
}

.selector-trigger-btn:hover {
  border-color: var(--border-medium);
  background-color: var(--surface-subtle);
}

/* ==========================================================================
 * 10. Animations & Utilities
 * ========================================================================== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

@keyframes slideLeft {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.shrink-0 { flex-shrink: 0; }
.whitespace-nowrap { white-space: nowrap; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.font-black { font-weight: 900; }
.text-muted { color: var(--text-muted); }

/* ==========================================================================
 * 11. Additional Enterprise SaaS Components (KPI, Drawer, Invoice, Tabs)
 * ========================================================================== */

/* KPI Summary Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background-color: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s, box-shadow 0.15s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.kpi-icon-badge {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 900;
  color: var(--text-primary);
  line-height: 1;
}

.kpi-unit {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.kpi-subtext {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Tenant Header Banner */
.tenant-banner {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-subtle) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  margin-bottom: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.tenant-banner-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.tenant-avatar {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #181B39 0%, #4F46E5 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(24, 27, 57, 0.2);
}

.tenant-company-name {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.tenant-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Tenant SSO App Launcher Cards Grid */
.launcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

.launcher-card {
  background-color: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.launcher-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--secondary);
}

.launcher-card-header {
  padding: 16px 20px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.launcher-card-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.launcher-card-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.launcher-card-footer {
  padding: 16px 20px;
  background-color: var(--surface-subtle);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Sub-nav Tabs inside SuperAdmin & Tenant Views */
.subnav-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 24px;
  overflow-x: auto;
}

.subnav-tab-item {
  padding: 12px 18px;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

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

.subnav-tab-item.active {
  color: var(--secondary);
  border-bottom-color: var(--secondary);
}

/* Invoice Modal Sheet (適格請求書) */
.invoice-sheet {
  background-color: #FFFFFF;
  color: #0F172A;
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 800px;
  margin: 0 auto;
  border: 1px solid var(--border-subtle);
}

.invoice-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  border-bottom: 2px solid #0F172A;
  padding-bottom: 20px;
}

.invoice-company-box {
  text-align: right;
  font-size: 12px;
  line-height: 1.6;
}

.invoice-total-highlight {
  background-color: #F8FAFC;
  border: 2px solid #0F172A;
  padding: 16px 24px;
  border-radius: var(--radius-md);
  margin: 24px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* User Profile Badge in Header */
.user-badge-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 4px 12px 4px 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.user-badge-wrap:hover {
  border-color: var(--border-medium);
  background-color: var(--surface);
}

.user-avatar-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  overflow: hidden;
}

.user-badge-info {
  display: flex;
  flex-direction: column;
}

.user-badge-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.user-badge-sub {
  font-size: 10px;
  color: var(--text-muted);
}
