:root {
  --paper: #efe8d4;
  --card: #fbf7ea;
  --ink: #26241f;
  --rule: #d4cbb0;
  --rule-strong: #a89e7f;
  --red: #b3261e;
  --muted: #8a8265;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.35 "Helvetica Neue", Helvetica, Arial, sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; min-height: 0; overflow: auto; }

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule-strong);
}
header h1 { font-size: 15px; letter-spacing: .3em; margin: 0; }
header nav { display: flex; align-items: center; gap: 6px; }
header .spacer { flex: 1; }
#period-label { min-width: 7em; text-align: center; }

button {
  font: inherit;
  padding: 3px 10px;
  background: var(--card);
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  cursor: pointer;
  color: var(--ink);
}
button.active { background: var(--ink); color: var(--card); }
/* every direct control in the header is a glyph, so they share one shape */
#lang-chip, #view-year, #view-month, #view-detail { display: inline-flex; align-items: center; padding: 4px 8px; }
#lang-chip svg, #view-year svg, #view-month svg, #view-detail svg { display: block; }
#more-list #lang-chip { padding: 3px 10px; gap: 6px; }

/* the ⋯ menu: same pattern as the calendar panel, anchored to the screen on a
   phone so it can never run off the edge (the header wraps) */
#more { position: relative; }
#more summary { cursor: pointer; padding: 3px 10px; background: var(--card); border: 1px solid var(--rule-strong); border-radius: 3px; list-style: none; line-height: 1; }
#more summary::-webkit-details-marker { display: none; }
#more[open] summary { background: var(--ink); color: var(--card); }
#more-list {
  position: absolute; right: 0; top: 110%;
  background: var(--card); border: 1px solid var(--rule-strong);
  padding: 8px; min-width: 160px; z-index: 11;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
}
#more-list button { text-align: left; }
#more-list #lang-chip { justify-content: flex-start; gap: 6px; }
#more-list #cal-picker { position: static; }

#cal-picker { position: relative; }
#cal-picker summary { cursor: pointer; padding: 3px 10px; background: var(--card); border: 1px solid var(--rule-strong); border-radius: 3px; list-style: none; }
#cal-list {
  position: absolute; right: 0; top: 110%;
  background: var(--card); border: 1px solid var(--rule-strong);
  padding: 8px 12px; min-width: 220px; z-index: 10;
  display: flex; flex-direction: column; gap: 4px;
}
#cal-list .cal-row { display: grid; grid-template-columns: 2.2em 2.2em 2.6em 1em 1fr; gap: 4px; align-items: center; white-space: nowrap; }
#cal-list .cal-head { font-size: 10px; color: var(--muted); letter-spacing: .05em; }
#cal-list .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, #999); display: inline-block; }
/* which build this device is running — settles "is the fix live yet?" */
#cal-list .cal-build { font-size: 10px; color: var(--muted); letter-spacing: .05em; margin-top: 6px; border-top: 1px solid var(--rule); padding-top: 5px; }

/* the day panel says which calendar a new event lands in — with three
   calendars in play, "did that go to the right one?" is a fair question */
/* the city is tappable: it is the quickest way to correct where you are */
.info.plan { cursor: pointer; }
.info.plan:hover .cty, .info.plan:hover { text-decoration: underline; text-underline-offset: 2px; }

.qa-target { margin: 4px 0 0; font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.qa-target .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #999); display: inline-block; flex: none; }

#banner {
  padding: 5px 14px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
}

/* ---------- month blocks ---------- */

.quarter {
  display: grid;
  grid-template-columns: repeat(3, minmax(300px, 1fr));
  gap: 14px;
  padding: 14px;
}

.month {
  background: var(--card);
  border: 1px solid var(--rule-strong);
}
.month h2 {
  margin: 0;
  padding: 5px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .35em;
  border-bottom: 1px solid var(--rule-strong);
}
.month h2 small { font-weight: 400; letter-spacing: .1em; color: var(--muted); }

.day {
  display: grid;
  --pre: 1.8em 1.7em;
  --own: repeat(var(--lanes, 1), minmax(0, 4fr));
  --det: minmax(0, 7fr);
  --wgt: ;
  --inf: 5.2em;
  grid-template-columns: var(--pre) var(--own) var(--wgt) var(--det) var(--inf);
  border-bottom: 1px solid var(--rule);
  min-height: 1.5em;
  font-size: 12px;
  position: relative;
  cursor: text;
}
.day:last-child { border-bottom: none; }
.day > span { padding: 1px 4px; overflow: hidden; }
.day .num { text-align: right; font-weight: 600; padding-right: 2px; white-space: nowrap; }
.day .wd { color: var(--muted); white-space: nowrap; }
.day.red .num, .day.red .wd { color: var(--red); }
/* project/tour lanes: tinted band, label at span start / month start / Mondays */
.day .lane { padding: 0; position: relative; }
/* a band label is always ONE line in its own row; a long title is written
   down the band one word per row instead of overflowing into the next day */
.day .lane.on { background: color-mix(in srgb, var(--c) 14%, var(--card)); border-left: 2px solid var(--ci, var(--c)); }
/* line-height/padding kept tight: on a phone a row can be ~21px, and a taller
   label box gets clipped by the row or covered by the next one — a band label
   sliced through the middle of its letters */
.day .lane i { font-style: normal; color: var(--ci, var(--c)); font-weight: 600; padding: 0 3px; line-height: 1.3; display: block; overflow: hidden; max-height: 100%; }
.day .lane i span { display: block; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* a label writes sideways across the free cells to its right, like handwriting;
   --spillw = how far it may reach, in multiples of its own lane width */
.day .lane.spill { overflow: visible; }
.day .lane.spill i {
  position: absolute;
  /* fills the row exactly: a box only as tall as its text leaves paper above
     and below, which reads as stripes down a band. Text centred inside. */
  left: 0; top: 0; bottom: 0;
  display: flex; align-items: center;
  z-index: 1;
  width: max-content; /* grow past the anchor cell, exactly as far as the words */
  max-width: var(--spillw, 100%);
  overflow: hidden;
  /* tint hugs the text; mixed with the paper so it never double-darkens the band */
  background: color-mix(in srgb, var(--c) 14%, var(--card));
  padding-right: 4px;
}
.day .lane.wg.spill i { background: color-mix(in srgb, var(--c) 22%, var(--card)); }

.day .lane i.ghost { color: transparent; user-select: none; }
/* a thin paper seam marks where one band ends and the next begins — drawn as
   an inset shadow, NOT a border, so it never pushes the label down out of the row */
.day .lane.on.bstart { box-shadow: inset 0 3px 0 var(--card); }
/* tbc in a title renders tentative: italic text, dashed lighter band */
/* tbc anywhere means tentative — including a planned move, so a city set by a
   trip that isn't booked yet reads italic */
.evt.tbc, #popover p.tbc b, .lane.tbc i, .info .cty.tbc, #popover .city-tag.tbc { font-style: italic; }
.day .lane.on.tbc { border-left-style: dashed; background: color-mix(in srgb, var(--c) 9%, var(--card)); }
/* shows ping red: band labels + a dot on the day number */
.day .lane.showband i { color: var(--red); }
.day.showday .num::after { content: '•'; color: var(--red); margin-left: 1px; }
.month.haswg .day { --wgt: repeat(var(--wg, 1), minmax(0, 4.5fr)); --det: minmax(0, 5.5fr); }
/* wg overlay lanes: clearly "context", not your own schedule */
.day .lane.wg {
  border-left: 2px dashed var(--ci, var(--c));
  border-right: 1px dashed color-mix(in srgb, var(--ci, var(--c)) 55%, var(--card));
  background: color-mix(in srgb, var(--c) 22%, var(--card));
}
.day .lane.wg i { font-weight: 400; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
#popover .wgrow { opacity: .8; }
#popover .wg-mark { font-size: 9px; text-transform: uppercase; letter-spacing: .08em; border: 1px solid var(--muted); color: var(--muted); border-radius: 2px; padding: 0 3px; vertical-align: middle; }
/* single-day details: always ONE line — joined with · , clipped with … ; tap the day for the full list */
.day .detail { border-left: 1px dotted var(--rule); align-self: center; width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .detail .evt { font-weight: 400; display: inline; }
.day .detail .evt + .evt::before { content: ' · '; color: var(--muted); }
.day .detail .evt.wgd { opacity: .55; } /* wg items: visibly "theirs", clipped first */
.day .detail .evt.showevt { opacity: 1; font-weight: 600; } /* shows pop at full red, never dimmed */
.day .info { font-size: 10px; color: var(--muted); text-align: right; border-left: 1px dotted var(--rule); align-self: center; white-space: nowrap; text-overflow: ellipsis; }
.day .info.red { color: var(--red); font-weight: 600; }
.day.today { outline: 2px solid #d97706; outline-offset: -2px; }

#popover {
  position: fixed;
  z-index: 30;
  background: var(--card);
  border: 1px solid var(--ink);
  box-shadow: 2px 3px 0 rgba(0,0,0,.15);
  padding: 8px 12px;
  width: min(340px, 92vw);
  font-size: 13px;
}
#popover p { margin: 0 0 4px; }
#popover .city-tag { float: right; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 600; }
#popover .dim { color: var(--muted); font-size: 11px; }
#popover .actions { display: flex; gap: 8px; margin-top: 6px; }

#popover .qa input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* <16px makes iOS Safari auto-zoom on focus */
  border: 1px solid var(--ink);
  background: #fff;
  padding: 4px 6px;
  margin-top: 6px;
}
#popover .x {
  font-size: 11px;
  padding: 0 6px;
  margin-left: 8px;
}

#toast {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink); color: var(--card);
  padding: 6px 14px; border-radius: 4px;
  font-size: 13px; z-index: 20;
}

/* ---------- phone strip ---------- */

main.strip { height: 100%; overflow-y: auto; }
.strip .month {
  max-width: 560px; margin: 0 auto;
  border-left: none; border-right: none;
  min-height: 100%; /* fill the screen when sparse, grow + scroll when dense */
  display: flex; flex-direction: column;
  /* keep the last day clear of the home indicator (PWA) and of Safari's
     floating toolbar, which overlays the bottom of the viewport */
  padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
}
/* the month must visibly END: without this the last row — and any tour band
   running through it — bleeds into the screen edge and reads as cut off */
.strip .day:last-child { border-bottom: 1px solid var(--rule-strong); }
.strip .day { flex: 1 0 auto; font-size: 13px; align-items: center; }
.strip .day .lane { align-self: stretch; display: flex; align-items: center; }
.strip .day .info { font-size: 11px; }

@media (max-width: 720px) {
  /* the header wraps, so the Kalendere button can sit at the far left — anchor
     the panel to the screen instead of the button, or it runs off the edge */
  #cal-picker, #more { position: static; }
  #more-list { left: auto; right: 8px; min-width: 150px; }
  #cal-list {
    left: 8px; right: 8px; top: 100%;
    min-width: 0;
    max-height: 65vh; overflow-y: auto;
  }
  #cal-list .cal-row { grid-template-columns: 2.2em 2.2em 2.6em 1em minmax(0, 1fr); }
  #cal-list .nm { overflow: hidden; text-overflow: ellipsis; }
  header { flex-wrap: wrap; padding: 4px 8px; gap: 4px 8px; }
  header nav { flex-wrap: wrap; gap: 4px; }
  header h1 { font-size: 13px; letter-spacing: .2em; flex-basis: auto; }
  header .spacer { display: none; }
  #period-label { min-width: 0; }
  button, #cal-picker summary, #more summary { padding: 2px 8px; font-size: 13px; }
  .quarter { grid-template-columns: 1fr; padding: 8px; }
}

/* ---------- "Detaljer" view: every event on its own row ---------- */

.detailed .day .detail { white-space: normal; }
.detailed .day .detail .evt { display: block; }
.detailed .day .detail .evt + .evt::before { content: ''; }

/* ---------- cities column (derived from flights) ---------- */

/* the city rides in the info column in tiny caps; a long name steps down a
   size rather than widen the column or clip (Alan, 2026-08-25) */
.day .info .cty { text-transform: uppercase; letter-spacing: .05em; }
.day .info .cty.long { font-size: .85em; letter-spacing: .02em; }
/* a long holiday name steps down too, rather than clipping ("K. himmelfartsdag") */
.day .info.long { font-size: .8em; letter-spacing: -.01em; }
.day .info.long.xlong { font-size: .72em; }
.month.cities .day { --inf: 6.4em; }

#toast button {
  margin-left: 12px;
  background: var(--card);
  color: var(--ink);
  border: none;
  border-radius: 3px;
  font-weight: 600;
  padding: 2px 10px;
}

#popover .qa { display: flex; gap: 6px; align-items: stretch; }
#popover .qa .add { margin-top: 6px; white-space: nowrap; }

/* ---------- print (A4 landscape; 3, 6 or 12 months per page) ---------- */

@media print {
  @page { size: A4 landscape; margin: 6mm; }
  header, #banner, #toast, #popover { display: none !important; }
  body { background: #fff; display: block; height: auto; }
  .quarter {
    gap: 3mm;
    padding: 0;
    page-break-after: always;
  }
  .quarter.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .quarter.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .quarter.g12 { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 1.5mm; }
  .quarter:last-child { page-break-after: auto; }
  .month { border-color: #999; break-inside: avoid; }
  .day { font-size: 6.5pt; min-height: 5.7mm; border-bottom-color: #ccc; --pre: 2.6em 2.2em; --inf: 6em; }
  .month.cities .day { --inf: 6.6em; }
  .day > span { padding: 1px 2px; }
  /* on paper: every day the same height — details stay on one line */
  .day .detail { overflow: hidden; }
  .day .info { font-size: 5.5pt; }
  .month h2 { font-size: 9pt; }
  .day.today { outline: none; }
  /* 6 months per page */
  body.print-6 .day { font-size: 5pt; --pre: 2.4em 2em; --inf: 5em; }
  body.print-6 .month.cities .day { --inf: 5.6em; }
  body.print-6 .day .info { font-size: 4.2pt; }
  body.print-6 .month h2 { font-size: 6.5pt; letter-spacing: .2em; }
  /* the whole year on one classic sheet */
  body.print-12 .day { font-size: 3.8pt; --pre: 2.2em 1.9em; --inf: 4em; --own: repeat(var(--lanes, 1), minmax(0, 3fr)); --det: minmax(0, 4fr); }
  body.print-12 .month.cities .day { --inf: 4.6em; }
  body.print-12 .day .info { font-size: 3.2pt; }
  body.print-12 .month h2 { font-size: 5pt; letter-spacing: .1em; padding: 2px; }
  body.print-12 .day .lane i { padding: 0 1px; }
}
