/* --- BASE & LAYOUT --- */
body {
    font-family: 'Inter', sans-serif;
    background-color: #f8fafc;
    margin: 0;
    padding: 0.5rem;
}
@media screen and (min-width: 768px) { body { padding: 1rem; } }
.main-container {
    max-width: 100%;
    margin: auto;
    background-color: #ffffff;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    padding: 1rem;
}

.header-content-table {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.header-text-table {
    flex-grow: 1;
}
.header-logo-table {
    max-height: 50px;
    width: auto;
}
h1 {
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}
header p {
    color: #64748b;
    margin-top: 0.25rem;
    font-size: 0.875rem;
}

/* --- CONTROLS --- */
.controls-container {
    display: flex;
    flex-wrap: wrap; 
    gap: 1.5rem; 
    margin-bottom: 1rem;
    align-items: flex-end; 
}
.control-group { 
    flex: 1; 
    min-width: 220px; 
}
.control-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #334155;
    margin-bottom: 0.25rem;
}
select#sort-by{
    display: block;
    width: 100%;
    padding: 0.45rem 2.5rem 0.45rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
}

select#change-office{
    display: block;
    width: 75%;
    padding: 0.45rem 2.5rem 0.45rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
}

/* --- Filter Styles --- */
.filter-wrapper {
    display: flex;
}
#filter-input {
    flex-grow: 1;
    border: 1px solid #d1d5db;
    padding: 0.45rem 0.75rem;
    font-size: 0.875rem;
    border-top-left-radius: 0.375rem;
    border-bottom-left-radius: 0.375rem;
    min-width: 150px;
}
#filter-button, #clear-filter-button {
    padding: 0.45rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid #d1d5db;
    background-color: #f9fafb;
    cursor: pointer;
    margin-left: -1px;
}
#clear-filter-button {
    border-top-right-radius: 0.375rem;
    border-bottom-right-radius: 0.375rem;
    background-color: #fee2e2;
    border-color: #fca5a5;
}
#clear-filter-button:hover {
    background-color: #fecaca;
}

/* --- NEW: Radio Group for Flood Filter --- */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.45rem 0;
    font-size: 0.875rem;
}
.radio-group label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}

/* --- Download Buttons Container --- */
.download-buttons {
    display: flex;
    gap: 0.5rem;
}
#download-pdf-button, #download-csv-button {
    padding: 0.45rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background-color: #fff;
    cursor: pointer;
    transition: background-color 0.2s;
}
#download-pdf-button:hover, #download-csv-button:hover {
    background-color: #f9fafb;
}

/* --- LOADER, TABLE, AND OTHER STYLES ... --- */
.loader-container { display: flex; justify-content: center; align-items: center; height: 16rem; }
.loader {
    border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%;
    width: 50px; height: 50px; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.table-container { 
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 70vh; /* Constrain height to 70% of the viewport */
    overflow-y: auto; /* Add vertical scroll when content overflows */
 }
table { border-collapse: separate; border-spacing: 0; font-size: 0.8rem; min-width: 100%; border: 1px solid #d1d5db; }
th, td { white-space: nowrap; padding: 4px 6px; }
#tide-table thead { border-bottom: 3px solid #111827; }
#tide-table tbody tr { border-top: 1px dashed #e5e7eb; }
#tide-table tbody tr:nth-child(even) { background-color: #f9fafb; }
.time-period-start { border-left: 1px solid #d1d5db; }
#forecast-timestamp { font-weight: 700; text-align: center; margin-top: 1rem; color: #334155; font-size: 0.875rem; }
thead th { position: sticky; top: 0; background-color: #f9fafb; z-index: 15; }
tbody td:first-child { position: sticky; left: 0; z-index: 5; }
#tide-table tbody tr:nth-child(odd) td:first-child { background-color: #fff; }
#tide-table tbody tr:nth-child(even) td:first-child { background-color: #f9fafb; }

/* Stick the first row of headers to the top */
thead tr:nth-of-type(1) th {
    top: 0;
}

/* Stick the second row below the first (adjust if needed) */
thead tr:nth-of-type(2) th {
    top: 23px;
}

/* Stick the third row below the first two (adjust if needed) */
thead tr:nth-of-type(3) th {
    top: 46px;
}


thead th#location-header { left: 0; position: sticky; z-index: 20; }
#tooltip-popup { display: none; position: absolute; padding: 10px; background-color: #fff; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.15); z-index: 1000; pointer-events: none; max-width: 350px; font-size: 0.875rem; text-align: center; line-height: 1.4; }
#tooltip-popup img { display: block; max-width: 100%; height: auto; border-radius: 4px; }
td.font-bold { font-weight: 700; }
td.flood-action { background-color: #fef08a; }
td.flood-minor { background-color: #fed7aa; }
td.flood-moderate { background-color: #f87171; }
td.flood-major { background-color: #d8b4fe; }
td.flood-record { background-color: #d8b4fe; color: #dc2626; }
footer { margin-top: 1.5rem; }
#info-footer { font-size: 0.875rem; color: #475569; margin-bottom: 1.5rem; }
#info-footer p { margin: 0.25rem 0; }
#info-footer a { color: #2563eb; }
#legend-container { 
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem; 
}
.legend-card {
    padding: 0.75rem;
    border-radius: 0.5rem;
}
.legend-card h3 {
    font-weight: 700;
    font-size: 1rem;
    text-decoration: underline;
    margin: 0;
}
.legend-card ul {
    list-style-position: inside;
    list-style-type: disc;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    padding-left: 0;
}
.legend-card.minor { background-color: #fed7aa; border: 1px solid #fb923c; }
.legend-card.minor h3 { color: #7c2d12; }
.legend-card.minor ul { color: #9a3412; }
.legend-card.moderate { background-color: #f87171; border: 1px solid #ef4444; }
.legend-card.moderate h3 { color: #7f1d1d; }
.legend-card.moderate ul { color: #991b1b; }
.legend-card.major { background-color: #d8b4fe; border: 1px solid #c084fc; }
.legend-card.major h3 { color: #5b21b6; }
.legend-card.major ul { color: #6d28d9; }
.hidden { display: none !important; }

/* The circular help button */
.help-wrapper {
  position: relative;
  display: inline-block;
}

.help-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background-color: #666;
  color: #fff;
  border-radius: 50%;
  font-size: 14px;
  font-weight: bold;
  cursor: help;
  transition: background 0.2s;
}

.help-icon:hover {
  background-color: #333;
}

/* The Pop-up CSV help Box */
.tooltip-box {
  visibility: hidden;
  opacity: 0;
  width: 280px;
  background-color: #ffffff;
  color: #333;
  text-align: left;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 12px;
  position: absolute;
  z-index: 999;
  bottom: 150%; /* Position above the icon */
  right: 0;      /* Align to the right edge of the icon */
  box-shadow: 0px 4px 12px rgba(0,0,0,0.15);
  transition: opacity 0.2s ease-in-out;
  font-size: 13px;
  line-height: 1.4;
}

/* Tooltip visible on hover */
.help-wrapper:hover .tooltip-box {
  visibility: visible;
  opacity: 1;
}

/* Style the format text to look like code */
.tooltip-box code {
  display: block;
  margin-top: 8px;
  padding: 6px;
  background: #f4f4f4;
  border-radius: 3px;
  font-family: monospace;
  word-break: break-all;
}

/* Small arrow pointing down to the icon */
.tooltip-box::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 5px;
  border-width: 8px;
  border-style: solid;
  border-color: #ccc transparent transparent transparent;
}