/* ========================================
   App Base Styles
   Shared variables, resets, layout shell,
   header/nav, flash messages, and utilities.
   Loaded on every page via base.html.
   ======================================== */

:root {
  /* Surfaces — a cool blue-grey family so every page sits in the same light */
  --bg: #f2f5f9;
  --panel: #ffffff;
  --sidebar: #f7fafc;
  --panel-border: #dde7f0;
  --panel-border-strong: #c7d8e5;

  /* Text */
  --text: #0b2447;
  --muted: #5b6b80;

  /* Brand */
  --primary: #0057a3;
  --primary-2: #004687;
  --primary-soft: rgba(0, 87, 163, 0.08);
  --accent: #1ea8e0;

  /* Semantic */
  --danger: #c04a4a;
  --danger-soft: rgba(192, 74, 74, 0.1);
  --success: #0e8a5f;
  --success-soft: rgba(14, 138, 95, 0.1);
  --warning: #b97b1f;
  --warning-soft: rgba(217, 155, 60, 0.14);

  /* Shape & elevation */
  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-xs: 0 1px 2px rgba(11, 36, 71, 0.05);
  --shadow-sm: 0 1px 2px rgba(11, 36, 71, 0.04), 0 4px 12px rgba(11, 36, 71, 0.06);
  --shadow-md: 0 2px 4px rgba(11, 36, 71, 0.05), 0 12px 28px rgba(11, 36, 71, 0.1);
  --shadow-lg: 0 24px 60px rgba(11, 36, 71, 0.18);
  --focus-ring: 0 0 0 3px rgba(0, 87, 163, 0.18);
}

/* --- Resets --- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 !important;
  font-family: "Gotham", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
    sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: 1rem;
}

/* --- Layout Shell --- */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

/* --- Site Header --- */

.site-header {
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
          backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: box-shadow 0.2s ease, background 0.2s ease;
}

/* Subtle shadow only once content scrolls beneath it. */
.site-header.shrunk {
  box-shadow: 0 4px 18px rgba(11, 36, 71, 0.08);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  transition: padding 0.2s ease;
  position: relative;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

.brand-link img {
  height: 48px;
  width: auto;
  display: block;
  transition: height 0.2s ease;
}

.site-header.shrunk .header-inner {
  padding: 8px 24px;
}

.site-header.shrunk .brand-link img {
  height: 38px;
}

/* --- Navigation --- */

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-self: center;
}

.nav-link {
  position: relative;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover,
.nav-link:focus-visible {
  background: rgba(0, 87, 163, 0.06);
  color: var(--text);
  outline: none;
}

.nav-link.active {
  background: rgba(0, 87, 163, 0.10);
  color: var(--primary);
  font-weight: 600;
}

.nav-link.active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 2px;
  height: 2px;
  background: var(--primary);
  border-radius: 999px;
  opacity: 0.85;
}

.nav-link:focus-visible {
  box-shadow: 0 0 0 3px rgba(0, 87, 163, 0.18);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}

/* --- Dropdowns --- */

.dropdown {
  position: relative;
}

.dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  min-height: 36px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition:
    border-color 0.15s ease,
    color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.dropdown-toggle:hover {
  border-color: rgba(0, 87, 163, 0.45);
  color: var(--primary);
  background: rgba(0, 87, 163, 0.04);
}

.dropdown-toggle.active,
.dropdown-toggle:focus-visible {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 87, 163, 0.18);
  outline: none;
}

.dropdown-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.dropdown-toggle.active svg {
  transform: rotate(180deg);
}

.dropdown.user-menu .dropdown-toggle {
  gap: 8px;
  padding: 4px 10px 4px 6px;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow:
    0 16px 32px rgba(11, 36, 71, 0.12),
    0 4px 8px rgba(11, 36, 71, 0.06);
  display: none;
  z-index: 1100;
  transform-origin: top right;
  animation: dropdown-pop 0.16s ease;
}

@keyframes dropdown-pop {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
  background: rgba(0, 87, 163, 0.08);
  color: var(--primary);
  outline: none;
}

.dropdown-item.active {
  background: rgba(0, 87, 163, 0.10);
  color: var(--primary);
  font-weight: 600;
}

.dropdown-divider {
  height: 1px;
  margin: 6px 4px;
  background: var(--panel-border);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.01em;
  flex-shrink: 0;
}

.header-login {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  font-weight: 600;
}
.header-login:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
  color: #ffffff;
}

.language-flag {
  font-size: 16px;
  line-height: 1;
}

/* --- Flash Messages --- */

.toast-container {
  font-family: "Gotham", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
    sans-serif;
}

.flash-messages {
  position: fixed;
  top: 88px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  z-index: 2000;
  pointer-events: none;
  align-items: flex-end;
}

.flash-message {
  border: 1px solid var(--panel-border);
  background: #ffffff;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 10px 30px rgba(47, 50, 55, 0.14);
  opacity: 0;
  transform: translateY(-12px);
  pointer-events: auto;
  animation: flash-in 0.35s ease forwards;
  transition: opacity 0.4s ease, transform 0.4s ease;
  width: max-content;
  max-width: min(420px, calc(100vw - 48px));
  word-break: break-word;
}

.flash-message.flash-success {
  border-color: rgba(30, 168, 224, 0.45);
  color: #0057a3;
}

.flash-message.flash-error {
  border-color: rgba(177, 93, 93, 0.45);
  color: #7e3e3e;
}

.flash-message.flash-warning {
  border-color: rgba(213, 233, 255, 0.55);
  color: #0057a3;
}

.flash-message.flash-info {
  border-color: rgba(0, 62, 115, 0.35);
  color: #0b2447;
}

.flash-message.fade-out {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

.flash-message svg {
  width: 14px;
  height: 14px;
}

@keyframes flash-in {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flash-message {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* --- Download cards (shared between user/admin dashboards) --- */

.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.download-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.download-card:hover,
.download-card:focus-visible {
  border-color: var(--primary);
  background: rgba(0, 87, 163, 0.04);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 87, 163, 0.12);
  outline: none;
}

.download-card-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(0, 87, 163, 0.10);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.download-card-icon svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.75;
}

.download-card:hover .download-card-icon,
.download-card:focus-visible .download-card-icon {
  background: rgba(0, 87, 163, 0.16);
}

.download-card-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.download-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}
.download-card-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.download-card-arrow {
  flex-shrink: 0;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, transform 0.15s ease;
}
.download-card-arrow svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.75;
}
.download-card:hover .download-card-arrow,
.download-card:focus-visible .download-card-arrow {
  color: var(--primary);
  transform: translateY(2px);
}

/* --- Shared Utilities --- */

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.opacity-25 {
  opacity: 0.25;
}

.opacity-75 {
  opacity: 0.75;
}

@keyframes spinner {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.spinner {
  width: 18px;
  height: 18px;
  animation: spinner 0.9s linear infinite;
}

/* --- Responsive Visibility --- */

.mobile-only {
  display: none !important;
}

/* --- Shared Page Background --- */

.page-gradient {
  position: relative;
  background: #0b2f6a;
  color: var(--text);
  overflow: hidden;
}

.page-gradient::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #0b2f6a 0%, #0d4c8a 55%, #1ea8e0 100%);
  opacity: 0.9;
  z-index: 0;
}

.page-gradient::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.2), transparent 55%);
  z-index: 0;
}

/* --- Responsive Header --- */

@media (max-width: 600px) {
  .flash-messages {
    top: 80px;
    right: 16px;
    left: 16px;
    width: auto;
    align-items: stretch;
  }

  .flash-message {
    width: auto;
    max-width: none;
  }
}

@media (max-width: 1024px) {
  .header-inner {
    gap: 12px;
    padding: 10px 20px;
  }
  .site-header.shrunk .header-inner {
    padding: 8px 20px;
  }
  .nav-links {
    gap: 2px;
  }
  .nav-link {
    padding: 7px 10px;
    font-size: 13.5px;
  }
}

@media (max-width: 720px) {
  .brand-link img { height: 40px; }
  .site-header.shrunk .brand-link img { height: 32px; }

  .desktop-only { display: none !important; }
  .dropdown-item.mobile-only { display: flex !important; }
  .dropdown-divider.mobile-only { display: block !important; }
}

@media (max-width: 480px) {
  .header-inner { padding: 8px 14px; gap: 8px; }
  .site-header.shrunk .header-inner { padding: 6px 14px; }
  .dropdown-toggle { padding: 5px 10px; font-size: 13px; }
  .dropdown-menu { right: -8px; min-width: 200px; }
}

/* ========================================
   Shared UI components (ui-*)
   Namespaced to avoid collisions with
   page-local classes (e.g. map.css .btn).
   ======================================== */

/* --- Buttons --- */

.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 16px;
  border: 1px solid var(--panel-border-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.ui-btn:hover {
  border-color: rgba(0, 87, 163, 0.45);
  color: var(--primary);
  background: rgba(0, 87, 163, 0.04);
}
.ui-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.ui-btn:active { transform: translateY(1px); }
.ui-btn:disabled,
.ui-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
.ui-btn svg { width: 16px; height: 16px; stroke-width: 1.9; flex-shrink: 0; }

.ui-btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 44, 84, 0.2), 0 6px 16px rgba(0, 87, 163, 0.22);
}
.ui-btn--primary:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
  color: #ffffff;
}

.ui-btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}
.ui-btn--danger:hover {
  background: #a63d3d;
  border-color: #a63d3d;
  color: #ffffff;
}

.ui-btn--danger-outline {
  color: var(--danger);
  border-color: rgba(192, 74, 74, 0.45);
}
.ui-btn--danger-outline:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.ui-btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.ui-btn--ghost:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: transparent;
}

.ui-btn--sm {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 13px;
  gap: 6px;
}
.ui-btn--sm svg { width: 14px; height: 14px; }

/* --- Status badges --- */

.ui-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.6;
}
.ui-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}
.ui-badge--neutral { background: rgba(91, 107, 128, 0.12); color: #4b5b6f; }
.ui-badge--info    { background: rgba(30, 168, 224, 0.14); color: #0069a8; }
.ui-badge--success { background: var(--success-soft); color: var(--success); }
.ui-badge--warning { background: var(--warning-soft); color: var(--warning); }
.ui-badge--danger  { background: var(--danger-soft); color: var(--danger); }
.ui-badge--running::before {
  animation: ui-badge-pulse 1.2s ease-in-out infinite;
}
@keyframes ui-badge-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

/* --- Progress bar --- */

.ui-progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 87, 163, 0.1);
  overflow: hidden;
}
.ui-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  transition: width 0.5s ease;
  min-width: 6px;
}
.ui-progress-fill--indeterminate {
  width: 40% !important;
  animation: ui-progress-slide 1.4s ease-in-out infinite;
}
@keyframes ui-progress-slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

/* --- Form fields --- */

.ui-field { display: flex; flex-direction: column; gap: 6px; }
.ui-field > label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.ui-field-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.ui-input,
.ui-select,
.ui-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--panel-border-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ui-textarea { resize: vertical; min-height: 64px; }
.ui-input::placeholder,
.ui-textarea::placeholder { color: #93a3b5; }
.ui-input:focus,
.ui-select:focus,
.ui-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.ui-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235b6b80' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* --- Modal --- */

.ui-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 22, 44, 0.45);
  -webkit-backdrop-filter: blur(3px);
          backdrop-filter: blur(3px);
  z-index: 1500;
  justify-content: center;
  align-items: flex-start;
  padding: 8vh 20px 40px;
  overflow-y: auto;
}
.ui-modal-overlay.is-open { display: flex; }

.ui-modal {
  width: 100%;
  max-width: 620px;
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: ui-modal-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.4);
  display: flex;
  flex-direction: column;
  max-height: 84vh;
}
.ui-modal--wide { max-width: 780px; }
.ui-modal--narrow { max-width: 460px; }
@keyframes ui-modal-pop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.ui-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px 0;
}
.ui-modal-title { margin: 0; font-size: 19px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.ui-modal-subtitle { margin: 6px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.55; }
.ui-modal-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.ui-modal-close:hover { background: var(--primary-soft); color: var(--text); }
.ui-modal-close svg { width: 17px; height: 17px; }

.ui-modal-body { padding: 18px 26px 8px; overflow-y: auto; }
.ui-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 26px 24px;
}

@media (max-width: 640px) {
  .ui-modal-overlay { padding: 4vh 12px 24px; }
  .ui-modal-header, .ui-modal-body { padding-left: 18px; padding-right: 18px; }
  .ui-modal-footer { padding: 16px 18px 20px; flex-wrap: wrap; }
}

/* --- Small chips (e.g. field type tags) --- */

.ui-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--sidebar);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.ui-chip code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--primary);
}
