/**
 * Institutional Confidence — design foundation (UNDP / World Bank–inspired).
 * Load after Bootstrap, design-system.css, design-tokens.css, and dashboard/public.css.
 */

:root {
  /* Primary palette */
  --color-navy: #0d2137;
  --color-navy-light: #1a3a5c;
  --color-teal: #0e9e76;
  --color-teal-light: #e8f8f3;
  --color-teal-dark: #0a7a5c;

  /* Backgrounds */
  --color-bg-page: #f2f4f7;
  --color-bg-surface: #ffffff;
  --color-bg-sidebar: #0d2137;
  --color-bg-header: #ffffff;

  /* Text */
  --color-text-primary: #0d2137;
  --color-text-secondary: #4a5568;
  --color-text-muted: #8896a5;
  --color-text-inverse: #ffffff;

  /* Status colors */
  --color-success: #16a34a;
  --color-success-bg: #f0fdf4;
  --color-warning: #d97706;
  --color-warning-bg: #fffbeb;
  --color-danger: #dc2626;
  --color-danger-bg: #fef2f2;
  --color-info: #1d4ed8;
  --color-info-bg: #eff6ff;

  /* UI elements */
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e0;
  --color-shadow: rgba(13, 33, 55, 0.08);

  /* Typography */
  --font-primary: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Spacing */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(13, 33, 55, 0.06), 0 1px 2px rgba(13, 33, 55, 0.04);
  --shadow-md: 0 4px 12px rgba(13, 33, 55, 0.08), 0 2px 4px rgba(13, 33, 55, 0.04);
  --shadow-lg: 0 10px 30px rgba(13, 33, 55, 0.12);

  /* Bootstrap 5 bridge (components using --bs-primary) */
  --bs-primary: #0e9e76;
  --bs-primary-rgb: 14, 158, 118;
  --bs-link-color: #0a7a5c;
  --bs-link-hover-color: #085c47;

  /* Legacy tokens used across design-system.css / dashboard.css */
  --color-midnight: var(--color-navy);
  --color-royal: var(--color-navy-light);
  --font-body: var(--font-primary);
  --font-display: var(--font-primary);
  --font-arabic: "Noto Sans Arabic", system-ui, sans-serif;
  --color-off-white: var(--color-bg-page);
  --color-gray-600: var(--color-text-secondary);
  --color-gray-500: var(--color-text-muted);
  --color-gray-200: var(--color-border);
  --color-white: #ffffff;
  --primary-color: var(--color-teal);
  --success-color: var(--color-success);
  --danger-color: var(--color-danger);
  --warning-color: var(--color-warning);
  --info-color: var(--color-info);
  --light-bg: var(--color-bg-page);
  --dark-text: var(--color-text-primary);
  --card-shadow: var(--shadow-sm);
  --card-shadow-hover: var(--shadow-md);

  /* design-tokens.css focus bridge */
  --dt-focus-ring-color: var(--color-teal);
}

[dir="rtl"] {
  font-family: var(--font-arabic);
  letter-spacing: 0;
}

body.mg-app-shell,
body.mg-register-body,
body.mg-public {
  font-family: var(--font-primary);
  background: var(--color-bg-page);
  color: var(--color-text-primary);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Remove decorative skyline / hero imagery on workspace and inner pages */
.dashboard-hero,
.page-hero,
.hero-bg,
[class*="hero-image"],
[class*="city-bg"],
[style*="background-image"] {
  background-image: none !important;
  background: var(--color-bg-page) !important;
}

/* Cards — institutional surface (works with Bootstrap .card-body) */
.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

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

/* Primary / secondary actions */
.btn.btn-primary {
  background: var(--color-teal);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn.btn-primary:hover {
  background: var(--color-teal-dark);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn.btn-primary:focus-visible {
  outline: 2px solid var(--color-teal-dark);
  outline-offset: 2px;
}

.btn.btn-secondary {
  background: transparent;
  color: var(--color-navy);
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 9px 20px;
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.btn.btn-secondary:hover {
  border-color: var(--color-teal);
  color: var(--color-teal);
  background: var(--color-teal-light);
}

/* ── Workspace shell: sidebar, top bar, mobile tab bar ───────────────── */
.mg-app-layout {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.mg-desktop-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--color-navy);
  color: rgba(255, 255, 255, 0.92);
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 1030;
  border-inline-end: 1px solid rgba(255, 255, 255, 0.06);
}

.mg-app-main-column {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin-inline-start: 240px;
  background: var(--color-bg-page);
}

@media (max-width: 767.98px) {
  .mg-app-main-column {
    margin-inline-start: 0;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

.sidebar-logo {
  display: flex;
  align-items: center;
  min-height: 68px;
  height: auto;
  padding: 10px 14px 10px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-logo-link {
  color: inherit;
}

.sidebar-logo-link:hover {
  color: #fff;
}

.logo-text {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  color: #fff;
}

/* Workspace sidebar / drawer — full-color wordmark: light tray on navy so blues stay readable */
.sidebar-brand-logo {
  display: block;
  box-sizing: content-box;
  max-width: min(204px, calc(100% - 2.5rem));
  width: auto;
  height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  object-fit: contain;
  object-position: left center;
}

.sidebar-logo-link:hover .sidebar-brand-logo {
  background: #fff;
  border-color: rgba(77, 217, 172, 0.55);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.22);
}

[dir="rtl"] .sidebar-brand-logo {
  object-position: right center;
}

/* Default circular mark: true transparency on navy + subtle lift for blue petals */
.sidebar-brand-logo.sidebar-brand-logo--mark {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 6px !important;
  max-width: min(52px, calc(100% - 2.5rem));
  height: 44px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 1px rgba(255, 255, 255, 0.2));
}

.sidebar-logo-link:hover .sidebar-brand-logo.sidebar-brand-logo--mark {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)) drop-shadow(0 0 2px rgba(255, 255, 255, 0.25));
}

.mg-sidebar-nav {
  padding-block: 6px 12px;
}

.mg-sidebar-nav-group + .mg-sidebar-nav-group {
  margin-top: 2px;
}

.sidebar-nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.3);
  padding: 16px 24px 6px;
  font-weight: 600;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: rgba(255, 255, 255, 0.65);
  border-radius: 8px;
  margin: 2px 8px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, font-weight 0.15s ease;
}

.sidebar-nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.95);
}

.sidebar-nav-item.active {
  background: rgba(14, 158, 118, 0.2);
  color: #4dd9ac;
  font-weight: 600;
}

.sidebar-nav-item.active .nav-icon {
  color: var(--color-teal);
}

.sidebar-nav-item .nav-icon {
  font-size: 1.1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.55);
}

.sidebar-nav-item:hover .nav-icon {
  color: rgba(255, 255, 255, 0.85);
}

.mg-nav-new-badge {
  margin-inline-start: auto;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #0d2137;
  background: #4dd9ac;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.mg-sidebar-profile {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mg-sidebar-profile-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
  color: rgba(255, 255, 255, 0.92);
}

.mg-sidebar-profile-main:hover {
  color: #fff;
}

.mg-sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  color: #fff;
}

.mg-sidebar-profile-text {
  min-width: 0;
}

.mg-sidebar-profile-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.mg-sidebar-profile-meta {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  margin-top: 2px;
}

.mg-sidebar-profile-gear {
  color: rgba(255, 255, 255, 0.45) !important;
  flex-shrink: 0;
  font-size: 1.1rem;
}

.mg-sidebar-profile-gear:hover {
  color: #fff !important;
}

.mg-app-topbar {
  background: var(--color-bg-header);
  min-height: 64px;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.mg-app-topbar__inner {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding-inline: 12px;
  padding-block: 8px;
}

.mg-app-topbar__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text-primary);
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.3;
}

.mg-app-topbar__menu {
  flex-shrink: 0;
  line-height: 1;
}

.mg-muni-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--color-bg-page);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  max-width: 10rem;
}

.mg-topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-teal-light);
  color: var(--color-teal-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.mg-topbar-avatar-btn:focus-visible {
  outline: 2px solid var(--color-teal);
  outline-offset: 2px;
  border-radius: 50%;
}

/* Mobile tab bar visuals: see mg-ui-polish.css (.mg-mobile-tabbar.mobile-nav) */
.mg-mobile-tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  min-height: 56px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mg-mobile-tab {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 6px 4px;
  color: var(--color-text-muted);
  background: transparent;
  border: 0;
  text-decoration: none;
  font-size: 1.25rem;
  transition: color 0.15s ease;
}

.mg-mobile-tab:hover {
  color: var(--color-text-primary);
}

.mg-mobile-tab.active {
  color: var(--color-teal);
}

.mg-mobile-tab:focus-visible {
  outline: 2px solid var(--color-teal);
  outline-offset: -2px;
}

.mg-sidebar-offcanvas {
  background: var(--color-navy) !important;
  width: min(300px, 92vw);
}

.mg-sidebar-offcanvas .offcanvas-body {
  overflow-y: auto;
}

/* 2FA reminder — orange dot on header avatar (replaces full-width banner) */
.mg-2fa-nudge-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #f97316;
  border: 2px solid #fff;
  border-radius: 50%;
  z-index: 2;
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-nav-item,
  .mg-mobile-tab {
    transition: none !important;
  }
}

.sidebar-nav-item:focus-visible {
  outline: 2px solid rgba(77, 217, 172, 0.9);
  outline-offset: 2px;
}

@media print {
  .mg-desktop-sidebar,
  .mg-mobile-tabbar,
  .mg-sidebar-offcanvas,
  .mg-app-topbar__menu {
    display: none !important;
  }

  .mg-app-main-column {
    margin-inline-start: 0 !important;
    padding-bottom: 0 !important;
  }

  .mg-app-topbar {
    position: static;
    box-shadow: none;
  }
}

/* Page load — subtle fade-in (respect reduced motion) */
@media (prefers-reduced-motion: no-preference) {
  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(12px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .page-content {
    animation: fadeInUp 0.3s ease forwards;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-content {
    animation: none;
  }
}

/* Export status — teal CSS spinner and step list */
@keyframes mg-export-spin {
  to {
    transform: rotate(360deg);
  }
}

.mg-export-teal-spinner {
  width: 3rem;
  height: 3rem;
  border: 3px solid rgba(14, 158, 118, 0.22);
  border-top-color: var(--color-teal);
  border-radius: 50%;
  animation: mg-export-spin 0.85s linear infinite;
}

.mg-export-steps {
  font-size: 0.95rem;
  color: var(--color-text-secondary);
}

.mg-export-step {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--color-border);
}

.mg-export-step:last-child {
  border-bottom: 0;
}

.mg-export-step__icon {
  flex: 0 0 1.5rem;
  text-align: center;
  font-weight: 600;
  color: var(--color-text-muted);
}

.mg-export-step--done .mg-export-step__icon {
  color: var(--color-teal);
}

.mg-export-step--active .mg-export-step__icon {
  color: var(--color-teal);
}

.mg-export-step--pending {
  opacity: 0.65;
}

.mg-export-icon-circle {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.mg-export-icon-circle--success {
  background: var(--color-teal);
}

.mg-export-icon-circle--danger {
  background: var(--color-danger);
}

.mg-export-icon-circle--warning {
  background: var(--color-warning);
  font-size: 1.75rem;
  font-weight: 700;
}
