/* Flight log, ported from /opt/flugbuch's ledger view.
 *
 * Every colour comes from the theme variables in theme.css, so the ledger reads
 * as parchment in the light theme and as the app's own surfaces in the dark one.
 * Card classes are prefixed fb- because the app already owns .card. */

.ldg-paper {
    position: relative;
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    box-shadow: 0 1px 0 rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .18);
    /* No overflow clipping and no radius: `overflow: hidden` on an ancestor
       silently disables position: sticky, so the column header would scroll
       away with the rows. Square corners suit a ledger page anyway. */
}

/* Foxing stain on the page itself */
.ldg-paper::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='800' height='500'%3E%3Cfilter id='s' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.06' numOctaves='3' seed='9'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.48 0 0 0 0 0.24 0 0 0 0 0.04 0 0 0 1.6 -1.5'/%3E%3C/filter%3E%3Crect width='800' height='500' filter='url(%23s)'/%3E%3C/svg%3E");
    background-size: 100% 100%;
    mix-blend-mode: multiply;
    opacity: var(--paper-texture);
    pointer-events: none;
    z-index: 1;
}

.ldg-paper::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: var(--paper-inner-shadow);
    pointer-events: none;
    z-index: 2;
}

.ldg-paper > * { position: relative; z-index: 3; }

.ldg-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--serif);
    font-size: .92rem;
    color: var(--ink);
    --ldg-pad-x: .55rem;
    --ldg-edge: .9rem;
}

.ldg-table thead th {
    /* Colour and gradient set separately, not via the `background` shorthand:
       the shorthand leaves background-color transparent, so the gradient is the
       only thing painting and anything that stops it rendering lets the rows
       scroll through visibly. */
    background-color: var(--paper-deep);
    background-image: linear-gradient(180deg, var(--paper-soft) 0%, var(--paper-deep) 100%);
    color: var(--ink-soft);
    font-family: inherit;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    text-align: left;
    vertical-align: middle;
    padding: .7rem var(--ldg-pad-x);
    position: sticky;
    /* Clears the top nav where there is one; see --nav-top-h in app.css. */
    top: var(--nav-top-h, 0px);
    /* The rule is an inset shadow, not a border. Under `border-collapse:
       collapse` a border belongs to the table rather than the cell, so it stays
       behind when the cell sticks — leaving a 2px line the rows show through.
       An inset shadow is painted by the cell and travels with it. */
    box-shadow: inset 0 -2px 0 var(--rule), 0 2px 6px rgba(0, 0, 0, .18);
    white-space: nowrap;
    z-index: 5;
}

.ldg-table thead th:first-child { padding-left: var(--ldg-edge); }
.ldg-table thead th:last-child { padding-right: var(--ldg-edge); }

.ldg-row {
    cursor: pointer;
    transition: background-color .08s ease-out;
}

.ldg-row:hover { background: var(--row-hover) !important; }
.ldg-row:focus { outline: none; background: var(--row-hover) !important; }

.ldg-row td {
    height: 2.15rem;
    padding: .12rem var(--ldg-pad-x);
    border-bottom: 1px solid var(--rule-faint);
    vertical-align: middle;
    line-height: 1.3;
}

.ldg-row td:first-child { padding-left: var(--ldg-edge); }
.ldg-row td:last-child { padding-right: var(--ldg-edge); }
.ldg-row.is-odd { background: var(--row-stripe); }

/* Only free-text columns may wrap, so the table shrinks to fit rather than
   overflowing — without splitting a name like "Heimann, T." across lines. */
.ldg-c-nr, .ldg-c-date, .ldg-c-reg, .ldg-c-time, .ldg-c-dur,
.ldg-c-pilot, .ldg-c-fi {
    white-space: nowrap;
}

.ldg-c-nr {
    width: 2.6rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-faint);
    font-size: .8rem;
    text-align: right;
}

.ldg-c-date { font-variant-numeric: tabular-nums; font-weight: 600; }

.ldg-c-reg {
    font-family: var(--mono);
    font-size: .82rem;
    font-weight: 600;
    letter-spacing: .04em;
    color: var(--ink-mid);
}

.ldg-c-type { font-weight: 600; }
.ldg-c-time, .ldg-c-dur { font-variant-numeric: tabular-nums; }
.ldg-c-dur { font-weight: 700; }
.ldg-arrow { color: var(--ink-faint); margin: 0 .15rem; }
.ldg-dash { color: var(--ink-faint); }

/* Section header rows (one per month) */
.ldg-section td {
    padding: .55rem var(--ldg-edge) .4rem;
    background: var(--section-bg);
    border-bottom: 1px solid var(--rule);
    border-top: 1px solid var(--rule);
    font-family: var(--serif);
    color: var(--ink-soft);
}

.ldg-sec-wrap,
.ldg-grand-wrap {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.ldg-sec-label {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -.01em;
    color: var(--ink);
}

.ldg-sec-meta {
    font-size: .88rem;
    font-style: italic;
    font-variant-numeric: tabular-nums;
}

.ldg-grand td {
    background: var(--paper-deep);
    border-top: 2px solid var(--rule);
    padding: .6rem var(--ldg-edge);
}

.ldg-grand-wrap { font-family: var(--serif); }

.ldg-grand-label {
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--ink-soft);
    font-size: .85rem;
    font-weight: 700;
}

.ldg-grand-meta {
    color: var(--ink);
    font-weight: 700;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

/* ===== Flight card modal ===== */

body.ldg-no-scroll { overflow: hidden; }

.ldg-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.ldg-modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--scrim);
}

.ldg-modal-panel {
    position: relative;
    width: min(420px, 100%);
    max-height: calc(100dvh - 3rem);
    overflow-y: auto;
    cursor: pointer;
}

.fb-card {
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25), 0 18px 36px rgba(0, 0, 0, .25);
    overflow: hidden;
    color: var(--ink);
    font-family: var(--serif);
}

.fb-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    padding: .75rem .9rem .6rem;
    border-bottom: 1px solid var(--rule-faint);
}

.fb-card-reg {
    font-family: var(--mono);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: .04em;
}

.fb-card-type {
    font-size: .9rem;
    color: var(--ink-soft);
}

.fb-card-head-r {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .35rem;
}

.fb-date-badge {
    background: var(--badge-bg);
    color: var(--badge-ink);
    border-radius: 3px;
    padding: .1rem .4rem;
    font-size: .78rem;
    font-variant-numeric: tabular-nums;
}

.fb-duration-pill {
    background: var(--pill-bg);
    color: var(--pill-ink);
    border-radius: 999px;
    padding: .1rem .55rem;
    font-size: .85rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.fb-card-photo {
    background: var(--paper-deep);
    border-bottom: 1px solid var(--rule-faint);
}

.fb-card-photo img {
    display: block;
    width: 100%;
    height: auto;
    filter: var(--photo-filter);
}

.fb-card-photo-fallback {
    padding: 1.75rem .9rem;
    text-align: center;
    color: var(--ink-faint);
}

.fb-card-photo-fallback .type {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink-soft);
}

.fb-card-stats { padding: .5rem .9rem .8rem; }

.fb-stat-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: .28rem 0;
    border-bottom: 1px solid var(--rule-faint);
}

.fb-stat-row:last-child { border-bottom: none; }

.fb-stat-label {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-faint);
}

.fb-stat-val { text-align: right; }
.fb-stat-val .sub { color: var(--ink-faint); }

/* ===== Responsive column cascade =====
   Columns drop from the lowest priority up as the viewport narrows:
   Flugart → Startart → Bem. → Platz → Pilot/Begleitung → Start/Land → Dauer → Typ.
   Startart outlives Flugart: how a flight got airborne varies flight to flight,
   where the flight type is near-constant down a page of training flights. */

@media (max-width: 1260px) { .ldg-c-fart, thead th.ldg-c-fart { display: none; } }
@media (max-width: 1180px) { .ldg-c-sart, thead th.ldg-c-sart { display: none; } }
@media (max-width: 1060px) { .ldg-c-rem, thead th.ldg-c-rem { display: none; } }
@media (max-width: 950px) { .ldg-c-route, thead th.ldg-c-route { display: none; } }
@media (max-width: 840px) {
    .ldg-c-pilot, thead th.ldg-c-pilot { display: none; }
    .ldg-c-fi, thead th.ldg-c-fi { display: none; }
}

@media (max-width: 700px) {
    .ldg-c-time, thead th.ldg-c-time { display: none; }

    .ldg-table { font-size: .84rem; --ldg-pad-x: .42rem; --ldg-edge: .6rem; }
    .ldg-table thead th { font-size: .7rem; padding: .6rem var(--ldg-pad-x); }
    .ldg-topbar { font-size: .82rem; padding: 0 .6rem; }
    .ldg-sec-label { font-size: 1rem; }
    .ldg-sec-meta { font-size: .8rem; }

    /* Push duration to the right edge so the row spans the width. */
    .ldg-c-dur, thead th.ldg-c-dur { text-align: right; }
}

@media (max-width: 360px) { .ldg-c-dur, thead th.ldg-c-dur { display: none; } }
@media (max-width: 300px) { .ldg-c-type, thead th.ldg-c-type { display: none; } }

/* Reconstructed OGN track, shown in the flight card when position data reaches
   that flight. Hidden until the fetch succeeds — most of the logbook predates
   the position history, and an empty map frame would be worse than nothing. */
.fb-track {
    border-top: 1px solid var(--rule-faint);
    padding: .6rem .9rem .7rem;
}

.fb-track-map {
    height: 190px;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--paper-edge);
    background: var(--paper-deep);
}

.fb-track-map .leaflet-container {
    height: 100%;
    width: 100%;
    background: var(--paper-deep);
    font-family: inherit;
}

.fb-track-meta {
    margin-top: 0 !important;
    margin-top: .4rem;
    font-size: .8rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-soft);
    text-align: right;
}

/* Playback control under the reconstructed track. */
/* Control and clock on one line, the flight's summary on its own below — on a
   phone the summary is long enough to wrap into the clock otherwise. */
.fb-track-foot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    margin-top: 0.5rem;
}

.fb-track-foot .fb-track-meta {
    flex: 1 1 100%;
    order: 3;
}

/* The two ways out of the card: the flight as a file, and the flight looping on
   the display. Both are links rather than buttons because both go somewhere.
   They ride the transport's row, to the right of the clock — sharing the
   summary's row instead only made the summary wrap in a card this narrow. */
.fb-track-link {
    flex: 0 0 auto;
    order: 2;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    line-height: 1.25;
    color: var(--ink);
    background: var(--paper-soft);
    border: 1px solid var(--rule);
    border-radius: 999px;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.fb-track-link:active { opacity: 0.6; }

.fb-track-play {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    padding: 0;
    font-size: 0.8rem;
    line-height: 1;
    color: var(--ink);
    background: var(--paper-soft);
    border: 1px solid var(--rule);
    border-radius: 50%;
    cursor: pointer;
}

.fb-track-play:active { opacity: 0.6; }

.fb-track-clock {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-size: 0.75rem;
    color: var(--ink-faint);
}
