:root {
  --color-bg:           #edeae4;
  --color-surface:      #ffffff;
  --color-ink:          #1a1a1a;
  --color-muted:        #5a5750;
  --color-subtle:       #6b6864;
  --color-focus:        #555;
  --color-border:       #e0ddd7;
  --color-border-input: #d4d0ca;
  --border-card:        1px solid var(--color-border);
  --radius-sm:          10px;
  --radius-md:          16px;
  --radius-pill:        100px;
  --shadow-card:        0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.06);
  --color-placeholder:  #b0ada8;
  --color-hover-bg:     #fafaf8;
  --color-ink-hover:    #333;
  --color-icon-muted:   #aaa;
  --note-bg:            #fff8ed;
  --note-border:        #f2d9a6;
  --note-text:          #7a5a1e;
  --note-icon:          #d99000;
  --error-bg:           #fff8f6;
  --error-border:       #f0d5cd;
  --error-text:         #8b3a2a;
  --tooltip-bg:         #1a1a1a;
  color-scheme: light;
}

/* Dark theme, set on <html data-theme> by the head script (saved choice, else OS).
   Contrast (on --color-surface / --color-bg): ink 13.3/14.9, muted 8.5/9.6, subtle 5.7/6.5, note text 10.3:1, error text 8.9:1. */
:root[data-theme="dark"] {
  --color-bg:           #1b1a18;
  --color-surface:      #262421;
  --color-ink:          #f0ede8;
  --color-muted:        #c4c0b8;
  --color-subtle:       #a29d95;
  --color-focus:        #c8c4bd;
  --color-border:       #36332f;
  --color-border-input: #4f4b45;
  --shadow-card:        0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25);
  --color-placeholder:  #7d7972;
  --color-hover-bg:     #2e2c28;
  --color-ink-hover:    #d6d2cb;
  --color-icon-muted:   #77736c;
  --note-bg:            #2c2518;
  --note-border:        #5a4723;
  --note-text:          #ecd29c;
  --note-icon:          #e3a83a;
  --error-bg:           #2e1e1a;
  --error-border:       #5e352b;
  --error-text:         #f3b2a3;
  --tooltip-bg:         #3a3733;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-ink);
  min-height: 100vh;
  padding: 2.5rem 1.25rem 5rem;
}

main {
  max-width: 740px;
  margin: 0 auto;
}

/* Header */
header { margin-bottom: 1.75rem; }

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.header-status {
  font-size: 0.85rem;
  color: var(--color-muted);
  white-space: nowrap;
}

/* Round icon buttons in the header. The ghost variant (share) has no chrome
   until hovered, so it sits quietly beside the theme switch. */
.icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: var(--color-subtle); background: var(--color-hover-bg); }
.icon-btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.icon-btn--ghost { background: transparent; border-color: transparent; color: var(--color-muted); }
.icon-btn--ghost svg { width: 18px; height: 18px; }
.icon-btn--ghost:hover { color: var(--color-ink); }

/* Sun/moon theme switch: shows the theme a click switches to. */
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

header h1 {
  font-size: clamp(1.9rem, 4vw + 1rem, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--color-ink);
}

header p {
  margin-top: 0.6rem;
  color: var(--color-muted);
  font-size: 1rem;
  line-height: 1.5;
  max-width: 480px;
}

/* Search */
.search-form {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.75rem;
}

.search-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-pin {
  position: absolute;
  left: 1rem;
  width: 18px;
  height: 18px;
  color: var(--color-subtle);
  pointer-events: none;
  flex-shrink: 0;
}

.search-input-wrap input {
  width: 100%;
  padding: 0.85rem 2.5rem 0.85rem 2.75rem;
  border: 1.5px solid var(--color-border-input);
  border-radius: var(--radius-pill);
  font-size: 1rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-ink);
  outline: none;
  transition: border-color 0.15s;
}

.search-input-wrap input:focus-visible {
  border-color: var(--color-focus);
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}
.search-input-wrap input::placeholder { color: var(--color-placeholder); }

.search-clear {
  position: absolute;
  right: 0.85rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-subtle);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.25rem;
  display: none;
}

.search-clear.visible { display: block; }
.search-clear:hover { color: var(--color-ink); }
.search-clear:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; border-radius: 4px; }

/* Address suggestions under the search field */
.suggestions {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0;
  z-index: 10;
  list-style: none;
  max-height: 20rem;
  overflow-y: auto;
  padding: 0.35rem;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
}

.suggestion {
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-size: 0.95rem;
  color: var(--color-ink);
  cursor: pointer;
}

.suggestion:hover { background: var(--color-hover-bg); }
.suggestion[aria-selected="true"] { background: var(--color-border); }

.search-form > button[type="submit"] {
  flex-shrink: 0;
  padding: 0.85rem 1.5rem;
  background: var(--color-ink);
  color: var(--color-surface);
  border: none;
  border-radius: var(--radius-pill);
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.search-form > button[type="submit"]:hover { background: var(--color-ink-hover); }
.search-form > button[type="submit"]:disabled { background: var(--color-subtle); cursor: default; }
.search-form > button[type="submit"]:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

/* Loading */
.loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--color-muted);
  font-size: 0.95rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-focus);
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Address label */
.address-header {
  font-size: 0.72rem;
  color: var(--color-subtle);
  margin-bottom: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Share / reminder actions above the timeline */
.schedule-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.6rem;
  margin: -0.4rem 0 1.25rem;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.action-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.action-btn:hover { border-color: var(--color-subtle); background: var(--color-hover-bg); }
.action-btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.action-btn:disabled { opacity: 0.6; cursor: default; }
.schedule-actions[hidden] { display: none; }
.action-btn[aria-pressed="true"] { background: var(--color-ink); border-color: var(--color-ink); color: var(--color-surface); }

.action-status {
  font-size: 0.85rem;
  color: var(--color-muted);
}

/* Shown when an offline / outage fallback renders a saved schedule */
.stale-note {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--note-text);
}

/* Urgency color tokens — inherited by all [data-urgency] children */
[data-urgency="urgent"] { --urgency-bg: #fee2e2; --urgency-dot: #fca5a5; --urgency-text: #991b1b; }
[data-urgency="soon"]   { --urgency-bg: #ffedd5; --urgency-dot: #fdba74; --urgency-text: #9a3412; }
[data-urgency="medium"] { --urgency-bg: #fef9c3; --urgency-dot: #fde047; --urgency-text: #854d0e; }
[data-urgency="near"]   { --urgency-bg: #dcfce7; --urgency-dot: #86efac; --urgency-text: #166534; }
[data-urgency="later"]  { --urgency-bg: #bbf7d0; --urgency-dot: #4ade80; --urgency-text: #14532d; }
[data-urgency="past"]   { --urgency-bg: #f1f5f9; --urgency-dot: #cbd5e1; --urgency-text: #64748b; }

/* Schedule timeline — a vertical line threading a node per pickup date.
   Rows sit flush (no gap) so each row's rail segment joins the next into
   one continuous line; --rail is the node column width, --line its centre. */
.schedule-grid {
  --rail: 40px;      /* node lane width */
  --line: 20px;      /* horizontal centre of the line within the lane */
  --node-cy: 20px;   /* vertical centre of a node from its row's top */
  display: flex;
  flex-direction: column;
}

/* Every timeline row carries its own segment of the connecting line. */
.schedule-grid > * {
  position: relative;
}

.schedule-grid > *::before {
  content: '';
  position: absolute;
  left: var(--line);
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-1px);
  background: var(--color-border-input);
  z-index: 0;
}

/* The projected stretch of the line is dashed, signalling estimated dates. */
.schedule-grid > .projected-note::before,
.schedule-grid > .pickup-projected::before {
  width: 0;
  background: none;
  border-left: 2px dashed var(--color-border-input);
}

/* Trim the line so it begins and ends at the first/last visible node's centre.
   The first row is always visible; the last visible one is the final child, or
   the toggle while collapsed (the rows after it are hidden). */
.schedule-grid > :first-child::before { top: var(--node-cy); }
.schedule-grid > :last-child::before,
.schedule-grid:not(.expanded) > .timeline-toggle::before { bottom: auto; height: var(--node-cy); }
.schedule-grid > :only-child::before { display: none; }

/* Pickup occasion — a plain node dot + label on the top row, box beneath. */
pickup-card {
  min-width: 0;
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  grid-template-rows: calc(var(--node-cy) * 2) auto;
  column-gap: 0.6rem;
  row-gap: 0.4rem;
  padding-bottom: 1.75rem;
}

/* Timeline marker: a small filled dot carrying a darker take on the urgency
   colour, so it reads clearly at 14px (and as the sole cue on mobile). */
.pickup-node {
  grid-column: 1;
  grid-row: 1;
  justify-self: center;
  align-self: center;
  position: relative;
  z-index: 1;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--urgency-dot), var(--urgency-text));
}

/* The urgency count badge inside the box — hidden on mobile, where the
   coloured node carries the urgency instead. */
.pickup-count {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--urgency-dot);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--urgency-text);
}

@media (max-width: 560px) {
  .pickup-count { display: none; }
  .pickup-tag { display: none; }
}

.dot-count { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.dot-unit  { font-size: 1em; font-weight: 800; }
.dot-today { font-size: 2.2rem; font-weight: 800; line-height: 1; }

/* Date + countdown sit above the box, level with the node. */
.pickup-label {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
}

.pickup-countdown {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--color-ink);
}

.pickup-sep { color: var(--color-subtle); }

.pickup-when {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-muted);
}

.pickup-box {
  position: relative;
  z-index: 1;              /* sit above the timeline line it overlaps */
  grid-column: 1 / -1;     /* full width on mobile, over the rail */
  grid-row: 2;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-card);
}

/* Card tag, pinned to the box's top-right corner. */
.pickup-tag {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.pickup-tag--next {
  background: var(--urgency-dot);
  color: var(--urgency-text);
}

.pickup-tag--est {
  background: transparent;
  border: 1px dashed var(--color-border-input);
  color: var(--color-subtle);
}

/* Next pickup — a dimmed status tint on the box (echoing the old dedicated
   next-pickup box) beneath its "Nästa tömning" corner tag. */
.pickup-next .pickup-box {
  background: color-mix(in srgb, var(--urgency-bg) 65%, var(--color-surface));
}

/* Dark: the pastel tint would glare (and sink light text) on a dark box;
   a faint wash of the dot colour keeps the "next" cue instead. */
[data-theme="dark"] .pickup-next .pickup-box {
  background: color-mix(in srgb, var(--urgency-dot) 14%, var(--color-surface));
}

.pickup-types {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.pickup-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.chip-icon, .chip-icon-fallback {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.chip-icon { object-fit: contain; border-radius: 7px; }
.chip-icon-fallback { color: var(--color-icon-muted); }

.chip-name {
  font-size: 0.9rem;
  color: var(--color-muted);
}

/* On mobile, keep the waste types on a single line and let the last chip's
   name truncate with an ellipsis rather than wrap. (Placed after the base
   chip rules so it wins the cascade.) */
@media (max-width: 560px) {
  .pickup-types { flex-wrap: nowrap; }
  .pickup-chip { flex-shrink: 0; }
  .pickup-chip:last-child { flex-shrink: 1; }
  .pickup-chip:last-child .chip-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Projected ("estimated") pickups — a node on the same timeline, revealed on
   demand. Collapsed, the note and projected rows are hidden and the line ends
   at the toggle node; expanded, the line threads on through the estimates. */
.timeline-toggle {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  grid-template-rows: calc(var(--node-cy) * 2);
  align-items: center;
  column-gap: 0.6rem;
  padding-bottom: 1.75rem;
}

.toggle-node {
  grid-column: 1;
  justify-self: center;
  position: relative;
  z-index: 1;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-bg);
  border: 2px dashed var(--color-border-input);
}

.show-projected {
  grid-column: 2;
  justify-self: start;
  padding: 0.55rem 1rem;
  background: transparent;
  border: 1.5px dashed var(--color-border-input);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.show-projected:hover { border-color: var(--color-subtle); background: var(--color-hover-bg); color: var(--color-ink); }
.show-projected:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

/* Collapsed state: keep estimates in the DOM but hidden. */
.schedule-grid:not(.expanded) .pickup-projected,
.schedule-grid:not(.expanded) .projected-note { display: none; }

pickup-card.pickup-projected .pickup-box {
  background: var(--color-bg);   /* opaque page colour, hides the line behind */
  border: 1.5px dashed var(--color-border-input);
  box-shadow: none;
}

pickup-card.pickup-projected .pickup-node { background: var(--color-border-input); }
pickup-card.pickup-projected .pickup-count { opacity: 0.55; }
pickup-card.pickup-projected .chip-icon { opacity: 0.7; }
pickup-card.pickup-projected .pickup-countdown { color: var(--color-muted); font-weight: 700; }
pickup-card.pickup-projected .chip-name { color: var(--color-subtle); }

.projected-note {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  column-gap: 0.6rem;
  padding-bottom: 1rem;
}

.projected-note-body {
  position: relative;
  z-index: 1;
  grid-column: 1 / -1;
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--note-text);
}

.projected-note-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--note-icon);
}

/* Desktop: enough gutter to hang the rail in the left margin, outside the
   full-width boxes. Narrower screens keep the rail behind the boxes (base).
   Placed after the base box/note rules so these overrides win the cascade. */
@media (min-width: 880px) {
  .schedule-grid { margin-left: calc(-1 * (var(--rail) + 0.6rem)); }
  .pickup-box { grid-column: 2; }
  .projected-note-body { grid-column: 2; }
  .chip-name { font-size: 1rem; }
}

/* Address picker */
.address-list-heading {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin-bottom: 0.75rem;
}

.address-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.address-btn {
  display: block;
  width: 100%;
  text-align: left;
  text-decoration: none;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--color-ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: var(--shadow-card);
}

.address-btn:hover { border-color: var(--color-subtle); background: var(--color-hover-bg); }

/* Error */
.error-msg {
  background: var(--error-bg);
  border: 1.5px solid var(--error-border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  color: var(--error-text);
  font-size: 0.95rem;
}

/* Footer */
.site-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.8rem;
  color: var(--color-subtle);
  line-height: 1.6;
}

.site-footer p + p { margin-top: 0.6rem; }

.site-footer a {
  color: var(--color-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-footer a:hover { color: var(--color-ink); }

.footer-byline {
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin-top: 1.25rem;
}

/* Warning icon for anomalous collection dates */
.schedule-warning {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  cursor: default;
}

.schedule-warning:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 3px;
  border-radius: 3px;
}

/* #d95f00 on white = 3.5:1 — passes WCAG 1.4.11 non-text contrast (≥3:1).
   White exclamation on #d95f00 = 3.5:1 — also ≥3:1. */
.warning-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: #d95f00;
}

/* Popover tooltip — rendered in the top layer, never clipped by overflow.
   Position is set entirely by JS; --arrow-left tracks the trigger midpoint. */
.warning-tooltip {
  position: fixed;
  margin: 0;
  padding: 0.35rem 0.7rem;
  background: var(--tooltip-bg);
  color: #fff;
  font-size: 0.78rem;
  font-family: inherit;
  line-height: 1.4;
  border: none;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.warning-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: var(--arrow-left, 50%);
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--tooltip-bg);
}

.warning-tooltip--below::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--tooltip-bg);
}

/* Source link below schedule */
.source-link {
  margin-top: 1.25rem;
  text-align: center;
}

.source-link a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s, background 0.15s;
}

.source-link a:hover { border-color: var(--color-subtle); background: var(--color-hover-bg); }
.source-link a:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; border-radius: var(--radius-sm); }
