:root {
  color-scheme: light dark;
  --fg: #1d1d1f;
  --muted: #6e6e73;
  --bg: #fafafa;
  --card: #fff;
  --line: #e3e3e8;
  --accent: #2563eb;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f2f2f5;
    --muted: #a1a1a6;
    --bg: #161618;
    --card: #1f1f22;
    --line: #333338;
    --accent: #60a5fa;
  }
}

body { margin: 0; background: var(--bg); color: var(--fg); }
main { position: relative; max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
a { color: var(--accent); }
h1 { margin-top: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; width: 100%; }

input, button {
  font: inherit;
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
}
button { cursor: pointer; background: var(--accent); color: #fff; border-color: transparent; }
button.danger { background: transparent; color: #dc2626; border-color: var(--line); }

.trip-name { display: flex; gap: .5rem; align-items: center; }
.trip-name input { flex: 1; font-size: 1.6rem; font-weight: 600; border-color: transparent; background: transparent; padding-left: 0; }
.trip-name input:focus { border-color: var(--line); background: var(--card); padding-left: .6rem; }
.hint, .empty { color: var(--muted); }

.views { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: .5rem 0 1rem; }
.views a { padding: .35rem .9rem; text-decoration: none; color: var(--fg); }
.views a[aria-current] { background: var(--accent); color: #fff; }

/* Timeline: one row per family, time goes from left to right. */
.timeline-scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .5rem; }
.timeline { min-width: calc(10rem + var(--days) * 4.5rem); }
.timeline .row { display: grid; grid-template-columns: 10rem 1fr; align-items: center; min-height: 2.2rem; }
.timeline .label { padding-right: .5rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timeline .label a { color: var(--fg); text-decoration: none; font-weight: 500; }
.timeline .people { color: var(--muted); }
.timeline .track {
  position: relative;
  height: 2.2rem;
  /* A thin line at the start of each day. */
  background: repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px calc(100% / var(--days)));
}
.timeline .axis .track { height: 1.6rem; }
.timeline .day { position: absolute; top: .2rem; padding-left: .3rem; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.timeline .bar {
  position: absolute;
  top: .3rem;
  bottom: .3rem;
  border-radius: 6px;
  background: hsl(var(--hue) 70% 55%);
  color: #fff;
  font-size: .75rem;
  line-height: 1.6rem;
  padding: 0 .4rem;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}
.timeline .total { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .3rem; }
.timeline .total .label { font-weight: 600; }
.timeline .seg {
  position: absolute;
  top: .2rem;
  bottom: .2rem;
  background: color-mix(in srgb, var(--accent) calc(var(--level) * 70% + 8%), transparent);
  border-right: 1px solid var(--card);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.timeline .count { font-weight: 600; font-size: .85rem; }

/* Table view */
table.families { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.families th, .families td { padding: .4rem; text-align: left; border-bottom: 1px solid var(--line); }
.families tr { border-left: 6px solid hsl(var(--hue) 70% 55%); }
.families input { width: 100%; box-sizing: border-box; }
.families input[type=number] { width: 5rem; }
.families .actions { display: flex; gap: .3rem; white-space: nowrap; }
.families tfoot td { font-weight: 600; border-bottom: none; }
.families .total-price { padding-left: 1rem; }
.families tr:target { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* History */
table.history { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.history th, .history td { padding: .4rem .6rem; text-align: left; border-bottom: 1px solid var(--line); }
.history .when { white-space: nowrap; color: var(--muted); }
.actions { display: flex; gap: .75rem; align-items: center; white-space: nowrap; }

form.add { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-top: 2rem; padding: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
form.add label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); }

.api { margin-top: 2rem; color: var(--muted); }
.agents { position: absolute; top: .3rem; right: 1rem; font-size: .8rem; color: var(--muted); }
.error { color: #dc2626; }
