/* Grejs_Bane_Byg – mobil først. Lyst tema med høj kontrast, så det kan læses udendørs. */
:root {
  --ink: #17211b;
  --ink-2: #4f564f;
  --ink-3: #737a72;
  --forest: #1f4d3a;
  --forest-2: #2a6a50;
  --forest-tint: #e4eee8;
  --paper: #f5f4ef;
  --card: #ffffff;
  --line: #dcd9cd;
  --blue: #1560bd;
  --red: #c81e25;
  --red-tint: #fbe9e9;
  --amber: #8a5a00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 33, 27, .08), 0 6px 18px rgba(23, 33, 27, .08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

/* manipulation slår browserens zoom ved dobbelttryk fra, men bevarer rulning og knibezoom. */
* { box-sizing: border-box; touch-action: manipulation; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body.in-editor { overflow: hidden; position: fixed; inset: 0; }
#app { min-height: 100%; }
h1, h2, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
input { font-size: 16px; } /* Under 16px zoomer iOS siden ved fokus */
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.ic { width: 24px; height: 24px; flex: none; display: block; }

/* ---------- Knapper ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; font-weight: 650;
  border: 1.5px solid transparent; transition: background .12s, transform .08s;
}
.btn .ic { width: 20px; height: 20px; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .42; }
.btn.primary { background: var(--forest); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--forest-2); }
.btn.secondary { background: var(--card); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--ink-3); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn.danger { background: var(--red); color: #fff; }
.btn.big { min-height: 54px; padding: 0 26px; font-size: 17px; }
.iconbtn {
  width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; color: inherit;
}
.iconbtn:hover:not(:disabled) { background: rgba(23, 33, 27, .07); }
.iconbtn:disabled { opacity: .3; }
.iconbtn.sm { width: 36px; height: 36px; }
.iconbtn.sm .ic { width: 20px; height: 20px; }
.linkbtn { min-height: 44px; font-weight: 600; color: var(--blue); text-align: left; }
.linkbtn.danger { color: var(--red); }

/* ---------- Sider ---------- */
.page { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  min-height: 58px; padding: calc(6px + var(--safe-t)) 10px 6px;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.01em; flex: 1; min-width: 0; padding-left: 6px; }
.brand-mark svg { display: block; }
.topbar-title { flex: 1; min-width: 0; padding-left: 2px; }
.topbar-title h1 { font-size: 18px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title small { color: var(--ink-2); }
.content { width: 100%; max-width: 1080px; margin: 0 auto; padding: 18px 16px calc(32px + var(--safe-b)); flex: 1; }
.content.narrow { max-width: 620px; display: flex; flex-direction: column; gap: 14px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h1, .section-head h2 { font-size: 22px; letter-spacing: -.01em; }
.footnote { margin-top: 26px; font-size: 14px; color: var(--ink-2); max-width: 60ch; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  position: relative; display: block; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; transition: box-shadow .15s, transform .08s;
}
a.card:hover, .course-card:hover { box-shadow: var(--shadow); }
a.card:active { transform: scale(.995); }
.card-link { display: block; }
.card-art { height: 150px; padding: 8px; background: var(--paper); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.card-art svg { width: 100%; height: 100%; display: block; }
.card-text { padding: 11px 14px 13px; display: flex; flex-direction: column; min-width: 0; }
.card-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-text small { color: var(--ink-2); font-size: 14px; }
.course-card .card-text { padding-right: 52px; }
.card-menu { position: absolute; right: 4px; bottom: 6px; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 14px 4px 8px; }
.empty h2 { font-size: 24px; letter-spacing: -.01em; }
.empty p { color: var(--ink-2); max-width: 44ch; }
.empty-art { width: 100%; max-width: 480px; }
.empty-art svg { display: block; width: 100%; height: auto; }
.empty.small { padding: 34px 8px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h2 { font-size: 18px; margin-bottom: 8px; }
.panel p { color: var(--ink-2); }
.panel-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.help { margin: 0; }
.help dt { font-weight: 700; margin-top: 10px; }
.help dd { margin: 0; color: var(--ink-2); }

/* ---------- Dialoger ---------- */
.dlg {
  border: 0; padding: 0; border-radius: 18px; width: min(460px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); overflow: auto;
}
.dlg:focus { outline: none; }
.dlg::backdrop { background: rgba(15, 22, 18, .45); }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 4px 18px; }
.dlg-head h2 { flex: 1; font-size: 19px; line-height: 1.25; min-width: 0; overflow-wrap: anywhere; }
.dlg-body { padding: 4px 18px 8px; }
.dlg-body p + p { margin-top: 10px; }
.dlg-actions { display: flex; gap: 10px; padding: 10px 18px calc(16px + var(--safe-b)); }
.dlg-actions .btn { flex: 1; }
.dlg-actions.stack { flex-direction: column; }
.dlg-sheet { margin: auto auto 0; width: min(520px, 100vw); max-width: 100vw; border-radius: 18px 18px 0 0; max-height: 88dvh; }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 15px; }
.field-input { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 11px; background: #fff; }
.field-input:focus-within { border-color: var(--blue); }
.field-input input { flex: 1; min-width: 0; height: 46px; border: 0; background: none; padding: 0 12px; outline: none; font-weight: 500; }
.field-input em { font-style: normal; font-weight: 500; color: var(--ink-2); padding-right: 12px; }
.form-err { color: var(--red); font-size: 15px; font-weight: 600; }
.intro-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.intro-list li { display: flex; gap: 12px; }
.intro-ic { width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--forest-tint); color: var(--forest); }
.intro-list p { color: var(--ink-2); font-size: 15px; }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); z-index: 100; transform: translate(-50%, 12px);
  width: max-content; max-width: min(92vw, 460px); padding: 11px 16px; border-radius: 12px; background: #1b241f; color: #fff;
  font-size: 15px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); font-weight: 600; }

/* ---------- Editor: mobil ---------- */
.editor { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--paper); }
.ed-top {
  display: flex; align-items: center; gap: 2px; padding: calc(3px + var(--safe-t)) 4px 3px;
  background: var(--forest); color: #fff; flex: none;
}
.ed-top .iconbtn:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.ed-title { flex: 1; min-width: 0; min-height: 44px; display: flex; flex-direction: column; justify-content: center; text-align: left; padding: 0 2px; }
.ed-title strong { font-size: 15px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-title small { font-size: 12px; opacity: .82; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-status { font-size: 12px; font-weight: 600; opacity: .88; padding: 0 4px; white-space: nowrap; }
.save-status[data-state="saving"] { opacity: .65; }
.save-status[data-state="error"] { background: #fff; color: var(--red); border-radius: 6px; opacity: 1; }
.ed-main { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--paper); }
.stage-svg {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.stage[data-mode="draw"] .stage-svg, .stage[data-mode="add"] .stage-svg { cursor: crosshair; }
.hint {
  position: absolute; top: 8px; left: 8px; right: 58px; width: fit-content; max-width: calc(100% - 66px);
  padding: 7px 12px; border-radius: 10px; background: rgba(23, 33, 27, .9); color: #fff; font-size: 14px; line-height: 1.3;
  opacity: 0; transform: translateY(-6px); transition: opacity .15s, transform .15s; pointer-events: none;
}
.hint.show { opacity: 1; transform: none; }
.zoom {
  position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column;
  background: rgba(255, 255, 255, .94); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.zoom button { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }
.zoom button + button { border-top: 1px solid var(--line); }
.zoom button:hover { background: var(--forest-tint); }
.zoom .ic { width: 22px; height: 22px; }

.dock { position: relative; flex: none; z-index: 3; background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 5px 6px; }
.modes button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-height: 52px; border-radius: 12px; font-size: 13px; font-weight: 650; color: var(--ink-2);
}
.modes button.on { background: var(--forest); color: #fff; }
.modes button:not(.on):hover { background: var(--forest-tint); }

/* Kontekstpanelet flyder over banen på mobil, så banen beholder sin størrelse */
.ctx {
  position: absolute; left: 0; right: 0; bottom: 100%; max-height: 54dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 18px rgba(23, 33, 27, .12); padding: 8px 10px;
}
.ctx[hidden] { display: none; }
.ctx-tiles { padding: 6px; }
.dock.is-dragging .ctx { visibility: hidden; }
.ctx-head { display: flex; align-items: center; justify-content: space-between; min-height: 30px; margin-bottom: 2px; padding-left: 4px; }
.ctx-head strong { font-size: 15px; }
.ctx-note { color: var(--ink-2); font-size: 14px; padding: 0 4px 6px; }
.ctx-empty { color: var(--ink-2); font-size: 14px; }
.ctx-warn { color: var(--amber); font-size: 13px; line-height: 1.3; padding: 6px 4px 0; }

.tiles { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; touch-action: pan-x; }
.tiles::-webkit-scrollbar { display: none; }
.tile {
  flex: 1 0 50px; min-height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 12px; font-size: 11.5px; letter-spacing: -.01em; font-weight: 650; border: 1.5px solid var(--line); background: #fff;
  -webkit-user-select: none; user-select: none; touch-action: pan-x;
}
.tile.on { border-color: var(--forest); background: var(--forest-tint); box-shadow: inset 0 0 0 1px var(--forest); }

.act-row { display: flex; gap: 4px; }
.act {
  flex: 1 1 0; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border-radius: 11px; background: #f3f2ec; font-size: 11.5px; line-height: 1.12; font-weight: 600; text-align: center; padding: 3px 2px;
}
.act:active { background: var(--forest-tint); }
.act.danger { color: var(--red); background: var(--red-tint); }
.act .ic { width: 22px; height: 22px; }

.num-row { display: flex; align-items: stretch; gap: 6px; margin-top: 6px; }
.num-field { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding-left: 11px; border: 1.5px solid var(--line); border-radius: 11px; font-weight: 700; font-size: 14px; }
.num-field:focus-within { border-color: var(--blue); }
.num-field input { flex: 1; min-width: 0; width: 100%; height: 44px; border: 0; background: none; outline: none; font-weight: 700; }
.chip {
  flex: none; min-height: 44px; display: inline-flex; align-items: center; gap: 4px; padding: 0 9px;
  border-radius: 11px; background: #f3f2ec; font-size: 13px; font-weight: 650;
}
.chip .ic { width: 20px; height: 20px; }
.chip.off { color: var(--ink-3); }
.more-toggle .ic { transition: transform .12s; }
.more-toggle.open .ic { transform: rotate(180deg); }
.more-word { color: var(--ink-2); font-weight: 500; }
.ctx-more { display: none; flex-direction: column; gap: 4px; margin-top: 6px; padding-top: 4px; border-top: 1px solid var(--line); }
.ctx-more.open { display: flex; }

.row-field { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; min-height: 48px; }
.row-field.col { flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 0; }
.row-label { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.row-label .ic { width: 20px; height: 20px; }
.row-label b { margin-left: auto; font-weight: 600; color: var(--ink-2); }
.panel .row-label { font-size: 15.5px; font-weight: 500; }

.seg { display: flex; background: #eeece4; border-radius: 11px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1; min-width: 42px; min-height: 40px; padding: 0 9px; border-radius: 9px; font-size: 13.5px; font-weight: 650; color: var(--ink-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
.seg .ic { width: 20px; height: 20px; }

.switch { width: 54px; height: 44px; display: flex; align-items: center; flex: none; }
.switch i { position: relative; display: block; width: 50px; height: 30px; margin-left: 2px; border-radius: 15px; background: #c9c7bb; transition: background .12s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .12s; }
.switch.on i { background: var(--forest); }
.switch.on i::after { transform: translateX(20px); }

.stepper { display: flex; align-items: center; gap: 3px; }
.stepper button { width: 44px; height: 44px; border-radius: 11px; background: #f3f2ec; display: flex; align-items: center; justify-content: center; }
.stepper button .ic { width: 20px; height: 20px; }
.stepper-in { display: flex; align-items: center; width: 82px; height: 44px; border: 1.5px solid var(--line); border-radius: 11px; padding-right: 7px; }
.stepper-in:focus-within { border-color: var(--blue); }
.stepper-in input { width: 100%; min-width: 0; height: 100%; border: 0; background: none; outline: none; text-align: right; padding: 0 3px 0 4px; font-weight: 600; }
.stepper-in em { font-style: normal; font-size: 14px; color: var(--ink-2); }

.small-input { width: 92px; height: 44px; border: 1.5px solid var(--line); border-radius: 11px; padding: 0 10px; font-weight: 700; outline: none; background: #fff; }
.small-input:focus { border-color: var(--blue); }
.swatches { display: flex; gap: 2px; }
.swatch { width: 40px; height: 44px; display: flex; align-items: center; justify-content: center; }
.swatch::before { content: ""; width: 28px; height: 28px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--line); }
.swatch.on::before { box-shadow: 0 0 0 2px #fff, 0 0 0 4.5px var(--ink); }

.draw-row { display: flex; align-items: stretch; gap: 6px; }
.draw-row .seg { flex: 1; }
.draw-row + .draw-row { margin-top: 6px; }
.draw-points .btn { flex: 1; min-height: 44px; padding: 0 10px; font-size: 14.5px; }
.draw-sample { width: 24px; height: 0; border-top: 3px dashed; }

.menu-body { display: flex; flex-direction: column; }
.menu-body hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 8px 0; }
.menu-body input[type="range"] { width: 100%; height: 36px; accent-color: var(--forest); }
.menu-item { display: flex; align-items: center; gap: 12px; min-height: 48px; font-weight: 550; text-align: left; border-radius: 10px; padding: 0 6px; }
.menu-item:hover { background: #f3f2ec; }
.menu-item.danger { color: var(--red); }
.menu-item .ic { width: 22px; height: 22px; }

/* ---------- Større skærme og telefon på langs: værktøjer i sidepanel ---------- */
@media (min-width: 900px), (orientation: landscape) and (min-width: 640px) and (max-height: 520px) {
  .ed-main { flex-direction: row-reverse; }
  .dock { width: 330px; display: flex; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding-bottom: 0; padding-left: env(safe-area-inset-left, 0px); }
  .ctx { position: static; flex: 1; min-height: 0; max-height: none; border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; padding: 12px; }
  .ctx[hidden] { display: block; visibility: hidden; }
  .dock.is-dragging .ctx { visibility: visible; }
  .ctx-tiles { padding: 12px; }
  .tiles { display: grid; grid-template-columns: repeat(3, 1fr); overflow: visible; gap: 8px; touch-action: none; }
  .tile { min-height: 74px; font-size: 13px; touch-action: none; }
  .tile:hover { border-color: var(--forest-2); }
  .ctx-more { display: flex; }
  .more-toggle[data-act="more"] { display: none; }
  .more-toggle[data-act="drawStyle"] { display: none; }
  .act { font-size: 12px; }
  .seg button { padding: 0 6px; }
  .toast { bottom: 28px; }
}
@media (orientation: landscape) and (min-width: 640px) and (max-height: 520px) {
  .dock { width: 280px; }
  .modes button { min-height: 44px; font-size: 12px; }
  .modes .ic { width: 20px; height: 20px; }
  .tile { min-height: 58px; }
}
@media (min-width: 900px) {
  .ed-title strong { font-size: 16px; }
  .ed-top { padding-left: 8px; padding-right: 8px; }
  .save-status { padding: 0 12px; }
}
@media (max-width: 360px) {
  .ed-title small { display: none; }
  .more-word { display: none; }
  .seg button { padding: 0 5px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Udskrift: kun banen ---------- */
/* Afstande mellem spring */
.dist-intro { color: var(--ink-2); font-size: 15px; margin-bottom: 10px; }
.dist-list { display: flex; flex-direction: column; gap: 8px; }
.dist-row { display: grid; grid-template-columns: minmax(92px, 1fr) minmax(96px, 1.2fr) auto; align-items: center; gap: 8px; }
.dist-row.bad .field-input { border-color: var(--red); }
.dist-leg { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.dist-leg i { font-style: normal; color: var(--red); padding: 0 2px; }
.dist-approx { min-width: 74px; min-height: 46px; padding: 0 10px; border-radius: 11px; background: #f3f2ec; color: var(--ink-2); font-size: 14px; font-weight: 600; white-space: nowrap; }
.dist-note { color: var(--ink-3); font-size: 13px; line-height: 1.35; margin-top: 2px; }
.dist-dlg .form-err { margin-top: 10px; }
.dist-dlg .linkbtn { margin-top: 6px; }
.dist-dlg .dlg-actions { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line); }

#printArea { display: none; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  body { position: static; overflow: visible; background: #fff; }
  #printArea { display: block; }
  #printArea svg { display: block; width: 100%; height: auto; max-height: 96vh; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: landscape; margin: 10mm; }
}
