/* 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 {
  position: relative;
  background-image: var(--header-background-image, url('/static/plumeria-background.png'));
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: white;
  padding: 1.5rem 1rem;
  text-align: center;
  overflow: hidden;
}

header::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: rgba(46, 139, 87, 0.65);
  z-index: 0;
}

header > * {
  position: relative;
  z-index: 1;
}

header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3rem;
  background: linear-gradient(
    to bottom,
    rgba(46, 139, 87, 0) 0%,
    rgba(46, 139, 87, 0.28) 35%,
    rgba(46, 139, 87, 0.12) 55%,
    rgba(248, 248, 248, 0.4) 75%,
    rgba(248, 248, 248, 1) 100%
  );
  pointer-events: none;
  z-index: 0;
}

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

.title-line1,
.title-line2 {
  display: block;
}

.title-line1 {
  font-size: 1.5rem;
  line-height: 1.1;
  font-style: italic;
  margin-top: 1rem;
  padding-bottom: 0.5rem;
}

.title-line2 {
  font-size: 1.15rem;
  line-height: 1.1;
}

@media (max-width: 400px) {
  .title-line2 {
    font-size: 0.9rem;
  }
}

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

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

@media (min-width: 1024px) {
  main {
    max-width: none;
    padding: 2rem 0;
  }
}

/* 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 listing table */
.listings {
  margin: 0;
  overflow-x: auto;
}

/* 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: 0 0 1rem;
  font-weight: bold;
}

/* Table layout for listings */
.listings-table {
  width: 100%;
  border-collapse: collapse;
  background-color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font-size: 0.95rem;
  table-layout: auto;
}

@media (min-width: 1024px) {
  .listings-table {
    width: min(80vw, 100%);
    margin: 0 auto;
  }
}

.listings-table thead {
  background-color: #f4f4f4;
}

.listings-table td {
  padding: 3px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.listings-table th + th,
.listings-table td + td {
  border-left: 1px solid var(--border-color);
}

.listings-table th {
  text-align: center;
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0.04em;
  vertical-align: middle;
  padding: 0;
}

.listings-table tbody tr:nth-child(even) {
  background-color: #fafafa;
}

.listings-table tbody tr:hover {
  background-color: #f1f1f1;
}

.sort-link {
  color: inherit;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 3px;
}

.sort-link:hover,
.sort-link:focus {
  color: var(--primary-color);
}

.sort-link.active {
  color: var(--primary-color);
  font-weight: 700;
}

.header-line {
  font-size: 0.95rem;
  display: inline;
  line-height: 1.1;
}

.header-subtext {
  font-size: 0.75rem;
  text-transform: none;
  font-weight: normal;
  color: #666;
  display: block;
  margin-top: 0;
  line-height: 1.1;
}

.col-date,
.listing-date-cell {
  text-align: center;
}

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

.col-location,
.listing-location {
  text-align: center;
}

.col-price {
  text-align: right;
}

.listing-date-text {
  white-space: normal;
  font-weight: 400;
  display: inline;
}

.listing-date-text.date-past {
  color: #e53935;
  font-weight: 500;
}

.has-calendar-tooltip {
  position: relative;
  cursor: help;
}

.calendar-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  transform: none;
  transform-origin: top left;
  background-color: #000;
  color: #fff;
  padding: 0.45rem 0.6rem 0.5rem;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  min-width: 0;
  width: max-content;
  max-width: calc(100vw - 1.5rem);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 600;
  transition: opacity 0.2s ease-in-out;
}

.has-calendar-tooltip:hover .calendar-tooltip,
.has-calendar-tooltip.active .calendar-tooltip,
.has-calendar-tooltip:focus-within .calendar-tooltip {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.calendar-tooltip-inner {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: flex-start;
  overflow-x: auto;
}

.calendar-tooltip-inner::-webkit-scrollbar {
  height: 4px;
}

.calendar-tooltip-inner::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 999px;
}

.calendar-month {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-width: 6rem;
}

.calendar-month-title {
  font-weight: 600;
  text-align: center;
  color: #fff;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.calendar-day {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  min-height: 1.4rem;
  border-radius: 4px;
  font-size: 0.62rem;
  line-height: 1;
  color: #fff;
  background-color: transparent;
}

.calendar-weekday {
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.calendar-day--outside {
  color: rgba(255, 255, 255, 0.35);
}

.calendar-day--available {
  background-color: #fff;
  color: #000;
  font-weight: 600;
}

.calendar-note {
  margin-top: 0.65rem;
  font-size: 0.7rem;
  text-align: left;
  color: rgba(255, 255, 255, 0.75);
}

@media (max-width: 720px) {
  .calendar-tooltip {
    max-width: min(92vw, 26rem);
  }

  .calendar-tooltip-inner {
    gap: 0.5rem;
  }

  .calendar-month {
    min-width: 6.3rem;
  }
}

.listing-property a,
.listing-location a {
  color: inherit;
  text-decoration: underline;
}

.listing-property a:hover,
.listing-property a:focus,
.listing-location a:hover,
.listing-location a:focus {
  color: var(--primary-color);
}

.listing-occupancy {
  text-align: center;
  white-space: nowrap;
}

.listing-price {
  text-align: right;
  font-weight: 400;
}

.listing-price-value {
  color: inherit;
  font-weight: inherit;
  display: inline-block;
}

.listing-row {
  cursor: pointer;
}

.listing-row:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: -2px;
}

/* 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;
  margin-left: 0.25rem;
}

.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%;
  }
}

@media (max-width: 640px) {
  .listings-table {
    font-size: 0.9rem;
  }

  .listings-table td {
    padding: 3px;
  }

  .header-line {
    font-size: 0.9rem;
  }

  .header-subtext {
    font-size: 0.7rem;
  }
}

@media (max-width: 480px) {
  .listings-table {
    font-size: 0.8rem;
    /* transform: scale(0.95); */
    transform-origin: top center;
  }

  .listings-table td {
    padding: 3px;
  }

  .listings {
    max-width: 100%;
  }
}

/* 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.25rem;
  font-weight: bold;
  width: 80px;
  vertical-align: top;
}

/* Text input and textarea styling */
input, textarea, select {
  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: top;
}

/* Textarea specific styling */
textarea {
  min-height: 100px;
  resize: vertical; /* Allow vertical resizing only */
  margin-top: 0;
}

/* Add listing page layout adjustments */
.add-listing-page main {
  width: 80vw;
  max-width: 80vw;
  margin: 0 auto;
}

.add-listing-page .add-listing-form {
  width: 80vw;
  max-width: 80vw;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.add-listing-page .form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.add-listing-page .form-group label {
  width: 100%;
  margin-bottom: 0;
}

.add-listing-page .form-group input,
.add-listing-page .form-group select {
  width: 100%;
}

.add-listing-page .submit-btn {
  margin: 1rem 0 0;
  justify-self: stretch;
}

@media (min-width: 768px) {
  .add-listing-page .add-listing-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .add-listing-page .submit-btn {
    grid-column: 1 / -1;
    justify-self: end;
  }
}

/* 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: 0;
  white-space: normal;
  font-family: var(--font-family);
  color: var(--text-color);
  display: inline-block;
  width: calc(100% - 90px);
  vertical-align: top;
  overflow-wrap: anywhere;
}

/* 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 0 0;
  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;
}

.contact-support {
  margin: 0.2rem 0 1.2rem;
  text-align: center;
}

.state-highlight {
  color: #ff6f61; /* "warm coral" -- light magenta was too vibrant on phone */
  display: inline-block;
  filter: drop-shadow(0 0 8px black) drop-shadow(2px 2px 4px black);
}

.listings .contact-support a {
  color: var(--info-color);
  font-weight: bold;
  font-size: 1.05rem;
}

.footer-legal {
  position: relative;
  background-color: #333333;
  color: #ffffff;
  padding: 1rem;
}

.footer-legal::before {
  content: "";
  position: absolute;
  top: -1rem;
  left: 0;
  right: 0;
  height: 1rem;
  background: linear-gradient(to bottom, #ffffff 0%, #ffffff 50%, #333333 100%);
  pointer-events: none;
}

.footer-legal a {
  color: inherit;
  text-decoration: none;
}

.footer-legal p {
  margin: 0.5rem 0;
}

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

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

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

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

/* Full-screen overlay spinner for form submissions */
.loading-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  z-index: 5000;
  pointer-events: all;
}

.loading-overlay img {
  width: 64px;
  height: 64px;
}

.loading-overlay .loading-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-color);
  text-align: center;
}

body.is-loading {
  overflow: hidden;
}

/* 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;
}

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

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

/*
 * Dark mode styles: honor the user's system preference while keeping the
 * header and footer untouched. These adjustments focus on the main listings
 * area, modal overlays, and the loading spinner overlay.
 */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #111a14;
  }

  main {
    background-color: #0f1a15;
    color: #f1f6f2;
    border-radius: 10px;
    padding: 1.5rem;
  }

  main .message {
    background-color: rgba(0, 118, 163, 0.35);
    color: #ebf8ff;
  }

  main .error-message {
    color: #ffb3b3;
    background-color: rgba(255, 99, 71, 0.15);
  }

  main .listings-table {
    background-color: #151f19;
    color: #f1f6f2;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  }

  main .listings-table thead {
    background-color: #1f2c24;
  }

  main .listings-table th,
  main .listings-table td {
    border-color: #2a3b31;
  }

  main .listings-table tbody tr {
    background-color: #111a14;
  }

  main .listings-table tbody tr:nth-child(even) {
    background-color: #162118;
  }

  main .listings-table tbody tr:hover {
    background-color: #24342a;
  }

  main .header-subtext {
    color: #c0d4c4;
  }

  main .sort-link:hover,
  main .sort-link:focus,
  main .sort-link.active {
    color: #8de6b6;
  }

  main .listing-date-text.date-past {
    color: #ff8a80;
  }

  main a,
  main .listing-property a,
  main .listing-location a {
    color: #8de6b6;
  }

  main .info-icon {
    color: #7ad1ff;
  }

  .modal-content {
    background-color: #0f1a15;
    color: #f1f6f2;
    border: 1px solid rgba(141, 230, 182, 0.35);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75);
  }

  .modal .close {
    color: #f1f6f2;
  }

  .modal-content input,
  .modal-content textarea,
  .modal-content select,
  .modal-content .listing-display {
    background-color: rgba(255, 255, 255, 0.04);
    color: #f1f6f2;
    border-color: rgba(255, 255, 255, 0.2);
  }

  .modal-content .listing-display {
    border: 1px solid rgba(255, 255, 255, 0.2);
  }


  footer .subscribe-form label,
  footer .unsubscribe-notice,
  footer .contact-support {
    color: #d9ebe0;
  }

  footer .subscribe-form input[type="email"] {
    background-color: #0d1612;
    color: #f1f6f2;
    border: 1px solid #2a3b31;
  }

  footer .subscribe-form a,
  footer .contact-support a {
    color: #8de6b6;
  }

  footer .subscribe-btn {
    background-color: #2f8a5f;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  footer .subscribe-btn:hover {
    background-color: #35a16f;
  }

  .loading-overlay {
    background-color: rgba(0, 0, 0, 0.8);
  }

  .loading-overlay .loading-text {
    color: #f1f6f2;
  }

  .unsubscribe-container {
    background-color: #0b1611;
    border-color: #1f2c24;
    color: #f1f6f2;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  }

  .unsubscribe-container h2,
  .unsubscribe-container h3 {
    color: #8de6b6;
  }

  .unsubscribe-container input[type="email"] {
    background-color: rgba(255, 255, 255, 0.04);
    color: #f1f6f2;
    border: 1px solid rgba(255, 255, 255, 0.2);
  }

  .unsubscribe-container .submit-btn {
    background-color: #2f8a5f;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  .unsubscribe-container .submit-btn:hover {
    background-color: #35a16f;
  }

  .unsubscribe-container .return-link a {
    color: #8de6b6;
  }

  .visitor-stats {
    background-color: #0f1a15;
    color: #f1f6f2;
    border: 1px solid #1f2c24;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  }

  .visitor-stats h3 {
    color: #8de6b6;
  }

  .visitor-stats table {
    color: inherit;
  }

  .visitor-stats th,
  .visitor-stats td {
    border-color: #2a3b31;
  }

  .visitor-stats th {
    background-color: #1f2c24;
  }

  .visitor-stats tr:nth-child(even) td {
    background-color: #111a14;
  }

  .visitor-stats tr:nth-child(odd) td {
    background-color: #151f19;
  }

  .visitor-stats tr:last-child td {
    border-bottom: none;
    color: #c0d4c4;
  }
}
