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

:root {
  --bg: #f4f2ec;
  --panel: #ffffff;
  --sidebar: #f1f7fb;
  --panel-border: #c7d8e5;
  --text: #0b2447;
  --muted: #556375;
  --primary: #0057a3;
  --primary-2: #003e73;
  --accent: #1ea8e0;
  --danger: #b15d5d;
  --success: #1ea8e0;
}

/* --- 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; }
}
