/* ============================================================
   Tide layer — station markers + station card (48 h curve)
   Ported from docs/ui-mockups/tide-mockup.html, mapped onto the
   app's design tokens. The mockup's --primary / --mono / --shadow /
   --ok / --err / --radius become --color-primary / --font-mono /
   --shadow-lg / --color-success / --color-error / --radius-lg here.
   ============================================================ */

/* Chart series colours — validated with the dataviz six-checks on the
   light (#FFFFFF) and night (#161D27) chart surfaces. Not defined by
   the base token set, so they live here. */
:root {
    --s-pred: #0077BE;
    --s-obs: #1E8E6E;
    --s-model: #C77A1E;
}

body.night {
    --s-pred: #3987e5;
    --s-obs: #199e70;
    --s-model: #d95926;
}

/* ---------- station markers ---------- */
.tm {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    height: 22px;
    padding: 0 6px 0 2px;
    border-radius: 999px;
    background: var(--paper);
    color: var(--ink);
    font: 500 11px var(--font-mono);
    border: 2px solid var(--color-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s;
}

.tm .i {
    width: 14px;
    height: 14px;
    color: var(--ink-2);
}

/* metre stations carry a small unit suffix (feet markers are bare numbers) */
.tm .tm__u {
    font-size: 9px;
    margin-left: 1px;
    opacity: .75;
}

.tm--s {
    border: 1.5px solid var(--ink-3);
    height: 20px;
    font-size: 10.5px;
    background: color-mix(in srgb, var(--paper) 88%, transparent);
}

.tm--s .i {
    width: 12px;
    height: 12px;
}

.tm.is-sel {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.tm.is-sel .i {
    color: #fff;
}

/* Hollow (subordinate) markers declutter below zoom 10 */
body.tide-zoomed-out .tm--s {
    display: none;
}

.leaflet-marker-icon.tm-wrap {
    background: none;
    border: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ---------- station card ---------- */
.tide {
    width: 100%;
    font-size: 13px;
    color: var(--ink);
}

.tide__head {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 8px 0 14px;
}

.tide__head > div {
    flex: 1;
    min-width: 0;
}

.tide__name {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
}

.tide__meta {
    font-size: 11px;
    color: var(--ink-3);
    margin-top: 2px;
}

.tide__now {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 14px 0;
}

.tide__h {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1;
}

.tide__h small {
    font-size: 12px;
    color: var(--ink-3);
    margin-left: 4px;
    font-weight: 600;
    letter-spacing: 0;
}

.tide__trend {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-weight: 600;
    color: var(--ink-2);
    font-size: 13px;
}

.tide__trend .i {
    width: 16px;
    height: 16px;
}

.tide__time {
    margin-left: auto;
    font-size: 11px;
    color: var(--ink-3);
    text-align: right;
    line-height: 1.3;
}

/* pan-y: vertical swipes still scroll the sheet, horizontal drags scrub */
.tide__chart {
    display: block;
    width: 100%;
    height: auto;
    margin-top: 4px;
    touch-action: pan-y;
    cursor: crosshair;
    user-select: none;
}

.tide__legend {
    display: flex;
    gap: 12px;
    padding: 0 14px;
    font-size: 11px;
    color: var(--ink-2);
    flex-wrap: wrap;
}

.key {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.key i {
    width: 14px;
    height: 0;
    border-top: 2px solid var(--kc);
}

.key--dash i {
    border-top-style: dashed;
}

.ev {
    list-style: none;
    margin: 8px 8px 0;
    padding: 0;
}

.ev li {
    display: grid;
    grid-template-columns: 78px 52px 1fr auto;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 6px;
    border-radius: 8px;
    cursor: pointer;
}

.ev li:hover {
    background: var(--paper-2);
}

.ev li.is-next {
    background: var(--color-primary-tint);
}

.ev li.is-past {
    opacity: .5;
}

.ev__when {
    font-family: var(--font-mono);
    font-size: 12px;
}

.ev__kind {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-3);
    display: inline-flex;
    align-items: center;
    gap: 1px;
}

.ev__kind .i {
    width: 12px;
    height: 12px;
}

.ev__val {
    font-weight: 700;
    font-family: var(--font-mono);
    font-size: 12.5px;
    text-align: right;
}

.ev__rel {
    font-size: 11px;
    color: var(--ink-3);
    text-align: right;
    min-width: 64px;
}

.tide__foot {
    padding: 8px 14px 12px;
    font-size: 10.5px;
    color: var(--ink-3);
    line-height: 1.4;
}

/* chart internals */
.ch text {
    font-family: var(--font-mono);
    font-size: 8.5px;
    fill: var(--ink-3);
}

.ch .ch__day {
    font-family: var(--font-primary);
    font-weight: 600;
    font-size: 9px;
    fill: var(--ink-2);
}

.ch__night {
    fill: var(--ink);
    opacity: .05;
}

.ch__grid {
    stroke: var(--line);
    stroke-width: 1;
}

.ch__area {
    fill: var(--s-pred);
    opacity: .1;
}

.ch__pred {
    stroke: var(--s-pred);
    stroke-width: 2;
    fill: none;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.ch__obs {
    stroke: var(--s-obs);
    stroke-width: 2;
    fill: none;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.ch__model {
    stroke: var(--s-model);
    stroke-width: 2;
    fill: none;
    stroke-dasharray: 4 3;
    stroke-linecap: round;
}

.ch__hl {
    fill: var(--s-pred);
    stroke: var(--paper);
    stroke-width: 2;
}

.ch__hl-lbl {
    fill: var(--ink-2);
    font-weight: 500;
}

.ch__now {
    stroke: var(--ink-3);
    stroke-width: 1;
}

.ch__cur {
    stroke: var(--ink);
    stroke-width: 1.5;
}

.ch__curdot {
    fill: var(--s-pred);
    stroke: var(--paper);
    stroke-width: 2;
}

.ch__badge rect {
    fill: var(--ink);
}

.ch__badge text {
    fill: var(--paper);
    font-weight: 500;
}

/* ---------- desktop popup host ---------- */
.tide-popup .leaflet-popup-content-wrapper {
    background: var(--paper);
    color: var(--ink);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0;
}

.tide-popup .leaflet-popup-content {
    margin: 0;
    width: auto !important;
    line-height: 1.35;
}

.tide-popup .leaflet-popup-tip {
    background: var(--paper);
}

.tide-popup .tide {
    width: 330px;
}

/* ---------- phone: card lives in a transient sheet tab ---------- */
.tab--tide {
    display: none;
}

body.has-tide-card .tab--tide {
    display: inline-flex;
}

/* parked (card not shown anywhere) */
#tide-card-parking {
    display: none;
}

.sec--tide .tide-host:empty::before {
    content: "Tap a tide marker on the map";
    display: block;
    padding: 24px 16px;
    color: var(--ink-3);
    font-size: 13px;
}

/* On desktop the card is a map popup, so the sheet section is redundant */
body.is-desktop .sec--tide {
    display: none;
}

/* Flush the card to the sheet edges on phone */
body.is-mobile .sec--tide {
    margin: -14px -16px calc(-20px - var(--safe-b));
}
