/* Planning — one stylesheet, light and dark from the same tokens. */

:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f0f3fa;
  --ink: #1f2430;
  --muted: #6b7280;
  --accent: #2f6fdb;
  --accent-ink: #ffffff;
  --ok: #2e9e5b;
  --warn: #d97706;
  --bad: #dc2626;
  --line: #e2e5ec;
  --today: #fff7d6;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(20, 30, 60, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --fs: 15px;
  --gap: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --panel: #1e2129;
    --panel-2: #262a34;
    --ink: #e8eaf0;
    --muted: #9aa1b1;
    --accent: #5b8def;
    --accent-ink: #0b1220;
    --ok: #4cc27a;
    --warn: #f0a83a;
    --bad: #f0605a;
    --line: #2e3340;
    --today: #33301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: var(--fs)/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand .logo { font-size: 26px; }
.brand b { display: block; font-size: 17px; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 999px; }
.tabs button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.me select { padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); }

/* ---------- layout ---------- */
.main { max-width: 1400px; margin: 0 auto; padding: 16px; }
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 4px 0 10px; }
.section-head h2 { margin: 0; font-size: 20px; }
.section-head .range { color: var(--muted); }
.section-head .weekno { color: var(--muted); font-size: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.badge { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; vertical-align: middle; }
.section-head .spacer { flex: 1; }
.section-head .mine { color: var(--muted); font-size: 14px; }
.section-head .hl { cursor: pointer; border-bottom: 1px dotted var(--muted); padding-bottom: 1px; }
.section-head .hl:hover { color: var(--ink); border-bottom-color: var(--ink); }
.section.hl-open .hl[data-hl="open"], .section.hl-mine .hl[data-hl="mine"] { color: var(--ink); border-bottom: 2px solid var(--accent); }

/* While a count is hovered or pinned: those rides pop, everything else recedes. */
.section.hl-open .item, .section.hl-mine .item { opacity: .45; }
.section.hl-open .item:has(.leg:not(.claimed):not(.trivial)),
.section.hl-mine .item:has(.leg.mine) { opacity: 1; }
.section.hl-open .leg:not(.claimed):not(.trivial),
.section.hl-mine .leg.mine {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
}
.section.hl-open .leg:not(.claimed):not(.trivial) .free { color: var(--ink); }
.section.hl-mine .leg.mine { box-shadow: inset 0 0 0 2px var(--ok); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--radius-s); padding: 8px 14px; cursor: pointer;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-s); color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }

/* ---------- week ---------- */
.week {
  display: grid;
  grid-template-columns: repeat(var(--days, 7), minmax(168px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.day {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  min-height: 90px;
  display: flex; flex-direction: column; gap: 8px;
}
.day.today { background: var(--today); border-color: var(--warn); }
.day.past { opacity: .72; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; cursor: pointer; border-radius: var(--radius-s); padding: 0 4px; margin: 0 -4px; }
.day-head:hover, .day-head:focus-visible { background: var(--panel-2); color: var(--accent); outline: none; }
.day-nav { display: inline-flex; align-items: center; gap: 2px; }
.day-nav .icon-btn { font-size: 18px; line-height: 1; padding: 2px 8px; }
.day-nav .icon-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.day-head b { font-size: 14px; }
.day-head span { color: var(--muted); font-size: 13px; }
.day .empty { color: var(--muted); font-size: 13px; text-align: center; padding: 10px 0; }

/* A card is three rows: the ride there, the activity, the ride back. The legs
   are flat bars glued to the top and bottom of the card. */
.item {
  border-left: 4px solid var(--kid, var(--accent));
  background: var(--panel-2);
  border-radius: var(--radius-s);
  overflow: hidden;
  font-size: 13px;
}
.item.done { opacity: .55; }
/* A custom ride: dashed edge, one leg row on top, the kid and the reason below. */
.item.custom { border-left-style: dashed; }
.leg.single { border-bottom: 1px dashed var(--line); }
.day-add {
  margin-top: auto; align-self: center;
  border: 1px dashed var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 3px 12px; font-size: 12px; cursor: pointer;
}
.day-add:hover { color: var(--accent); border-color: var(--accent); }
.day.quiet .day-add { margin-top: 0; }
.item-main { display: flex; align-items: center; gap: 8px; padding: 7px 8px; }

/* Current time, in today's column only. */
.now-line { display: flex; align-items: center; gap: 6px; color: var(--bad); font-size: 11px; font-weight: 700; margin: -2px 0; }
.now-line::before, .now-line::after { content: ""; flex: 1; border-top: 2px solid var(--bad); }
.now-line::before { flex: 0 0 8px; }
.now-line span { font-variant-numeric: tabular-nums; }
.bell { font-size: 18px; }
.bell.off { filter: grayscale(1); opacity: .7; }
.user { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.user .who { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user .logout { text-decoration: none; font-size: 16px; color: var(--muted); }
.user .logout:hover { color: var(--accent); }
.user .login { text-decoration: none; color: var(--ink); }
/* Anonymous visitor: everything is readable, the edit affordances fade. A
   tap on one still works — it leads to the login. */
body.readonly .leg .free, body.readonly .day-add, body.readonly .tile.add, body.readonly [data-add-activity] { opacity: .45; }
.item-main .avatar { flex: none; border-radius: 50%; }
.item-text { min-width: 0; }
.item-title { font-weight: 500; }
.item-title b { font-weight: 700; }
.item-where { color: var(--muted); }
.item-note { color: var(--muted); font-style: italic; margin-top: 2px; }

.leg {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  width: 100%; text-align: left;
  border: 0; background: var(--panel);
  padding: 4px 6px; cursor: pointer; font-size: 12px;
  box-shadow: inset 0 0 0 1px transparent;
}
.leg.to { border-bottom: 1px dashed var(--line); }
.leg.from { border-top: 1px dashed var(--line); }
.leg.claimed { border-style: solid; }
.leg:hover { box-shadow: inset 0 0 0 1px var(--accent); }
.leg.trivial { color: var(--muted); }
.leg.trivial .t { font-weight: 500; }
.leg .free.dim { color: var(--muted); font-size: 12px; opacity: .5; }
.leg.trivial:hover .free.dim { opacity: 1; color: var(--accent); }
.leg.mine { background: color-mix(in srgb, var(--ok) 14%, var(--panel)); }
.leg.mine .t { color: var(--ok); }
.leg .arrow { color: var(--muted); width: 10px; text-align: center; }
.leg .t { font-weight: 600; font-variant-numeric: tabular-nums; }
.leg .route { color: var(--muted); white-space: nowrap; flex: 1; }
/* Fits on the first line next to the route and time when it can; a long name
   drops to a second line, right-aligned, instead of being cut to "Gr…". */
.leg .driver { display: flex; align-items: center; gap: 4px; font-weight: 600; min-width: 0; max-width: 100%; margin-left: auto; }
.leg .driver span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leg .driver .avatar { border-radius: 50%; }
.leg .free { color: var(--accent); font-weight: 700; font-size: 14px; line-height: 1; margin-left: auto; }
.leg .driver.bus, .leg .driver.guest { font-weight: 500; }
.leg .pen { color: var(--warn); font-size: 11px; }
/* A leg filled from the activity's default driver: dotted, slightly faded,
   until someone confirms it for that date. */
.leg.default { border-style: dotted; }
.leg.default .driver { opacity: .7; font-style: italic; font-weight: 500; }
.leg.default.mine { background: color-mix(in srgb, var(--ok) 7%, var(--panel)); }
.leg .riders { color: var(--muted); font-size: 11px; white-space: nowrap; }
.row.trip .field.time { flex: 0 0 auto; }
.trip-usual { font-size: 13px; margin-top: 4px; }

/* ---------- ride picker ---------- */
.ride-summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel-2); border-radius: var(--radius-s); }
.ride-summary .avatar { flex: none; border-radius: 50%; }
.ride-summary .hint { font-size: 13px; }
.ride-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ride-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius-s); cursor: pointer; font-size: 14px; position: relative;
}
.ride-opt input { position: absolute; opacity: 0; pointer-events: none; }
.ride-opt .avatar { border-radius: 50%; }
.ride-opt .ride-ico { font-size: 34px; line-height: 44px; }
.ride-opt small { color: var(--muted); }
.ride-opt.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); font-weight: 600; }
.ride-opt:hover { border-color: var(--accent); }

/* ---------- today: time grid, one column per kid ---------- */
.timeline {
  display: grid;
  grid-template-columns: 44px repeat(var(--cols), minmax(170px, 1fr));
  gap: 0;
  overflow-x: auto;
  padding: 0;
  position: relative;
}
.tl-corner, .tl-head { border-bottom: 1px solid var(--line); background: var(--panel-2); position: sticky; top: 0; z-index: 3; }
.tl-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.tl-head .avatar { border-radius: 50%; }
.tl-gutter { position: relative; border-right: 1px solid var(--line); }
.tl-hour { position: absolute; right: 6px; transform: translateY(-50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-hour:first-child { transform: none; }
.tl-hour:last-child { transform: translateY(-100%); }
.tl-col {
  position: relative; border-right: 1px solid var(--line);
  background: repeating-linear-gradient(to bottom, var(--line) 0, var(--line) 1px, transparent 1px, transparent var(--hour-px, 96px));
}
.tl-col:last-child { border-right: 0; }
.tl-item {
  position: absolute; left: 6px; right: 6px; overflow: hidden;
  background: var(--panel-2); border-left: 4px solid var(--kid, var(--accent)); border-radius: var(--radius-s);
  padding: 4px 8px; font-size: 13px; box-shadow: var(--shadow); z-index: 1;
}
.tl-item.done { opacity: .55; }
.tl-item.pad-top { padding-top: 26px; }
.tl-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-where { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-leg { position: absolute; left: 6px; right: 6px; height: 22px; z-index: 2; }
.tl-leg .leg { height: 22px; padding: 0 6px; border-radius: var(--radius-s); border: 1px solid var(--line); flex-wrap: nowrap; overflow: hidden; }
.tl-leg .leg.to { border-bottom: 1px solid var(--line); }
.tl-leg .leg.from { border-top: 1px solid var(--line); }
.tl-leg .leg .driver span { max-width: 80px; }
.tl-ride .leg { border-style: dashed; }
.tl-now { position: absolute; left: 44px; right: 0; border-top: 2px solid var(--bad); z-index: 4; pointer-events: none; }
.tl-now span { position: absolute; left: -44px; top: -9px; width: 40px; text-align: right; font-size: 11px; font-weight: 700; color: var(--bad); font-variant-numeric: tabular-nums; }
.section-head .day-add { margin: 0; align-self: center; }
@media (max-width: 600px) {
  .timeline { grid-template-columns: 40px repeat(var(--cols), minmax(150px, 1fr)); }
}

/* ---------- lists (people, places, activities) ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--gap); }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 12px; text-align: center; cursor: pointer;
}
.tile:hover { border-color: var(--accent); }
.tile .avatar { border-radius: 50%; }
.tile .name { font-weight: 600; }
.tile .role, .tile .addr { color: var(--muted); font-size: 13px; }
.tile .big { font-size: 44px; line-height: 1; }
.tile.add { justify-content: center; color: var(--muted); border-style: dashed; min-height: 150px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.table tr:last-child td { border-bottom: 0; }
.table tr.act { cursor: pointer; }
.table tr.act:hover td { background: var(--panel-2); }
.table .muted { color: var(--muted); }
.group-head { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; font-weight: 600; }
.group-head .avatar { border-radius: 50%; }

.hint { color: var(--muted); }
.callout { padding: 20px; text-align: center; }
.callout h3 { margin: 0 0 6px; }
.callout p { margin: 0 0 12px; color: var(--muted); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(10, 14, 24, .5); display: flex; align-items: flex-end; justify-content: center; z-index: 20;
  padding: 0;
}
.modal-card {
  background: var(--panel); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: var(--radius) var(--radius) 0 0; box-shadow: var(--shadow);
}
@media (min-width: 700px) {
  .modal { align-items: center; padding: 20px; }
  .modal-card { border-radius: var(--radius); }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--panel); width: 100%;
}
.field textarea { resize: vertical; min-height: 60px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.radios { display: flex; gap: 6px; flex-wrap: wrap; }
.radios label {
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.radios input { margin: 0; }
.radios label:has(input:checked) { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.actions { display: flex; gap: 8px; margin-top: 6px; }
.actions .spacer { flex: 1; }
.error { color: var(--bad); font-size: 13px; min-height: 1em; }

.emoji-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.emoji-grid button {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-s); font-size: 22px; width: 40px; height: 40px; cursor: pointer;
}
.emoji-grid button.sel, .emoji-grid button:hover { border-color: var(--accent); background: var(--panel-2); }

.avatar-editor { display: flex; gap: 16px; align-items: flex-start; }
.avatar-editor .preview { flex: none; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.avatar-editor .preview .avatar { border-radius: 50%; }
.avatar-editor .parts { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.part { display: grid; grid-template-columns: 32px 1fr 32px; align-items: center; gap: 4px; }
.part .lbl { text-align: center; font-size: 13px; }
.part .lbl small { display: block; color: var(--muted); font-size: 11px; }
.part button { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-s); height: 30px; cursor: pointer; }
.part button:hover { background: var(--panel-2); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; opacity: 0; transition: .2s; pointer-events: none; z-index: 30;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- phone ---------- */
@media (max-width: 960px) {
  .week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .top { padding: 8px 12px; }
  .brand small { display: none; }
  .tabs { order: 3; width: 100%; justify-content: space-between; }
  .tabs button { flex: 1; padding: 6px 4px; font-size: 14px; }
  .main { padding: 10px; }
  .week { grid-template-columns: 1fr; overflow: visible; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 8px; }
  /* Activities: the table becomes a list of cards, one activity per block. */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table tr { padding: 8px 12px; border-bottom: 1px solid var(--line); }
  .table tr:last-child { border-bottom: 0; }
  .table td { padding: 0; border: 0; }
  .table td.when, .table td.where { display: inline-block; color: var(--muted); font-size: 13px; margin-right: 10px; margin-top: 2px; }
  .day.quiet { flex-direction: row; align-items: center; min-height: 0; padding: 6px 10px; }
  .day.quiet .day-head { flex: 1; }
  .day.quiet .empty { padding: 0; }
  .avatar-editor { flex-direction: column; align-items: center; }
  .avatar-editor .parts { width: 100%; }
}
