:root {
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(30, 41, 59, 0.9);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.3);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-indigo: #6366f1;
  --accent-violet: #8b5cf6;
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.35);
  --accent-amber: #f59e0b;
  --accent-amber-glow: rgba(245, 158, 11, 0.35);
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  --glow-indigo: 0 0 25px rgba(99, 102, 241, 0.4);

  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', Courier, monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(6, 182, 212, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(15, 23, 42, 0.8) 0%, #090d16 100%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header & Navigation */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.5);
  font-size: 20px;
}

.brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-indigo);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}

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

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.user-badge-no {
  font-size: 11px;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-indigo), #4f46e5);
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
  background: linear-gradient(135deg, #7073ff, #5c54f5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-unlock {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #ffffff;
  border: 1px solid rgba(6, 182, 212, 0.4);
  box-shadow: 0 4px 14px var(--accent-cyan-glow);
}

.btn-unlock:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(6, 182, 212, 0.6);
  transform: translateY(-1px);
}

.btn-refill {
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #ffffff;
  border: 1px solid rgba(245, 158, 11, 0.4);
  box-shadow: 0 4px 14px var(--accent-amber-glow);
}

.btn-refill:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(245, 158, 11, 0.6);
  transform: translateY(-1px);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(244, 63, 94, 0.25);
  color: #ffffff;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.badge-unlock {
  background: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(6, 182, 212, 0.35);
}

.badge-refill {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.badge-both {
  background: rgba(139, 92, 246, 0.15);
  color: #c084fc;
  border: 1px solid rgba(139, 92, 246, 0.35);
}

.badge-none {
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

/* Main Container */
.container {
  max-width: 1760px;
  margin: 0 auto;
  padding: 32px 24px;
  flex: 1;
  width: 96%;
}

/* Cards */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

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

.card-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

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

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  background: rgba(15, 23, 42, 0.9);
}

/* Checkbox with stylish checkmark */
.checkbox-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.checkbox-card:hover {
  background: rgba(30, 41, 59, 0.5);
  border-color: rgba(255, 255, 255, 0.15);
}

.checkbox-card input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--accent-indigo);
  cursor: pointer;
}

.checkbox-info {
  display: flex;
  flex-direction: column;
}

.checkbox-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.checkbox-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

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

.data-table th {
  background: rgba(15, 23, 42, 0.7);
  padding: 14px 18px;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.6px;
}

.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

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

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.active,
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.active .modal,
.modal-backdrop.open .modal {
  transform: scale(1) translateY(0);
}

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

.modal-body {
  padding: 24px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  background: rgba(15, 23, 42, 0.6);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

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

.toast {
  pointer-events: auto;
  min-width: 300px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: #1e293b;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-success {
  border-color: rgba(16, 185, 129, 0.4);
  background: #064e3b;
}

.toast-error {
  border-color: rgba(244, 63, 94, 0.4);
  background: #881337;
}

.toast-info {
  border-color: rgba(99, 102, 241, 0.4);
  background: #1e1b4b;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Utilities */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

@media (max-width: 768px) {
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  .navbar {
    padding: 12px 16px;
  }
  .container {
    padding: 16px 12px;
  }
}

/* ========================================== */
/* DUAL-PORTAL SEGMENTED CHOICE PILL */
/* ========================================== */
.portal-choice-pill {
  display: inline-flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 9999px;
  padding: 3px;
  gap: 3px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.choice-pill-item {
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 9999px;
  text-decoration: none;
  color: var(--text-muted);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  background: transparent;
}

.choice-pill-item:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.07);
}

.choice-pill-item.active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.45);
}

/* High-contrast custom checkmarks for Authorities & Permissions Matrix */
.auth-matrix-cb-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  vertical-align: middle;
  cursor: pointer;
}

.auth-matrix-cb-wrap .auth-matrix-cb {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  pointer-events: none;
}

.auth-matrix-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.75);
  transition: all 0.15s ease-in-out;
  box-sizing: border-box;
}

.auth-matrix-indicator .auth-check-icon {
  width: 15px;
  height: 15px;
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.auth-matrix-cb-wrap:hover .auth-matrix-cb:not(:disabled) + .auth-matrix-indicator {
  border-color: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
  transform: scale(1.08);
}

/* Active / Granted States: Solid high-contrast background with deep dark bold check mark */
.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="director"],
.auth-matrix-indicator.granted[data-role="director"] {
  background: #34d399 !important;
  border-color: #10b981 !important;
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.5);
}
.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="director"] .auth-check-icon,
.auth-matrix-indicator.granted[data-role="director"] .auth-check-icon {
  opacity: 1 !important;
  transform: scale(1) !important;
  color: #022c22 !important;
}

.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="company_admin"],
.auth-matrix-indicator.granted[data-role="company_admin"] {
  background: #c084fc !important;
  border-color: #a855f7 !important;
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.5);
}
.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="company_admin"] .auth-check-icon,
.auth-matrix-indicator.granted[data-role="company_admin"] .auth-check-icon {
  opacity: 1 !important;
  transform: scale(1) !important;
  color: #2e1065 !important;
}

.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="manager"],
.auth-matrix-indicator.granted[data-role="manager"] {
  background: #38bdf8 !important;
  border-color: #0284c7 !important;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}
.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="manager"] .auth-check-icon,
.auth-matrix-indicator.granted[data-role="manager"] .auth-check-icon {
  opacity: 1 !important;
  transform: scale(1) !important;
  color: #082f49 !important;
}

.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="field_tech"],
.auth-matrix-indicator.granted[data-role="field_tech"] {
  background: #fbbf24 !important;
  border-color: #d97706 !important;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}
.auth-matrix-cb-wrap .auth-matrix-cb:checked + .auth-matrix-indicator[data-role="field_tech"] .auth-check-icon,
.auth-matrix-indicator.granted[data-role="field_tech"] .auth-check-icon {
  opacity: 1 !important;
  transform: scale(1) !important;
  color: #451a03 !important;
}

/* Disabled / View-Only States */
.auth-matrix-cb-wrap .auth-matrix-cb:disabled + .auth-matrix-indicator {
  cursor: not-allowed;
}

/* When disabled AND checked (e.g. view-only permissions in other companies): Keep FULL vibrant solid contrast! */
.auth-matrix-cb-wrap .auth-matrix-cb:disabled:checked + .auth-matrix-indicator {
  opacity: 1 !important;
  filter: none !important;
  cursor: default !important;
}

/* When disabled and NOT checked (unassigned / restricted permissions): Clean subtle dashed box */
.auth-matrix-cb-wrap .auth-matrix-cb:disabled:not(:checked) + .auth-matrix-indicator,
.auth-matrix-indicator.not-granted {
  background: rgba(15, 23, 42, 0.35) !important;
  border: 1px dashed rgba(148, 163, 184, 0.25) !important;
  opacity: 0.45 !important;
  cursor: default !important;
}
.auth-matrix-indicator.not-granted .auth-check-icon {
  display: none;
}

/* Daily Cap Bypass Waiting Modal & Spinner */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.bypass-pulse-spinner {
  animation: spin 1s linear infinite;
}

