/* Common UI overrides to match main pages (event_list/useful_people_list).
 * Goal: unify header sizing/spacing and perceived typography across pages.
 */

/* ===== Design tokens (single source of truth) ===== */
:root {
  --container-max: 1200px;
  --container-pad-desktop: 15px;
  --container-pad-tablet: 10px;
  --container-pad-mobile: 8px;

  --header-h: 56px;
  --header-pad-y: 6px;
  --header-pad-x: 15px;
  --header-gap: 10px;
  --header-z: 1200;

  --primary: #007bff;
  --bg: #161a1f;
  --surface: #1a1a1a;
  --text: #b8b5bd;
  --stroke: #333;
}

/* Global safety: never overflow viewport on mobile */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Prevent layout "jump" between pages due to scrollbar */
html {
  scrollbar-gutter: stable;
}

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

img,
video,
canvas,
svg {
  max-width: 100%;
}

/* Make common modal dialogs fit mobile width */
@media (max-width: 480px) {
  .modal-content {
    max-width: calc(100vw - 24px) !important;
    width: calc(100vw - 24px) !important;
  }
}

/* Prevent long strings from causing horizontal scroll */
body {
  overflow-wrap: anywhere;
  word-break: break-word;
  /* Keep scrollbar reserved to avoid width shift on desktop */
  overflow-y: scroll;
}

/* Keep layout consistent on mobile (main pages use zero body padding). */
body {
  padding: 0 !important;
}

/* Sticky footer layout (for pages using base.html) */
.site-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-body .site-container {
  flex: 1 0 auto;
  width: 100%;
}

/* Reliable pinned header (sticky can break in some layouts/browsers) */
.site-body .header {
  position: fixed !important;
  top: 0 !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  width: min(var(--container-max), 100%) !important;
}

/* Reserve space for the fixed header so content doesn't go under it */
.site-body .site-container {
  padding-top: calc(var(--container-pad-desktop) + var(--header-h)) !important;
}

.site-body .site-footer {
  margin-top: auto;
}

/* Chat pages manage their own full-screen layout */
.chat-body {
  display: block;
}

/* ===== Site container (base.html pages) ===== */
.site-container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--container-pad-desktop);
}

/* Desktop: unify page wrapper width (avoid "narrow" pages) */
@media (min-width: 769px) {
  /* Most templates wrap content into a single root <div class="...-page"> with max-width: 480px.
     Since common.css is loaded after page-level styles, we override to match homepage width. */
  .site-container > div:not(.chat-detail-page):not(.talk-chat-detail-page):not(.useful-person-chat-detail-page) {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* Content width helper (narrow on small screens) */
.content-narrow {
  max-width: 720px;
  margin: 0 auto;
}

/* Desktop: keep same 1200px width as other pages */
@media (min-width: 769px) {
  .content-narrow {
    max-width: 1200px;
  }
}

@media (max-width: 768px) {
  .site-container {
    padding: var(--container-pad-tablet);
  }
  .site-body .site-container {
    padding-top: calc(var(--container-pad-tablet) + var(--header-h)) !important;
  }
}

@media (max-width: 480px) {
  .site-container {
    padding: var(--container-pad-mobile);
  }
  .site-body .site-container {
    padding-top: calc(var(--container-pad-mobile) + var(--header-h)) !important;
  }
}

/* Mobile: avoid extra per-page padding around header/content */
@media (max-width: 768px) {
  .site-container > div:not(.chat-detail-page):not(.talk-chat-detail-page):not(.useful-person-chat-detail-page) {
    padding: 0 !important;
  }
}

/* ===== Site footer ===== */
.site-footer {
  margin-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.08);
}

.site-footer__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 15px calc(14px + env(safe-area-inset-bottom, 0px));
}

.site-footer__nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.site-footer__link {
  color: rgba(184, 181, 189, 0.95);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.3;
}

.site-footer__link:hover {
  text-decoration: underline;
}

@media (min-width: 769px) {
  .site-footer__nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
  }
}

/* Header sizing/spacing (shared .header pages) */
.header {
  /* Normalize header across ALL pages (many templates override .header in page CSS) */
  display: flex !important;
  flex-wrap: nowrap !important;
  justify-content: space-between !important;
  align-items: center !important;

  position: sticky !important;
  top: 0 !important;
  z-index: var(--header-z) !important;
  background: var(--bg) !important;

  padding: var(--header-pad-y) var(--header-pad-x) !important;
  gap: var(--header-gap) !important;
  margin-bottom: 8px !important;

  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

.header-left {
  /* Critical: some templates have `.header > div { flex-wrap: wrap; }`,
     which causes menu + title to wrap and makes header taller on some pages. */
  display: flex !important;
  align-items: center !important;
  gap: var(--header-gap) !important;
  flex: 1 1 auto !important;
  min-width: 0 !important;
  flex-wrap: nowrap !important;
}

.header h1 {
  font-size: 1.5em !important;
  line-height: 1.1 !important;
  /* keep header height consistent across pages */
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 !important;
}

/* Also prevent wrapping for any direct header child */
.header > div {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  gap: var(--header-gap) !important;
  min-width: 0 !important;
}

.header > div:not(.header-left) {
  flex: 0 1 auto !important;
  justify-content: flex-end !important;
}

.header a,
.header form {
  font-size: 0.9em !important;
}

.menu-icon {
  padding: 8px !important;
  font-size: 1.5em !important;
}

/* Make menu icon behave like an icon button */
button.menu-icon {
  position: relative;
  background: transparent;
  border: none;
  color: inherit;
}

button.menu-icon:hover {
  color: #cccccc;
}

button.menu-icon:focus-visible {
  outline: 2px solid rgba(0, 123, 255, 0.7);
  outline-offset: 2px;
  border-radius: 10px;
}

/* ===== Event photos collage (match homepage cards) ===== */
.event-photos-container {
  width: 100%;
  aspect-ratio: 16 / 11;
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 2px;
  background: #0f1318;
}

.event-photos-container[data-photo-count="1"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.event-photos-container[data-photo-count="1"] .photo-item {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
}

.event-photos-container .photo-item {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  cursor: pointer;
}

.event-photos-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.event-photos-container .photo-item.is-more::after {
  content: attr(data-more);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  font-weight: 700;
  font-size: 18px;
}

/* Date picker: allow a left "Reset" button */
.date-picker-reset {
  margin-right: auto;
}

/* ===== Unified button style (match organizer "Редактировать") ===== */
.action-btn,
.event-action-btn,
.btn,
button,
input[type="submit"],
input[type="button"],
input[type="reset"],
.search-button,
.filter-btn,
.create-btn,
.favorites-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;

  color: var(--primary);
  background: transparent;
  border: 1px solid var(--primary);
  border-radius: 5px;

  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.2;

  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Icon-only buttons (calendar/search): no blue outline on mobile */
.icon-btn,
.search-button.icon-btn {
  border-color: transparent !important;
  background: transparent !important;
  color: var(--text) !important;
}

.icon-btn:hover,
.search-button.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08) !important;
}

.icon-btn:focus-visible,
.search-button.icon-btn:focus-visible {
  outline: 2px solid rgba(184, 181, 189, 0.45);
  outline-offset: 2px;
  border-radius: 10px;
}

/* Event detail action buttons: keep text left-aligned (some have icons) */
.event-action-btn {
  justify-content: flex-start;
  text-align: left;
}

.action-btn:hover,
.event-action-btn:hover,
.btn:hover,
button:hover,
input[type="submit"]:hover,
input[type="button"]:hover,
input[type="reset"]:hover,
.search-button:hover,
.filter-btn:hover,
.create-btn:hover,
.favorites-btn:hover {
  background: rgba(0, 123, 255, 0.12);
  text-decoration: none;
}

.action-btn:disabled,
.event-action-btn:disabled,
.btn:disabled,
button:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled,
input[type="reset"]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Keep icon-only buttons unchanged */
.event-share-icon-btn,
.menu-icon,
button.menu-icon {
  padding: 8px !important;
  border: none !important;
  background: transparent !important;
}

/* Dropdown menu (used across pages via include) */
.menu-container {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  max-width: 90vw;
  z-index: 1000;
  display: none;
  margin-top: 5px;
}

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

.dropdown-menu a,
.dropdown-menu form {
  display: block;
  padding: 12px 15px;
  color: #b8b5bd;
  text-decoration: none;
  border-bottom: 1px solid #333;
  transition: background 0.2s;
  font-size: inherit;
}

.dropdown-menu a:last-child,
.dropdown-menu form:last-child {
  border-bottom: none;
}

.dropdown-menu a:hover,
.dropdown-menu form:hover {
  background: #333333;
}

.dropdown-menu form {
  margin: 0;
}

.dropdown-menu form button {
  background: none;
  border: none;
  padding: 0;
  width: 100%;
  text-align: left;
  color: #b8b5bd;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
}

/* Notification dot on menu button */
button.menu-icon .notification-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 10px;
  height: 10px;
  background: #dc3545;
  border-radius: 50%;
  border: 2px solid #161a1f;
  display: none;
}

button.menu-icon.has-notifications .notification-dot {
  display: block;
}

@media (max-width: 768px) {
  body {
    padding: 0 !important;
    padding-bottom: 30px !important;
  }
  .header {
    padding: 6px 15px !important;
    gap: 8px !important;
  }
}

@media (max-width: 480px) {
  body {
    padding: 0 !important;
    padding-bottom: 30px !important;
    font-size: 14px !important;
  }
  .header {
    padding: 6px 15px !important;
  }
  .header h1 {
    font-size: 1.3em !important;
  }

  /* Mobile button sizing: match "Создать чат" baseline */
  .action-btn,
  .event-action-btn,
  .filter-btn,
  .create-btn,
  .favorites-btn,
  .btn {
    font-size: 11px;
    padding: 7px 8px;
  }
}

/* Chat pages use .chat-header-bar instead of .header; bring it closer to main header */
.chat-header-bar {
  padding: 6px 15px !important;
}

/* Chat input bottom spacing: match "useful person" chat */
.chat-input-container {
  padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px)) !important;
}

/* Prevent iOS auto-zoom on map search input (font-size must be >=16px) */
.map-search-input {
  font-size: 16px !important;
}

.chat-header-avatar-wrap,
.chat-header-avatar,
.chat-header-avatar-placeholder {
  width: 32px !important;
  height: 32px !important;
}

.back-btn {
  font-size: 18px !important;
  padding: 4px !important;
}

/* ===== Date range picker (event_list) ===== */
.search-container {
  position: relative;
}

.date-range-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.date-range-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  line-height: 1.2;
  padding-left: 12px; /* align with .search-input text start (padding-left) */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.date-range-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Modal overlay */
.date-picker-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10050;
  background: rgba(0, 0, 0, 0.65);
  padding: 12px;
}

.date-picker-modal.open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.date-picker-modal-content {
  width: min(420px, calc(100vw - 24px));
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.date-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.date-picker-nav {
  background: none;
  border: 1px solid #333;
  color: #b8b5bd;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 16px;
  line-height: 1;
}

.date-picker-month {
  font-weight: 600;
  color: #b8b5bd;
}

.date-picker-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  font-size: 12px;
  color: #888;
  margin-bottom: 6px;
}

.date-picker-weekdays > div {
  text-align: center;
}

.date-picker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.dp-day {
  height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #161a1f;
  color: #b8b5bd;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.dp-day.is-empty {
  background: transparent;
  border-color: transparent;
}

.dp-day:hover {
  border-color: #444;
}

.dp-day.is-selected,
.dp-day.is-range-start,
.dp-day.is-range-end {
  background: rgba(0, 123, 255, 0.22);
  border-color: rgba(0, 123, 255, 0.55);
}

.dp-day.is-in-range {
  background: rgba(0, 123, 255, 0.12);
}

.date-picker-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.date-picker-ok {
  padding: 8px 14px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
}

.date-picker-ok:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .date-range-text {
    font-size: 13px;
  }
}

/* Keep calendar/search buttons equal width (desktop). */
@media (min-width: 769px) {
  .search-container .search-button {
    width: 44px;
    padding-left: 0 !important;
    padding-right: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Mobile: keep search input + button in one row */
@media (max-width: 768px) {
  .search-container .search-form {
    flex-direction: row !important;
    align-items: center !important;
  }
  .search-container .search-input {
    width: auto !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }
  .search-container .search-button {
    width: 44px !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

