/* =============================================================
   Planning Aviron, Stylesheet
   planning.css
   ============================================================= */

/* ** DESIGN TOKENS ***************************************** */
:root {
    --color-today:        rgb(40, 155, 140);
    --color-month:        rgb(55, 110, 155);
    --color-bg:           rgb(70, 130, 155);
    --color-page-bg:      #ffffff;
    --color-header:       rgb(50, 100, 130);
    --color-row-alt:      rgba(255,255,255,0.08);
    --color-row:          rgba(255,255,255,0.04);
    --color-text:         #ffffff;
    --color-muted:        rgba(255,255,255,0.65);
    --color-border:       rgba(255,255,255,0.40);
    --color-border-even:  rgba(0,0,0,0.10);
    --color-tide-btn:     rgba(255,255,255,0.18);
    --color-tide-btn-odd: rgba(50, 100, 130, 0.68);
    --font-display:       'Arial Narrow', 'Helvetica Neue Condensed', ui-sans-serif, sans-serif;
    --font-body:          system-ui, 'Helvetica Neue', Arial, sans-serif;
    --radius-card:        30px;
    --radius-inner:       8px;
}

/* ** RESET ************************************************* */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ** UTILITY *********************************************** */

/* Replaces element.style.display toggling in JS, allowing
   style-src-attr 'unsafe-inline' to be removed from the CSP. */
.hidden {
    display: none !important;
}

/* Empty-state message shown when no planning entries exist
   for the selected period (table cell and card list paragraph). */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255, 255, 255, 0.6);
}

/* Body overflow control (replaces inline style) */
.body-no-scroll {
    overflow: hidden !important;
}

/* Error text inside the tide modal (replaces inline style). */
.modal-error {
    color: #ffcdd2;
}

/* ** BASE ************************************************** */
body {
    font-family: var(--font-body);
    font-size: 16px;
    background: var(--color-page-bg);
    color: var(--color-text);
    min-height: 100vh;
    padding: 24px 16px 48px;
}

/* ** MAIN CARD CONTAINER *********************************** */
.app-card {
    max-width: 1280px;
    margin: 0 auto;
    background: white;
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
    color: var(--color-text);
}

/* ** HEADER ************************************************ */
.page-header {
    background: var(--color-header);
    padding: 20px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-family: var(--font-display);
    font-size: 30px;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.datepicker-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-inner);
    padding: 7px 14px;
}

.datepicker-wrap label {
    font-size: 14px;
    color: var(--color-muted);
    white-space: nowrap;
}

#date-picker,
#tide-date-picker {
    background: transparent;
    border: none;
    color: #fff;
    font-family: var(--font-body);
    font-size: 15px;
    cursor: pointer;
    outline: none;
}

#date-picker::-webkit-calendar-picker-indicator,
#tide-date-picker::-webkit-calendar-picker-indicator {
    filter: invert(1) opacity(0.7);
    cursor: pointer;
}

.refresh-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid var(--color-border);
    color: #fff;
    font-family: var(--font-body);
    font-size: 15px;
    padding: 7px 16px;
    border-radius: var(--radius-inner);
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.refresh-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* ** LOADING / ERROR *************************************** */
#loading {
    text-align: center;
    padding: 60px 20px;
    background: var(--color-bg);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 14px;
}

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

#error {
    text-align: center;
    padding: 40px 20px;
    color: #b71c1c;
    background: #ffebee;
    font-size: 16px;
}

/* ** DESKTOP TABLE ***************************************** */
.table-wrap {
    background: var(--color-bg);
}

table {
    width: 100%;
    border-collapse: collapse;
}

col.col-date {
    width: 15%;
}
col.col-time {
    width: 14%;
}
col.col-activity-note {
    width: auto;
}
col.col-sun {
    width: 14%;
}
col.col-tide {
    width: 12%;
}

thead th {
    background: var(--color-header);
    font-family: var(--font-display);
    font-size: 18px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.9);
    padding: 13px 16px;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
}

thead th.col-center {
    text-align: center;
}

/* Month separator */
tr.month-sep td {
    background: var(--color-month);
    font-family: var(--font-display);
    font-size: 20px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: center;
    padding: 8px;
    color: rgba(255, 255, 255, 0.95);
    font-weight: 700;
}

/* Data rows */
tr.data-row {
    border-bottom: 1px solid var(--color-border);
    transition: background 0.15s;
}

/* Alternating week backgrounds */
tr.data-row.week-odd {
    background: white;
    color: var(--color-header);
    border-color: var(--color-border-even);
}
tr.data-row.week-even {
    background: var(--color-row-alt);
}

/* Fallback for rows without week classes */
tr.data-row:not(.week-odd):not(.week-even):nth-child(even) {
    background: var(--color-row-alt);
}
tr.data-row:not(.week-odd):not(.week-even):nth-child(odd) {
    background: var(--color-row);
}

/* Hover states */
tr.data-row.week-odd:hover {
    background: rgba(245, 245, 245, 0.9);
}
tr.data-row.week-even:hover {
    background: rgba(255, 255, 255, 0.13);
}
tr.data-row:hover {
    background: rgba(255, 255, 255, 0.13);
}

/* Today, highest specificity wins, no !important needed */
tr.data-row.is-today,
tr.data-row.week-odd.is-today,
tr.data-row.week-even.is-today {
    background: var(--color-today) !important;
    color: white !important;
}
tr.data-row.is-today:hover {
    background: rgba(30, 145, 130, 0.9) !important;
}

/* Selected state */
tr.data-row.is-selected,
tr.data-row.is-selected.week-odd,
tr.data-row.is-selected.week-even {
    background: rgba(40, 155, 140, 0.35);
    outline: 2px solid var(--color-today);
    outline-offset: -2px;
}

td {
    padding: 11px 16px;
    font-size: 18px;
    vertical-align: middle;
}

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

.td-date {
    font-weight: 600;
    white-space: nowrap;
}
.td-time {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.td-activity-note {
    display: table-cell;
    vertical-align: middle;
    padding: 11px 16px;
}
.td-activity-note-container {
    display: flex;
    align-items: center;
    gap: 8px;
}
.td-activity-note .activity-emoji {
    font-size: 22px;
}
.td-activity-note .note-text {
    flex: 1;
}

.td-sun {
    text-align: center;
    font-size: 15px;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.88);
    line-height: 1.7;
}

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

/* Fix text colours on week-odd (white background) rows */
tr.data-row.week-odd .td-activity-note {
    color: var(--color-header);
}
tr.data-row.week-odd .td-sun {
    color: var(--color-header);
}
tr.data-row.week-odd .tide-btn {
    background: var(--color-tide-btn-odd);
    border-color: var(--color-border);
}

.tide-btn {
    background: var(--color-tide-btn);
    border: 1px solid var(--color-border);
    color: #fff;
    font-family: var(--font-body);
    font-size: 14px;
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.tide-btn:hover {
    background: rgba(255, 255, 255, 0.32);
}

/* ** MOBILE CARDS ***************************************** */
.card-list {
    display: none; /* Hidden on desktop, shown via media query */
    background: var(--color-bg);
    padding: 12px 14px 24px;
    border-top: 2px solid rgba(255, 255, 255, 0.12);
}

.card-section-title {
    font-family: var(--font-display);
    font-size: 22px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.7);
    padding: 10px 4px 14px;
    font-weight: 700;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.month-label-card {
    background: var(--color-month);
    font-family: var(--font-display);
    font-size: 20px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    text-align: center;
    padding: 7px;
    margin: 14px 0 7px;
    border-radius: var(--radius-inner);
    font-weight: 700;
    color: #fff;
}

.card {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-inner);
    margin-bottom: 8px;
    overflow: hidden;
}

/* Card week alternating backgrounds */
.card.week-odd {
    background: rgba(255, 255, 255, 0.8);
    color: var(--color-header);
    border-color: var(--color-border-even);
}
.card.week-even {
    background: rgba(100, 170, 225, 0.65);
    color: #fff;
}

.card.is-today {
    background: rgb(40, 155, 140) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #fff !important;
}
.card.is-today .card-sun-header,
.card.is-today .card-time,
.card.is-today .card-body,
.card.is-today .card-note {
    color: #fff !important;
}
.card.is-today .card-header,
.card.is-today .card-middle {
    border-bottom-color: rgba(255, 255, 255, 0.25) !important;
}
.card.is-today .tide-btn,
.card.is-today .card-tide-btn {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}

.card.is-selected {
    background: rgba(40, 155, 140, 0.4);
    border: 2px solid var(--color-today);
}

/* Fix text/button colours on white (week-odd) cards */
.card.week-odd .card-sun-header,
.card.week-odd .card-time,
.card.week-odd .card-body,
.card.week-odd .card-note {
    color: var(--color-header);
}
.card.week-odd .card-header {
    border-bottom-color: var(--color-border-even);
}
.card.week-odd .card-middle {
    border-bottom-color: var(--color-border-even);
}
.card.week-odd .tide-btn,
.card.week-odd .card-tide-btn {
    background: var(--color-tide-btn-odd);
    border-color: var(--color-border);
    color: #fff;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
}

.card-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.card-emoji {
    font-size: 22px;
}
.card-date {
    font-weight: 600;
    font-size: 16px;
}

.card-sun-header {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.88);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40%;
}

.card-middle {
    display: flex;
    align-items: center;
    padding: 8px 14px;
    border-bottom: 1px solid var(--color-border);
    min-width: 0;
    gap: 12px;
}

.card-time {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.card-middle .tide-btn {
    flex-shrink: 0;
    margin-left: auto;
}

.card-body {
    padding: 10px 14px 12px;
    font-size: 15px;
    color: rgba(255, 255, 255, 0.82);
}

.card-note {
    margin-bottom: 0;
}

/* ** MODAL ************************************************* */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
}

.modal-box {
    background: var(--color-header);
    border-radius: 16px;
    width: 100%;
    max-width: 860px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.45);
    position: relative;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #fff;
}

.modal-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.modal-body {
    padding: 20px 24px 24px;
}

.modal-sun {
    display: flex;
    gap: 28px;
    margin-bottom: 18px;
    font-size: 18px;
    font-weight: 500;
    flex-wrap: wrap;
}

.modal-sun span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-tide-wrap {
    position: relative;
    min-height: 180px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-inner);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-tide-wrap img {
    width: 100%;
    display: block;
    border-radius: var(--radius-inner);
}

.modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--color-muted);
    font-size: 15px;
}

.spinner-sm {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ** RESPONSIVE ******************************************** */
@media (max-width: 720px) {
    body {
        padding: 0;
    }
    .page-header {
        padding: 16px 18px;
    }
    .page-title {
        font-size: 22px;
    }
    .table-wrap {
        display: none;
    }
    .card-list {
        display: block;
        border-top: none;
    }
    .card-section-title {
        display: none;
    }
    .app-card {
        border-radius: 0;
    }
    .modal-body {
        padding: 5px;
    }
}

@media (max-width: 400px) {
    .card-sun-header {
        font-size: 12px;
        max-width: 35%;
    }
    .card-time {
        font-size: 14px;
    }
    .card-middle .tide-btn {
        font-size: 12px;
        padding: 4px 10px;
    }
}

/* =============================================================
   NIGHT MODE 
   activated by JS adding class="night" on <html>
   ============================================================= */
html.night {
    --night-page-bg:    rgb(25, 40, 55);
    --night-bg:         rgb(35, 50, 65);
    --night-header:     rgb(50, 100, 130);
    --night-month:      rgb(25, 60, 80);
    --night-odd-bg:     rgb(35, 55, 65);
    --night-odd-border: rgb(175, 200, 220);
    --night-even-bg:    rgb(25, 45, 55);
    --night-even-border:rgb(175, 200, 220);
    --night-text:       rgb(255, 255, 255);
    --night-border:     rgba(175, 200, 220, 0.35);
    --night-tide-btn:   rgba(175, 200, 220, 0.35);
    --night-today:      rgb(25, 90, 95);
}

/* ** Page & card shell **************************************** */
html.night body {
    background: var(--night-page-bg);
}
html.night .app-card {
    background: var(--night-bg);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
}

/* ** Header *************************************************** */
html.night .page-header {
    background: var(--night-header);
}
html.night .refresh-btn {
    background: rgba(175, 200, 220, 0.12);
    border-color: var(--night-border);
}
html.night .refresh-btn:hover {
    background: rgba(175, 200, 220, 0.24);
}
html.night .datepicker-wrap {
    background: rgba(175, 200, 220, 0.08);
    border-color: var(--night-border);
}

/* ** Loading / error ****************************************** */
html.night #loading {
    background: var(--night-bg);
}

/* ** Desktop table ******************************************** */
html.night .table-wrap {
    background: var(--night-bg);
}

html.night thead th {
    background: var(--night-header);
    color: var(--night-text);
    border-bottom-color: rgba(175, 200, 220, 0.2);
}

html.night tr.month-sep td {
    background: var(--night-month);
    color: var(--night-text);
}

/* Odd weeks */
html.night tr.data-row.week-odd {
    background: var(--night-odd-bg);
    color: var(--night-text);
    border-color: var(--night-odd-border);
}
html.night tr.data-row.week-odd:hover {
    background: rgb(55, 65, 82);
}

/* Even weeks */
html.night tr.data-row.week-even {
    background: var(--night-even-bg);
    color: var(--night-text);
    border-color: var(--night-even-border);
}
html.night tr.data-row.week-even:hover {
    background: rgb(65, 82, 88);
}

/* Fallback rows */
html.night tr.data-row {
    border-color: var(--night-border);
    color: var(--night-text);
}
html.night tr.data-row:hover {
    background: rgba(175, 200, 220, 0.1);
}

/* Today */
html.night tr.data-row.is-today,
html.night tr.data-row.week-odd.is-today,
html.night tr.data-row.week-even.is-today {
    background: var(--night-today) !important;
    color: #fff !important;
}
html.night tr.data-row.is-today:hover {
    background: rgb(25, 105, 95) !important;
}

/* Selected */
html.night tr.data-row.is-selected,
html.night tr.data-row.is-selected.week-odd,
html.night tr.data-row.is-selected.week-even {
    background: rgba(30, 120, 110, 0.35);
    outline-color: var(--night-today);
}

/* Cell text overrides for odd rows (were white-bg, now dark-bg) */
html.night tr.data-row.week-odd .td-activity-note-container {
    color: var(--night-text);
}
html.night tr.data-row.week-odd .td-sun {
    color: var(--night-text);
}
html.night tr.data-row.week-odd .tide-btn {
    background: var(--night-tide-btn);
    border-color: var(--night-border);
    color: var(--night-text);
}

/* General td text */
html.night td {
    color: var(--night-text);
}
html.night .td-activity-note-container {
    color: var(--night-text);
}
html.night .td-sun {
    color: var(--night-text);
}
html.night .tide-btn {
    background: var(--night-tide-btn);
    border-color: var(--night-border);
    color: var(--night-text);
}
html.night .tide-btn:hover {
    background: rgba(175, 200, 220, 0.3);
}

/* ** Mobile cards ********************************************* */
html.night .card-list {
    background: var(--night-bg);
    border-top-color: rgba(175, 200, 220, 0.15);
}

html.night .month-label-card {
    background: var(--night-month);
}

/* Odd-week cards */
html.night .card.week-odd {
    background: var(--night-odd-bg);
    color: var(--night-text);
    border-color: var(--night-odd-border);
}
html.night .card.week-odd .card-sun-header,
html.night .card.week-odd .card-time,
html.night .card.week-odd .card-body,
html.night .card.week-odd .card-note {
    color: var(--night-text);
}
html.night .card.week-odd .card-header {
    border-bottom-color: rgba(175, 200, 220, 0.25);
}
html.night .card.week-odd .card-middle {
    border-bottom-color: rgba(175, 200, 220, 0.25);
}
html.night .card.week-odd .tide-btn,
html.night .card.week-odd .card-tide-btn {
    background: var(--night-tide-btn);
    border-color: var(--night-border);
    color: var(--night-text);
}

/* Even-week cards */
html.night .card.week-even {
    background: var(--night-even-bg);
    color: var(--night-text);
    border-color: var(--night-even-border);
}

/* Generic card overrides */
html.night .card {
    border-color: var(--night-border);
    color: var(--night-text);
}
html.night .card-sun-header {
    color: var(--night-text);
}
html.night .card-time {
    color: var(--night-text);
}
html.night .card-body,
html.night .card-note {
    color: var(--night-text);
}
html.night .card-header {
    border-bottom-color: rgba(175, 200, 220, 0.2);
}
html.night .card-middle {
    border-bottom-color: rgba(175, 200, 220, 0.2);
}

/* Today cards */
html.night .card.is-today {
    background: var(--night-today) !important;
    border-color: rgba(175, 200, 220, 0.4) !important;
    color: #fff !important;
}

/* ** Modal **************************************************** */
html.night .modal-overlay {
    background: rgba(0, 0, 0, 0.8);
}
html.night .modal-box {
    background: var(--night-page-bg);
}
html.night .modal-header {
    border-bottom-color: var(--night-border);
}
html.night .modal-title {
    color: var(--night-text);
}
html.night .modal-close {
    background: rgba(175, 200, 220, 0.15);
}
html.night .modal-close:hover {
    background: rgba(175, 200, 220, 0.3);
}
html.night .modal-tide-wrap {
    background: rgba(0, 0, 0, 0.3);
}
