/* ==========================================================================
   КАРКАС: шапка, подвал, внутренние страницы, динамический контент,
   блочные контролы, hero-редактор, автокомплит локации.
   Подключать ПОСЛЕ base.css.
   ========================================================================== */

/* ==========================================================================
   1. Шапка
   ==========================================================================
   z-index берём из --z-header (2000). Это важно: .block-controls и
   .page-editor-toolbar теперь ниже (500), поэтому выпадающее меню профиля
   в шапке не перекрывается кнопками редактирования блоков на странице.
*/
.header {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) minmax(0, auto);
  align-items: center;
  gap: clamp(8px, 1.2vw, 20px);
  padding: clamp(10px, 1.2vw, 18px) clamp(12px, 2vw, 40px);
  background: var(--header-bg);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  position: relative;
  z-index: var(--z-header);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  transition: background-color 0.25s ease;
}
[data-theme="dark"] .header { box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35); }

.logo {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: clamp(6px, 0.8vw, 15px);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.2s;
}
a.logo:hover { opacity: 0.85; }

.logo-icon {
  width: clamp(30px, 3.5vw, 45px);
  height: clamp(30px, 3.5vw, 45px);
  object-fit: contain;
  flex-shrink: 0;
}

.logo-icon--tinted {
  display: inline-block;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  background-color: var(--primary);
}

.logo-text { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.logo-text .title,
.logo-text .subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logo-text .title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(13px, 1.4vw, 18px);
  color: var(--primary);
  line-height: 1.15;
}
.logo-text .subtitle {
  font-size: clamp(9px, 0.8vw, 11px);
  letter-spacing: 1px;
  color: var(--text-light);
}

.nav {
  justify-self: stretch;
  display: flex;
  justify-content: center;
  gap: clamp(10px, 1.2vw, 22px);
  font-size: clamp(12px, 0.9vw, 15px);
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 2px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--divider) transparent;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.nav::-webkit-scrollbar { height: 4px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb {
  background: var(--divider);
  border-radius: 2px;
}
.nav::-webkit-scrollbar-thumb:hover { background: var(--text-light); }
.nav a {
  color: var(--text-light);
  font-weight: 500;
  position: relative;
  white-space: nowrap;
  padding: 6px 2px;
  transition: color 0.25s ease;
  flex: 0 0 auto;
}
.nav a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--primary);
  border-radius: 2px;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.25s ease;
}
.nav a:hover,
.nav a.active { color: var(--primary); }
.nav a:hover::after,
.nav a.active::after { transform: scaleX(1); }
.nav > a:first-child { margin-left: auto; }
.nav > a:last-child { margin-right: auto; }

.header-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}
#auth-buttons {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}
#auth-buttons .btn-header {
  padding: 11px 22px !important;
  font-size: 14px !important;
  border-radius: 26px !important;
  font-weight: 500;
  white-space: nowrap;
  line-height: 1.2;
  box-shadow: none !important;
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
  margin: 0 !important;
  min-width: 100px;
  justify-content: center;
}
#auth-buttons .btn-header[style*="ff9800"] {
  background: #f0a13a !important;
  color: #fff !important;
}
#auth-buttons .btn-header[style*="ff9800"]:hover { background: #d98820 !important; }
#auth-buttons .btn-header:not([style*="ff9800"]) {
  background: var(--primary) !important;
  color: var(--surface) !important;
}
#auth-buttons .btn-header:not([style*="ff9800"]):hover { background: var(--primary-dark) !important; }

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}
.theme-toggle:hover {
  background: var(--primary);
  color: var(--surface);
  transform: rotate(15deg);
}
.theme-toggle .theme-icon-dark,
.theme-toggle .theme-icon-light { display: none; }
[data-theme="light"] .theme-toggle .theme-icon-dark { display: inline-block; }
[data-theme="dark"]  .theme-toggle .theme-icon-light { display: inline-block; }

.nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--primary);
  border-radius: 10px;
  cursor: pointer;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  transition: background 0.2s;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-toggle:hover { background: var(--hover-tint); opacity: 1; }
.nav-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.header.nav-open .nav-toggle span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
.header.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.header.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }

@media (max-width: 1440px) {
  #auth-buttons .btn-header {
    padding: 9px 14px !important;
    font-size: 12.5px !important;
    border-radius: 22px !important;
    min-width: auto;
  }
  .nav { gap: clamp(8px, 1vw, 16px); font-size: 13px; }
  .logo-text .title { font-size: 16px; }
  .logo-text .subtitle { font-size: 10px; }
}
@media (max-width: 1280px) {
  .header { padding: 10px 16px; gap: 10px; }
  #auth-buttons .btn-header {
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
  .nav { gap: 10px; font-size: 12.5px; }
  .logo-icon { width: 34px; height: 34px; }
  .logo-text .title { font-size: 15px; }
  .logo-text .subtitle { font-size: 9px; }
  .theme-toggle { width: 36px; height: 36px; font-size: 13px; }
}
@media (max-width: 1180px) {
  .header {
    display: flex;
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 10px;
  }
  .logo { order: 1; }
  .header-right { order: 2; margin-left: auto; }
  .nav-toggle { display: flex; }

  .nav {
    order: 3;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    padding: 0 12px;
    font-size: 15px;
    background: var(--header-bg);
    border-radius: 0 0 12px 12px;
    border-top: 1px solid var(--divider);
    transition: max-height 0.4s ease, padding 0.4s ease;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .header.nav-open .nav {
    max-height: 70vh;
    padding: 10px 12px 16px;
    overflow-y: auto;
  }
  .nav a {
    padding: 13px 10px;
    border-bottom: 1px solid var(--divider);
    font-size: 15px;
  }
  .nav a:last-child { border-bottom: none; }
  .nav a::after { display: none; }
}
@media (max-width: 640px) {
  #auth-buttons .btn-header {
    padding: 7px 10px !important;
    font-size: 11px !important;
    min-width: auto;
  }
  .logo-text .title { font-size: 14px; }
  .logo-text .subtitle { display: none; }
  .logo-icon { width: 30px; height: 30px; }
  .theme-toggle { width: 34px; height: 34px; font-size: 12px; }
}

/* ==========================================================================
   2. Внутренние страницы — общий шаблон hero
   ========================================================================== */
.page-hero {
  background: var(--primary);
  color: var(--surface);
  text-align: center;
  padding: clamp(36px, 5vw, 60px) 20px;
}
.page-hero h1 { font-size: var(--fs-2xl); }
.page-subtitle, .admin-subtitle { margin-top: 10px; font-size: var(--fs-sm); }

/* ==========================================================================
   3. Подвал
   ========================================================================== */
.footer {
  background: var(--footer-bg);
  color: var(--footer-text);
  padding: clamp(28px, 4vw, 50px) clamp(16px, 4vw, 50px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: clamp(20px, 2.5vw, 30px);
  align-items: start;
  transition: background-color 0.25s ease;
}
.footer-logo {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.2s;
}
a.footer-logo:hover { opacity: 0.9; }
.logo-icon.white { filter: brightness(0) invert(1); }
.logo-text.white-text .title { color: var(--footer-text); white-space: normal; }
.logo-text.white-text .subtitle { color: var(--footer-text); opacity: 0.75; }
.footer-contacts { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.contact-item { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); }
.contact-item i { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.footer-socials h4 { margin-bottom: 20px; font-size: var(--fs-sm); letter-spacing: 1px; }
.socials { display: flex; gap: 12px; flex-wrap: wrap; }
.socials a {
  width: clamp(38px, 3.5vw, 45px);
  height: clamp(38px, 3.5vw, 45px);
  border: 1px solid var(--footer-text);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(15px, 1.3vw, 18px);
  transition: var(--transition);
  flex-shrink: 0;
  color: var(--footer-text);
}
.socials a:hover { background: var(--footer-text); color: var(--footer-bg); }
.footer-copy { text-align: right; font-size: var(--fs-xs); color: var(--footer-text); opacity: 0.8; }

@media (max-width: 1024px) {
  .footer { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .footer-copy { text-align: left; }
}
@media (max-width: 768px) {
  .footer { grid-template-columns: 1fr; text-align: center; }
  .footer-copy { text-align: center; margin-top: 20px; }
  .footer-logo, .footer-contacts, .socials, .contact-item { justify-content: center; align-items: center; }
}
@media (max-width: 640px) {
  .footer-copy { text-align: center; }
  .footer-logo, .footer-contacts, .contact-item { justify-content: center; }
  .socials { justify-content: center; }
}

.footer .contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: none;
  border-bottom: none;
  background: transparent;
  cursor: default;
  font-size: var(--fs-sm);
  text-align: left;
  width: auto;
  min-width: 0;
  transition: none;
}
.footer .contact-item:hover { background: transparent; }
.footer .contact-item i {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.footer .contact-item span { font-size: var(--fs-sm); }

/* ==========================================================================
   4. Динамический контент страниц
   ========================================================================== */
#dynamic-content {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(14px, 1.5vw, 20px);
  padding: clamp(16px, 2.5vw, 40px);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  height: auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: visible;
  align-items: flex-start;
}
.dynamic-block-wrap {
  position: relative;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  flex-shrink: 1;
  height: auto;
  min-height: 0;
  overflow: visible;
}
.dynamic-block {
  position: relative;
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
  height: auto;
  min-height: 0;
  overflow: visible;
  overflow-wrap: break-word;
  word-break: break-word;
}
.dynamic-block img,
.dynamic-block video,
.dynamic-block iframe,
.container-block img {
  max-width: 100% !important;
  height: auto !important;
  box-sizing: border-box;
  display: block;
}
.dynamic-block-wrap[draggable="false"] { user-select: none; }
.container-block {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 20px;
  background: var(--tint-bg);
  border: 1px solid var(--divider);
  position: relative;
  box-sizing: border-box;
  max-width: 100%;
  height: auto;
  min-height: 0;
  overflow: visible;
  align-items: flex-start;
}
.container-block > .dynamic-block-wrap {
  flex: 0 0 auto;
  min-width: auto;
  max-width: 100%;
  box-sizing: border-box;
  height: auto;
}
.dynamic-block-wrap.dragging {
  opacity: 0.5;
  border: 2px dashed var(--primary);
  cursor: grabbing;
}
@media (max-width: 1024px) {
  #dynamic-content { padding: 26px 18px; }
}
@media (max-width: 768px) {
  #dynamic-content { padding: 18px 12px; gap: 14px; }
  .dynamic-block-wrap { max-width: 100% !important; }
  .container-block { padding: 14px; gap: 14px; }
}

/* ==========================================================================
   5. Управление блоком + тулбар редактора страниц
   ==========================================================================
   z-index 500 (--z-block-controls) — ниже шапки (2000) и модалок
   (>99999). Так выпадающее меню профиля всегда поверх кнопок
   редактирования блоков.
*/
.block-controls {
  position: absolute;
  top: -14px;
  right: 0;
  display: flex;
  gap: 6px;
  z-index: var(--z-block-controls);
  pointer-events: auto;
}
.dynamic-block-wrap > .container-block ~ .block-controls { top: -32px; }
body.swal2-shown .block-controls,
body.swal2-shown .page-editor-toolbar,
body.swal2-shown .hero-controls,
body.swal2-shown .idx-edit-btn { display: none !important; }

.ctrl-btn {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--icon-btn-color);
  transition: transform 0.15s, background 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  padding: 0;
}
.ctrl-btn:hover { transform: scale(1.12); }

.ctrl-edit {
  background: var(--icon-btn-primary-bg);
}
.ctrl-edit:hover {
  background: var(--icon-btn-primary-hover);
}
.ctrl-delete {
  background: var(--icon-btn-danger-bg);
}
.ctrl-delete:hover {
  background: var(--icon-btn-danger-hover);
}
.ctrl-drag {
  background: var(--icon-btn-drag-bg);
  cursor: grab;
}
.ctrl-drag:hover { background: var(--icon-btn-drag-hover); }
.ctrl-drag:active { cursor: grabbing; }

.page-editor-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 20px;
  margin-bottom: 20px;
  background: var(--surface);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  max-width: 100%;
  box-sizing: border-box;
}
.page-editor-toolbar .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 0;
}
.page-editor-toolbar .btn.toolbar-right { margin-left: auto; }

@media (max-width: 900px) {
  .page-editor-toolbar { padding: 10px 12px; gap: 8px; }
  .page-editor-toolbar .btn { flex: 1 1 auto; justify-content: center; font-size: 13px; }
  .page-editor-toolbar .btn.toolbar-right { margin-left: 0; flex: 1 1 100%; }
}
@media (max-width: 768px) {
  .ctrl-btn { width: 24px; height: 24px; flex: 0 0 24px; font-size: 11px; }
  .block-controls { top: -12px; gap: 4px; }
  .dynamic-block-wrap > .container-block ~ .block-controls { top: -28px; }
  .page-editor-toolbar .btn.toolbar-right { margin-left: 0; flex: 1 1 100%; justify-content: center; }
}
@media (max-width: 480px) {
  .page-editor-toolbar { padding: 10px 12px; }
  .page-editor-toolbar .btn { flex: 1 1 auto; justify-content: center; }
}

/* ==========================================================================
   6. Плавающая панель черновика
   ========================================================================== */
.draft-save-bar {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%); z-index: var(--z-floating-bar);
  display: flex; align-items: center; gap: 20px;
  padding: 14px 22px; background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--divider);
  max-width: calc(100vw - 32px);
  animation: draft-slide-up 0.25s ease;
}
.draft-save-bar[hidden] { display: none !important; }
@keyframes draft-slide-up {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.draft-save-bar-info {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--primary); font-weight: 500;
}
.draft-save-bar-info i { font-size: 16px; }
.draft-save-bar-info b {
  color: var(--primary); background: var(--hover-tint);
  padding: 2px 8px; border-radius: 10px; font-size: 13px;
}
.draft-save-bar-actions { display: flex; gap: 8px; }
.draft-save-bar-actions .btn {
  padding: 9px 18px; font-size: 13px; border-radius: 22px; white-space: nowrap;
}
@media (max-width: 640px) {
  .draft-save-bar {
    left: 16px; right: 16px; bottom: 16px;
    transform: none; flex-direction: column;
    align-items: stretch; gap: 10px; padding: 14px 16px;
  }
  .draft-save-bar-info { justify-content: center; }
  .draft-save-bar-actions { justify-content: stretch; }
  .draft-save-bar-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* ==========================================================================
   7. Hero — редактируемая hero-секция
   ========================================================================== */
.page-hero.hero-custom { position: relative; box-sizing: border-box; width: 100%; }
.page-hero.hero-custom > .dynamic-block-wrap { width: 100%; max-width: 100%; position: relative; }
.page-hero.hero-custom .dynamic-block { width: 100%; max-width: 100%; }
.hero-placeholder {
  font-family: 'Playfair Display', serif;
  font-size: clamp(28px, 4vw, 64px);
  margin: 0; letter-spacing: 1px; opacity: 0.5;
}
.page-hero.hero-empty { border: 2px dashed rgba(255, 255, 255, 0.35); }
.page-hero.hero-editable { position: relative; }
.hero-convert-btn {
  position: absolute; top: 14px; right: 14px;
  padding: 8px 16px; border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  color: inherit; font-family: inherit;
  font-size: 12.5px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.2s, border-color 0.2s;
  z-index: 5;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.hero-convert-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.85);
}
.hero-convert-btn i { font-size: 12px; }
.hero-controls {
  position: absolute; top: 14px; right: 14px; z-index: 50;
  display: flex; gap: 6px; padding: 6px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--divider); border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0; transform: translateY(-6px);
  transition: opacity 0.2s, transform 0.2s;
}
.page-hero:hover .hero-controls,
.hero-controls:focus-within { opacity: 1; transform: translateY(0); }
.hero-ctrl-btn {
  width: 34px; height: 34px; border: none; border-radius: 8px;
  background: var(--hover-tint); color: var(--primary);
  cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  transition: background 0.15s, color 0.15s;
}
.hero-ctrl-btn:hover { background: var(--primary); color: #fff; }
.hero-ctrl-primary {
  background: var(--icon-btn-primary-bg);
  color: var(--icon-btn-color);
}
.hero-ctrl-primary:hover { background: var(--icon-btn-primary-hover); }
.hero-ctrl-danger {
  background: var(--icon-btn-danger-bg);
  color: var(--icon-btn-color);
}
.hero-ctrl-danger:hover { background: var(--icon-btn-danger-hover); }
@media (max-width: 768px) {
  .hero-controls { opacity: 1; transform: none; top: 10px; right: 10px; padding: 4px; }
  .hero-ctrl-btn { width: 30px; height: 30px; font-size: 12px; }
  .hero-convert-btn { font-size: 11.5px; padding: 7px 12px; }
}
.editor-hero-hint {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; background: var(--hover-tint);
  border-left: 3px solid var(--primary); border-radius: 8px;
  margin-bottom: 16px; font-size: 13px; line-height: 1.5; color: var(--text);
}
.editor-hero-hint i {
  color: var(--primary); font-size: 16px; margin-top: 1px; flex-shrink: 0;
}
#hover-gradient-controls {
  padding-left: 20px; border-left: 2px solid var(--divider); margin-left: 4px;
}

/* ==========================================================================
   8. Автокомплит локации
   ========================================================================== */
.location-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}
.location-dropdown[hidden] { display: none !important; }

.location-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.location-option:hover {
  background: var(--hover-tint);
  color: var(--primary);
}
.location-option i {
  color: var(--text-light);
  font-size: 13px;
  flex-shrink: 0;
}
.location-option:hover i { color: var(--primary); }