:root {
  accent-color: var(--accent);
  --bg: #f3efe6; --surface: #fbf9f3; --surface-2: #f0ebdf; --text: #24301f; --muted: #6b7466;
  --border: #ddd5c3; --accent: #1f7a5c; --accent-2: #17604a; --accent-soft: #dcefe6; --on-accent: #fff;
  --danger: #b3412f; --warn: #b7791f;
  --run: #d9622b; --ride: #1f7a5c; --hike: #8a5a2b; --walk: #6b8e23; --ski: #3b82c4; --swim: #0f8fa8; --other: #7a6f9b;
  --radius: 10px; --shadow: 0 1px 2px rgba(40,50,30,.08), 0 4px 14px rgba(40,50,30,.07);
  --sidebar-w: 214px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121b17; --surface: #1a2620; --surface-2: #22322a; --text: #e6ece3; --muted: #93a398;
  --border: #2d3f35; --accent: #4fc29a; --accent-2: #6fd6b2; --accent-soft: #1f3a2f; --on-accent: #0c1a14;
  --danger: #ef7d68; --warn: #e2b04a;
  --run: #f08a58; --ride: #4fc29a; --hike: #c99a62; --walk: #a3c75a; --ski: #6fb0ea; --swim: #4cc3d9; --other: #a99dce;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: 12px; } .num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* --- buttons / inputs --- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.icon { padding: 6px 8px; }
.btn[disabled] { opacity: .5; cursor: default; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.field > input, label.field > select { color: var(--text); font-size: 14px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; cursor: default; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
button.chip { cursor: pointer; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--other); }
.sport-run { --c: var(--run); } .sport-ride { --c: var(--ride); } .sport-hike { --c: var(--hike); } .sport-walk { --c: var(--walk); }
.sport-ski { --c: var(--ski); } .sport-swim { --c: var(--swim); } .sport-other, .sport-row, .sport-paddle { --c: var(--other); }
.dot[class*=sport-] { background: var(--c); }
.sport-ico { display: inline-flex; vertical-align: middle; color: var(--c); flex: none; }
.sport-ico svg { stroke-width: 2; }

/* --- shell --- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100dvh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; overflow-y: auto; z-index: 1200; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; padding: 4px 10px 14px; }
.brand svg { width: 26px; height: 26px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav .sep { height: 1px; background: var(--border); margin: 8px 6px; }
.sidebar .spacer { flex: 1; }
.sidebar .tools { display: flex; gap: 6px; padding: 8px 6px 0; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 9px; cursor: pointer; font-size: 12px; }
.seg button.on { background: var(--accent); color: var(--on-accent); }
.topbar { display: none; }
.main { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#page { position: absolute; inset: 0; overflow: auto; padding: 18px 22px 40px; }
#map-layer { position: absolute; inset: 0 var(--side-w, 0px) var(--dock-h, 0px) 0; display: none; }
#map-layer.show { display: block; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
#overlay { position: absolute; inset: 0; pointer-events: none; z-index: 500; }
#overlay > * { pointer-events: auto; }
.leaflet-container { font: inherit; }

/* --- generic page bits --- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .grow { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.card h2 { margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px; }
.kpi .l { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi .v { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi .v small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.dash { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.dash > .span-4 { grid-column: span 4; } .dash > .span-5 { grid-column: span 5; } .dash > .span-6 { grid-column: span 6; }
.dash > .span-7 { grid-column: span 7; } .dash > .span-8 { grid-column: span 8; } .dash > .span-12 { grid-column: span 12; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
table.t td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--surface-2); }
table.t td.r, table.t th.r { text-align: right; }
.scroll-x { overflow-x: auto; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.toast-wrap { position: fixed; right: 14px; bottom: 14px; display: grid; gap: 8px; z-index: 3000; }
.toast { background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 340px; }
.toast.err { background: var(--danger); color: #fff; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* calendar heatmap */
.cal { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 11px); grid-auto-columns: 11px; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.cal i { border-radius: 2px; background: var(--surface-2); }
.cal i[data-l="1"] { background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.cal i[data-l="2"] { background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.cal i[data-l="3"] { background: color-mix(in srgb, var(--accent) 80%, var(--surface-2)); }
.cal i[data-l="4"] { background: var(--accent); }

.login .seg { justify-self: start; }
/* login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 55%), var(--bg); }
.login { width: min(380px, 100%); display: grid; gap: 14px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }

/* map view */
.mapbar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; pointer-events: none; }
.mapbar > * { pointer-events: auto; }
.floating { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.mapbar .floating { padding: 4px 6px; display: flex; gap: 6px; align-items: center; }
.mapbar input[type=search] { width: 170px; border: 0; background: transparent; }
.legend { position: absolute; left: 10px; bottom: 22px; padding: 6px 10px; font-size: 12px; display: flex; gap: 10px; align-items: center; }
.legend .ramp { width: 110px; height: 8px; border-radius: 4px; }
.preview { position: absolute; right: 10px; top: 56px; width: 270px; padding: 12px; }

/* activity view */
.panel { position: absolute; background: var(--surface); border: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; z-index: 600; }
.panel.dock { left: 0; right: 0; bottom: 0; height: var(--dock-h); border-width: 1px 0 0 0; }
.panel.side { top: 0; right: 0; bottom: 0; width: var(--side-w); border-width: 0 0 0 1px; }
.panel-head { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head .title { font-weight: 650; margin-right: 8px; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.tabs button { border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.panel-body { flex: 1; overflow: auto; padding: 10px 12px; min-height: 0; }
.resize { position: absolute; background: transparent; z-index: 5; }
.dock > .resize { top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }
.side > .resize { left: -4px; top: 0; bottom: 0; width: 8px; cursor: ew-resize; }
.resize:hover { background: var(--accent-soft); }
.chart-block { margin-bottom: 8px; }
.chart-block .ch-title { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 0 2px; }
.ch-title b { color: var(--text); font-variant-numeric: tabular-nums; }
.chart-wrap { width: 100%; }
.u-legend { display: none; }
.uplot { font-family: inherit; }
.photo-pin { width: 38px; height: 38px; border-radius: 8px; border: 2px solid #fff; background-size: cover; background-position: center; box-shadow: 0 1px 6px rgba(0,0,0,.5); }
.cursor-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.km-mark { background: #fff; color: #222; border: 1px solid #555; border-radius: 9px; font-size: 10px; padding: 0 4px; line-height: 15px; font-weight: 600; text-align: center; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.stat-grid .kpi .v { font-size: 18px; }

/* --- responsive --- */
@media (max-width: 899px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 1300; }
  .topbar .brand { padding: 0; flex: 1; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 250px; transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1100; }
  #page { padding: 12px 12px 40px; }
  .dash > * { grid-column: 1 / -1 !important; }
  .panel.side { top: auto; left: 0; width: auto; height: var(--dock-h); border-width: 1px 0 0 0; }
  .panel.side > .resize { left: 0; right: 0; top: -4px; bottom: auto; width: auto; height: 10px; cursor: ns-resize; }
  .preview { left: 10px; right: 10px; width: auto; top: auto; bottom: 14px; }
  .legend { bottom: 60px; }
  .hide-sm { display: none !important; }
}

/* modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 20, 15, .5); display: grid; place-items: center; z-index: 3500; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 14px 16px; overflow: auto; display: grid; gap: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); }
.form-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .form-2 { grid-template-columns: 1fr; } }

/* library cards */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.lib-card { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; align-items: start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; cursor: pointer; }
.lib-card:hover { border-color: var(--accent); }
.lib-card.retired { opacity: .6; }
.lib-pic { width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 20px; }
.lib-pic.round { border-radius: 50%; }
.lib-card .nm { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-card .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-card .stats { display: flex; gap: 10px; font-size: 12px; margin-top: 4px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip img { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; margin-left: -4px; }
.bulkbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 10px; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius); }

/* search palette */
.search-btn { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--muted); cursor: pointer; text-align: left; }
.search-btn span { flex: 1; }
.search-btn kbd { font: 11px var(--font); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.pal-item { display: block; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.pal-item:hover, .pal-item.on { background: var(--accent-soft); text-decoration: none; }

/* timeline */
.timeline { max-width: 760px; }
.tl-month { margin: 22px 0 10px; font-size: 15px; color: var(--muted); text-transform: capitalize; }
.tl-card { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px; margin-bottom: 10px; }
.tl-title { display: block; font-size: 17px; font-weight: 650; color: var(--text); margin: 2px 0 4px; }
.tl-stats { display: flex; gap: 14px; flex-wrap: wrap; }
.tl-desc { margin: 6px 0 0; white-space: pre-wrap; max-height: 4.4em; overflow: hidden; }
.tl-photos { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; }
.tl-photos img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; cursor: zoom-in; flex: none; }
.tl-more { width: 72px; height: 72px; display: grid; place-items: center; background: var(--surface-2); border-radius: 8px; flex: none; }
@media (max-width: 560px) { .tl-card { grid-template-columns: 1fr; } .tl-map svg { width: 100%; height: 140px; } }

/* gallery */
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.gal-item { margin: 0; position: relative; cursor: zoom-in; }
.gal-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.gal-item figcaption { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.6)); border-radius: 0 0 8px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity .15s; }
.gal-item:hover figcaption { opacity: 1; }

/* long-running task status */
.spin-inline { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; flex: none; }
.task-status { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.task-status.ok { border-color: var(--accent); color: var(--accent-2); background: var(--accent-soft); }
.task-status.warn { border-color: var(--warn); }
.task-status.err { border-color: var(--danger); color: var(--danger); }

/* per-navigation containers */
#overlay > .view-overlay, .view-overlay { position: absolute; inset: 0; pointer-events: none; }
.view-overlay > * { pointer-events: auto; }

/* photo lightbox: EXIF info panel */
.lb-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 100%); z-index: 1; overflow-y: auto; padding: 56px 14px 14px;
  background: rgba(16, 22, 19, .93); color: #e9efe9; font-size: 13px; border-left: 1px solid rgba(255,255,255,.15); }
.lb-panel.hidden { display: none; }
.lb-name { font-weight: 650; word-break: break-all; margin-bottom: 4px; }
.lb-sec { margin: 12px 0 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: #8fd3b6; }
.lb-row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.07); }
.lb-row > span:first-child { color: #aab6ae; flex: none; }
.lb-row > span:last-child { text-align: right; word-break: break-word; }
.lb-row a, .lb-note a { color: #8fd3b6; }
.lb-note { color: #aab6ae; padding: 6px 0; }
.lb-all { margin-top: 14px; }
.lb-all summary { cursor: pointer; color: #aab6ae; }
