/* ==========================================================================
   CrewLog — Apple-maritime mobile-native design system
   Single source of truth for the new "cl-*" primitives.
   Mobile-first. iPhone = 1 column. iPad = 2 columns. Desktop = 2-3 columns.
   ========================================================================== */

/* --- Design tokens (global, so any page can use cl-* primitives) ---------- */
/* Default: HarborDeck dark maritime theme. Day mode restores light in ui_night_mode.css */
:root {
    --cl-bg:           #0b1d2e;
    --cl-surface:      #112233;
    --cl-surface-2:    #1a3350;
    --cl-border:       #1d3d60;
    --cl-border-strong:#2a5580;
    --cl-text:         #eef2f6;
    --cl-text-muted:   #8a9fb4;
    --cl-text-subtle:  #587080;
    --cl-navy:         #f0f5fa;
    --cl-navy-soft:    #2a7ab5;
    --cl-accent:       #3b9ad4;
    --cl-accent-soft:  #0e2438;
    --cl-success:      #3dbf78;
    --cl-success-soft: #0a2518;
    --cl-warn:         #f5a020;
    --cl-warn-soft:    #2e1e05;
    --cl-danger:       #df5454;
    --cl-danger-soft:  #2e0a0a;

    --cl-radius:       12px;
    --cl-radius-sm:    8px;
    --cl-shadow:       0 1px 4px rgba(0,8,22,.6), 0 4px 16px rgba(0,8,22,.5);

    --cl-space-1:      4px;
    --cl-space-2:      8px;
    --cl-space-3:      12px;
    --cl-space-4:      16px;
    --cl-space-5:      24px;
    --cl-space-6:      32px;
    --cl-space-7:      48px;
    --cl-space-8:      64px;

    /* Reserved heights (measured at runtime by cl_shell.js) */
    --cl-tabbar-h:     0px;
    --cl-actionbar-h:  0px;
}

/* --- Page wrapper --------------------------------------------------------- */
.cl-page {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--cl-space-6) var(--cl-space-4) 0;
    color: var(--cl-text);
    font-size: 15px;
    line-height: 1.45;
}
/* The 768px literal here MUST equal `--cl-tablet-small-min` declared in
   static/ui_breakpoints.css. */
@media (min-width: 768px) {
    .cl-page { padding: var(--cl-space-7) var(--cl-space-5) 0; }
}
.cl-page--wide { max-width: 1200px; }

/* New component links inherit the component's text color unless they opt into
   a button, navigation, or prose-link treatment. This avoids the browser's
   default blue link color on dark surfaces. */
:where(.cl-page, .cl-pageheader, .cl-card, .cl-entry, .cl-hero, .cl-row-card) a:not(.btn):not(.cl-btn):not(.nav-item):not(.cl-page-nav__link):not(.cl-tabbar__item):not([role="button"]) {
    color: inherit;
}

/* --- Page header ---------------------------------------------------------- */
.cl-pageheader {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--cl-space-4);
    margin-bottom: var(--cl-space-5);
    flex-wrap: wrap;
}
.cl-pageheader__main { min-width: 0; flex: 1 1 auto; }
.cl-pageheader__actions {
    display: flex;
    gap: var(--cl-space-2);
    flex-wrap: wrap;
}
.cl-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--cl-navy);
    margin: 0 0 var(--cl-space-2);
    line-height: 1.2;
}
/* 768px == `--cl-tablet-small-min` (static/ui_breakpoints.css). */
@media (min-width: 768px) { .cl-title { font-size: 30px; } }
.cl-subtitle {
    font-size: 14px;
    color: var(--cl-text-muted);
    margin: 0;
    max-width: 60ch;
}
.cl-section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--cl-navy);
    margin: 0 0 var(--cl-space-3);
    letter-spacing: -0.005em;
}

/* --- Stack (vertical rhythm replacement for space-y-*) -------------------- */
.cl-stack { display: flex; flex-direction: column; gap: var(--cl-space-5); }
.cl-stack--sm { gap: var(--cl-space-3); }
.cl-stack--lg { gap: var(--cl-space-6); }

/* --- Form layout ---------------------------------------------------------- */
.cl-form {
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-5);
    /* Reserve space so any FIXED action bar never overlaps the last card.
       --cl-actionbar-h already includes the bar's own safe-area padding
       (measured at runtime by cl_shell.js), so we don't add env() again. */
    padding-bottom: calc(var(--cl-actionbar-h, 0px) + var(--cl-space-3));
}

/* --- Card ----------------------------------------------------------------- */
.cl-card {
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    box-shadow: var(--cl-shadow);
    padding: var(--cl-space-5);
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-4);
}
/* The 768px literal here MUST equal `--cl-tablet-small-min` declared in
   static/ui_breakpoints.css. */
@media (min-width: 768px) {
    .cl-card { padding: var(--cl-space-6); gap: var(--cl-space-5); }
}
.cl-card--flat { box-shadow: none; }
.cl-card--quiet { background: var(--cl-surface-2); }
.cl-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cl-space-3);
    flex-wrap: wrap;
}
.cl-card__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--cl-navy);
    margin: 0;
    letter-spacing: -0.005em;
}
.cl-card__footer {
    display: flex;
    align-items: center;
    gap: var(--cl-space-3);
    flex-wrap: wrap;
    margin-top: var(--cl-space-2);
}
.cl-card__hint { margin-top: var(--cl-space-2); }

/* Tappable card (whole card acts as link) */
.cl-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform .15s, box-shadow .15s;
}
.cl-card-link:hover { transform: translateY(-1px); box-shadow: 0 4px 18px rgba(15,41,66,.08); }
.cl-card-link:active { transform: translateY(0); }

/* --- Field grid ----------------------------------------------------------- */
.cl-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--cl-space-4);
}
/* The 640px literal here MUST equal `--cl-phone-max` (used as the
   `min-width` flip from 1-col to 2-col) declared in static/ui_breakpoints.css. */
@media (min-width: 640px) {
    .cl-grid--2,
    .cl-grid--3,
    .cl-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* The 1024px literal here MUST equal `--cl-tablet-min` declared in
   static/ui_breakpoints.css. */
@media (min-width: 1024px) {
    .cl-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .cl-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* --- Field & input -------------------------------------------------------- */
.cl-field {
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-2);
    min-width: 0;
}
.cl-field--full { grid-column: 1 / -1; }
.cl-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--cl-text-muted);
    letter-spacing: 0.01em;
    line-height: 1.3;
    /* Reserve space for one or two label lines so wrapping never staggers
       adjacent fields in the same grid row. */
    min-height: 2.6em;
    display: flex;
    align-items: flex-end;
}
.cl-label--inline { min-height: 0; }
.cl-input {
    width: 100%;
    box-sizing: border-box;
    height: 44px;
    padding: 0 var(--cl-space-3);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius-sm);
    background: var(--cl-surface);
    font-size: 16px;            /* prevents iOS auto-zoom */
    line-height: 1.4;
    color: var(--cl-text);
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.cl-input:focus {
    outline: none;
    border-color: var(--cl-accent);
    box-shadow: 0 0 0 3px rgba(29,111,187,.18);
}
.cl-input--textarea {
    height: auto;
    min-height: 72px;
    padding: var(--cl-space-3);
    resize: vertical;
}
.cl-input--file {
    height: auto;
    padding: var(--cl-space-3);
    background: var(--cl-surface-2);
    cursor: pointer;
}
.cl-input--error {
    border-color: var(--cl-danger);
    background: var(--cl-danger-soft);
}
.cl-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%235a6479' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
}
.cl-field__error {
    font-size: 12px;
    color: var(--cl-danger);
    margin: 0;
}

/* Checkbox / radio rows */
.cl-check-row {
    display: flex;
    align-items: center;
    gap: var(--cl-space-3);
    padding: var(--cl-space-2) var(--cl-space-3);
    border-radius: var(--cl-radius-sm);
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    cursor: pointer;
    min-height: 44px;
    box-sizing: border-box;
}
.cl-check-row:hover { background: var(--cl-surface-2); }
.cl-check-row input[type="checkbox"],
.cl-check-row input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--cl-accent);
    flex-shrink: 0;
}
.cl-check-row__label { font-size: 15px; color: var(--cl-text); flex: 1 1 auto; }

/* --- Buttons -------------------------------------------------------------- */
.cl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--cl-space-2);
    height: 44px;
    padding: 0 var(--cl-space-4);
    border-radius: var(--cl-radius-sm);
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
    box-sizing: border-box;
    white-space: nowrap;
    font-family: inherit;
}
.cl-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(29,111,187,.25);
}
.cl-btn--sm { height: 36px; padding: 0 var(--cl-space-3); font-size: 13px; }
.cl-btn--block { width: 100%; }
.cl-btn--primary {
    background: #c8d4e0;
    color: #0c1e30;
    border-color: transparent;
}
.cl-btn--primary:hover { background: #b4c2d0; color: #0c1e30; }
.cl-btn--accent {
    background: #c8d4e0;
    color: #0c1e30;
    border-color: transparent;
}
.cl-btn--accent:hover { background: #b4c2d0; color: #0c1e30; }
.cl-btn--success {
    background: var(--cl-success);
    color: #fff;
}
.cl-btn--success:hover { background: #25623d; }
.cl-btn--warn {
    background: var(--cl-warn);
    color: #fff;
}
.cl-btn--warn:hover { background: #976015; }
.cl-btn--secondary {
    background: #c8d4e0;
    color: #0c1e30;
    border-color: transparent;
}
.cl-btn--secondary:hover { background: #b4c2d0; color: #0c1e30; }
.cl-btn--ghost {
    background: rgba(255, 255, 255, 0.07);
    color: #eef2f6 !important;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.18);
}
.cl-btn--ghost:hover {
    background: rgba(255, 255, 255, 0.13);
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.32);
}
/* Success variant — used for "Reopen" in trip cards */
.cl-btn--ghost-success,
a.cl-btn--ghost-success {
    background: rgba(255, 255, 255, 0.07);
    color: var(--cl-success) !important;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.18);
}
.cl-btn--ghost-success:hover,
a.cl-btn--ghost-success:hover {
    background: rgba(255, 255, 255, 0.13);
    color: var(--cl-success) !important;
    border-color: var(--cl-success);
    text-decoration: none;
}

.cl-btn--ghost-danger,
a.cl-btn--ghost-danger {
    background: transparent;
    color: var(--cl-danger) !important;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.12);
}
.cl-btn--ghost-danger:hover,
a.cl-btn--ghost-danger:hover {
    background: var(--cl-danger-soft);
    border-color: var(--cl-danger);
    color: var(--cl-danger) !important;
    text-decoration: none;
}

.cl-iconbtn {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--cl-border);
    background: var(--cl-surface);
    border-radius: var(--cl-radius-sm);
    color: var(--cl-text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.cl-iconbtn:hover { background: var(--cl-surface-2); border-color: var(--cl-border-strong); }
.cl-iconbtn[disabled],
.cl-iconbtn:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }

/* --- Pills / Badges ------------------------------------------------------- */
.cl-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--cl-space-1);
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
    border-radius: 999px;
    background: var(--cl-surface-2);
    color: var(--cl-text-muted);
    border: 1px solid var(--cl-border);
}
.cl-pill--accent  { background: var(--cl-accent-soft);  color: var(--cl-accent);  border-color: transparent; }
.cl-pill--success { background: var(--cl-success-soft); color: var(--cl-success); border-color: transparent; }
.cl-pill--warn    { background: var(--cl-warn-soft);    color: var(--cl-warn);    border-color: transparent; }
.cl-pill--danger  { background: var(--cl-danger-soft);  color: var(--cl-danger);  border-color: transparent; }
.cl-pill--solid-success { background: var(--cl-success); color: #fff; border-color: transparent; }
.cl-pill--solid-danger  { background: var(--cl-danger);  color: #fff; border-color: transparent; }
.cl-pill--solid-accent  { background: var(--cl-accent);  color: #fff; border-color: transparent; }

/* --- Helpers -------------------------------------------------------------- */
.cl-help {
    font-size: 12px;
    color: var(--cl-text-subtle);
    margin: 0;
}
.cl-help--muted   { color: var(--cl-text-muted); }
.cl-help--success { color: var(--cl-success); font-weight: 500; }
.cl-help--warn    { color: var(--cl-warn); }

.cl-muted   { color: var(--cl-text-muted); }
.cl-subtle  { color: var(--cl-text-subtle); }

/* --- Alerts --------------------------------------------------------------- */
.cl-alert {
    padding: var(--cl-space-3) var(--cl-space-4);
    border-radius: var(--cl-radius-sm);
    font-size: 14px;
    margin-bottom: var(--cl-space-4);
    border: 1px solid transparent;
}
.cl-alert--danger {
    background: var(--cl-danger-soft);
    color: var(--cl-danger);
    border-color: color-mix(in srgb, var(--cl-danger) 25%, transparent);
}
.cl-alert--warn {
    background: var(--cl-warn-soft);
    color: var(--cl-warn);
    border-color: color-mix(in srgb, var(--cl-warn) 25%, transparent);
}
.cl-alert--success {
    background: var(--cl-success-soft);
    color: var(--cl-success);
    border-color: color-mix(in srgb, var(--cl-success) 25%, transparent);
}
.cl-alert--info {
    background: var(--cl-accent-soft);
    color: var(--cl-accent);
    border-color: color-mix(in srgb, var(--cl-accent) 25%, transparent);
}
.cl-alert > div + div { margin-top: var(--cl-space-1); }

/* --- Entries list & entry card ------------------------------------------- */
.cl-entries { display: flex; flex-direction: column; gap: var(--cl-space-4); }
.cl-entry {
    background: var(--cl-surface-2);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    padding: var(--cl-space-4);
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-5);
}
/* 768px == `--cl-tablet-small-min` (static/ui_breakpoints.css). */
@media (min-width: 768px) { .cl-entry { padding: var(--cl-space-5); } }
.cl-entry--error { background: var(--cl-danger-soft); border-color: var(--cl-danger); }
.cl-entry__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cl-space-3);
    flex-wrap: wrap;
}
.cl-entry__head-left {
    display: flex;
    align-items: center;
    gap: var(--cl-space-2);
}
.cl-entry__index {
    font-weight: 600;
    color: var(--cl-text-muted);
    font-size: 14px;
    margin-left: var(--cl-space-2);
}

/* --- Group within an entry: eyebrow + grid ------------------------------- */
.cl-group { display: flex; flex-direction: column; gap: var(--cl-space-3); }
.cl-eyebrow {
    display: flex;
    align-items: center;
    gap: var(--cl-space-2);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--cl-text-subtle);
    padding-bottom: var(--cl-space-2);
    border-bottom: 1px solid var(--cl-border);
}
.cl-eyebrow__icon { font-size: 13px; line-height: 1; opacity: .85; filter: grayscale(.2); }

/* --- Photo grid ----------------------------------------------------------- */
.cl-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: var(--cl-space-2);
}
.cl-photo-grid:empty { display: none; }
.cl-photo-grid .photo-pill {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: var(--cl-radius-sm);
    overflow: hidden;
    border: 1px solid var(--cl-border);
    background: var(--cl-surface-2);
}
.cl-photo-grid .photo-pill img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Backwards-compat with JS that targets #dayPhotosPreview */
#dayPhotosPreview { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--cl-space-2); }
#dayPhotosPreview .photo-pill { position: relative; aspect-ratio: 1/1; border-radius: var(--cl-radius-sm); overflow: hidden; border: 1px solid var(--cl-border); background: var(--cl-surface-2); }
#dayPhotosPreview .photo-pill img { width:100%; height:100%; object-fit: cover; display: block; }

/* --- Tables (clean, mobile-aware) ---------------------------------------- */
.cl-table-wrap {
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    overflow: hidden;
    box-shadow: var(--cl-shadow);
}
.cl-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.cl-table thead th {
    text-align: left;
    padding: var(--cl-space-3) var(--cl-space-4);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--cl-text-subtle);
    background: var(--cl-surface-2);
    border-bottom: 1px solid var(--cl-border);
    white-space: nowrap;
}
.cl-table tbody td {
    padding: var(--cl-space-3) var(--cl-space-4);
    border-bottom: 1px solid var(--cl-border);
    background: var(--cl-surface);
    color: var(--cl-text);
    vertical-align: middle;
}
.cl-table tbody tr:last-child td { border-bottom: none; }
.cl-table tbody tr:hover,
.cl-table tbody tr:hover td {
    background: var(--cl-surface-2);
    color: var(--cl-text);
}
.cl-table .cl-num { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.cl-table .cl-actions {
    display: flex;
    gap: var(--cl-space-1);
    flex-wrap: wrap;
    align-items: center;
}

/* Mobile meta line inside the name cell (hidden on desktop) */
.cl-trip-meta {
    display: none;
}

/* --- Phone card layout for trip table (≤640 px) -------------------------- */
/* Scoped to .cl-trips-table so other .cl-table instances are unaffected.   */
@media (max-width: 640px) {
    /* Kill horizontal scroll on the trips scroll-wrapper only */
    .cl-trips-table-scroll { overflow-x: visible; }

    /* Hide table header — card layout is self-labelled */
    .cl-trips-table thead { display: none; }

    /* Collapse table structure to block flow */
    .cl-trips-table,
    .cl-trips-table tbody,
    .cl-trips-table tr,
    .cl-trips-table td { display: block; }

    /* Each row becomes a card */
    .cl-trips-table tbody tr {
        margin: var(--cl-space-3) var(--cl-space-3);
        padding: var(--cl-space-3) var(--cl-space-4);
        border: 1px solid var(--cl-border);
        border-radius: var(--cl-radius);
        background: var(--cl-surface);
        box-shadow: var(--cl-shadow);
    }
    .cl-trips-table tbody tr:hover { background: var(--cl-surface); }

    /* Strip per-cell borders and padding — card provides spacing */
    .cl-trips-table tbody td {
        padding: 0;
        border-bottom: none;
    }

    /* Hide standalone date / distance / status columns on trips table only */
    .cl-trips-table .cl-td-desktop { display: none !important; }

    /* Show the mobile meta line */
    .cl-trip-meta {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 4px;
        margin-top: var(--cl-space-1);
        font-size: 12px;
        color: var(--cl-text-subtle);
    }
    .cl-trip-meta .cl-num {
        font-size: 12px;
        font-weight: 600;
        color: var(--cl-text);
    }
    .cl-trip-meta__sep {
        color: var(--cl-text-subtle);
    }

    /* Actions row: full width, decent tap targets, divider above */
    .cl-trips-table td:last-child {
        margin-top: var(--cl-space-2);
        padding-top: var(--cl-space-2);
        border-top: 1px solid var(--cl-border);
    }
    .cl-trips-table .cl-actions {
        gap: var(--cl-space-2);
        flex-wrap: wrap;
    }
    .cl-trips-table .cl-actions .cl-btn,
    .cl-trips-table .cl-actions a.cl-btn {
        min-height: 36px;
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }
}

/* --- Phone card layout for expenses table (≤640 px) ---------------------- */
/* Scoped to .cl-expenses-table so other .cl-table instances are unaffected. */
@media (max-width: 640px) {
    .cl-expenses-table-scroll { overflow-x: visible; }
    .cl-expenses-table thead { display: none; }
    .cl-expenses-table,
    .cl-expenses-table tbody,
    .cl-expenses-table tr,
    .cl-expenses-table td { display: block; }
    .cl-expenses-table tbody tr {
        margin: var(--cl-space-3) var(--cl-space-3);
        padding: var(--cl-space-3) var(--cl-space-4);
        border: 1px solid var(--cl-border);
        border-radius: var(--cl-radius);
        background: var(--cl-surface);
        box-shadow: var(--cl-shadow);
    }
    .cl-expenses-table tbody tr:hover { background: var(--cl-surface); }
    .cl-expenses-table tbody td { padding: 0; border-bottom: none; }
    .cl-expenses-table .cl-td-desktop { display: none !important; }
    /* Amount cell: a touch of top spacing to separate from description */
    .cl-expenses-table td.cl-num { margin-top: var(--cl-space-2); }
    /* Actions row */
    .cl-expenses-table td:last-child {
        margin-top: var(--cl-space-2);
        padding-top: var(--cl-space-2);
        border-top: 1px solid var(--cl-border);
    }
    .cl-expenses-table .cl-actions { gap: var(--cl-space-2); flex-wrap: wrap; }
    .cl-expenses-table .cl-actions .cl-btn,
    .cl-expenses-table .cl-actions a.cl-btn {
        min-height: 36px;
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }
}

/* --- Phone card layout for crew table (≤640 px) -------------------------- */
/* Scoped to .cl-crew-table so other .cl-table instances are unaffected.    */
@media (max-width: 640px) {
    .cl-crew-table-scroll { overflow-x: visible; }
    .cl-crew-table thead { display: none; }
    .cl-crew-table,
    .cl-crew-table tbody,
    .cl-crew-table tr,
    .cl-crew-table td { display: block; }
    .cl-crew-table tbody tr {
        margin: var(--cl-space-3) var(--cl-space-3);
        padding: var(--cl-space-3) var(--cl-space-4);
        border: 1px solid var(--cl-border);
        border-radius: var(--cl-radius);
        background: var(--cl-surface);
        box-shadow: var(--cl-shadow);
    }
    .cl-crew-table tbody tr:hover { background: var(--cl-surface); }
    .cl-crew-table tbody td { padding: 0; border-bottom: none; }
    .cl-crew-table .cl-td-desktop { display: none !important; }
    /* Actions row */
    .cl-crew-table td:last-child {
        margin-top: var(--cl-space-2);
        padding-top: var(--cl-space-2);
        border-top: 1px solid var(--cl-border);
    }
    .cl-crew-table .cl-actions { gap: var(--cl-space-2); flex-wrap: wrap; }
    .cl-crew-table .cl-actions .cl-btn,
    .cl-crew-table .cl-actions a.cl-btn,
    .cl-crew-table .cl-actions button.cl-btn {
        min-height: 36px;
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }
}

/* --- Phone card layout for balances table (≤640 px) ---------------------- */
/* Scoped to .cl-balances-table so other .cl-table instances are unaffected. */
@media (max-width: 640px) {
    .cl-balances-table-scroll { overflow-x: visible; }
    .cl-balances-table thead { display: none; }
    .cl-balances-table,
    .cl-balances-table tbody,
    .cl-balances-table tr,
    .cl-balances-table td { display: block; }
    .cl-balances-table tbody tr {
        margin: var(--cl-space-3) var(--cl-space-3);
        padding: var(--cl-space-3) var(--cl-space-4);
        border: 1px solid var(--cl-border);
        border-radius: var(--cl-radius);
        background: var(--cl-surface);
        box-shadow: var(--cl-shadow);
    }
    .cl-balances-table tbody tr:hover { background: var(--cl-surface); }
    .cl-balances-table tbody td { padding: var(--cl-space-1) 0; border-bottom: none; }
    /* Hide paid/share columns — values shown in mobile meta line instead */
    .cl-balances-table .cl-td-desktop { display: none !important; }
    /* Group summary rows: pull up to attach visually to the representative card above */
    .cl-balances-table .cl-balances-summary-row {
        margin-top: calc(-1 * var(--cl-space-3) + 2px);
        margin-bottom: var(--cl-space-3);
        border-top: 1px dashed var(--cl-accent);
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        background: var(--cl-accent-soft) !important;
        box-shadow: none;
        padding: var(--cl-space-2) var(--cl-space-4);
    }
    /* The single colspan td in summary row: no extra divider border */
    .cl-balances-table .cl-balances-summary-row td:last-child {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }
    /* Net value: small top margin to separate from member meta line */
    .cl-balances-table td.cl-num { margin-top: var(--cl-space-2); }
    /* Status cell: divider above to separate from net */
    .cl-balances-table td:last-child {
        margin-top: var(--cl-space-2);
        padding-top: var(--cl-space-2);
        border-top: 1px solid var(--cl-border);
    }
}

/* Mobile meta line inside the member cell (hidden on desktop) */
.cl-bal-meta { display: none; }
@media (max-width: 640px) {
    .cl-bal-meta {
        display: block;
        font-size: 12px;
        color: var(--cl-text-muted);
        margin-top: 2px;
    }
}

/* --- Phone card layout for deposits table (≤640 px) ---------------------- */
/* Scoped to .cl-deposits-table so other .cl-table instances are unaffected. */
@media (max-width: 640px) {
    .cl-deposits-table-scroll { overflow-x: visible; }
    .cl-deposits-table thead { display: none; }
    .cl-deposits-table,
    .cl-deposits-table tbody,
    .cl-deposits-table tr,
    .cl-deposits-table td { display: block; }
    .cl-deposits-table tbody tr {
        margin: var(--cl-space-3) var(--cl-space-3);
        padding: var(--cl-space-3) var(--cl-space-4);
        border: 1px solid var(--cl-border);
        border-radius: var(--cl-radius);
        background: var(--cl-surface);
        box-shadow: var(--cl-shadow);
    }
    .cl-deposits-table tbody tr:hover { background: var(--cl-surface); }
    .cl-deposits-table tbody td { padding: 0; border-bottom: none; }
    /* Hide standalone date and note columns — shown in mobile meta line */
    .cl-deposits-table .cl-td-desktop { display: none !important; }
    /* Amount cell: small top margin to separate from member meta line */
    .cl-deposits-table td.cl-num { margin-top: var(--cl-space-2); }
    /* Actions row */
    .cl-deposits-table td:last-child {
        margin-top: var(--cl-space-2);
        padding-top: var(--cl-space-2);
        border-top: 1px solid var(--cl-border);
    }
    .cl-deposits-table .cl-actions { gap: var(--cl-space-2); flex-wrap: wrap; }
    .cl-deposits-table .cl-actions .cl-btn,
    .cl-deposits-table .cl-actions a.cl-btn,
    .cl-deposits-table .cl-actions button.cl-btn {
        min-height: 36px;
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }
}

/* Mobile meta line inside the member cell (hidden on desktop) */
.cl-dep-meta { display: none; }
@media (max-width: 640px) {
    .cl-dep-meta {
        display: block;
        font-size: 12px;
        color: var(--cl-text-muted);
        margin-top: 2px;
    }
}

/* --- Phone card layout for templates table (≤640 px) --------------------- */
/* Scoped to .cl-templates-table so other .cl-table instances are unaffected.*/
@media (max-width: 640px) {
    .cl-templates-table-scroll { overflow-x: visible; }
    .cl-templates-table thead { display: none; }
    .cl-templates-table,
    .cl-templates-table tbody,
    .cl-templates-table tr,
    .cl-templates-table td { display: block; }
    .cl-templates-table tbody tr {
        margin: var(--cl-space-3) var(--cl-space-3);
        padding: var(--cl-space-3) var(--cl-space-4);
        border: 1px solid var(--cl-border);
        border-radius: var(--cl-radius);
        background: var(--cl-surface);
        box-shadow: var(--cl-shadow);
    }
    .cl-templates-table tbody tr:hover { background: var(--cl-surface); }
    .cl-templates-table tbody td { padding: 0; border-bottom: none; }
    /* Hide category/amount/paid_from/split columns — shown in mobile meta line */
    .cl-templates-table .cl-td-desktop { display: none !important; }
    /* Actions row */
    .cl-templates-table td:last-child {
        margin-top: var(--cl-space-2);
        padding-top: var(--cl-space-2);
        border-top: 1px solid var(--cl-border);
    }
    .cl-templates-table .cl-actions { gap: var(--cl-space-2); flex-wrap: wrap; }
    .cl-templates-table .cl-actions .cl-btn,
    .cl-templates-table .cl-actions a.cl-btn,
    .cl-templates-table .cl-actions button.cl-btn {
        min-height: 36px;
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }
}

/* Mobile meta line inside the template name cell (hidden on desktop) */
.cl-tmpl-meta { display: none; }
@media (max-width: 640px) {
    .cl-tmpl-meta {
        display: block;
        font-size: 12px;
        color: var(--cl-text-muted);
        margin-top: 2px;
    }
}

/* --- Mobile button fix for groups page action buttons (≤640 px) ---------- */
@media (max-width: 640px) {
    .cl-groups-actions {
        flex-wrap: wrap;
        gap: var(--cl-space-2);
    }
    .cl-groups-actions .btn {
        min-height: 44px;
        flex: 1 1 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* --- KPI tiles (Apple-style soft surfaces) ------------------------------- */
.cl-kpi {
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    padding: var(--cl-space-4);
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-1);
    box-shadow: var(--cl-shadow);
}
.cl-kpi__label { font-size: 12px; color: var(--cl-text-muted); font-weight: 500; }
.cl-kpi__value { font-size: 22px; font-weight: 700; color: var(--cl-navy); font-variant-numeric: tabular-nums; }
/* 768px == `--cl-tablet-small-min` (static/ui_breakpoints.css). */
@media (min-width: 768px) { .cl-kpi__value { font-size: 28px; } }
.cl-kpi__delta { font-size: 12px; color: var(--cl-text-subtle); }

/* --- Tile (icon + label, tappable) --------------------------------------- */
.cl-tile {
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    padding: var(--cl-space-4);
    min-height: 88px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--cl-space-2);
    text-decoration: none;
    color: inherit;
    transition: transform .15s, box-shadow .15s;
    box-shadow: var(--cl-shadow);
}
.cl-tile:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(15,41,66,.08); }
.cl-tile__icon { font-size: 22px; line-height: 1; opacity: .8; }
.cl-tile__label { font-size: 14px; font-weight: 600; color: var(--cl-text); }

/* --- Hero row (icon + text + arrow) -------------------------------------- */
.cl-hero {
    display: flex;
    align-items: center;
    gap: var(--cl-space-4);
    padding: var(--cl-space-4) var(--cl-space-5);
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    text-decoration: none;
    color: inherit;
    box-shadow: var(--cl-shadow);
    transition: transform .15s, box-shadow .15s;
}
.cl-hero:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(15,41,66,.08); }
.cl-hero__icon { font-size: 26px; line-height: 1; opacity: .85; }
.cl-hero__body { flex: 1 1 auto; min-width: 0; }
.cl-hero__title { font-size: 16px; font-weight: 700; color: var(--cl-navy); margin: 0 0 2px; }
.cl-hero__desc  { font-size: 13px; color: var(--cl-text-muted); margin: 0; }
.cl-hero__chev  { color: var(--cl-text-subtle); font-size: 18px; }

/* --- Fixed action bar ----------------------------------------------------
   Anchored to the viewport. Form reserves matching padding-bottom via
   --cl-actionbar-h (set by cl_shell.js). iOS safe area added on top.
   ----------------------------------------------------------------------- */
.cl-actionbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    padding: var(--cl-space-3) var(--cl-space-4);
    padding-bottom: calc(var(--cl-space-3) + env(safe-area-inset-bottom, 0px));
    background: rgba(255,255,255,.94);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--cl-border);
    display: flex;
    gap: var(--cl-space-3);
    justify-content: flex-end;
    align-items: center;
    box-shadow: 0 -6px 20px rgba(15,41,66,.06);
}
.cl-actionbar > * { flex: 0 0 auto; }
/* 480px is intentionally one-off (narrow actionbar tightening) and not
   centralized in static/ui_breakpoints.css — only thresholds that recur
   across multiple files live there. */
@media (max-width: 480px) {
    .cl-actionbar { gap: var(--cl-space-2); padding-left: var(--cl-space-3); padding-right: var(--cl-space-3); }
    .cl-actionbar .cl-btn { flex: 1 1 auto; min-width: 0; }
}

/* --- Bottom tab bar (mobile only, native iOS look) -----------------------
   Hidden on desktop. Hidden on pages that have a .cl-actionbar (handled by
   cl_shell.js adding body[data-has-actionbar]).
   ----------------------------------------------------------------------- */
.cl-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: none;             /* shown on mobile via media query below */
    background: rgba(255,255,255,.96);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--cl-border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.cl-tabbar__inner {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    height: 56px;
}
.cl-tabbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--cl-text-subtle);
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 2px;
    background: none;
    border: 0;
    cursor: pointer;
    font-family: inherit;
    transition: color .15s;
}
.cl-tabbar__item:hover,
.cl-tabbar__item:focus-visible { color: var(--cl-accent); outline: none; }
.cl-tabbar__icon {
    font-size: 20px;
    line-height: 1;
    opacity: .9;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 24px;
}
.cl-tabbar__icon svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}
.cl-tabbar__item--active { color: var(--cl-accent); }
.cl-tabbar__item--active .cl-tabbar__icon { opacity: 1; }

/* The 1279px literal here MUST equal `--cl-desktop-min - 1px` declared in
   static/ui_breakpoints.css. Pairs with the (min-width: 1280px) sidebar
   block in static/ui_ios_prime.css. */
@media (max-width: 1279px) {
    .cl-tabbar { display: block; }
    /* --cl-tabbar-h already includes safe-area-inset-bottom (the tab bar's own
       padding-bottom: env(...)), measured at runtime — do not double-count. */
    body { padding-bottom: var(--cl-tabbar-h, 56px); }
    /* When an actionbar exists on the page, the tab bar yields. */
    body[data-has-actionbar="1"] .cl-tabbar { display: none; }
    body[data-has-actionbar="1"] { padding-bottom: 0; }

    /* Keep browser focus scrolling clear of whichever fixed bottom bar is
       present. Heights are measured by cl_shell.js and include safe-area. */
    html {
        scroll-padding-block-end: calc(max(var(--cl-tabbar-h, 0px), var(--cl-actionbar-h, 0px)) + 12px);
    }
}

/* Deposits entry is a short, page-specific form; keep its submit control above
   the fixed tab bar on a phone without changing the shared form/card system. */
@media (max-width: 640px) {
    .cl-page:has(form[action="/deposits/new"]) .cl-card {
        padding: var(--cl-space-4);
    }
    .cl-page:has(form[action="/deposits/new"]) form[action="/deposits/new"] {
        gap: var(--cl-space-2);
    }
    .cl-page:has(form[action="/deposits/new"]) form[action="/deposits/new"] .cl-grid--3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--cl-space-2) var(--cl-space-3);
    }
    .cl-page:has(form[action="/deposits/new"]) form[action="/deposits/new"] .cl-field .cl-label {
        min-height: 0;
    }
    .cl-page:has(form[action="/deposits/new"]) form[action="/deposits/new"] .cl-grid--3 > .cl-field:first-child,
    .cl-page:has(form[action="/deposits/new"]) form[action="/deposits/new"] .cl-grid--3 > .cl-field:nth-child(4) {
        grid-column: 1 / -1;
    }
    .cl-page:has(form[action="/deposits/new"]) form[action="/deposits/new"] .cl-card__footer {
        margin-top: 0;
    }
    .cl-page:has(form[action="/deposits/new"]) form[action="/deposits/new"] :is(input, select, button[type="submit"]) {
        scroll-margin-block-end: calc(max(var(--cl-tabbar-h, 0px), var(--cl-actionbar-h, 0px)) + 12px);
    }
}

/* --- Compatibility shims for legacy JS hooks ----------------------------- */
.cl-entry .move-up-btn[disabled],
.cl-entry .move-down-btn[disabled] { opacity: .35; cursor: not-allowed; pointer-events: none; }

/* --- Night mode adjustments for cl-* surfaces ---------------------------- */
html[data-theme="night"] .cl-actionbar {
    background: rgba(20, 0, 0, .85);
    border-top-color: rgba(255, 90, 90, .25);
}
html[data-theme="night"] .cl-tabbar {
    background: rgba(20, 0, 0, .9);
    border-top-color: rgba(255, 90, 90, .25);
}
html[data-theme="night"] .cl-tabbar__item { color: rgba(255, 80, 80, .55); }
html[data-theme="night"] .cl-tabbar__item--active,
html[data-theme="night"] .cl-tabbar__item:hover { color: rgba(255, 80, 80, .95); }

/* --- Collapsible logbook entry row (compact list, Phase 2) --------------- */
.cl-entry-collapse {
    background: var(--cl-surface-2);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    overflow: hidden;
}
.cl-entry-collapse__summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--cl-space-2);
    padding: var(--cl-space-3) var(--cl-space-4);
    cursor: pointer;
    font-size: 14px;
    color: var(--cl-text);
}
.cl-entry-collapse__summary::-webkit-details-marker { display: none; }
.cl-entry-collapse__chevron {
    display: inline-block;
    transition: transform .15s ease;
    color: var(--cl-text-subtle);
    flex-shrink: 0;
}
.cl-entry-collapse[open] > .cl-entry-collapse__summary .cl-entry-collapse__chevron {
    transform: rotate(90deg);
}
.cl-entry-collapse__time { font-weight: 700; color: var(--cl-navy); flex-shrink: 0; }
.cl-entry-collapse__icon { flex-shrink: 0; }
.cl-entry-collapse__route {
    color: var(--cl-accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.cl-entry-collapse__preview {
    color: var(--cl-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.cl-entry-collapse__badge { margin-left: auto; flex-shrink: 0; }
.cl-entry-collapse__body {
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-4);
    padding: 0 var(--cl-space-4) var(--cl-space-4);
    border-top: 1px solid var(--cl-border);
    padding-top: var(--cl-space-4);
}

/* --- Leg group header within the day-grouped logbook list ---------------- */
.cl-leg-header {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--cl-accent);
    padding: var(--cl-space-2) var(--cl-space-1) 0;
}
.cl-leg-header--muted { color: var(--cl-text-subtle); }

/* --- Topbar back button -------------------------------------------------- */
.topbar-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 32px;
    padding: 0 10px;
    border-radius: 7px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #1a2e44;
    background: #f5a623;
    background: linear-gradient(135deg, #f5c842 0%, #f5a623 100%);
    box-shadow: 0 1px 4px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.25);
    transition: opacity 0.15s, transform 0.1s;
    flex-shrink: 0;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.topbar-back-btn:hover  { opacity: 0.88; }
.topbar-back-btn:active { transform: scale(0.95); opacity: 0.8; }
.topbar-back-btn svg    { flex-shrink: 0; }

/* ==========================================================================
   Trips — two-view switcher (Cards / Log)
   ========================================================================== */

/* ── Section header with toggle ─────────────────────────────────────── */
.cl-trips-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cl-space-3);
    flex-wrap: wrap;
    padding: var(--cl-space-4) var(--cl-space-5);
    background: var(--cl-surface-2);
    border-bottom: 1px solid var(--cl-border);
}
.cl-trips-toggle {
    display: flex;
    align-items: center;
    background: var(--cl-border);
    border-radius: 10px;
    padding: 2px;
    gap: 2px;
    flex-shrink: 0;
}
.cl-trips-toggle__btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 13px;
    border-radius: 8px;
    border: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--cl-text-subtle);
    background: transparent;
    transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}
.cl-trips-toggle__btn.is-active {
    background: var(--cl-surface);
    color: var(--cl-accent);
    box-shadow: 0 1px 3px rgba(15,41,66,.10);
}
.cl-trips-toggle__btn svg { flex-shrink: 0; }

/* ── View show/hide ─────────────────────────────────────────────────── */
#cl-trips-view-wrap[data-view="cards"] .cl-trv-log  { display: none; }
#cl-trips-view-wrap[data-view="log"]   .cl-trv-cards { display: none; }

/* ── Cards view container ───────────────────────────────────────────── */
.cl-trv-cards { padding: var(--cl-space-4) var(--cl-space-4) var(--cl-space-5); }

/* ── Hero (featured voyage) card ────────────────────────────────────── */
.cl-trv-hero {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    padding: 24px 22px 22px;
    min-height: 220px;
    margin-bottom: var(--cl-space-5);
    color: #fff;
    background: linear-gradient(148deg, #0d2742 0%, #163d68 55%, #1e4f80 100%);
    box-shadow: 0 8px 32px rgba(13,39,66,.30), 0 2px 8px rgba(13,39,66,.20);
}
/* Decorative rings */
.cl-trv-hero::before,
.cl-trv-hero::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.07);
    pointer-events: none;
}
.cl-trv-hero::before { right: -30px; top: -50px; width: 200px; height: 200px; }
.cl-trv-hero::after  { right: -55px; top:  10px; width: 250px; height: 250px; border-color: rgba(255,255,255,.04); }

/* Wave animation container */
.cl-trv-hero-waves {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 90px;
    overflow: hidden;
    border-radius: 0 0 20px 20px;
    pointer-events: none;
}
.cl-trv-hero-wave {
    position: absolute;
    bottom: 0; left: 0;
    height: 100%;
    width: 200%;
    fill: white;
}
@keyframes cl-trv-wave1 { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@keyframes cl-trv-wave2 { from { transform: translateX(-50%); } to { transform: translateX(0); } }
@keyframes cl-trv-wave3 { from { transform: translateX(-20%); } to { transform: translateX(-70%); } }
.cl-trv-hero-wave--1 { animation: cl-trv-wave1  9s linear infinite; opacity: .18; }
.cl-trv-hero-wave--2 { animation: cl-trv-wave2 13s linear infinite; opacity: .13; }
.cl-trv-hero-wave--3 { animation: cl-trv-wave3 17s linear infinite; opacity: .09; }

/* Sailboat watermark */
.cl-trv-hero-boat {
    position: absolute;
    right: 28px;
    bottom: 38px;
    opacity: .22;
    pointer-events: none;
}
@keyframes cl-trv-boat {
    0%   { transform: translateY(0)    rotate(-1deg); }
    30%  { transform: translateY(-7px) rotate(1.2deg); }
    60%  { transform: translateY(-4px) rotate(-0.8deg); }
    100% { transform: translateY(0)    rotate(-1deg); }
}
.cl-trv-hero-boat svg { animation: cl-trv-boat 7s ease-in-out infinite; }

/* Hero content (above waves) */
.cl-trv-hero-content { position: relative; z-index: 1; }
.cl-trv-hero-eyebrow {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
}
.cl-trv-hero-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .2em;
    color: rgba(186,216,255,.7);
}
.cl-trv-hero-date {
    font-size: 11px;
    color: rgba(255,255,255,.5);
    margin-top: 4px;
}
.cl-trv-hero-name {
    font-size: 30px;
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -.04em;
    color: #fff;
    margin: 0 0 6px;
}
.cl-trv-hero-route {
    font-size: 11px;
    color: rgba(255,255,255,.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 18px;
}
.cl-trv-hero-stats {
    display: flex;
    gap: 24px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,.12);
}
.cl-trv-hero-stat-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .18em;
    color: rgba(255,255,255,.45);
    margin-bottom: 3px;
}
.cl-trv-hero-stat-value {
    font-size: 22px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -.04em;
    color: #fff;
}
.cl-trv-hero-stat-unit {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255,255,255,.5);
    margin-left: 2px;
}

/* Status badge — dark pill for use on the hero card */
.cl-trv-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 10px;
    padding: 5px 10px;
    font-size: 9.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .14em;
    white-space: nowrap;
    border: 1px solid transparent;
}
.cl-trv-badge--active   { background: rgba(16,185,129,.12); border-color: rgba(52,211,153,.20); color: #34d399; }
.cl-trv-badge--archived { background: rgba(150,168,200,.12); border-color: rgba(150,168,200,.20); color: #94a3b8; }
.cl-trv-badge--closed   { background: rgba(239,68,68,.12);   border-color: rgba(239,68,68,.20);  color: #f87171; }

/* ── Card list ──────────────────────────────────────────────────────── */
.cl-trv-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cl-trv-card {
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    box-shadow: var(--cl-shadow);
    padding: 14px 16px;
    transition: box-shadow 140ms ease;
}
.cl-trv-card:active { box-shadow: none; }
.cl-trv-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.cl-trv-card-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--cl-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cl-trv-card-date {
    font-size: 11px;
    color: var(--cl-text-subtle);
    margin-top: 2px;
}
.cl-trv-card-divider {
    height: 1px;
    background: var(--cl-border);
    margin: 10px 0;
}
.cl-trv-card-bottom {
    display: flex;
    align-items: center;
    gap: var(--cl-space-4);
}
.cl-trv-card-stat {
    display: flex;
    align-items: baseline;
    gap: 3px;
}
.cl-trv-card-stat-val {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -.03em;
    color: var(--cl-text);
}
.cl-trv-card-stat-unit {
    font-size: 10px;
    font-weight: 600;
    color: var(--cl-text-subtle);
}
.cl-trv-card-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

/* ── Log view wrapper ───────────────────────────────────────────────── */
.cl-trv-log .cl-table-scroll { margin: 0; }

/* ── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .cl-trv-hero-wave,
    .cl-trv-hero-boat svg { animation: none; }
}

/* ==========================================================================
   HarborDeck Maritime Dark — page heroes, row cards, spacing
   ========================================================================== */

/* ── Wave gradient hero on every .cl-pageheader ─────────────────────────── */
.cl-pageheader {
    background: linear-gradient(148deg, #071929 0%, #0c3260 52%, #1455a8 100%);
    margin: calc(-1 * var(--cl-space-6)) calc(-1 * var(--cl-space-4)) 0;
    padding: 36px var(--cl-space-4) 64px;
    position: relative;
    overflow: hidden;
    align-items: flex-end;
    border-radius: 0;
}
@media (min-width: 768px) {
    .cl-pageheader {
        margin: calc(-1 * var(--cl-space-7)) calc(-1 * var(--cl-space-5)) 0;
        padding: 52px var(--cl-space-5) 80px;
    }
}
/* wave cutout at the bottom edge */
.cl-pageheader::after {
    content: '';
    position: absolute;
    bottom: -1px; left: -5%; right: -5%;
    height: 52px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 52'%3E%3Cpath d='M0,26 C240,52 480,0 720,26 C960,52 1200,0 1440,26 L1440,52 L0,52 Z' fill='%230b1d2e'/%3E%3C/svg%3E") center bottom / 100% 52px no-repeat;
    pointer-events: none;
}
/* radial shimmer accent */
.cl-pageheader::before {
    content: '';
    position: absolute;
    top: -40%; right: -10%;
    width: 55%; height: 200%;
    background: radial-gradient(ellipse at center, rgba(61,154,212,0.13) 0%, transparent 70%);
    pointer-events: none;
}
/* text + button colours on the dark hero */
.cl-pageheader .cl-title {
    color: #ffffff;
    text-shadow: 0 1px 6px rgba(0,0,0,0.5);
    position: relative; z-index: 1;
}
.cl-pageheader .cl-subtitle { color: rgba(200,228,255,0.75); position: relative; z-index: 1; }
.cl-pageheader .cl-pageheader__main,
.cl-pageheader .cl-pageheader__actions { position: relative; z-index: 1; }
.cl-pageheader .cl-btn--primary {
    background: rgba(255,255,255,0.92);
    border-color: transparent;
    color: #071929;
    font-weight: 600;
    backdrop-filter: none;
}
.cl-pageheader .cl-btn--primary:hover {
    background: #ffffff;
    border-color: transparent;
    color: #071929;
}
/* ── Hero button variants (inside .cl-pageheader wave gradient) ──────────── */
/* Primary: solid white chip — maximum contrast, unmissable CTA              */
.cl-hero-btn--primary {
    background: rgba(255, 255, 255, 0.95) !important;
    border: 1.5px solid transparent !important;
    color: #071929 !important;
    font-weight: 700 !important;
}
.cl-hero-btn--primary:hover {
    background: #ffffff !important;
    color: #071929 !important;
}
/* Secondary: dark navy overlay — sits below the gradient, white text forced  */
.cl-hero-btn--secondary {
    background: rgba(5, 18, 35, 0.60) !important;
    border: 1.5px solid rgba(255, 255, 255, 0.35) !important;
    color: #ffffff;
    font-weight: 500 !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
}
.cl-hero-btn--secondary:hover {
    background: rgba(5, 18, 35, 0.80) !important;
    border-color: rgba(255, 255, 255, 0.55) !important;
    color: #ffffff;
}
/* Destructive action in the hero: clear danger affordance without using
   the bright success/primary fills reserved for safe actions. */
.cl-hero-btn--danger {
    background: rgba(110, 24, 35, 0.48) !important;
    border: 1.5px solid rgba(255, 132, 145, 0.48) !important;
    color: #ffb4bc !important;
    font-weight: 700 !important;
}
.cl-hero-btn--danger:hover {
    background: rgba(150, 28, 43, 0.72) !important;
    border-color: rgba(255, 173, 182, 0.78) !important;
    color: #ffffff !important;
}

/* Photo upload controls use the same dark-glass language as card actions.
   Disabled upload remains visibly actionable but cannot be mistaken for a
   completed upload. */
.cl-photo-panel {
    border-color: rgba(87, 151, 211, 0.48);
}
.cl-photo-source-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--cl-space-2);
}
.cl-photo-source-btn {
    width: 100%;
}
.cl-photo-upload-btn {
    min-width: 160px;
}
.cl-photo-upload-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    filter: saturate(.65);
}
.cl-photo-submit {
    display: flex;
    justify-content: flex-start;
}

@media (max-width: 560px) {
    .cl-photo-source-actions {
        grid-template-columns: 1fr;
    }
    .cl-photo-submit .cl-photo-upload-btn {
        width: 100%;
    }
}

/* Legacy fallback — keep secondary/ghost in pageheader readable if used elsewhere */
.cl-pageheader .cl-btn--secondary,
.cl-pageheader .cl-btn--ghost,
.cl-pageheader .cl-btn--accent {
    background: rgba(5, 18, 35, 0.60);
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    color: #ffffff !important;
}

/* ── Row cards (replaces tables) ─────────────────────────────────────────── */
.cl-row-list {
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-2);
}
.cl-row-card--wrap {
    display: flex;
    flex-direction: column;
}
.cl-row-card--wrap .cl-row-card {
    border-radius: var(--cl-radius) var(--cl-radius) 0 0;
    border-bottom-color: transparent;
}
.cl-row-card {
    display: flex;
    align-items: center;
    gap: var(--cl-space-3);
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius);
    padding: var(--cl-space-3) var(--cl-space-4);
    text-decoration: none;
    color: var(--cl-text);
    transition: background 0.14s, border-color 0.14s;
}
.cl-row-card:hover {
    background: var(--cl-surface-2);
    border-color: var(--cl-border-strong);
    text-decoration: none;
    color: var(--cl-text);
}
.cl-row-card__foot {
    display: flex;
    gap: var(--cl-space-2);
    padding: 5px var(--cl-space-3) 7px;
    background: var(--cl-surface);
    border: 1px solid var(--cl-border);
    border-top: none;
    border-radius: 0 0 var(--cl-radius) var(--cl-radius);
}
.cl-row-card__main { flex: 1 1 auto; min-width: 0; }
.cl-row-card__title {
    font-weight: 600;
    font-size: 15px;
    color: var(--cl-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cl-row-card__meta {
    font-size: 12px;
    color: var(--cl-text-muted);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cl-row-card__aside {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    text-align: right;
}
.cl-row-card__amount {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--cl-text);
}
/* semantic amount colours */
.cl-row-card--expense   .cl-row-card__amount { color: var(--cl-danger); }
.cl-row-card--deposit   .cl-row-card__amount { color: var(--cl-success); }
.cl-row-card--balance-positive .cl-row-card__amount { color: var(--cl-success); }
.cl-row-card--balance-negative .cl-row-card__amount { color: var(--cl-danger); }
.cl-row-card--balance-even     .cl-row-card__amount { color: var(--cl-text-muted); }

/* ── Body / page background ──────────────────────────────────────────────── */
body { background: var(--cl-bg); }

/* ── Pill size modifier ──────────────────────────────────────────────────── */
.cl-pill--sm {
    font-size: 11px;
    padding: 2px 8px;
    height: 20px;
    line-height: 1;
}

/* ── Pill info colour (neutral/blue) ─────────────────────────────────────── */
.cl-pill--info {
    background: rgba(61,154,212,0.18);
    color: #7ecdf5;
    border-color: transparent;
}

/* ── Logbook: day-section wrapper ────────────────────────────────────────── */
.cl-day-section {
    display: flex;
    flex-direction: column;
    gap: var(--cl-space-3);
}

/* ── Logbook: day-group header bar ───────────────────────────────────────── */
.cl-day-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cl-space-3);
    padding: var(--cl-space-2) var(--cl-space-1);
    border-bottom: 1px solid var(--cl-border);
    margin-bottom: var(--cl-space-1);
    flex-wrap: wrap;
}
.cl-day-header__left {
    display: flex;
    align-items: center;
    gap: var(--cl-space-3);
    min-width: 0;
}
.cl-day-header__num {
    font-size: 36px;
    font-weight: 800;
    line-height: 1;
    color: var(--cl-accent);
    letter-spacing: -0.03em;
    min-width: 2ch;
    text-align: center;
}
.cl-day-header__info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cl-day-header__month {
    font-size: 13px;
    font-weight: 600;
    color: var(--cl-text);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cl-day-header__count {
    font-size: 11px;
    color: var(--cl-text-subtle);
}
.cl-day-header__link {
    flex-shrink: 0;
}

/* ── Logbook: entry expand/collapse (overrides + extensions) ─────────────── */
.cl-entry-collapse__time {
    font-weight: 700;
    color: var(--cl-text);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    min-width: 3.5ch;
}
.cl-entry-collapse__summary {
    gap: var(--cl-space-3);
}
.cl-entry-collapse:hover > .cl-entry-collapse__summary {
    background: var(--cl-surface-hover, rgba(255,255,255,0.04));
    border-radius: var(--cl-radius) var(--cl-radius) 0 0;
}

/* ── Logbook: entry photo thumbnail ─────────────────────────────────────── */
.cl-entry-photo {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: var(--cl-radius-sm);
    cursor: pointer;
    flex-shrink: 0;
    border: 1px solid var(--cl-border);
}

/* ── Logbook: entry data grid (position / wind / sea / temp / nm) ────────── */
.cl-entry-data-grid {
    display: grid;
    /* 130px minimum: fits 2 columns on iPhone SE (375px) and wider. */
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: var(--cl-space-2);
}
.cl-entry-data-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--cl-surface-2);
    border: 1px solid var(--cl-border);
    border-radius: var(--cl-radius-sm);
    padding: var(--cl-space-2) var(--cl-space-3);
}
.cl-entry-data-cell__label {
    font-size: 11px;
    color: var(--cl-text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cl-entry-data-cell__value {
    font-size: 14px;
    font-weight: 600;
    color: var(--cl-text);
    word-break: break-word;
}
.cl-entry-data-cell__value--accent {
    color: var(--cl-accent);
}

/* ── Logbook: watch crew row ─────────────────────────────────────────────── */
.cl-entry-watch {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.cl-entry-watch__label {
    font-size: 12px;
    color: var(--cl-text-subtle);
}

/* ── Logbook: notes block ────────────────────────────────────────────────── */
.cl-entry-notes {
    background: rgba(255,255,255,0.04);
    border-left: 3px solid var(--cl-accent);
    border-radius: 0 var(--cl-radius-sm) var(--cl-radius-sm) 0;
    padding: var(--cl-space-3) var(--cl-space-4);
    font-size: 14px;
    color: var(--cl-text);
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ── Logbook detail: narrow viewport safeguards ──────────────────────────── */
.logbook-detail-wrapper {
    min-width: 0;
}
.logbook-detail-wrapper .cl-subtitle {
    overflow-wrap: anywhere;
}
.logbook-detail-wrapper .cl-entry-data-grid {
    /* The detail page has nested main + page/card padding on small screens.
       120px keeps two compact values side by side even at 375px. */
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.cl-photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--cl-space-3);
    min-width: 0;
}
.cl-entry-photo-card {
    min-width: 0;
}
.cl-entry-photo-card p {
    overflow-wrap: anywhere;
}
.cl-entry-photo-image {
    max-width: 100%;
}

/* ── Page nav strip (secondary actions below the wave hero) ──────────────── */
/* Lives on the flat dark body — never inside the gradient. Always readable.  */
.cl-page-nav {
    display: flex;
    gap: var(--cl-space-2);
    flex-wrap: wrap;
    margin-bottom: var(--cl-space-5);
}
.cl-page-nav__link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 var(--cl-space-4);
    border-radius: var(--cl-radius);
    border: 1.5px solid rgba(255, 255, 255, 0.30);
    background: rgba(255, 255, 255, 0.10);
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease;
}
.cl-page-nav__link:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.50);
    color: #ffffff;
    text-decoration: none;
}
/* Day-mode: dark text on light chip */
html[data-theme="day"] .cl-page-nav__link {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #1e293b;
}
html[data-theme="day"] .cl-page-nav__link:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
    color: #1e293b;
}

/* ── Empty state (used on logbook and other zero-data pages) ─────────────── */
.cl-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--cl-space-3);
    text-align: center;
    padding: var(--cl-space-8) var(--cl-space-5);
}
.cl-empty-state__icon {
    font-size: 48px;
    line-height: 1;
}
.cl-empty-state__title {
    font-size: 20px;
    font-weight: 700;
    color: var(--cl-navy);
    margin: 0;
}
.cl-empty-state__desc {
    font-size: 14px;
    color: var(--cl-text-muted);
    max-width: 40ch;
    margin: 0;
}
