/* 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; }
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) 440px; height: 100%; }
.dash-map { position: relative; min-height: 420px; }
#map { position: absolute; inset: 0; }
.map-legend { position: absolute; left: 12px; bottom: 26px; 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: 1fr 1fr; gap: .6rem; margin: 1rem 0; }
.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: 260px; display: flex; flex-direction: column; }
.chartbox canvas { flex: 1; min-height: 0; }
.notes { margin-top: 1rem; font-size: .9rem; }
.leaflet-container { font: inherit; background: #aad3df; }
@media (max-width: 900px) {
  body.full { height: auto; display: block; }
  .dash { grid-template-columns: 1fr; }
  .dash-map { height: 60vh; }
  .dash-side { border-left: 0; }
}
