/* Improved CSS with better organization and enhancements */

/* ========== Global Styles ========== */
:root {
  --primary-color: #FFD700;
  --secondary-color: #1F1F1F;
  --accent-color: #4CAF50;
  --text-color: #FFFFFF;
  --text-secondary: #CCCCCC;
  --card-bg: #2F2F2F;
  --header-bg: #000000;
  --footer-bg: #262626;
  --error-color: #FF5252;
  --success-color: #4CAF50;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--secondary-color);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.3s ease;
}

a:hover {
  color: var(--text-color);
}

button {
  cursor: pointer;
  transition: all 0.3s ease;
}

img {
  max-width: 100%;
  height: auto;
}

/* ========== Header Styles ========== */
header {
  background-color: var(--header-bg);
  height: 65px;
  display: flex;
  align-items: center;
  padding: 5px 20px;
  justify-content: space-between;
  position: fixed;
  width: 100%;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.user-profile {
  display: flex;
  align-items: center;
  margin-left: 15px;
}

.user-profile img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #ffffff;
  cursor: pointer;
  transition: all 0.3s ease;
}

.user-profile img:hover {
  transform: scale(1.1);
  border-color: rgba(255, 215, 0, 0.1);
}

/* For mobile version */
.mobile .user-profile {
  margin: 10px 0;
  justify-content: center;
}

/* Profile Modal Styles */
.profile-container {
  display: flex;
  gap: 20px;
  margin-top: 20px;
}

.profile-picture-section {
  flex: 1;
  text-align: center;
}

.profile-picture-section img {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 15px;
  border: 3px solid #4e54c8;
}

.profile-details-section {
  flex: 2;
}

#profileTable {
  width: 100%;
  border-collapse: collapse;
}

#profileTable td {
  padding: 8px;
  border-bottom: 1px solid #ddd;
}

#profileTable tr:last-child td {
  border-bottom: none;
}

nav ul {
  display: flex;
  list-style: none;
  gap: 15px;
  padding: 0;
  margin: 0;
  align-items: center;
}

nav ul li {
  cursor: pointer;
  padding: 10px;
  border-radius: 5px;
  color: var(--text-color);
  transition: all 0.3s ease;
  font-weight: 500;
}

nav ul li:hover, 
nav ul li:focus {
  background-color: rgba(255, 215, 0, 0.1);
  color: var(--primary-color);
}

/* ========== Search Styles ========== */
.inputSearch, 
.inputSearch form {
  display: flex;
  align-items: center;
  height: 40px;
  width: 100%;
  max-width: 400px;
  border-radius: 35px;
  overflow: hidden;
  border: 1.5px solid var(--primary-color);
  background: var(--card-bg);
}

.inputSearch input {
  width: 100%;
  height: 100%;
  padding: 0 15px;
  border: none;
  outline: none;
  font-size: 16px;
  background: transparent;
  color: var(--text-color);
}

.inputSearch input::placeholder {
  color: var(--text-secondary);
}

.inputSearch button {
  width: 70px;
  background-color: var(--primary-color);
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  color: #000000;
  border: none;
  transition: all 0.3s ease;
}

.inputSearch button:hover {
  background-color: #e6c200;
}

/* Profile Action Buttons */
.profile-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

.edit-btn, .close-btn {
  padding: 10px 20px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.edit-btn {
  background-color: var(--primary-color);
  color: #000;
  border: none;
}

.edit-btn:hover {
  background-color: #e6c200;
}

.close-btn {
  background-color: transparent;
  color: var(--text-color);
  border: 1px solid var(--text-secondary);
}

.close-btn:hover {
  background-color: rgba(255,255,255,0.1);
}

.modal-content {
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

/* Modal Header */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  position: relative;
}

.modal-header h2 {
  margin: 0;
  flex-grow: 1;
  text-align: center;
}

.modal-header .close {
  position: absolute;
  right: 0;
  top: 0;
  margin: 0;
  font-size: 28px;
}

/* Edit Profile Modal Specific */
#editProfileModal .modal-content {
  max-height: 80vh; /* Slightly smaller for edit modal */
}

#editProfileForm {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  overflow: hidden;
}

#editProfileForm input,
#editProfileForm textarea {
  width: 100%;
  padding: 12px;
  margin-bottom: 15px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #3F3F3F;
  color: var(--text-color);
  font-size: 16px;
}

#editProfileForm input {
  margin-bottom: 15px;
}

#editProfileForm textarea {
  min-height: 100px;
  resize: vertical;
}

.modal-content {
  scroll-behavior: smooth;
}

/* Form Scroll Container */
.form-scroll-container {
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 10px;
  margin-bottom: 20px;
  max-height: calc(80vh - 150px); /* Adjust based on your header/buttons height */
}

/* Custom Scrollbar */
.form-scroll-container::-webkit-scrollbar {
  width: 6px;
}

.form-scroll-container::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
}

.form-scroll-container::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 10px;
}

/* Form Actions */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 15px;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: auto; /* Push to bottom */
  flex-shrink: 0; /* Prevent shrinking */
}

/* ========== Menu Button Styles ========== */
.menuBtn {
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  color: var(--text-color);
  background: transparent;
  border: none;
}

.menuBtn:hover {
  background-color: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
}

/* ========== Desktop View Styles ========== */
.desktop {
  display: none;
}

@media all and (min-width: 768px) {
  header {
    padding: 5px 30px;
  }

  .desktop {
    display: flex;
    align-items: center;
    gap: 20px;
  }

  .menuBtn {
    display: none;
  }
}

/* ========== Mobile Menu Styles ========== */
.mobile {
  position: fixed;
  top: 65px;
  left: 0;
  width: 100%;
  background-color: var(--secondary-color);
  height: calc(100vh - 65px);
  padding: 20px;
  z-index: 999;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

.mobile.active {
  transform: translateX(0);
}

.mobile nav, 
.mobile nav ul {
  flex-direction: column;
}

.mobile .inputSearch {
  margin: 0 auto 20px;
}

.hidden {
  display: none;
}

/* ========== Card Styles ========== */
main {
  display: flex;
  flex-direction: column;
  gap: 25px;
  padding: 20px;
  margin: 65px auto 0;
  width: 100%;
  max-width: 1400px;
}

.card {
  display: flex;
  flex-direction: column;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(255, 215, 0, 0.2);
}

.card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background-color: #000000;
}

.card-content {
  padding: 15px;
}

.card h4 {
  margin: 0 0 10px;
  font-size: 1.2rem;
  font-weight: 600;
}

.publishbyDate {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.desc {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 10px;
}

@media all and (min-width: 768px) {
  main {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    padding: 30px;
  }

  .card {
    max-width: 350px;
  }
}

/* ========== Loading Styles ========== */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  width: 100%;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(255, 215, 0, 0.3);
  border-radius: 50%;
  border-top-color: var(--primary-color);
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 20px;
}

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

/* ========== Back to Top Button ========== */
.back-to-top {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background-color: var(--primary-color);
  color: #000;
  border-radius: 50%;
  text-align: center;
  line-height: 50px;
  font-size: 24px;
  z-index: 99;
  cursor: pointer;
  border: none;
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
  transition: all 0.3s ease;
}

.back-to-top:hover {
  background-color: #000;
  color: var(--primary-color);
  transform: scale(1.1);
}

/* ========== Modal Styles ========== */
.modal {
  display: none;
  position: fixed;
  z-index: 1001;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto; /* Enable scrolling for tall modals */
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: var(--card-bg);
  margin: 2% auto; /* More responsive vertical positioning */
  padding: 30px;
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  position: relative;
  animation: modalFadeIn 0.3s ease;
  max-height: 90vh; /* Limit modal height */
  overflow: hidden; /* Contain all content */
  display: flex;
  flex-direction: column;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.close {
  color: var(--text-secondary);
  float: right;
  font-size: 28px;
  font-weight: bold;
  transition: color 0.3s ease;
}

.close:hover, 
.close:focus {
  color: var(--primary-color);
  cursor: pointer;
}

.modal h2 {
  margin-bottom: 20px;
  color: var(--primary-color);
  text-align: center;
}

.modal label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-color);
}

.modal input {
  width: 100%;
  padding: 12px;
  margin-bottom: 20px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #3F3F3F;
  color: var(--text-color);
  font-size: 16px;
}

.modal input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.modal button[type="submit"] {
  background-color: var(--primary-color);
  color: #000;
  border: none;
  padding: 12px;
  width: 100%;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.modal button[type="submit"]:hover {
  background-color: #e6c200;
}

.modal-footer {
  margin-top: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.modal-footer a {
  color: var(--primary-color);
  font-weight: 500;
}

/* ========== Footer Styles ========== */
footer {
  background: var(--footer-bg);
  padding: 50px 20px;
  margin-top: auto;
}

.newsletter {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  margin-bottom: 40px;
}

.newsletter h2 {
  font-size: 1.8rem;
  color: var(--primary-color);
}

.newsletter p {
  font-size: 1rem;
  color: var(--text-secondary);
}

.newsletter input {
  padding: 15px;
  border: none;
  border-radius: 8px 0 0 8px;
  flex-grow: 1;
  background: #3F3F3F;
  color: var(--text-color);
}

.newsletter .button-1 {
  border-radius: 0 8px 8px 0;
  padding: 15px 25px;
}

.f-contact {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
  margin-top: 30px;
  padding-bottom: 30px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.f-contact > div {
  margin-bottom: 20px;
}

.f-contact h1 {
  font-size: 1.3rem;
  color: var(--primary-color);
  margin-bottom: 15px;
}

.footer-link {
  display: block;
  color: var(--text-secondary);
  margin-bottom: 10px;
  transition: color 0.3s ease;
  position: relative;
  padding-left: 15px;
}

.footer-link:hover {
  color: var(--primary-color);
}

.footer-link::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--primary-color);
  opacity: 0;
  transition: all 0.3s ease;
}

.footer-link:hover::before {
  opacity: 1;
  left: 5px;
}

.social-links {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.social-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--primary-color);
  color: #000;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.social-links a:hover {
  background: transparent;
  color: var(--primary-color);
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(255, 215, 0, 0.3);
}

.copyright {
  padding-top: 30px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ========== Responsive Styles ========== */
@media all and (min-width: 768px) {
  .newsletter {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  
  .f-contact {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media all and (min-width: 1024px) {
  footer {
    padding: 50px 100px;
  }
}

/* ========== Animation Classes ========== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.5s ease forwards;
}

/* ========== Utility Classes ========== */
.hidden {
  display: none !important;
}

.visible {
  display: block;
}

.text-center {
  text-align: center;
}

.mt-20 {
  margin-top: 20px;
}

.error-message {
  color: var(--error-color);
  font-size: 0.9rem;
  margin-top: 5px;
}

.success-message {
  color: var(--success-color);
  font-size: 0.9rem;
  margin-top: 5px;
}

/* Mobile responsiveness */
@media (max-height: 700px) {
  .modal-content {
    margin: 1% auto;
    max-height: 98vh;
  }
  
  #editProfileModal .modal-content {
    max-height: 96vh;
  }
  
  .form-scroll-container {
    max-height: calc(96vh - 180px);
  }
}