/* CSS Variables for theming and consistent colors */
:root {
  --primary-color: #2e8b57; /* Sea Green - main brand color */
  --secondary-color: #f8f8f8; /* Light background color */
  --text-color: #333; /* Dark text */
  --border-color: #ddd; /* Light border color */
  --highlight-color: #3cb371; /* Medium Sea Green - for buttons and highlights */
  --info-color: #00a1e0; /* Blue for information elements */
  --success-color: #4caf50; /* Green for success messages */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* Base styles for all elements */
* {
  box-sizing: border-box; /* Include padding and border in element width */
  margin: 0;
  padding: 0;
}

/* Body styling with font and color variables */
body {
  font-family: var(--font-family);
  background-color: var(--secondary-color);
  color: var(--text-color);
  line-height: 1.6; /* Better readability with increased line height */
}

/* Header styling - contains brand name and navigation */
header {
  background-color: var(--primary-color);
  color: white;
  padding: 1rem;
  text-align: center;
}

/* Main heading styling */
h1 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

/* Logo image styling with responsive adjustments */
.header-logo {
  width: 90%; /* Full width on mobile */
  max-width: 425px; /* Never wider than 425px on any screen size */
  height: auto;
  margin: 0 auto 0.75rem;
  display: block;
}

/* Make logo smaller on larger screens */
@media (min-width: 768px) {
  .header-logo {
    width: 30%;
  }
}

/* Sorting button container */
.sort-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem; /* Space between buttons */
  margin-top: 0.5rem;
}

/* Individual sort button styling */
.sort-btn {
  padding: 0.5rem 1rem;
  background-color: rgba(255, 255, 255, 0.2); /* Semi-transparent background */
  color: white;
  border-radius: 4px;
  text-decoration: none;
  font-weight: bold;
  transition: background-color 0.3s; /* Smooth hover transition */
}

/* Hover and active state for sort buttons */
.sort-btn:hover, .sort-btn.active {
  background-color: rgba(255, 255, 255, 0.4); /* More opaque on hover/active */
}

/* Main content area */
main {
  padding: 1rem;
  max-width: 700px; /* Limit width for readability on large screens */
  margin: 0 auto; /* Center on page */
}

/* Status message styling */
.message {
  background-color: var(--info-color);
  color: white;
  padding: 0.75rem;
  margin-bottom: 1rem;
  border-radius: 4px;
  text-align: center;
}

/* Container for all listing cards */
.listings {
  display: flex;
  flex-direction: column;
  gap: 1rem; /* Space between listings */
  margin-bottom: 0; /* Remove bottom margin */
}

/* Error message styling */
.error-message {
  color: #f44336; /* Red text for errors */
  background-color: rgba(244, 67, 54, 0.1); /* Light red background */
  padding: 0.5rem;
  border-radius: 4px;
  text-align: center;
  margin: 0rem 1rem;
  font-weight: bold;
  grid-column: 1 / -1; /* Span all columns */
}

/* Header row for listings table */
.listing-header {
  display: grid;
  grid-template-columns: 0.675fr 0.5fr 1.2fr 0.3fr 0.5fr;
  grid-template-areas: "date location name size price";
  padding: 0.4rem 0.6rem;
  font-weight: bold;
  font-size: 0.85rem;
  background-color: var(--primary-color);
  color: white;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

/* Individual header cells */
.header-date {
  grid-area: date;
}

.header-location {
  grid-area: location;
}

.header-name {
  grid-area: name;
  text-align: center;
}

.header-size {
  grid-area: size;
}

.header-price {
  grid-area: price;
  text-align: center;
}

.header-book {
  grid-area: book;
  text-align: right;
}

/* Desktop layout adjustments */
@media (min-width: 768px) {
  .listings {
    display: flex;
    flex-direction: column;
  }
  
  /* Grid layout for header on desktop */
  .listing-header {
    display: grid;
    grid-template-columns: 0.675fr 0.5fr 1.2fr 0.3fr 0.5fr;
    grid-template-areas: "date location name size price";
    align-items: center;
  }
  
  /* Grid layout for listing cards on desktop */
  .listing-card {
    display: grid;
    grid-template-columns: 0.675fr 0.5fr 1.2fr 0.3fr 0.5fr;
    grid-template-areas: 
      "date location name size price"
      ". . . . book";
    align-items: center;
  }
}

/* Individual listing card styling */
.listing-card {
  display: grid;
  grid-template-columns: 0.675fr 0.5fr 1.2fr 0.3fr 0.5fr;
  grid-template-areas: 
    "date location name size price"
    ". . . . book";
  padding: 0.6rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--secondary-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Subtle shadow for depth */
  font-size: 0.9rem;
  row-gap: 0.5rem;
  /* No transitions or initial hiding, allowing true progressive rendering */
}

/* Date display in listing */
.listing-date {
  grid-area: date;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap; /* Prevent wrapping */
}

/* Styling for past dates */
.date-past {
  color: #e53935; /* Red color to indicate past dates */
}

/* Location styling */
.listing-location {
  grid-area: location;
  font-style: italic;
  word-wrap: break-word; /* Allow wrapping for long location names */
  overflow-wrap: break-word;
  hyphens: auto; /* Enable hyphenation for long words */
}

/* Property name styling */
.listing-name {
  grid-area: name;
  font-weight: bold;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Size (bedrooms) display */
.listing-size {
  grid-area: size;
  font-size: 0.85rem;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  text-align: center;
}

/* Price display */
.listing-price {
  grid-area: price;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

/* Information icon for tooltips */
.info-icon {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  color: var(--info-color);
  cursor: help;
  position: relative;
  font-weight: bold;
  font-size: 1.1rem;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
}

.info-icon .tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--text-color);
  color: var(--secondary-color);
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  width: max-content;
  min-width: 200px;
  max-width: 280px;
  white-space: normal;
  word-wrap: break-word;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
}

.info-icon:hover .tooltip {
  opacity: 1;
}

.info-icon.active .tooltip {
  opacity: 1;
}

@media (hover: none) {
  .info-icon .tooltip {
    bottom: 150%;
  }
}

/* Book button container */
.listing-book {
  display: inline-block;
}

/* Book button styling */
.book-btn {
  padding: 0.3rem 0.8rem;
  background-color: var(--highlight-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.85rem;
  transition: background-color 0.3s;
}

/* Book button hover effect */
.book-btn:hover {
  opacity: 0.9; /* Slightly reduce opacity on hover */
}

/* Modal dialog base styling */
.modal {
  display: none; /* Hidden by default */
  position: fixed;
  z-index: 100; /* High z-index to appear above other content */
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
}

/* Modal content container */
.modal-content {
  background-color: var(--secondary-color);
  margin: 5% auto; /* Center vertically with 5% from top */
  padding: 1.5rem;
  border-radius: 5px;
  width: 90%;
  max-width: 600px; /* Limit width on large screens */
  max-height: 85vh; /* Limit height to 85% of viewport */
  overflow-y: auto; /* Add scrollbar if content is too tall */
}

/* Adjust modal position for desktop screens */
@media (min-width: 768px) {
  .modal-content {
    margin: 3% auto; /* Even higher on desktop (3% from top) */
  }
}

/* Modal close button */
.close {
  color: var(--text-color);
  float: right;
  font-size: 1.5rem;
  font-weight: bold;
  cursor: pointer;
}

/* Form field group */
.form-group {
  margin-bottom: 1rem;
}

/* Form labels */
label {
  display: inline-block;
  margin-bottom: 0.5rem;
  font-weight: bold;
  width: 80px;
  vertical-align: middle;
}

/* Text input and textarea styling */
input, textarea {
  width: calc(100% - 90px);
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--secondary-color);
  color: var(--text-color);
  display: inline-block;
  vertical-align: middle;
}

/* Textarea specific styling */
textarea {
  min-height: 100px;
  resize: vertical; /* Allow vertical resizing only */
  width: 100%;
  display: block;
  margin-top: 0.5rem;
}

/* Message-specific label should be block for textarea */
label[for="message"], label[for="support-message"] {
  display: block;
  width: 100%;
}

/* Read-only textarea styling */
textarea[readonly] {
  background-color: rgba(0, 0, 0, 0.05); /* Slight darkening to indicate readonly */
}

/* Listing display area in form */
.listing-display {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 10px;
  border-radius: 4px;
  min-height: 100px;
  white-space: pre-wrap; /* Preserve line breaks */
  font-family: var(--font-family);
  color: var(--text-color);
}

/* Form submit button */
.submit-btn {
  padding: 0.75rem 1.5rem;
  background-color: var(--highlight-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.3s;
  display: block;
  margin: 1rem 0 0 auto; /* Right-align button */
}

/* Submit button hover effect */
.submit-btn:hover {
  opacity: 0.9;
}

/* Link styling */
a {
  color: var(--highlight-color);
  text-decoration: none;
}

/* Footer link styling */
footer a {
  color: var(--info-color);
  font-weight: bold;
  font-size: 1.05rem;
}

/* Link hover effect */
a:hover {
  text-decoration: underline;
}

/* Footer styling */
footer {
  text-align: center;
  margin-top: 0;
  padding: 1rem;
  color: var(--text-color);
}

/* Footer paragraph spacing */
footer p {
  margin: 0.5rem 0;
}

/* Subscribe form styling */
.subscribe-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.subscribe-form label {
  margin-bottom: 0;
  width: auto;
  font-weight: normal;
}

.subscribe-form input[type="email"] {
  width: auto;
  max-width: 250px;
  padding: 0.3rem 0.5rem;
}

.subscribe-btn {
  padding: 0.3rem 0.8rem;
  background-color: var(--highlight-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.85rem;
  transition: background-color 0.3s;
}

.subscribe-btn:hover {
  opacity: 0.9;
}

.unsubscribe-notice {
  width: 100%;
  font-size: 0.8rem;
  margin: 0.2rem 0 0.5rem !important;
  opacity: 0.8;
}

/* Unsubscribe page styling */
.unsubscribe-container {
  max-width: 600px;
  margin: 2rem auto;
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  background-color: var(--secondary-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.unsubscribe-container h2 {
  color: var(--primary-color);
  margin-bottom: 1rem;
}

.unsubscribe-form {
  margin: 1.5rem 0;
}

.unsubscribe-form input[type="email"] {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 1rem;
}

.return-link {
  margin-top: 1.5rem;
  text-align: center;
}

/* Tagline styling */
.tagline {
  font-style: italic;
  color: white;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
}

/* Privacy policy text styling */
.privacy-text {
  font-size: 0.8rem;
  margin: 0.5rem 0;
}

/* Copyright text styling */
.copyright-text {
  font-size: 0.8rem;
}

/* Loading spinner styling */
.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1rem auto;
}

.loading-spinner img {
  width: 50px;
  height: 50px;
}
