/*
 * "Тёплая мастерская" — Game Catalog Design
 * Warm, playful, distinctive aesthetic for kids educational materials
 * Light + Dark theme support
 */

/* Fonts loaded via <link> in layout for faster parallel loading */

/* ── Design Tokens: Light ── */
:root {
  --color-bg: #FFF8F0;
  --color-bg-warm: #FFF3E6;
  --color-surface: #FFFFFF;
  --color-primary: #E85D4A;
  --color-primary-dark: #C94835;
  --color-secondary: #6BAB90;
  --color-secondary-light: #A8D5BA;
  --color-accent: #F2A93B;
  --color-accent-light: #FCEBD0;
  --color-text: #2D2A26;
  --color-text-muted: #7A7067;
  --color-text-light: #A89E94;
  --color-border: #EDE5DA;
  --color-tag-bg: #F5EFE7;

  --header-gradient: linear-gradient(135deg, #E85D4A 0%, #D4724A 40%, #F2A93B 100%);
  --header-blob-1: rgba(255, 255, 255, 0.08);
  --header-blob-2: rgba(255, 255, 255, 0.05);
  --bg-blob-amber: rgba(242, 169, 59, 0.07);
  --bg-blob-sage: rgba(107, 171, 144, 0.06);
  --img-fade: var(--color-surface);
  --external-link-bg: linear-gradient(135deg, #6BAB90 0%, #5A9A7E 100%);
  --external-link-hover: linear-gradient(135deg, #5A9A7E 0%, #4A8A6E 100%);
  --btn-primary-bg: linear-gradient(135deg, #E85D4A 0%, #D4724A 100%);

  --font-display: "Comfortaa", cursive;
  --font-body: "Nunito", sans-serif;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 32px;

  --shadow-sm: 0 2px 8px rgba(45, 42, 38, 0.06);
  --shadow-md: 0 4px 20px rgba(45, 42, 38, 0.08);
  --shadow-lg: 0 8px 40px rgba(45, 42, 38, 0.12);
  --shadow-glow: 0 0 0 4px rgba(232, 93, 74, 0.15);

  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Design Tokens: Dark ── */
[data-theme="dark"] {
  --color-bg: #181513;
  --color-bg-warm: #211D1A;
  --color-surface: #272220;
  --color-primary: #EF8A7D;
  --color-primary-dark: #E06B5C;
  --color-secondary: #7EC4A4;
  --color-secondary-light: #5FAA88;
  --color-accent: #F5C266;
  --color-accent-light: #3D3127;
  --color-text: #F0E8DF;
  --color-text-muted: #B5A99D;
  --color-text-light: #6E6259;
  --color-border: #3A3330;
  --color-tag-bg: #302A26;

  --header-gradient: linear-gradient(135deg, #7A2E22 0%, #6B3A28 40%, #8B6529 100%);
  --header-blob-1: rgba(255, 200, 150, 0.05);
  --header-blob-2: rgba(255, 200, 150, 0.03);
  --bg-blob-amber: rgba(242, 169, 59, 0.04);
  --bg-blob-sage: rgba(107, 171, 144, 0.03);
  --img-fade: var(--color-surface);
  --external-link-bg: linear-gradient(135deg, #4A8A6E 0%, #3D7A5E 100%);
  --external-link-hover: linear-gradient(135deg, #3D7A5E 0%, #2E6A4E 100%);
  --btn-primary-bg: linear-gradient(135deg, #C95A4A 0%, #A8533E 100%);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 0 4px rgba(239, 138, 125, 0.2);
}

/* ── Smooth theme transition ── */
html {
  transition: background-color 0.4s ease;
}

body,
.search-box,
.tags-cloud,
.material-card,
.material-detail,
.pagination a,
.pagination span,
.pagination em,
.tag,
.badge,
.reset-btn {
  transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  top: -50%;
  right: -30%;
  width: 80vw;
  height: 80vw;
  border-radius: 50%;
  background: radial-gradient(circle, var(--bg-blob-amber) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  bottom: -40%;
  left: -20%;
  width: 70vw;
  height: 70vw;
  border-radius: 50%;
  background: radial-gradient(circle, var(--bg-blob-sage) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Site Header ── */
.site-header {
  position: relative;
  background: var(--header-gradient);
  padding: 48px 0 56px;
  overflow: hidden;
  z-index: 1;
}

.site-header::before {
  content: "";
  position: absolute;
  top: -60px;
  right: -40px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: var(--header-blob-1);
}

.site-header::after {
  content: "";
  position: absolute;
  bottom: -80px;
  left: 10%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: var(--header-blob-2);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 28px;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.header-text {
  flex: 1;
}

.site-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  color: #FFFFFF;
  margin: 0 0 8px 0;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.site-subtitle {
  font-family: var(--font-body);
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  color: rgba(255, 255, 255, 0.85);
  margin: 0;
  font-weight: 400;
}

/* ── Theme Toggle ── */
.theme-toggle {
  position: relative;
  width: 56px;
  height: 30px;
  border-radius: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.15);
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 8px;
  backdrop-filter: blur(8px);
  transition: var(--transition);
  overflow: hidden;
}

.theme-toggle:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.22);
}

.theme-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  transition: transform 0.4s cubic-bezier(0.68, -0.2, 0.27, 1.3);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.theme-toggle-thumb::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent);
  transition: var(--transition);
}

[data-theme="dark"] .theme-toggle-thumb {
  transform: translateX(26px);
}

[data-theme="dark"] .theme-toggle-thumb::before {
  background: transparent;
  box-shadow: inset -3px -1px 0 0 #F5C266;
  width: 12px;
  height: 12px;
}

[data-theme="dark"] .theme-toggle {
  border-color: rgba(245, 194, 102, 0.35);
  background: rgba(245, 194, 102, 0.1);
}

[data-theme="dark"] .theme-toggle:hover {
  border-color: rgba(245, 194, 102, 0.6);
  background: rgba(245, 194, 102, 0.18);
}

/* ── Container ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 28px 40px;
  position: relative;
  z-index: 1;
}

/* ── Search Box ── */
.search-box {
  background: var(--color-surface);
  padding: 24px 28px;
  border-radius: var(--radius-lg);
  margin: -28px 0 28px 0;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 3;
  border: 1px solid var(--color-border);
}

.search-box form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input-wrap {
  flex: 1;
  min-width: 220px;
  position: relative;
  display: flex;
  align-items: center;
}
.search-input-wrap input[type="text"] {
  width: 100%;
  padding-right: 42px;
}
.search-input-clear {
  position: absolute;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--color-border);
  color: var(--color-text-muted);
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 0;
}
.search-input-clear:hover {
  background: var(--color-primary);
  color: #fff;
}

.search-box input[type="text"] {
  flex: 1;
  min-width: 220px;
  padding: 12px 18px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg-warm);
  transition: var(--transition);
  outline: none;
}

.search-box input[type="text"]::placeholder {
  color: var(--color-text-light);
}

.search-box input[type="text"]:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-glow);
  background: var(--color-surface);
}

.search-box select {
  padding: 12px 16px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg-warm);
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

.search-box select:focus {
  border-color: var(--color-secondary);
}

.search-box input[type="submit"] {
  padding: 12px 28px;
  background: linear-gradient(135deg, #FFB347 0%, #E85D4A 50%, #9B1C1C 100%);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  transition: var(--transition);
  letter-spacing: 0.3px;
}

.search-box input[type="submit"]:hover {
  background: linear-gradient(135deg, #FFA020 0%, #D4472A 50%, #7A1010 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(232, 93, 74, 0.3);
}

.search-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.reset-btn {
  padding: 12px 20px;
  background: var(--color-tag-bg);
  color: var(--color-text-muted);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.reset-btn:hover {
  background: var(--color-border);
  color: var(--color-text);
}

/* ── Tags Cloud ── */
.tags-cloud {
  background: var(--color-surface);
  padding: 20px 24px;
  border-radius: var(--radius-lg);
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.tags-cloud strong {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-right: 8px;
}

.tag {
  display: inline-block;
  padding: 7px 14px;
  margin: 4px;
  background: var(--color-tag-bg);
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: var(--radius-xl);
  font-size: 13px;
  font-family: var(--font-body);
  font-weight: 600;
  border: 1.5px solid transparent;
}

.tag:hover {
  background: var(--color-accent-light);
  color: var(--color-primary);
  border-color: var(--color-accent);
  transform: translateY(-1px);
}

.tag.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(232, 93, 74, 0.25);
}

.toggle-tags-btn {
  display: inline-block;
  padding: 7px 16px;
  margin: 4px;
  background: var(--color-secondary);
  color: white;
  border: none;
  border-radius: var(--radius-xl);
  font-size: 13px;
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.toggle-tags-btn:hover {
  background: #5A9A7E;
  transform: translateY(-1px);
}

/* ── Section Title ── */
.section-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--color-text-muted);
  margin: 0 0 20px 4px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* ── Materials Grid ── */
.materials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
  margin-bottom: 36px;
}

/* ── Material Card ── */
.material-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--color-border);
  animation: cardReveal 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
  position: relative;
}

.material-card:nth-child(1) { animation-delay: 0.05s; }
.material-card:nth-child(2) { animation-delay: 0.1s; }
.material-card:nth-child(3) { animation-delay: 0.15s; }
.material-card:nth-child(4) { animation-delay: 0.2s; }
.material-card:nth-child(5) { animation-delay: 0.25s; }
.material-card:nth-child(6) { animation-delay: 0.3s; }
.material-card:nth-child(7) { animation-delay: 0.35s; }
.material-card:nth-child(8) { animation-delay: 0.4s; }
.material-card:nth-child(9) { animation-delay: 0.45s; }
.material-card:nth-child(10) { animation-delay: 0.5s; }
.material-card:nth-child(11) { animation-delay: 0.55s; }
.material-card:nth-child(12) { animation-delay: 0.6s; }

@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.material-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-accent);
}

.card-link {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.material-image {
  width: 100%;
  height: 260px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--color-bg-warm) 0%, var(--color-tag-bg) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.material-image::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(to top, var(--img-fade), transparent);
  pointer-events: none;
}

.material-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.material-card:hover .material-image img {
  transform: scale(1.05);
}

.material-content {
  padding: 20px 22px 16px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.material-content h3 {
  margin: 0 0 10px 0;
  font-size: 17px;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.35;
  height: 46px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.description {
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 12px;
  flex-grow: 1;
}

.tags {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  background: var(--color-accent-light);
  color: var(--color-primary);
  border-radius: var(--radius-xl);
  font-size: 11px;
  font-family: var(--font-body);
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.3px;
}

.badge:hover {
  background: var(--color-primary);
  color: white;
}

.external-link {
  display: block;
  text-align: center;
  padding: 14px;
  background: var(--external-link-bg);
  color: white;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  transition: var(--transition);
  margin-top: auto;
  flex-shrink: 0;
}

.external-link:hover {
  background: var(--external-link-hover);
  letter-spacing: 1.5px;
}

/* ── Pagination ── */
.pagination {
  text-align: center;
  margin: 36px 0 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pagination a,
.pagination span,
.pagination em {
  padding: 10px 16px;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text-muted);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  transition: var(--transition);
  font-style: normal;
}

.pagination a:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.pagination .current,
.pagination em.current {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(232, 93, 74, 0.25);
}

.pagination .disabled,
.pagination .gap {
  color: var(--color-text-light);
  border-color: transparent;
  background: transparent;
}

/* ── Loading Sentinel (Infinite Scroll) ── */
.loading-sentinel {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Detail Page ── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 28px 0 24px;
  color: var(--color-primary);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  transition: var(--transition);
  padding: 8px 0;
}

.back-link:hover {
  color: var(--color-primary-dark);
  transform: translateX(-4px);
}

.material-detail {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
  animation: cardReveal 0.4s ease backwards;
}

.material-image-large {
  width: 100%;
  max-width: 640px;
  margin: 0 auto 36px;
}

.material-image-large img {
  width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.material-title-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.material-title-row h1 {
  margin: 0;
}

.material-info h1 {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 16px 0;
  line-height: 1.3;
}

.favorite-btn--detail {
  position: static;
  flex-shrink: 0;
  margin-top: 4px;
}

.material-info .description {
  font-size: 16px;
  line-height: 1.8;
  color: var(--color-text-muted);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: var(--btn-primary-bg);
  color: white;
  text-decoration: none;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  margin-top: 24px;
  transition: var(--transition);
  box-shadow: 0 4px 16px rgba(232, 93, 74, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(232, 93, 74, 0.4);
}

/* ── Favorite Button ── */
.favorite-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-width: 36px;
  height: 36px;
  border: none;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: var(--transition);
  padding: 0 8px;
  color: var(--color-text-light);
}

.favorite-count {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.favorite-count:empty {
  display: none;
}

.favorite-btn:hover {
  background: rgba(255, 255, 255, 0.95);
  color: var(--color-primary);
  transform: scale(1.1);
}

.favorite-btn.favorited {
  color: var(--color-primary);
}

.favorite-btn.favorited svg {
  fill: var(--color-primary);
}

[data-theme="dark"] .favorite-btn {
  background: rgba(39, 34, 32, 0.85);
}

[data-theme="dark"] .favorite-btn:hover {
  background: rgba(39, 34, 32, 0.95);
}

/* ── Favorite Tag in Cloud ── */
.favorite-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.favorite-icon-inline {
  vertical-align: middle;
}

.tags-cloud-header {
  display: inline;
}

/* ── Related Section ── */
.related-section {
  margin-top: 48px;
  padding-top: 36px;
  border-top: 2px solid var(--color-border);
}

.related-title {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 24px 0;
}

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 28px;
  color: var(--color-text-light);
  font-size: 13px;
  font-family: var(--font-display);
  position: relative;
  z-index: 1;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .site-header {
    padding: 32px 0 44px;
  }

  .header-content {
    flex-direction: row;
    align-items: center;
  }

  .theme-toggle {
    margin-top: 0;
  }

  .container {
    padding: 0 16px 32px;
  }

  .search-box {
    padding: 18px 20px;
    margin: -20px 0 20px 0;
    border-radius: var(--radius-md);
  }

  .search-box form {
    flex-direction: column;
  }

  .search-box input[type="text"],
  .search-box select {
    min-width: 100%;
  }

  .search-actions {
    width: 100%;
  }

  .search-actions input[type="submit"] {
    flex: 1;
  }

  .materials-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
  }

  .material-detail {
    padding: 24px 20px;
  }

  .tags-cloud {
    padding: 16px 18px;
  }
}

@media (max-width: 480px) {
  .materials-grid {
    grid-template-columns: 1fr;
  }

  .material-image {
    height: 220px;
  }
}

/* ── Flash Messages ── */
.flash {
  max-width: 1200px;
  margin: 16px auto;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
}

.flash-notice {
  background: #E8F5E9;
  color: #2E7D32;
  border: 1px solid #A5D6A7;
}

.flash-alert {
  background: #FFEBEE;
  color: #C62828;
  border: 1px solid #EF9A9A;
}

[data-theme="dark"] .flash-notice {
  background: #1B3A1F;
  color: #81C784;
  border-color: #2E7D32;
}

[data-theme="dark"] .flash-alert {
  background: #3A1B1B;
  color: #EF9A9A;
  border-color: #C62828;
}

/* ── Site Title Link ── */
.site-title-link {
  text-decoration: none;
}


/* ══════════════════════════════════════════
   Analytics Dashboard — "Тёплая мастерская"
   ══════════════════════════════════════════ */

/* ── Animations ── */
@keyframes ana-fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ana-bar-grow {
  from { width: 0; }
  to   { width: var(--pct); }
}
@keyframes ana-kpi-pop {
  0%   { opacity: 0; transform: scale(0.85) translateY(12px); }
  60%  { transform: scale(1.03) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes ana-hero-blob {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(20px, -15px) scale(1.05); }
  66%      { transform: translate(-10px, 10px) scale(0.97); }
}

/* ── Container ── */
.ana {
  min-height: 100vh;
  background: var(--color-bg);
  font-family: var(--font-body);
  color: var(--color-text);
}

/* ── Hero header ── */
.ana-hero {
  position: relative;
  overflow: hidden;
  background: var(--header-gradient);
  padding: 2.5rem 1.5rem 2rem;
}
.ana-hero__blobs {
  position: absolute; inset: 0; pointer-events: none;
}
.ana-hero__blob {
  position: absolute;
  border-radius: 50%;
}
.ana-hero__blob--1 {
  width: 260px; height: 260px;
  background: var(--header-blob-1);
  top: -60px; right: -40px;
  animation: ana-hero-blob 12s ease-in-out infinite;
}
.ana-hero__blob--2 {
  width: 180px; height: 180px;
  background: var(--header-blob-2);
  bottom: -40px; left: 10%;
  animation: ana-hero-blob 16s ease-in-out infinite reverse;
}
.ana-hero__content {
  position: relative; z-index: 1;
  max-width: 1100px; margin: 0 auto;
}
.ana-hero__top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.ana-hero__top-row .theme-toggle {
  margin-top: 0;
}
.ana-hero__back {
  display: inline-flex; align-items: center; gap: 0.3rem;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color var(--transition);
}
.ana-hero__back:hover { color: #fff; }
.ana-hero__title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  letter-spacing: -0.01em;
}
.ana-hero__sub {
  color: rgba(255,255,255,0.7);
  font-size: 0.9375rem;
  margin: 0.25rem 0 0;
}

/* ── Body ── */
.ana-body {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

/* ── Period selector ── */
.ana-periods {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
  animation: ana-fade-up 0.5s ease-out both;
}
.ana-periods__btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  transition: all var(--transition);
  letter-spacing: 0.01em;
}
.ana-periods__btn:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: var(--color-bg-warm);
}
.ana-periods__btn--active {
  background: var(--btn-primary-bg);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}
.ana-periods__btn--active:hover {
  color: #fff;
  border-color: transparent;
  filter: brightness(1.05);
}

/* ── KPI Cards ── */
.ana-kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
@media (min-width: 640px) {
  .ana-kpis { grid-template-columns: repeat(4, 1fr); }
}
.ana-kpi {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  animation: ana-kpi-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--delay, 0) * 0.1s);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.ana-kpi:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-glow);
}
.ana-kpi__icon {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  margin-bottom: 0.6rem;
  color: #fff;
}
.ana-kpi--visits .ana-kpi__icon  { background: var(--color-primary); }
.ana-kpi--pages .ana-kpi__icon   { background: var(--color-secondary); }
.ana-kpi--searches .ana-kpi__icon { background: var(--color-accent); }
.ana-kpi--clicks .ana-kpi__icon  { background: #8B7EC8; }
[data-theme="dark"] .ana-kpi--clicks .ana-kpi__icon { background: #A599D6; }

.ana-kpi__num {
  font-family: var(--font-display);
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
}
.ana-kpi__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
}

/* ── Cards ── */
.ana-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.ana-card:hover {
  box-shadow: var(--shadow-md);
}
.ana-card--wide {
  margin-bottom: 2rem;
}
.ana-card__title {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ana-card__title svg {
  flex-shrink: 0;
  opacity: 0.7;
}

/* ── Fade-in ── */
.ana-fade {
  animation: ana-fade-up 0.5s ease-out both;
  animation-delay: calc(var(--delay, 0) * 0.1s);
}

/* ── Bar chart ── */
.ana-bars {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.ana-bars__row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: ana-fade-up 0.4s ease-out both;
  animation-delay: calc(var(--i, 0) * 0.05s + 0.2s);
}
.ana-bars__date {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  min-width: 2.75rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.ana-bars__track {
  flex: 1;
  height: 26px;
  background: var(--color-bg-warm);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.ana-bars__fill {
  height: 100%;
  background: var(--header-gradient);
  border-radius: var(--radius-sm);
  min-width: 3px;
  animation: ana-bar-grow 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--i, 0) * 0.05s + 0.3s);
}
.ana-bars__val {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--color-text);
  min-width: 2rem;
  font-variant-numeric: tabular-nums;
}

/* ── Data grid ── */
.ana-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}
@media (min-width: 700px) {
  .ana-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Table ── */
.ana-table {
  width: 100%;
  border-collapse: collapse;
}
.ana-table tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}
.ana-table tr:last-child { border-bottom: none; }
.ana-table tr:hover { background: var(--color-bg-warm); }
.ana-table td {
  padding: 0.5rem 0;
  font-size: 0.8125rem;
  color: var(--color-text);
}
.ana-table__path {
  word-break: break-all;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.ana-table__count {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-left: 1rem;
  color: var(--color-primary);
  font-size: 0.875rem;
}

/* ── Empty state ── */
.ana-empty {
  color: var(--color-text-light);
  font-size: 0.8125rem;
  font-style: italic;
  text-align: center;
  padding: 1rem 0;
}

/* ── Map ── */
.ana-map {
  height: 400px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  z-index: 0;
}
.ana-map .leaflet-popup-content-wrapper {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  border-radius: var(--radius-sm);
}

/* ── Filter chips ── */
.ana-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 1.25rem;
  animation: ana-fade-up 0.3s ease-out both;
}
.ana-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-xl);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-body);
  transition: all var(--transition);
  line-height: 1.3;
}
.ana-filter-chip:hover {
  background: var(--color-primary-dark);
  transform: translateY(-1px);
}
.ana-filter-chip__label {
  opacity: 0.8;
}
.ana-filter-chip__x {
  opacity: 0.7;
  flex-shrink: 0;
}
.ana-filter-chip:hover .ana-filter-chip__x {
  opacity: 1;
}
.ana-filter-chip--reset {
  background: var(--color-tag-bg);
  color: var(--color-text-muted);
}
.ana-filter-chip--reset:hover {
  background: var(--color-border);
  color: var(--color-text);
}

/* ── Clickable table rows ── */
.ana-table__link {
  text-decoration: none;
  color: inherit;
  display: block;
  width: 100%;
}
.ana-table__link:hover {
  color: var(--color-primary);
}
.ana-table tr {
  cursor: pointer;
}
.ana-table__row--active {
  background: var(--color-accent-light) !important;
}
.ana-table__row--active td {
  color: var(--color-text);
  font-weight: 700;
}
.ana-table__row--dimmed {
  opacity: 0.45;
}
.ana-table__row--dimmed:hover {
  opacity: 0.75;
}

/* ── Clickable bar chart rows ── */
a.ana-bars__row {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0.125rem 0.25rem;
  margin: -0.125rem -0.25rem;
  transition: background var(--transition), opacity var(--transition);
}
a.ana-bars__row:hover {
  background: var(--color-bg-warm);
}
.ana-bars__row--active {
  background: var(--color-accent-light) !important;
  border-radius: var(--radius-sm);
}
.ana-bars__row--active .ana-bars__val {
  color: var(--color-primary);
}
.ana-bars__row--dimmed {
  opacity: 0.4;
}
.ana-bars__row--dimmed:hover {
  opacity: 0.7;
}

/* ── Map marker cursor ── */
.ana-map .leaflet-interactive {
  cursor: pointer !important;
}

/* ── Mobile adjustments ── */
@media (max-width: 480px) {
  .ana-hero { padding: 2rem 1rem 1.5rem; }
  .ana-hero__title { font-size: 1.5rem; }
  .ana-body { padding: 1rem 1rem 2rem; }
  .ana-kpi { padding: 1rem 0.75rem; }
  .ana-kpi__num { font-size: 1.5rem; }
  .ana-kpi__icon { width: 36px; height: 36px; }
  .ana-kpi__icon svg { width: 18px; height: 18px; }
  .ana-map { height: 280px; }
  .ana-filters { gap: 0.25rem; }
  .ana-filter-chip { font-size: 0.6875rem; padding: 0.3rem 0.6rem; }
}
