:root {
  --bg-dark: #070a13;
  --bg-darker: #04060b;
  --card-bg: rgba(17, 25, 44, 0.75);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --info: #06b6d4;
  --info-bg: rgba(6, 182, 212, 0.15);
  --font-family: 'Outfit', sans-serif;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --glow-indigo: 0 0 15px rgba(99, 102, 241, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.1) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: auto;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-darker);
}
::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

.glass {
  background: var(--card-bg);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border: 1px solid var(--card-border);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  font-family: var(--font-family);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  gap: 8px;
  text-decoration: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: var(--glow-indigo);
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-main);
}
.btn-outline:hover {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-warning {
  background-color: var(--warning);
  color: #000000;
  font-weight: 600;
}
.btn-warning:hover {
  background-color: #d97706;
  transform: translateY(-1px);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover {
  background-color: #dc2626;
  transform: translateY(-1px);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.badge-indigo { background: rgba(99, 102, 241, 0.2); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }
.badge-success { background: var(--success-bg); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-danger { background: var(--danger-bg); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-warning { background: var(--warning-bg); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }

/* Overlays / Login Gate */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-darker);
  z-index: 1000;
  transition: var(--transition);
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 40px;
  border-radius: 16px;
  animation: floatIn 0.5s ease-out;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.logo-icon {
  font-size: 40px;
  margin-bottom: 15px;
  display: inline-block;
  animation: float 3s ease-in-out infinite;
}

.login-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.login-header p {
  color: var(--text-muted);
  font-size: 14px;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input,
.form-group select,
select {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  background-color: #0f172a;
  border: 1px solid var(--card-border);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 14px;
  transition: var(--transition);
}

.form-group select,
select {
  cursor: pointer;
  appearance: auto;
}

/* Global Select Option Styling (Prevents OS white-on-white text bug) */
select option,
select optgroup {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  padding: 10px 14px;
  font-size: 13.5px;
}

select option:checked,
select option:hover {
  background-color: #1e293b !important;
  color: #60a5fa !important;
}

.form-group input:focus,
.form-group select:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  background-color: #1e293b;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.input-addon-wrapper {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: hidden;
  transition: var(--transition);
}

.input-addon-wrapper:focus-within {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-addon-wrapper input {
  border: none;
  background: transparent;
  flex: 1;
}
.input-addon-wrapper input:focus {
  box-shadow: none;
  background: transparent;
}

.addon-suffix {
  padding-right: 16px;
  font-size: 14px;
  color: var(--text-muted);
  user-select: none;
}

.form-help {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.section-divider {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 25px 0 15px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.06);
}

/* Error / Success messages */
.error-msg {
  background-color: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #f87171;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 20px;
}
.success-msg {
  background-color: var(--success-bg);
  border: 1px solid rgba(16, 185, 129, 0.2);
  color: #34d399;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 20px;
}

/* App Layout */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-icon {
  font-size: 24px;
}

.header-brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 20px;
}

#user-name-display {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.app-main {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 20px 24px;
}

/* Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.metric-card {
  padding: 24px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--transition);
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.15);
}

.metric-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.metric-label {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.bg-indigo { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.bg-success { background: var(--success-bg); color: #34d399; }
.bg-danger { background: var(--danger-bg); color: #f87171; }
.bg-warning { background: var(--warning-bg); color: #fbbf24; }

/* Content grid */
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  align-items: start;
}

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

.main-content {
  min-width: 0;
  padding: 24px;
  border-radius: 14px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 25px;
  flex-wrap: wrap;
  gap: 15px;
}

.section-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 15px;
}

.search-input {
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  font-size: 14px;
  width: 240px;
  transition: var(--transition);
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.06);
}

/* Tables */
.table-container {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  -webkit-overflow-scrolling: touch;
}

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

.data-table th {
  background: rgba(255, 255, 255, 0.02);
  padding: 12px 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--card-border);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.01);
}

.company-cell {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.subdomain-link {
  color: var(--info);
  text-decoration: none;
  transition: var(--transition);
}
.subdomain-link:hover {
  text-decoration: underline;
}

.actions-cell {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

/* Sidebar Utilities */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.quick-actions-card {
  padding: 24px;
  border-radius: 12px;
}

.quick-actions-card h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.quick-actions-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.feed-log {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 12px;
  font-family: monospace;
  font-size: 11px;
  max-height: 250px;
  overflow-y: auto;
}

.feed-item {
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.03);
  word-break: break-all;
}
.feed-item:last-child {
  margin-bottom: 0;
  border-bottom: none;
}
.feed-item.info { color: var(--text-muted); }
.feed-item.success { color: #34d399; }
.feed-item.warning { color: #fbbf24; }
.feed-item.error { color: #f87171; }

.mt-4 { margin-top: 16px; }

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(4, 6, 11, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
  overflow-y: auto;
  animation: fadeIn 0.3s ease-out;
}

.modal-card {
  width: 95%;
  max-width: 650px;
  max-height: calc(100vh - 32px);
  border-radius: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  margin: auto;
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.max-w-lg {
  max-width: 500px;
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
.modal-close-btn:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
  flex-shrink: 0;
}

/* User Inspector in Modal */
.users-list-container {
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  margin-bottom: 20px;
}

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

.users-table th {
  background: rgba(255, 255, 255, 0.02);
  padding: 10px 14px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text-muted);
}

.users-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--card-border);
}

.reset-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 16px;
  animation: slideDown 0.3s ease-out;
}

.action-buttons-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 15px;
}

/* Loader Spinner */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: inline-block;
}

.text-center { text-align: center; }

/* Animations */
@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
  100% { transform: translateY(0px); }
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   SAAS ENTITLEMENT MATRIX & TREE STYLES
   ========================================================================== */

.ent-tree-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tree-node-module {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
  transition: var(--transition);
}

.tree-node-module:hover {
  border-color: rgba(99, 102, 241, 0.3);
  background: rgba(255, 255, 255, 0.03);
}

.tree-node-module.collapsed .node-children {
  display: none !important;
}

.tree-node-module.collapsed .node-expander {
  transform: rotate(-90deg);
}

.node-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.02);
  user-select: none;
}

.node-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.node-checkbox {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  cursor: pointer;
}

.node-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.node-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.node-desc {
  font-size: 11.5px;
  color: var(--text-muted);
}

.node-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.node-expander {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: transform 0.2s ease;
}

.node-children {
  padding: 8px 16px 14px 45px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
  background: rgba(0, 0, 0, 0.15);
}

.tree-node-tab, .tree-node-cap {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  transition: var(--transition);
}

.tree-node-tab:hover, .tree-node-cap:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

/* Badges for Deltas */
.badge-addon {
  background: rgba(245, 158, 11, 0.18) !important;
  color: #fbbf24 !important;
  border: 1px solid rgba(245, 158, 11, 0.5) !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  padding: 2px 7px !important;
  border-radius: 4px !important;
  letter-spacing: 0.03em !important;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.2) !important;
}

.badge-override {
  background: rgba(239, 68, 68, 0.18) !important;
  color: #f87171 !important;
  border: 1px solid rgba(239, 68, 68, 0.5) !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  padding: 2px 7px !important;
  border-radius: 4px !important;
  letter-spacing: 0.03em !important;
}

.badge-blueprint {
  background: rgba(255, 255, 255, 0.05) !important;
  color: #94a3b8 !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
}

/* Blueprint selector buttons */
.bp-btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.bp-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-main);
}

.bp-btn.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
  color: #a5b4fc;
}

/* Audit Cards */
.audit-card {
  padding: 14px 18px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.audit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.audit-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.audit-notes {
  font-size: 13px;
  color: #e2e8f0;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--primary);
}

.audit-diff {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 11px;
}

