/**
 * AECS4U Component Styles
 * Cards, Buttons, Forms, Tables, Alerts
 */

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  transition: var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

[data-bs-theme="dark"] .card {
  background: var(--color-bg-secondary);
}

.card-header {
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border-light);
  padding: 1rem 1.25rem;
  font-weight: var(--font-weight-semibold);
}

[data-bs-theme="dark"] .card-header {
  background: var(--color-bg-tertiary);
}

.card-body {
  padding: 1.25rem;
}

.card-footer {
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border-light);
  padding: 1rem 1.25rem;
}

.icon-size-2xl {
  font-size: 2rem;
}

.user-menu-icon {
  font-size: 1.5rem;
}

.avatar-placeholder-lg {
  width: 120px;
  height: 120px;
  font-size: 3rem;
}

.avatar-placeholder-sm {
  width: 48px;
  height: 48px;
  font-size: 1.25rem;
}

.account-provider-icon {
  width: 40px;
  text-align: center;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
  transition: var(--transition-base);
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-secondary-500));
  border: none;
  color: white;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-secondary-600));
  color: white;
}

.btn-secondary {
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-medium);
  color: var(--color-text-primary);
}

.btn-secondary:hover {
  background: var(--color-bg-secondary);
  border-color: var(--color-primary-500);
  color: var(--color-primary-600);
}

.btn-outline-primary {
  background: transparent;
  border: 1px solid var(--color-primary-500);
  color: var(--color-primary-600);
}

.btn-outline-primary:hover {
  background: var(--color-primary-500);
  color: white;
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
}

.btn-ghost:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-primary-600);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: var(--text-sm);
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: var(--text-lg);
}

.btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: var(--radius-full);
}

.btn-icon.btn-sm {
  width: 2rem;
  height: 2rem;
}

/* ============================================================
   FORMS
   ============================================================ */

.form-control,
.form-select {
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-md);
  padding: 0.625rem 0.875rem;
  color: var(--color-text-primary);
  transition: var(--transition-base);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  outline: none;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background-color: var(--color-bg-secondary);
}

.form-control::placeholder {
  color: var(--color-text-muted);
}

.form-label {
  font-weight: var(--font-weight-medium);
  margin-bottom: 0.5rem;
  color: var(--color-text-secondary);
}

.form-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* ============================================================
   TABLES
   ============================================================ */

.table {
  background: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table th {
  background: var(--color-bg-tertiary);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
}

.table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: var(--color-bg-secondary);
}

[data-bs-theme="dark"] .table {
  background: var(--color-bg-secondary);
}

[data-bs-theme="dark"] .table th {
  background: var(--color-bg-tertiary);
}

[data-bs-theme="dark"] .table tbody tr:hover {
  background: rgba(59, 130, 246, 0.1);
}

/* ============================================================
   ALERTS
   ============================================================ */

.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.alert-icon {
  flex-shrink: 0;
  font-size: 1.25rem;
}

.alert-success {
  background: var(--color-success-50);
  border-color: var(--color-success-500);
  color: var(--color-success-700);
}

.alert-warning {
  background: var(--color-warning-50);
  border-color: var(--color-warning-500);
  color: var(--color-warning-700);
}

.alert-danger {
  background: var(--color-danger-50);
  border-color: var(--color-danger-500);
  color: var(--color-danger-700);
}

.alert-info {
  background: var(--color-info-50);
  border-color: var(--color-info-500);
  color: var(--color-info-700);
}

[data-bs-theme="dark"] .alert-success {
  background: rgba(16, 185, 129, 0.1);
  color: #6ee7b7;
}

[data-bs-theme="dark"] .alert-warning {
  background: rgba(245, 158, 11, 0.1);
  color: #fcd34d;
}

[data-bs-theme="dark"] .alert-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
}

[data-bs-theme="dark"] .alert-info {
  background: rgba(6, 182, 212, 0.1);
  color: #67e8f9;
}

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-full);
}

.badge-primary {
  background: var(--color-primary-100);
  color: var(--color-primary-700);
}

.badge-success {
  background: var(--color-success-100);
  color: var(--color-success-700);
}

.badge-warning {
  background: var(--color-warning-100);
  color: var(--color-warning-700);
}

.badge-danger {
  background: var(--color-danger-100);
  color: var(--color-danger-700);
}

/* ============================================================
   MODALS
   ============================================================ */

.modal-content {
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
}

[data-bs-theme="dark"] .modal-content {
  background: var(--color-bg-secondary);
}

.modal-header {
  border-bottom: 1px solid var(--color-border-light);
  padding: 1.25rem 1.5rem;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  border-top: 1px solid var(--color-border-light);
  padding: 1rem 1.5rem;
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

[data-bs-theme="dark"] .toast {
  background: var(--color-bg-secondary);
}

.toast-header {
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border-light);
  padding: 0.75rem 1rem;
}

[data-bs-theme="dark"] .toast-header {
  background: var(--color-bg-tertiary);
}

/* ============================================================
   CODE
   ============================================================ */

code {
  background: var(--color-bg-tertiary);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-base);
  font-family: var(--font-mono);
  font-size: 0.875em;
  color: var(--color-text-primary);
}

pre {
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: 1rem;
  overflow-x: auto;
}

pre code {
  background: transparent;
  padding: 0;
}

/* ============================================================
   PROGRESS
   ============================================================ */

.progress {
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-full);
  height: 0.5rem;
  overflow: hidden;
}

.progress-bar {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-secondary-500));
  transition: width var(--duration-slow) var(--ease-in-out);
}

/* ============================================================
   SPINNER
   ============================================================ */

.spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--color-border-light);
  border-top-color: var(--color-primary-500);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

/* ============================================================
   COOKIE CONSENT MODAL
   ============================================================ */

.cookie-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.cookie-modal {
  background: var(--color-bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 420px;
  width: 100%;
  padding: 2rem;
  text-align: center;
  animation: modalSlideIn 0.3s ease-out;
}

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

[data-bs-theme="dark"] .cookie-modal {
  background: var(--color-bg-secondary);
}

.cookie-modal-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1.25rem;
  background: linear-gradient(135deg, var(--color-warning-100), var(--color-warning-200));
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cookie-modal-icon i {
  font-size: 1.75rem;
  color: var(--color-warning-600);
}

[data-bs-theme="dark"] .cookie-modal-icon {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(245, 158, 11, 0.3));
}

[data-bs-theme="dark"] .cookie-modal-icon i {
  color: var(--color-warning-400);
}

.cookie-modal-title {
  font-size: 1.25rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0 0 0.75rem;
}

.cookie-modal-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin: 0 0 1rem;
}

.cookie-modal-link {
  display: inline-block;
  font-size: var(--text-sm);
  color: var(--color-primary-600);
  text-decoration: underline;
  margin-bottom: 1.5rem;
}

.cookie-modal-link:hover {
  color: var(--color-primary-700);
}

.cookie-modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.cookie-modal-actions .btn {
  flex: 1;
  padding: 0.625rem 1.25rem;
}

@media (max-width: 480px) {
  .cookie-modal {
    padding: 1.5rem;
  }

  .cookie-modal-actions {
    flex-direction: column;
  }

  .cookie-modal-actions .btn {
    width: 100%;
  }
}

/* ============================================================
   SWAGGER UI
   ============================================================ */

.swagger-ui {
  font-family: var(--font-family-base);
}

.swagger-ui .topbar {
  display: none;
}

.swagger-ui .info {
  margin: 20px 0;
}

.swagger-ui .info .title {
  font-size: var(--text-2xl);
  color: var(--color-text-primary);
}

.swagger-ui .info .description {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
}

/* Version badges */
.swagger-ui .info .version {
  background: var(--color-primary-500);
  color: white;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  display: inline-block;
  margin: 0;
}

.swagger-ui .info .version-stamp {
  margin-left: 8px;
}

.swagger-ui .info .version-stamp .version {
  background: var(--color-gray-600);
  color: white;
  font-size: var(--text-xs);
  padding: 3px 8px;
}

.swagger-ui .info pre.version {
  background: var(--color-primary-500);
  color: white;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  display: inline-block;
  margin: 0;
  font-family: var(--font-family-base);
}

.swagger-ui .info .version-stamp pre.version {
  background: var(--color-gray-500);
  font-size: var(--text-xs);
  padding: 3px 8px;
}

/* Operation blocks */
.swagger-ui .opblock-tag {
  font-size: var(--text-lg);
  border-bottom: 1px solid var(--color-border-light);
}

.swagger-ui .opblock {
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
}

.swagger-ui .opblock .opblock-summary {
  padding: var(--space-3);
}

.swagger-ui .opblock.opblock-get {
  background: rgba(97, 175, 254, 0.1);
  border-color: var(--color-info-500);
}

.swagger-ui .opblock.opblock-post {
  background: rgba(73, 204, 144, 0.1);
  border-color: var(--color-success-500);
}

.swagger-ui .opblock.opblock-put {
  background: rgba(252, 161, 48, 0.1);
  border-color: var(--color-warning-500);
}

.swagger-ui .opblock.opblock-delete {
  background: rgba(249, 62, 62, 0.1);
  border-color: var(--color-danger-500);
}

/* Form elements */
.swagger-ui .btn {
  border-radius: var(--radius-md);
}

.swagger-ui select {
  border-radius: var(--radius-md);
}

.swagger-ui input[type="text"],
.swagger-ui textarea {
  border-radius: var(--radius-md);
}

/* Dark mode adjustments */
[data-bs-theme="dark"] .swagger-ui {
  filter: invert(88%) hue-rotate(180deg);
}

[data-bs-theme="dark"] .swagger-ui .opblock-body pre {
  filter: invert(100%) hue-rotate(180deg);
}

[data-bs-theme="dark"] .swagger-ui img {
  filter: invert(100%) hue-rotate(180deg);
}

/* Keep version badges visible in dark mode (override invert) */
[data-bs-theme="dark"] .swagger-ui .info pre.version,
[data-bs-theme="dark"] .swagger-ui .info .version {
  filter: invert(100%) hue-rotate(180deg);
}

/* ============================================================
   REDOC
   ============================================================ */

.card-body redoc {
  display: block;
  min-height: 800px;
}

redoc .menu-content {
  background: var(--color-bg-primary) !important;
}

redoc .api-content {
  background: var(--color-bg-secondary) !important;
}

[data-bs-theme="dark"] redoc {
  --text-color: var(--color-text-primary);
  --bg-color: var(--color-bg-primary);
}

/* ============================================================
   PANEL / BOKEH DASHBOARD
   ============================================================ */

#panel-dashboard-container {
  min-height: 800px;
  overflow: auto;
}

#panel-dashboard-container .bk-root {
  color: var(--color-text-primary);
}

/* ============================================================
   LEGAL PAGES
   ============================================================ */

.legal-container,
.legal-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.legal-header {
  text-align: center;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border-light);
}

.legal-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 1rem;
}

.legal-header .last-updated {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
}

/* Legal header gradient variant */
.legal-header.gradient {
  background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
  color: white;
  padding: 3rem 2rem;
  border-radius: var(--radius-lg);
  margin-bottom: 2rem;
  border-bottom: none;
  text-align: left;
}

.legal-header.gradient h1 {
  color: white;
  margin-bottom: 0.5rem;
}

.legal-header.gradient .last-updated {
  opacity: 0.85;
  color: white;
}

/* Table of Contents */
.legal-toc,
.toc-card {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
  border: 1px solid var(--color-border-light);
}

.legal-toc h3,
.toc-card h5 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--color-text-primary);
}

.legal-toc ul,
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list {
  columns: 2;
  column-gap: 2rem;
}

.legal-toc li,
.toc-list li {
  margin-bottom: 0.5rem;
  break-inside: avoid;
}

.legal-toc a,
.toc-list a {
  color: var(--color-primary-600);
  text-decoration: none;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: color var(--duration-fast);
}

.legal-toc a:hover,
.toc-list a:hover {
  text-decoration: underline;
  color: var(--color-primary-700);
}

.toc-list a i {
  color: var(--color-primary-500);
  font-size: 0.75rem;
}

/* Legal Sections */
.legal-section {
  background: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
}

.legal-section:last-child {
  border-bottom: none;
}

.legal-section h2 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.legal-section h2 i {
  color: var(--color-primary-500);
  font-size: 1.2rem;
}

.legal-section h3 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--color-border-light);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.legal-section h3 .section-number {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-secondary-500));
  color: white;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.legal-section h4 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin: 1.5rem 0 0.75rem;
}

.legal-section p,
.legal-section li {
  color: var(--color-text-secondary);
  line-height: 1.7;
  margin-bottom: 1rem;
}

.legal-section ul {
  padding-left: 1.5rem;
}

.legal-section ul li {
  margin-bottom: 0.5rem;
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border: 1px solid var(--color-border-light);
}

.data-table th {
  background: var(--color-bg-secondary);
  font-weight: 600;
  color: var(--color-text-primary);
}

.data-table td {
  color: var(--color-text-secondary);
}

/* Highlight Box */
.highlight-box {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
  border-left: 4px solid var(--color-primary-500);
  padding: 1rem 1.5rem;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 1.5rem 0;
}

.highlight-box.info {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(96, 165, 250, 0.1));
  border-left-color: var(--color-info-500);
}

.highlight-box.warning {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(251, 191, 36, 0.1));
  border-left-color: var(--color-warning-500);
}

.highlight-box.danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(248, 113, 113, 0.1));
  border-left-color: var(--color-danger-500);
}

.highlight-box p {
  margin: 0;
  color: var(--color-text-primary);
}

/* Contact Card */
.contact-card {
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-top: 1rem;
}

.contact-card.gradient {
  background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
  color: white;
  border: none;
  padding: 2rem;
  margin-top: 2rem;
}

.contact-card h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.contact-card.gradient h4 {
  color: white;
}

.contact-card p {
  margin-bottom: 0.5rem;
}

.contact-card.gradient p {
  color: rgba(255, 255, 255, 0.9);
}

.contact-card a {
  color: var(--color-primary-600);
}

.contact-card.gradient a {
  color: #93c5fd;
}

/* Back to Top Button */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--color-primary-500);
  color: white;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
  opacity: 0;
  transition: opacity var(--duration-normal);
}

.back-to-top.visible {
  opacity: 1;
}

.back-to-top:hover {
  background: var(--color-primary-600);
  color: white;
}

/* Legal Pages Dark Mode */
[data-bs-theme="dark"] .legal-header h1,
[data-bs-theme="dark"] .legal-section h2,
[data-bs-theme="dark"] .legal-section h3,
[data-bs-theme="dark"] .legal-toc h3,
[data-bs-theme="dark"] .toc-card h5 {
  color: var(--color-text-primary);
}

[data-bs-theme="dark"] .legal-toc,
[data-bs-theme="dark"] .toc-card,
[data-bs-theme="dark"] .data-table th {
  background: var(--color-bg-tertiary);
}

[data-bs-theme="dark"] .toc-card {
  border-color: var(--color-border-medium);
}

[data-bs-theme="dark"] .toc-list a {
  color: var(--color-text-secondary);
}

[data-bs-theme="dark"] .toc-list a:hover {
  color: var(--color-text-primary);
}

[data-bs-theme="dark"] .legal-section {
  background: var(--color-bg-secondary);
  border-color: var(--color-border-medium);
}

[data-bs-theme="dark"] .legal-section h3 {
  border-bottom-color: var(--color-border-medium);
}

[data-bs-theme="dark"] .legal-section h4 {
  color: var(--color-text-secondary);
}

[data-bs-theme="dark"] .legal-section p,
[data-bs-theme="dark"] .legal-section li {
  color: var(--color-text-secondary);
}

[data-bs-theme="dark"] .data-table th,
[data-bs-theme="dark"] .data-table td {
  border-color: var(--color-border-medium);
}

[data-bs-theme="dark"] .highlight-box {
  background: rgba(99, 102, 241, 0.15);
}

[data-bs-theme="dark"] .highlight-box.info {
  background: rgba(59, 130, 246, 0.15);
}

[data-bs-theme="dark"] .highlight-box.warning {
  background: rgba(245, 158, 11, 0.15);
}

[data-bs-theme="dark"] .highlight-box.danger {
  background: rgba(239, 68, 68, 0.15);
}

[data-bs-theme="dark"] .highlight-box p {
  color: var(--color-text-primary);
}

[data-bs-theme="dark"] .contact-card {
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-medium);
}

[data-bs-theme="dark"] .contact-card.gradient {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

[data-bs-theme="dark"] .legal-header.gradient {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

@media (max-width: 768px) {
  .toc-list {
    columns: 1;
  }

  .legal-header {
    padding: 2rem 1.5rem;
  }

  .legal-section {
    padding: 1.5rem;
  }
}

/* ============================================================
   ORGANIZATION SWITCHER
   ============================================================ */

.org-switcher {
  position: relative;
}

.org-switcher-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-base);
}

.org-switcher-btn:hover {
  background: var(--color-bg-tertiary);
}

.org-switcher-current {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.org-switcher-logo,
.org-item-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.org-switcher-logo-placeholder,
.org-item-logo-placeholder {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-secondary-500));
  color: white;
  font-weight: 600;
  font-size: 14px;
}

.org-switcher-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.org-switcher-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text-primary);
}

.org-switcher-role {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.org-switcher-arrow {
  margin-left: auto;
  color: var(--color-text-secondary);
}

.org-switcher-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  min-width: 320px;
  max-width: 400px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
}

.org-switcher-dropdown[hidden] {
  display: none;
}

.org-switcher-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.org-switcher-list {
  max-height: 300px;
  overflow-y: auto;
}

.org-switcher-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: inherit;
  transition: background var(--duration-fast);
}

.org-switcher-item:hover {
  background: var(--color-bg-secondary);
}

.org-switcher-item.active {
  background: var(--color-bg-tertiary);
}

.org-item-info {
  flex: 1;
  min-width: 0;
}

.org-item-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-item-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 0.25rem;
}

.org-item-separator {
  color: var(--color-text-muted);
}

.org-item-check {
  color: var(--color-primary-500);
}

.org-switcher-empty {
  padding: 2rem 1rem;
  text-align: center;
}

.org-switcher-empty-icon {
  font-size: 48px;
  margin-bottom: 0.5rem;
}

.org-switcher-empty-text {
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: 0.25rem;
}

.org-switcher-empty-subtext {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.org-switcher-footer {
  border-top: 1px solid var(--color-border-light);
  padding: 0.5rem;
}

.org-switcher-footer-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  color: var(--color-text-primary);
  border-radius: var(--radius-base);
  font-size: 14px;
  transition: background var(--duration-fast);
}

.org-switcher-footer-link:hover {
  background: var(--color-bg-secondary);
}

.org-switcher-footer-link svg {
  color: var(--color-text-secondary);
}

/* ============================================================
   PROFILE CONTENT
   ============================================================ */

.profile-header-inline {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  border: 1px solid var(--color-border-light);
}

.profile-avatar-inline,
.profile-avatar-placeholder-inline {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.profile-avatar-placeholder-inline {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-secondary-500));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
}

.profile-info-inline h2 {
  margin: 0 0 var(--space-1);
  font-size: 1.25rem;
}

.profile-info-inline p {
  margin: 0;
  color: var(--color-text-muted);
}

/* ============================================================
   DETAIL PAGES (.pd-*) — shared "entity detail" page layout
   Used for record/dossier/party detail screens: a stacked set
   of bordered sections with an uppercase title and label/value
   rows. Fully token-driven so it adapts to dark mode.
   ============================================================ */
.pd-header {
  background: var(--color-bg-primary);
  border-bottom: 1px solid var(--color-border-light);
  padding: var(--space-5) var(--space-6);
}
.pd-header h1 {
  font-size: 1.25rem;
  font-weight: var(--font-weight-bold);
  margin: 0;
}
.pd-meta {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}
.pd-section {
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}
.pd-section-title {
  font-size: 0.7rem;
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-text-secondary);
  padding: 0.6rem var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.pd-body {
  padding: var(--space-4) var(--space-5);
}
.pd-row {
  display: flex;
  align-items: baseline;
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--color-border-light);
  font-size: 0.82rem;
}
.pd-row:last-child {
  border-bottom: none;
}
.pd-label {
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  min-width: 170px;
  flex-shrink: 0;
}
.pd-value {
  font-weight: var(--font-weight-medium);
  word-break: break-word;
}
.pd-value.mono {
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.pd-back-link,
.back-link {
  font-size: 0.82rem;
}

/* ── Procedure / nested record cards ── */
.proc-card {
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.proc-card-header {
  background: var(--color-bg-secondary);
  padding: 0.6rem var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.proc-card-header a {
  text-decoration: none;
  font-weight: var(--font-weight-semibold);
  font-size: 0.88rem;
}
.proc-meta {
  font-size: 0.72rem;
  color: var(--color-text-secondary);
}

/* ── Attachment rows ── */
.attach-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--color-border-light);
  font-size: 0.82rem;
}
.attach-row:last-child {
  border-bottom: none;
}
.attach-icon {
  font-size: 1rem;
  flex-shrink: 0;
}
.attach-name {
  flex: 1;
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}
.attach-size {
  color: var(--color-text-secondary);
  font-size: 0.72rem;
  white-space: nowrap;
}

/* ── Collapsible chevron affordance inside detail sections ── */
.pd-section .accordion-button {
  background: var(--color-bg-secondary);
  box-shadow: none;
}
.pd-section .accordion-button:not(.collapsed) {
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
}
.pd-section .accordion-button::after {
  width: 0.7rem;
  height: 0.7rem;
  background-size: 0.7rem;
}
.btn-link[aria-expanded="true"] .bi-chevron-down {
  transform: rotate(180deg);
}
.btn-link .bi-chevron-down {
  transition: transform var(--duration-base) ease;
}

/* ══════════════════════════════════════════════════════════════════
   Alpine.js — hide elements before Alpine initialises
   ══════════════════════════════════════════════════════════════════ */
[x-cloak] { display: none !important; }

/* ══════════════════════════════════════════════════════════════════
   Error pages  (.error-code colour overrideable via --error-code-color)
   ══════════════════════════════════════════════════════════════════ */
.error-container {
  text-align: center;
  padding: 2rem;
}
.error-code {
  font-size: 8rem;
  font-weight: 800;
  color: var(--error-code-color, var(--color-primary-500));
  line-height: 1;
  margin-bottom: 1rem;
}
.error-title {
  font-size: 1.5rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: 0.5rem;
}
.error-message {
  color: var(--color-text-secondary);
  margin-bottom: 2rem;
}

/* ══════════════════════════════════════════════════════════════════
   Admin dashboard primitives
   (stat cards, page headers, action strips, tables, status badges)
   ══════════════════════════════════════════════════════════════════ */
.admin-card {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-light);
}
.admin-card-title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0;
}
.stat-card {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-align: center;
  transition: transform var(--duration-base), box-shadow var(--duration-base);
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.stat-value {
  font-size: 2rem;
  font-weight: var(--font-weight-bold);
  color: var(--stat-value-color, var(--color-primary-600));
}
.stat-label {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}
.page-header { margin-bottom: var(--space-6); }
.page-header h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  margin: 0;
}
.page-header .breadcrumb {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
}
.quick-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.quick-action-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  text-decoration: none;
  font-weight: var(--font-weight-medium);
  transition: all var(--duration-base);
}
.quick-action-btn:hover {
  background: var(--color-primary-50);
  border-color: var(--color-primary-200);
  color: var(--color-primary-700);
}
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th,
.admin-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
}
.admin-table th {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.admin-table tbody tr:hover { background: var(--color-bg-tertiary); }
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
}
.status-badge.success { background: var(--color-success-100); color: var(--color-success-700); }
.status-badge.warning { background: var(--color-warning-100); color: var(--color-warning-700); }
.status-badge.danger  { background: var(--color-danger-100);  color: var(--color-danger-700); }
.status-badge.info    { background: var(--color-primary-100); color: var(--color-primary-700); }

/* ══════════════════════════════════════════════════════════════════
   Simulation / calculator cards
   Override --sim-accent per page to colour the header bar,
   active pills, range thumbs, and range-value readout.
   ══════════════════════════════════════════════════════════════════ */
.sim-card {
  --sim-accent: var(--color-primary-500);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-light);
  padding: var(--space-5);
  background: var(--color-bg-primary);
}
.sim-card-header {
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-base, 1rem);
  color: var(--color-text-primary);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--sim-accent);
}
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: 0.3rem;
}
.pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  background: var(--color-gray-100);
  color: var(--color-gray-600);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--duration-fast, 0.1s) ease;
}
.pill.active { background: var(--sim-accent); color: #fff; }
.pill.muted  { background: var(--color-gray-50); color: var(--color-gray-400); cursor: default; }
.solution-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-light);
  background: var(--color-bg-primary);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.solution-card.current { border-left: 4px solid var(--color-primary-500); }
.solution-card.best    { border-left: 4px solid var(--color-success-500); }
.kpi {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  padding: 0.25rem 0;
  border-bottom: 1px dashed var(--color-gray-100);
}
.kpi:last-child { border-bottom: none; }
.kpi .v       { font-weight: var(--font-weight-bold); color: var(--color-text-primary); }
.kpi .v.pos   { color: var(--color-success-500); }
.kpi .v.neg   { color: var(--color-danger-500); }
.kpi .v.muted { color: var(--color-gray-400); font-weight: var(--font-weight-medium); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.summary-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--color-gray-100); }
.summary-table tr:last-child td { border-bottom: none; font-weight: var(--font-weight-bold); }
.summary-table .value-col { text-align: right; font-weight: var(--font-weight-semibold); white-space: nowrap; }
.summary-table .negative { color: var(--color-danger-500); }
.summary-table .positive { color: var(--color-success-500); }
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-gray-400);
  margin-top: 0.25rem;
}
.range-value {
  text-align: center;
  font-size: 1.25rem;
  font-weight: var(--font-weight-bold);
  color: var(--sim-accent);
  margin-top: 0.25rem;
}
.sim-card input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--color-gray-200);
  outline: none;
}
.sim-card input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--sim-accent);
  cursor: pointer;
}
.verdict-positive { background: linear-gradient(135deg, #ecfdf5, #d1fae5); border-color: #a7f3d0; }
.verdict-negative { background: linear-gradient(135deg, #fef2f2, #fee2e2); border-color: #fecaca; }
.verdict-neutral  { background: linear-gradient(135deg, #fffbeb, #fef3c7); border-color: #fde68a; }
.ranking-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr 7rem 7rem 7rem 6rem;
  gap: var(--space-2);
  align-items: center;
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--color-gray-100);
}
.ranking-row.head {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  background: var(--color-gray-50);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
@media (max-width: 700px) {
  .ranking-row { grid-template-columns: 2rem 1fr 5.5rem 5.5rem; }
  .ranking-row .col-payback,
  .ranking-row .col-co2 { display: none; }
}
.tier-card {
  cursor: pointer;
  border: 2px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  transition: all var(--duration-base);
}
.tier-card.selected {
  border-color: var(--sim-accent);
  background: var(--color-primary-50);
  box-shadow: 0 0 0 3px var(--color-primary-100);
}
.tier-card:hover { border-color: var(--color-primary-300); }
.compare-bar {
  height: 32px;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  background: var(--color-gray-200);
  position: relative;
}
.compare-bar-fill {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: var(--font-weight-semibold);
  font-size: 0.85rem;
  transition: width 0.5s ease;
}
.chart-wrapper      { position: relative; height: 280px; }
.chart-wrapper-tall { position: relative; height: 360px; }
.input-num {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.share-bar { height: 8px; border-radius: var(--radius-sm); overflow: hidden; display: flex; }

/* ══════════════════════════════════════════════════════════════════
   Panel / iframe embed  (Grafana panels, embedded dashboards)
   ══════════════════════════════════════════════════════════════════ */
.panel-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 140px);
  min-height: 600px;
}
.panel-iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-bg-primary);
}
.panel-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--color-bg-primary);
  opacity: 0.9;
  z-index: 10;
}
