:root {
  --bg: #f4f8f7;
  --surface: #ffffff;
  --text: #16241f;
  --text-muted: #5c6b66;
  --primary: #0f8b6c;
  --primary-dark: #0b6b53;
  --accent: #2b9fd8;
  --danger: #c94a4a;
  --border: #dbe6e2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 40, 33, 0.08), 0 1px 2px rgba(15, 40, 33, 0.06);
  --shadow-lift: 0 10px 24px rgba(15, 40, 33, 0.12), 0 2px 6px rgba(15, 40, 33, 0.08);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 40px;

  --transition-fast: 120ms;
  --transition-base: 200ms;
  --transition-slow: 340ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary-dark); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* Nav */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary-dark);
  text-decoration: none;
  margin-right: auto;
  transition: opacity var(--transition-fast) var(--ease-out);
}
.nav-brand:hover { opacity: 0.8; }
.nav a.nav-link, .nav button.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.92rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition-fast) var(--ease-out), color var(--transition-fast) var(--ease-out);
}
.nav a.nav-link.active, .nav a.nav-link:hover,
.nav button.nav-link.active, .nav button.nav-link:hover {
  background: #e7f4f0;
  color: var(--primary-dark);
}
.nav .points-pill {
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

h1 { font-size: 1.6rem; margin: 24px 0 8px; }
h2 { font-size: 1.25rem; margin: 24px 0 8px; }
p.lead { color: var(--text-muted); margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  transition: transform var(--transition-base) var(--ease-out), box-shadow var(--transition-base) var(--ease-out);
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.grid > .card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast) var(--ease-out), transform var(--transition-fast) var(--ease-out),
    box-shadow var(--transition-fast) var(--ease-out);
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--surface); color: var(--primary-dark); border: 1px solid var(--primary); }
.btn.secondary:hover { background: #e7f4f0; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #a83c3c; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  transition: border-color var(--transition-fast) var(--ease-out), box-shadow var(--transition-fast) var(--ease-out);
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 139, 108, 0.15);
  outline: none;
}

.badge {
  display: inline-block;
  background: #e7f4f0;
  color: var(--primary-dark);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge.pending { background: #fdf1e0; color: #9a6a10; }
.badge.approved { background: #e2f6e7; color: #1b7a3d; }
.badge.rejected { background: #fbe4e4; color: var(--danger); }

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  animation: fadeInUp var(--transition-slow) var(--ease-out);
}
.alert.error { background: #fbe4e4; color: #8c2f2f; }
.alert.success { background: #e2f6e7; color: #1b7a3d; }
.alert.info { background: #e6f3fa; color: #1b5e80; }

.muted { color: var(--text-muted); font-size: 0.88rem; }

table { width: 100%; border-collapse: collapse; }
table th, table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }

.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 32px 24px;
  margin: 20px 0;
  animation: fadeInUp var(--transition-slow) var(--ease-out);
}
.hero h1 { color: #fff; margin-top: 0; }
.hero p { color: rgba(255,255,255,0.9); }

.greeting-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-4) 0;
  animation: fadeInUp var(--transition-slow) var(--ease-out);
}
.greeting-strip p { margin: 0; }

.slider-wrap { margin: 12px 0; }
.slider-wrap input[type=range] { width: 100%; }

#map { height: 420px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }

.lesson-card-quiz label { display: block; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; cursor: pointer; transition: background var(--transition-fast) var(--ease-out); }
.lesson-card-quiz label:hover { background: #f4f8f7; }

.progress-bar { background: var(--border); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar > div { background: var(--primary); height: 100%; transition: width var(--transition-slow) var(--ease-out); }

.frame-none { border: 2px solid transparent; }
.frame-bronze { border: 3px solid #b08d57; box-shadow: 0 0 0 2px #f0e0c8; }
.frame-silver { border: 3px solid #b9c2c9; box-shadow: 0 0 0 2px #eef1f3; }
.frame-gold { border: 3px solid #e0b23a; box-shadow: 0 0 0 2px #fbeec2; }
.frame-emerald { border: 3px solid var(--primary); box-shadow: 0 0 0 2px #cdeee2; }

/* Модалки: CSS-анимация появления при снятии [hidden] (transition не сработал бы
   через display:none, поэтому используем @keyframes, а не .show + transition) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 40, 33, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100;
  animation: fadeIn var(--transition-base) var(--ease-out);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  max-width: 420px; width: 100%; box-shadow: var(--shadow-lift);
  animation: modalPop var(--transition-base) var(--ease-out);
}
.modal h2 { margin-top: 0; }

.notification-item { border-bottom: 1px solid var(--border); padding: 10px 0; transition: background var(--transition-fast) var(--ease-out); }
.notification-item:last-child { border-bottom: none; }
.notification-item.unread { background: #f4faf8; }

/* Выпадающий список (уведомления и т.п.) */
.dropdown { position: relative; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(340px, 90vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  z-index: 50;
  max-height: 70vh;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity var(--transition-base) var(--ease-out), transform var(--transition-base) var(--ease-out);
}
.dropdown-panel.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.dropdown-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 0.9rem;
}
.dropdown-panel-body { padding: 4px 14px; }
.dropdown-panel-footer {
  padding: 8px 14px; border-top: 1px solid var(--border); text-align: center;
}
.dropdown-panel-footer a { font-size: 0.88rem; }

.nav-bell-wrap { position: relative; }
.nav-badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--danger); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
  animation: pulse 1.6s ease-in-out infinite;
}
/* .nav-badge{display:flex} выше специфичнее браузерного [hidden]{display:none} —
   без этого правила бейдж (и его пульс) виден и без непрочитанных уведомлений */
.nav-badge[hidden] { display: none; animation: none; }

/* Логотип в навбаре и футере (вместо текстового названия) */
.brand-logo { height: 34px; width: auto; display: block; }
.footer-logo { height: 40px; width: auto; display: block; }

/* Кнопка входа через Госуслуги — картинка вместо текстовой кнопки */
.gos-btn {
  display: inline-block; padding: 0; border: none; background: none; cursor: pointer;
  border-radius: 6px; overflow: hidden;
  transition: transform var(--transition-fast) var(--ease-out), box-shadow var(--transition-fast) var(--ease-out);
}
.gos-btn img { display: block; height: 40px; width: auto; }
.gos-btn:hover { transform: translateY(-2px) scale(1.02); box-shadow: var(--shadow-lift); }
.gos-btn:active { transform: translateY(0) scale(0.99); }
.gos-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

/* Автоподсказки адреса (Яндекс Suggest) */
.suggest-panel {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-lift); z-index: 60; max-height: 220px; overflow-y: auto;
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity var(--transition-fast) var(--ease-out), transform var(--transition-fast) var(--ease-out);
}
.suggest-panel.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.suggest-item { padding: 8px 12px; cursor: pointer; font-size: 0.9rem; border-bottom: 1px solid var(--border); }
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover { background: #f4f8f7; }

/* Встроенный дашборд Grafana (страница /admin) */
.grafana-embed {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--surface);
}
.grafana-embed iframe {
  display: block;
  width: 100%;
  height: 80vh;
  min-height: 640px;
  border: none;
}

/* Футер */
.site-footer {
  background: var(--surface); border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer-inner { max-width: 960px; margin: 0 auto; padding: 24px 16px; }
.footer-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 14px;
}
.site-footer p { margin: 4px 0; font-size: 0.85rem; color: var(--text-muted); }
.site-footer a { color: var(--text-muted); text-decoration: underline; }

/* Skeleton-заглушки для загрузки */
.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(90deg, #e9f1ee 25%, #f4f8f7 37%, #e9f1ee 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  height: 14px;
  margin-bottom: 8px;
}
.skeleton.skeleton-card { height: 150px; margin-bottom: 12px; }
.skeleton.skeleton-line-short { width: 40%; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Toast / snackbar */
.toast-stack {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
  width: min(360px, 90vw);
}
.toast {
  background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 0.9rem;
  box-shadow: var(--shadow-lift);
  animation: fadeInUp var(--transition-base) var(--ease-out);
}
.toast.error { background: #8c2f2f; }
.toast.success { background: var(--primary-dark); }

/* Появление карточек */
.card, .fade-in {
  animation: fadeInUp var(--transition-slow) var(--ease-out) backwards;
}
.grid > .card:nth-child(1) { animation-delay: 0ms; }
.grid > .card:nth-child(2) { animation-delay: 40ms; }
.grid > .card:nth-child(3) { animation-delay: 80ms; }
.grid > .card:nth-child(4) { animation-delay: 120ms; }
.grid > .card:nth-child(5) { animation-delay: 160ms; }
.grid > .card:nth-child(6) { animation-delay: 200ms; }
.grid > .card:nth-child(7) { animation-delay: 240ms; }
.grid > .card:nth-child(8) { animation-delay: 280ms; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalPop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201, 74, 74, 0.5); }
  50% { box-shadow: 0 0 0 4px rgba(201, 74, 74, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .hero { padding: 20px 16px; }
  .dropdown-panel { position: fixed; top: 60px; left: 8px; right: 8px; width: auto; }
}
