/* --- SECTION: VARIABLES --- */
:root {
  --background-color: #2b2b2b;
  --text-color: #f0fff0;
  --header-footer-color: #3b3b3b;
  --accent-color: #76c7c0;
  --accent-hover-color: #8be3e0;

  /* Reaction Specifics */
  --like-color: #76c7c0;
  --dislike-color: #ff7675;
  --like-btn-color: #f0fff0;
  --dislike-btn-color: #f0fff0;
  --widget-padding: 10px;

  --nav-active-color: #fff; /* Default active nav text color */

  --border-color: #555;
  --sidebar-bg: #3b3b3b;
  --leaflet-bg: #353535;

  /* Background Image Handling */
  --bg-image: none;
  --bg-size: cover;
  --bg-repeat: no-repeat;
}

/* --- SECTION: BASE --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  background-color: var(--background-color);
  background-image: var(--bg-image);
  background-size: var(--bg-size);
  background-repeat: var(--bg-repeat);
  background-attachment: fixed;
  background-position: center;
  color: var(--text-color);
  font-family: "MS Gothic", "Courier New", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
body.modal-open {
  overflow: hidden;
}
a {
  color: var(--accent-color);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover-color);
  text-decoration: underline;
}

/* --- SECTION: LAYOUT --- */
.container {
  max-width: 950px;
  margin: 0 auto;
  min-height: 90vh;
}

/* --- SUBSECTION: HEADER LAYOUT --- */
header {
  position: relative;
  border-bottom: 1px dotted var(--border-color);
  margin-bottom: 20px;
  min-height: 120px; /* Minimum height for banner visibility */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* Align content to bottom */
}

/* Overlay to ensure text readability on banners */
.header-overlay {
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.9) 0%,
    rgba(0, 0, 0, 0.4) 60%,
    rgba(0, 0, 0, 0) 100%
  );
  padding: 15px 20px;
  width: 100%;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 15px;
}

.header-identity {
  display: flex;
  align-items: center;
  gap: 15px;
}

.site-pfp {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--accent-color);
  object-fit: cover;
  flex-shrink: 0;
  display: none; /* Hidden by default if no URL provided */
  background-color: var(--background-color);
}

.header-titles {
  display: flex;
  flex-direction: column;
}

header h1 {
  color: var(--accent-color);
  font-size: 24px;
  line-height: 1.2;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.site-tagline {
  font-size: 12px;
  color: #ccc;
  font-style: italic;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

#db-status {
  font-size: 11px;
  color: #aaa;
  text-align: right;
  white-space: nowrap;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}
#db-status.online {
  color: var(--accent-color);
}

.layout-wrapper {
  display: flex;
  gap: 20px;
  padding: 20px;
}
main {
  flex: 1;
  min-width: 0;
}

/* --- SECTION: SIDEBAR --- */
.sidebar {
  width: 180px;
  flex-shrink: 0;
}
.nav-btn {
  display: block;
  width: 100%;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--sidebar-bg);
  border: 1px dotted var(--border-color);
  color: var(--accent-color);
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  opacity: 0.9;
}
.nav-btn:hover {
  background-color: var(--border-color);
  color: #fff;
  opacity: 1;
}
.nav-btn.active {
  background-color: var(--border-color);
  color: var(--nav-active-color);
  opacity: 1;
  border-color: var(--accent-color);
}

/* --- SECTION: CONTENT VIEWS --- */
.view-section {
  display: none;
  animation: fadeIn 0.3s ease;
}
.view-section.active {
  display: block;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
h2 {
  border-bottom: 1px dotted var(--border-color);
  padding-bottom: 5px;
  margin-bottom: 15px;
  color: var(--accent-color);
}

/* --- SECTION: LEAFLETS --- */
.leaflet-item {
  display: flex;
  gap: 15px;
  padding: 15px;
  background-color: var(--leaflet-bg);
  border: 1px dotted var(--border-color);
  margin-bottom: 15px;
  cursor: pointer;
  transition: background-color 0.2s;
  opacity: 0.95;
}
.leaflet-item:hover {
  background-color: var(--header-footer-color);
  opacity: 1;
}
.leaflet-avatar {
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border: 1px dotted var(--accent-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
.leaflet-body {
  flex: 1;
}
.leaflet-header {
  margin-bottom: 5px;
  font-size: 12px;
  color: #aaa;
}
.leaflet-author {
  color: var(--text-color);
  margin-right: 8px;
}
.leaflet-media-container {
  margin-top: 10px;
}
.leaflet-media-container img,
.leaflet-media-container video {
  max-width: 50%;
  height: auto;
  border: 1px dotted var(--border-color);
  display: block;
  cursor: zoom-in; /* Indicate clickable media */
}

/* --- SECTION: REACTIONS --- */
.reaction-widget {
  margin-top: var(--widget-padding);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #888;
}
.reaction-btn {
  background: none;
  border: 1px dotted var(--border-color);
  padding: 2px 8px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.reaction-btn:hover {
  background-color: var(--border-color);
}

/* Specific Colors for Reaction Buttons */
.reaction-btn.like-btn {
  color: var(--like-btn-color);
}
.reaction-btn.dislike-btn {
  color: var(--dislike-btn-color);
}

.reaction-bar {
  flex: 1;
  height: 6px;
  background: #444;
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.reaction-fill {
  height: 100%;
  background: var(--like-color);
  width: 50%;
  transition: width 0.3s ease;
}

/* --- SECTION: GALLERY --- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.gallery-item {
  border: 1px dotted var(--border-color);
  background-color: var(--leaflet-bg);
  padding: 5px;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s;
  opacity: 0.95;
}
.gallery-item:hover {
  transform: scale(1.02);
  border-color: var(--accent-color);
  opacity: 1;
}
.gallery-item img,
.gallery-item video {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
  margin-bottom: 5px;
}
.gallery-caption {
  font-size: 12px;
  text-align: center;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- SECTION: LIGHTBOX (POST DETAILS) --- */
.lightbox {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;

  /* Fade In/Out Transition */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lightbox.open {
  opacity: 1;
  visibility: visible;
}

.lightbox-content {
  background-color: var(--background-color);
  border: 1px dotted var(--border-color);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  position: relative;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);

  /* Content Scale Transition */
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.lightbox.open .lightbox-content {
  transform: scale(1);
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 28px;
  cursor: pointer;
  color: #aaa;
  z-index: 10;
}
.close-btn:hover {
  color: #fff;
}

/* Custom Scrollbar for Lightbox */
.lightbox-content::-webkit-scrollbar {
  width: 8px;
}
.lightbox-content::-webkit-scrollbar-track {
  background: var(--sidebar-bg);
}
.lightbox-content::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  border-radius: 4px;
}
.lightbox-content::-webkit-scrollbar-thumb:hover {
  background: var(--accent-hover-color);
}

/* --- SECTION: FULLSCREEN MEDIA OVERLAY --- */
.media-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 2000; /* Higher than post lightbox */
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.media-overlay.active {
  display: flex;
  opacity: 1;
}
.media-overlay img, 
.media-overlay video {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  box-shadow: 0 0 20px rgba(0,0,0,0.8);
}
.close-media-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  color: #fff;
  font-size: 40px;
  cursor: pointer;
  z-index: 2001;
  opacity: 0.7;
}
.close-media-btn:hover {
  opacity: 1;
}

/* --- SECTION: COMMENTS --- */
.comments-section {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px dotted var(--border-color);
}
#comments-container {
  padding-bottom: 10px;
}
.comments-list,
.reply-list {
  list-style: none;
}
.reply-list {
  margin-left: 20px;
  padding-left: 10px;
  border-left: 2px dotted var(--border-color);
  margin-top: 10px;
}
.comment-item {
  background-color: #353535;
  padding: 10px;
  margin-bottom: 10px;
  border-bottom: 1px dotted var(--border-color);
}
.comment-item.admin-comment {
  border: 1px solid var(--accent-color);
}
.comment-header {
  font-size: 12px;
  color: #aaa;
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
}
.comment-author {
  font-weight: bold;
}
.admin-badge {
  color: var(--accent-color);
}
.reply-btn {
  background: none;
  border: none;
  color: var(--accent-color);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 5px;
}

.comment-form input,
.comment-form textarea {
  width: 100%;
  padding: 8px;
  background-color: #222;
  border: 1px dotted var(--border-color);
  color: var(--text-color);
  font-family: inherit;
  margin-bottom: 5px;
}

/* --- SECTION: ADMIN PANEL --- */
.admin-panel {
  background-color: var(--leaflet-bg);
  border: 1px dotted var(--accent-color);
  padding: 15px;
}
.file-upload-wrapper {
  display: flex;
  gap: 10px;
  align-items: center;
  background: #222;
  padding: 5px;
  border: 1px dotted var(--border-color);
}
.preview-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  display: none;
}
button.action-btn {
  background-color: var(--accent-color);
  color: #222;
  border: none;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
  width: 100%;
}
button.action-btn:hover {
  background-color: var(--accent-hover-color);
}

#db-status {
  font-size: 11px;
  padding: 5px;
  text-align: center;
  color: #888;
}
#db-status.online {
  color: var(--accent-color);
}

/* --- SECTION: CONFIG UI --- */
.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 15px;
}
.config-item {
  display: flex;
  flex-direction: column;
}
.config-item label {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 3px;
}
.color-picker {
  width: 100%;
  height: 30px;
  border: 1px solid #555;
  background: #222;
  cursor: pointer;
  padding: 2px;
}
.setup-input {
  width: 100%;
  background: #111;
  color: var(--accent-color);
  border: 1px solid #444;
  padding: 8px;
  font-family: monospace;
}

/* --- SECTION: SETUP OVERLAY --- */
#setup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  z-index: 9999;
  /* Use flex layout to ensure proper centering and scrolling behavior */
  display: flex;
  align-items: flex-start; /* Start align prevents top clipping */
  justify-content: center;
  padding: 20px;
  overflow-y: auto; /* Scroll bar on the overlay */
}
.setup-box {
  background: #2b2b2b;
  border: 2px dashed var(--accent-color);
  padding: 30px;
  max-width: 600px;
  width: 100%;
  text-align: left;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  /* Auto margins vertically center in flexbox if space allows */
  margin: auto;
  flex-shrink: 0; /* Prevent the box from shrinking smaller than content */
}

@media (max-width: 768px) {
  .layout-wrapper {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
  }
}