/* Sail Analyzer */
:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #0f1b2d; --muted: #5b6b80; --line: #dde3ea;
  --accent: #0b5cad; --accent-ink: #fff; --accent-soft: #e6f0fa;
  --ok: #157f3b; --ok-bg: #e7f6ec; --err: #b42318; --err-bg: #fdecea; --info-bg: #eef4fb; --warn: #b54708;
  --radius: 10px; --shadow: 0 1px 2px rgba(15,27,45,.06), 0 2px 8px rgba(15,27,45,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1520; --panel: #142030; --ink: #e6edf5; --muted: #93a3b8; --line: #24344a;
    --accent: #4ea1f3; --accent-ink: #06121f; --accent-soft: #16304d;
    --ok: #5fd08a; --ok-bg: #12301f; --err: #ff8a7a; --err-bg: #3a1714; --info-bg: #15283d; --warn: #f5a35c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }
h3 { font-size: .95rem; margin: 0 0 .4rem; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { color: var(--warn); font-weight: 600; font-size: .9rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem 1.25rem; background: #0f2742; color: #fff; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { color: #cfe0f3; padding: .35rem .7rem; border-radius: 6px; }
.topbar nav a:hover, .topbar nav a.on { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.topbar nav a.muted { color: #8fa9c6; }

.main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.main-full { padding: 0; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.back { font-size: .85rem; display: inline-block; margin-bottom: .2rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.narrow, .narrow { max-width: 640px; }
.card.empty { text-align: center; padding: 2rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.cards.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.cards .card { margin: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .9rem; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--err); border-color: var(--err); background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .82rem; }
.btn:disabled { opacity: .6; cursor: wait; }

.form label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; color: var(--muted); margin-bottom: .75rem; }
.form.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form .span2 { grid-column: span 2; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: .45rem .6rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=file] { padding: .35rem; background: transparent; }
@media (max-width: 600px) { .form.grid2 { grid-template-columns: 1fr; } .form .span2 { grid-column: span 1; } }

.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.flash.info { background: var(--info-bg); color: var(--ink); }
pre.err { white-space: pre-wrap; background: var(--err-bg); color: var(--err); padding: .6rem; border-radius: 6px; }
.danger-zone { margin-top: 1rem; }

dl.mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .8rem 0; }
dl.mini.wide { grid-template-columns: repeat(4, 1fr); }
dl.mini div { background: var(--bg); border-radius: 7px; padding: .4rem .6rem; }
dl.mini dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
dl.mini dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

table.list { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.list th, table.list td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
table.list th { color: var(--muted); font-weight: 500; font-size: .8rem; }
table.list tr.dim td { color: var(--muted); }
.card .list { margin-bottom: .8rem; }
.card:has(table.list) { overflow-x: auto; }
ul.plain { list-style: none; padding: 0; }
ol.steps { text-align: left; display: inline-block; }

.year { color: var(--muted); font-weight: 600; }
.eventlist { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.event-row { display: grid; grid-template-columns: 150px 1fr 140px 130px 110px auto; gap: .75rem; align-items: center; padding: .65rem 1rem; border-bottom: 1px solid var(--line); color: var(--ink); }
.event-row:last-child { border-bottom: 0; }
.event-row:hover { background: var(--accent-soft); text-decoration: none; }
.ename { font-weight: 600; }
@media (max-width: 760px) { .event-row { grid-template-columns: 1fr; gap: .1rem; } }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; justify-self: start; }
.tag.t-distance { background: #fdf0e1; color: #9a4f00; }
.tag.t-onsdag { background: #e4f4ee; color: #146c4a; }
@media (prefers-color-scheme: dark) { .tag.t-distance { background: #3a2a14; color: #f5b971; } .tag.t-onsdag { background: #143326; color: #6fd3a5; } }

/* polar */
.polar-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1rem; }
@media (max-width: 900px) { .polar-layout { grid-template-columns: 1fr; } }
.tablewrap { overflow-x: auto; margin: .5rem 0 1rem; }
.polar-table { border-collapse: collapse; font-size: .85rem; }
.polar-table th, .polar-table td { border: 1px solid var(--line); padding: 0; text-align: center; position: relative; }
.polar-table th { background: var(--bg); padding: .2rem .25rem; white-space: nowrap; }
.polar-table th.corner { font-size: .72rem; color: var(--muted); padding: .2rem .5rem; }
.polar-table input { width: 54px; border: 0; border-radius: 0; background: transparent; text-align: center; padding: .3rem .2rem; font-variant-numeric: tabular-nums; }
.polar-table input.axis { font-weight: 700; width: 44px; }
.polar-table .x { position: absolute; top: -2px; right: 0; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .8rem; padding: 0 2px; opacity: 0; }
.polar-table th:hover .x { opacity: 1; }
#polarCanvas { width: 100%; max-width: 520px; display: block; }
.legend, .map-legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .8rem; color: var(--muted); }
.legend i, .map-legend i { display: inline-block; width: 12px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* dashboard */
body.full { height: 100vh; display: flex; flex-direction: column; }
body.full .main-full { flex: 1; min-height: 0; }
.dash { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: 100%; }
.dash-map { position: relative; min-height: 420px; display: flex; flex-direction: column; }
#map { flex: 1; min-height: 0; }
.map-legend { position: absolute; left: 12px; bottom: 62px; max-width: calc(50% + 120px); flex-wrap: wrap; z-index: 500; background: var(--panel); padding: .45rem .7rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.2); color: var(--ink); align-items: center; }
.dash-side { overflow-y: auto; border-left: 1px solid var(--line); background: var(--panel); padding: 1rem 1.2rem 2rem; }
.side-head h1 { font-size: 1.3rem; margin-bottom: .2rem; }
.side-head p { margin: 0 0 .5rem; font-size: .88rem; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; margin: 1rem 0; }
@media (max-width: 1500px) { .kpis { grid-template-columns: 1fr 1fr; } }
.kpi { background: var(--bg); border-radius: 9px; padding: .7rem .8rem; }
.kl { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kv { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kv small { font-size: .85rem; font-weight: 500; color: var(--muted); }
.ks { font-size: .74rem; color: var(--muted); }
.stattable { width: 100%; border-collapse: collapse; font-size: .86rem; font-variant-numeric: tabular-nums; }
.stattable th, .stattable td { padding: .35rem .4rem; border-bottom: 1px solid var(--line); text-align: right; }
.stattable th:first-child { text-align: left; color: var(--muted); font-weight: 500; }
.stattable thead th { color: var(--muted); font-weight: 500; font-size: .78rem; }
.chartbox { margin-top: 1rem; height: 280px; display: flex; flex-direction: column; }
.chartwrap2 { flex: 1; min-height: 0; position: relative; }
.chartwrap2 canvas { position: absolute; inset: 0; }
.chartbox.max { position: fixed; inset: 0; z-index: 3000; height: auto; margin: 0; padding: 1rem 1.25rem; background: var(--panel); }
.ba-ok { color: var(--ok); font-weight: 600; } .ba-bad { color: var(--err); font-weight: 600; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 1rem; }
.grid4 .span2 { grid-column: span 2; } .grid4 .span4 { grid-column: 1 / -1; }
@media (max-width: 800px) { .grid4 { grid-template-columns: 1fr 1fr; } }
.callog { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.verdict .period { margin-top: .5rem; }
.notes { margin-top: 1rem; font-size: .9rem; }
.leaflet-container { font: inherit; background: #aad3df; }
.leaflet-container:focus { outline: none; }
@media (max-width: 900px) {
  body.full { height: auto; display: block; }
  .dash { grid-template-columns: 1fr; }
  .dash-map { height: 60vh; }
  .dash-side { border-left: 0; }
}

/* ---- v2 ---- */
body.full .flash { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 2000; box-shadow: 0 4px 16px rgba(0,0,0,.18); animation: fadeout 6s forwards; }
@keyframes fadeout { 0%, 80% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
.timebar { display: flex; align-items: center; gap: .5rem; padding: .45rem .75rem; background: var(--panel); border-top: 1px solid var(--line); }
.timebar input[type=range] { flex: 1; padding: 0; accent-color: var(--accent); }
.timebar select { padding: .2rem .3rem; font-size: .82rem; }
.tlabel { font-variant-numeric: tabular-nums; font-size: .88rem; min-width: 8.5em; text-align: right; }
.infobox { position: absolute; top: 64px; right: 10px; z-index: 600; background: var(--panel); color: var(--ink); border-radius: 9px; box-shadow: 0 2px 10px rgba(0,0,0,.22); padding: .55rem .75rem; font-size: .84rem; min-width: 210px; max-width: 290px; }
.infobox .ib-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.infobox .ib-course { color: var(--muted); font-size: .78rem; margin-bottom: .3rem; }
.infobox dl { display: grid; grid-template-columns: auto 1fr; gap: .1rem .7rem; margin: 0; }
.infobox dt { color: var(--muted); }
.infobox dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.infobox .ib-sails { margin-top: .35rem; padding-top: .35rem; border-top: 1px solid var(--line); font-size: .8rem; }
.boat-icon { background: none; border: 0; }
.boat-rot { width: 26px; height: 26px; transform-origin: 50% 50%; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.map-legend i.chg { width: 9px; height: 9px; border-radius: 50%; border: 2px solid #0f2742; background: #fff; }
.sectortable { width: 100%; border-collapse: collapse; font-size: .84rem; font-variant-numeric: tabular-nums; }
.sectortable th, .sectortable td { padding: .32rem .4rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.sectortable thead th { color: var(--muted); font-weight: 500; font-size: .76rem; }
.sectortable .l { text-align: left; }
.sectortable tbody th { font-weight: 500; }
.sectortable tr.total th, .sectortable tr.total td { font-weight: 700; border-bottom: 0; }
.sectortable td.worse { color: var(--err); font-weight: 700; }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.sw.s0 { background: #d7263d; } .sw.s1 { background: #f2994a; } .sw.s2 { background: #f2c14e; } .sw.s3 { background: #7bc950; } .sw.s4 { background: #2d9cdb; }
.sails { margin-top: 1.4rem; }
.sails h2 { margin-top: 0; }
.sailform { margin: .8rem 0; background: var(--bg); }
.sailform h3 { margin-bottom: .6rem; }
.sailrow { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start; }
fieldset.reefs { border: 0; padding: 0; margin: 0 0 .75rem; font-size: .88rem; color: var(--muted); }
fieldset.reefs legend { padding: 0; margin-bottom: .25rem; }
label.inline { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: .35rem; margin: 0 .9rem .35rem 0 !important; color: var(--ink) !important; font-size: .9rem !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.list.compact th, .list.compact td { padding: .3rem .4rem; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
td.actions .btn { margin-left: .2rem; }
.card.flush { padding: .3rem .6rem; }
.tag.t-crew { background: #e8e6fb; color: #4b3fb0; }
.tag.t-weight { background: #eef0f3; color: #475467; }
.tag.t-retired { background: #f2e9e9; color: #8a3b3b; }
@media (prefers-color-scheme: dark) { .tag.t-crew { background: #29234f; color: #b9b0ff; } .tag.t-weight { background: #243244; color: #b5c3d6; } .tag.t-retired { background: #3a2222; color: #f0a8a8; } }
.ename .tag { margin-left: .35rem; vertical-align: 1px; }
.boathead { margin-bottom: .5rem; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.2rem; overflow-x: auto; }
.tabs a { padding: .5rem .85rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.sail-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 1.25rem; align-items: start; }
.sail-layout > div > h2:first-child { margin-top: 0; }
@media (max-width: 860px) { .sail-layout { grid-template-columns: 1fr; } }
.crewpick { grid-column: span 2; margin-bottom: .75rem; }
.crewpick .lbl { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .35rem; }
.formtable th { text-align: left; font-weight: 500; padding: .25rem 1rem .25rem 0; }
.formtable td { padding: .25rem .4rem .25rem 0; white-space: nowrap; }
.formtable td.muted { white-space: normal; }
input.num { width: 5.5em; text-align: right; }
.settings .span-all { grid-column: 1 / -1; }
.cards.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 1rem; }
.verdict { color: var(--ink); border-left: 5px solid var(--line); }
.verdict:hover { text-decoration: none; border-color: var(--accent); }
.verdict .vhead { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.verdict .vhead h3 { margin: 0; flex: 1; }
.verdict .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.verdict .vlabel { font-size: .78rem; font-weight: 700; }
.verdict p { margin: 0; font-size: .88rem; }
.v-ok { border-left-color: #16a34a; } .v-ok .dot { background: #16a34a; } .v-ok .vlabel { color: #16a34a; }
.v-warn { border-left-color: #e39b12; } .v-warn .dot { background: #e39b12; } .v-warn .vlabel { color: #b97a06; }
.v-bad { border-left-color: #d7263d; } .v-bad .dot { background: #d7263d; } .v-bad .vlabel { color: #d7263d; }
.calib-grid { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.calib-grid .chartwrap { height: 300px; position: relative; }
.calib-grid .chartwrap.wide2 { grid-column: span 2; }
@media (max-width: 1000px) { .calib-grid { grid-template-columns: 1fr; } .calib-grid .chartwrap.wide2 { grid-column: span 1; } }
.calib-grid dl.mini.wide { grid-template-columns: 1fr 1fr; }
.evpick summary { cursor: pointer; font-weight: 600; }
.evlist { margin-top: .75rem; display: flex; flex-direction: column; }
@media (max-width: 900px) {
  .dash { grid-template-columns: 1fr; }
  .dash-map { height: 70vh; }
  .infobox { font-size: .78rem; min-width: 0; }
}
