/* ===== Global elements ===== */
body {
  margin: 0;
  font-family: sans-serif;
}

/* scrollable container to disable native pull refresh */
.content {
  position: relative;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}
/* Блокирует прокрутку фона при открытой модалке */

body.no-scroll {
  overflow: hidden;
}

[hidden] {
  display: none !important; /* quick hide utility */
}

/* ===== Drawer navigation ===== */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 250px;
  background: #eee;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.3);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  padding: 1rem;
  overflow-y: auto;
  z-index: 10;
}

/* visible state of the drawer */
.drawer.open {
  transform: translateX(0);
}

.board-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 0.5rem 0;
  text-align: left;
  cursor: pointer;
  font-size: 1rem;
}

.boards-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.boards-list summary {
  cursor: pointer;
  font-weight: bold;
}

.boards-list details ul {
  list-style: none;
  margin: 0;
  padding-left: 1rem;
}

#favoritesList,
#historyList {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.boards-list li li,
#favoritesList li,
#historyList li {
  padding: 0.3rem 0;
  cursor: pointer;
}

/* ===== Header bar ===== */

header {
  display: flex;
  align-items: center;
  background: #2196f3;
  color: #fff;
  padding: 0.5rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#menuButton {
  font-size: 1.5rem;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
}

#backButton {
  font-size: 1.5rem;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  margin-left: 0.5rem;
}

.board-label {
  margin-left: 0.5rem;
}

/* clickable label with thread id */
.thread-label {
  font-weight: bold;
  color: #2196f3;
  cursor: pointer;
  margin-bottom: 0.3rem;
  display: inline-block;
}

/* main application area */
main {
  padding: 1rem;
}

/* service worker version label */
#swVersion {
  margin-left: auto;
  font-size: 0.8rem;
}

/* event log container */
#log {
  background: #f5f5f5;
  padding: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* individual thread preview */
.thread {
  border: 1px solid #ccc;
  padding: 0.5rem;
  margin-bottom: 1rem;
}

.thread.collapsed-thread {
  display: flex;
  align-items: center;
  padding: 0.4rem 0.5rem;
  background: #f8f8f8;
  color: #555;
}

.collapsed-thread-summary {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* wrap long links and words inside posts */
.thread p,
.thread a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* post thumbnail */
.thumb {
  width: 150px;
  cursor: pointer;
  display: block;
  margin-bottom: 0.5rem;
}

/* row of thumbnails */
.thumbs-row {
  display: flex;
  width: 100%;
  overflow: hidden;
  gap: 0.5rem;
}

/* wrapper around thumbnail image */
.thumb-wrapper {
  position: relative;
  display: inline-block;
}

/* mark thumbnails with multiple files */
.thumb.multiple {
  filter: grayscale(60%);
}

/* overlay showing total files count */
.thumb-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  font-weight: bold;
  font-size: 2rem;
  pointer-events: none;
}

.play-overlay { /* play icon for video files */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 3rem;
  text-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

/* ===== Media viewer modal ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

/* limit media size within modal */
.modal img,
.modal video {
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100vh;
}

/* container for media element in modal */
.media-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
}

/* link to open media in external app */
.open-external {
  display: block;
  margin-top: 0.5rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
  padding: 0.3rem 0.5rem;
  text-align: center;
  text-decoration: none;
  border-radius: 4px;
}

.nav-overlay { /* clickable navigation zones */
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.25), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
  cursor: pointer;
  pointer-events: none;
  z-index: 2;
}

.nav-overlay.right {
  right: 0;
  left: auto;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.25), transparent);
}

.nav-overlay.left {
  left: 0;
}

.nav-overlay .nav-hint {
  background: rgba(0, 0, 0, 0.5);
  padding: 0.35rem 0.6rem;
  border-radius: 1.5rem;
  font-size: 0.9rem;
  pointer-events: none;
}

.nav-button { /* explicit navigation controls */
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  padding: 0.35rem 0.75rem;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 3;
}

.nav-button:hover {
  transform: translateY(-50%) scale(1.05);
}

.nav-button.left { left: 1rem; }
.nav-button.right { right: 1rem; }

.nav-overlay.visible,
.nav-button.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal .counter { /* media index indicator */
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  padding: 0.5rem;
  font-family: monospace;
}

/* gallery with thumbnails */
.gallery-modal {
  z-index: 21;
  overflow-y: auto;
  padding: 0.5rem;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.gallery-thumb {
  position: relative;
}

.gallery-grid img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.gallery-video-icon {
  position: absolute;
  right: 6px;
  top: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: 0.1rem 0.3rem;
  font-size: 0.8rem;
  border-radius: 4px;
  line-height: 1;
  pointer-events: none;
}

/* posts/media counters in threads */
.thread-stats {
  font-family: monospace;
  font-size: 0.8rem;
  color: #555;
  margin-top: 0.3rem;
}

/* button to show full post */
.expand-btn {
  border: none;
  background: #2196f3;
  color: #fff;
  cursor: pointer;
  font-size: 0.9em;
  margin-left: 0.3em;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}

/* links to replies inside posts */
.replies {
  font-size: 0.8rem;
  color: #555;
  margin-top: 0.3rem;
}
.replies a {
  color: #2196f3;
  margin-left: 0.2rem;
}

.s {
  text-decoration: line-through;
}

.u {
  text-decoration: underline;
}

.o {
  text-decoration: overline;
}

/* hidden spoiler text */
.spoiler {
  background: #000;
  color: #000;
  padding: 0 2px;
}
.spoiler:hover {
  color: #fff; /* reveal spoiler */
}

/* quote links */
.unkfunc,
.quote {
  color: #789922;
}

/* pagination controls */
.pagination {
  text-align: center;
  margin: 1rem 0;
}

/* page number button */
.page-btn {
  margin: 0 0.3rem;
  padding: 0.2rem 0.5rem;
  background: #f0f0f0;
  border: 1px solid #ccc;
  cursor: pointer;
}

/* current page button */
.page-btn.active {
  background: #2196f3;
  color: #fff;
  border-color: #2196f3;
}

/* persistent bottom action bar */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #2196f3;
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding: 0.5rem;
  z-index: 15;
}
/* hide bar when not pinned */
.bottom-bar.hidden,
.bottom-bar[hidden] {
  display: none;
}
/* buttons inside bottom bar */
.bottom-bar button {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

/* settings modal dialog */
.settings-modal .settings-form {
  background: #fff;
  padding: 1rem;
  border-radius: 4px;
  color: #000;
}

/* modal with single post */
.post-modal .post-content {
  background: #fff;
  color: #000;
  padding: 1rem;
  border-radius: 4px;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}
/* spacing for form groups */
.settings-form > div {
  margin: 0.5rem 0;
}
/* each label on new line */
.settings-form > label {
  display: block;
  margin: 0.5rem 0;
}
/* margin for closing button */
.settings-form button {
  margin-top: 1rem;
}

/* refresh indicators shown on pull gestures */
.pull-refresh {
  position: absolute;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  color: #2196f3;
  font-size: 1.5rem;
}

.pull-refresh.pull-bottom {
  bottom: -50px;
}

.pull-refresh.active {
  opacity: 1;
}

/* hidden search bar revealed on pull */
.search-bar {
  display: none;
  position: sticky;
  top: 0;
  padding: 0.5rem;
  background: #f1f1f1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  z-index: 5;
  width: 100%;
  flex: 1 1 100%;
}

.search-bar.visible {
  display: block;
}

.search-bar input {
  width: 100%;
  box-sizing: border-box;
  font-size: 16px;
  line-height: 1.4;
}

.search-results {
  margin: 1rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.search-results-status {
  margin: 0;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  font-size: 0.9rem;
}

.search-results .thread {
  cursor: pointer;
}

.search-results .search-result-item {
  border-left: 4px solid transparent;
  padding-left: 1rem;
  padding-top: 0.75rem;
}

.search-results .search-result-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  color: #fff;
  margin-bottom: 0.5rem;
}

.search-results .search-result-thread {
  border-left-color: #2196f3;
}

.search-results .search-result-thread .search-result-badge {
  background: #2196f3;
}

.search-results .search-result-post {
  border-left-color: #4caf50;
}

.search-results .search-result-post .search-result-badge {
  background: #4caf50;
}

.search-results .search-result-meta {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.25rem;
}

.search-results-empty {
  margin: 0;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.posts .thread.search-hit {
  border-color: #ff9800;
  box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.3);
  animation: searchHitGlow 2s ease-out;
}

@keyframes searchHitGlow {
  0% {
    background-color: rgba(255, 235, 59, 0.4);
  }
  100% {
    background-color: transparent;
  }
}

@media (pointer: fine) {
  header {
    align-items: center;
    flex-wrap: wrap;
  }

  #searchBar {
    display: block;
    position: relative;
    top: auto;
    padding: 0;
    background: transparent;
    box-shadow: none;
    flex: 0 1 320px;
    width: min(320px, 100%);
    margin-left: auto;
  }

  #searchBar.visible {
    display: block;
  }

  #swVersion {
    margin-left: 0;
    font-size: 0.8rem;
    order: 99;
    width: 100%;
    text-align: right;
  }

  .search-results {
    margin-top: 1rem;
  }
}

/* context menu for media */
.context-menu {
  position: fixed;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 0.5rem;
  border-radius: 4px;
  z-index: 22;
  display: flex;
  flex-direction: column;
  min-width: 200px;
}

.context-menu button {
  background: none;
  border: none;
  color: inherit;
  text-align: left;
  padding: 0.5rem;
  width: 100%;
  font-size: 1rem;
}

.context-menu button:not(:last-child) {
  border-bottom: 1px solid #555;
}

.context-menu .info {
  padding: 0.5rem;
  font-size: 0.9rem;
  text-align: center;
  border-bottom: 1px solid #555;
}
