:root {
  --bg: #f3f4f6;
  --card: #fff;
  --text: #1f2328;
  --muted: #667085;
  --line: #d9dce1;
  --accent: #2563eb;

  --sat: #fde1e5;
  --sun: #f6a5b3;
  --school: #8fe07b;
  --school-soft: #c3e4b4;
  --vac: #b9d3ff;
  --run: #2563eb;
  --free-line: #8db4ff;
  --free-bg: #e8f0ff;
  --sugg: #ffe39a;
  --sugg-run: #e89b0c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; }

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { border-color: #a9b0bb; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.link { border: 0; background: none; padding: 0 4px; color: var(--muted); }
button.link:hover { color: #b42318; }

.app {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.card, .cal-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

h1 { font: bold 20px Arial, Helvetica, sans-serif; margin: 0; }
h2 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; color: var(--muted); font-size: 12px; flex: 1; min-width: 0; }
.field input, .field select {
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  background: #fff;
  width: 100%;
}
.row { display: flex; gap: 8px; }
.row[hidden] { display: none; }

.year-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.year-nav strong { font-size: 20px; }
.year-nav button { width: 34px; font-size: 18px; line-height: 1; }

.list { list-style: none; margin: 10px 0 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.list li > div { flex: 1; min-width: 0; }
.list .sub { color: var(--muted); font-size: 12px; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; }
.ratio { font-weight: bold; color: var(--sugg-run); white-space: nowrap; }

.sug-summary { margin: 10px 0 4px; padding: 8px; background: #fff8e1; border-radius: 8px; }
.sug-actions { display: flex; gap: 6px; margin-top: 6px; }
.sug-actions button { flex: 1; }
h3 { font-size: 12px; margin: 14px 0 0; color: var(--muted); font-weight: 600; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.members li { flex-wrap: wrap; row-gap: 2px; }
.members .name { flex: 1; min-width: 0; border: 1px solid transparent; border-radius: 6px; padding: 3px 5px; }
.members .name:hover, .members .name:focus { border-color: var(--line); }
.members .mbudget { width: 62px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 5px; }
.members .sub { flex-basis: 100%; padding-left: 18px; }
.members .sub.warn { color: #b42318; }
#member-add { margin-top: 8px; width: 100%; }
.field[hidden] { display: none; }
.names { color: var(--muted); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.field .chips { margin-top: 2px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px 1px 6px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--c); }
.chip.on { color: var(--text); border: 1px solid var(--c); background: color-mix(in srgb, var(--c) 12%, #fff); }
.chip.on::before { background: var(--c); }

details summary { cursor: pointer; color: var(--accent); margin-top: 8px; }
.preset-form { margin-top: 8px; }
.form-title { font-weight: 600; margin: 0 0 8px; }
.field select:disabled { color: var(--muted); background: var(--bg); }

/* ---------- calendar ---------- */

.cal-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.cal-title { flex: 1; min-width: 0; }
.sidebar-toggle { width: 32px; height: 32px; padding: 0; font-size: 16px; line-height: 1; flex: none; }

.app.collapsed { grid-template-columns: minmax(0, 1fr); }
.app.collapsed .sidebar { display: none; }
.cal-head p { margin: 2px 0 0; font: 12px Arial, Helvetica, sans-serif; }
.cal-scroll { overflow-x: auto; }

.cal {
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
  min-width: 1040px;
  font: 11px Arial, Helvetica, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
.cal th { border: 1px solid #000; font-size: 13px; padding: 2px; background: #fff; }
.cal td {
  border: 1px solid #000;
  height: 27px;
  padding: 2px 4px 0 6px;
  position: relative;
  vertical-align: top;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
}
.cal td.empty { cursor: default; }
.cal td:not(.empty):hover { box-shadow: inset 0 0 0 2px rgba(37, 99, 235, .35); }
.cal td.sa { background: var(--sat); font-weight: bold; }
.cal td.so { background: var(--sun); font-weight: bold; }
.cal td.extra-free {
  background:
    repeating-linear-gradient(45deg, var(--free-line) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(-45deg, var(--free-line) 0 2px, transparent 2px 8px),
    var(--free-bg);
  font-weight: bold;
}
.cal td.extra-free.part { --free-line: #a6c4ff; --free-bg: #fff; }
.cal td.vac { background: var(--vac); font-weight: bold; }
.cal td.vac-preset {
  background: repeating-linear-gradient(135deg, var(--vac) 0 5px, #dce8ff 5px 10px);
  font-weight: bold;
}
.cal td.sugg { background: repeating-linear-gradient(135deg, var(--sugg) 0 5px, #fff4d1 5px 10px); font-weight: bold; }
.cal td.selecting { box-shadow: inset 0 0 0 2px var(--accent); }

/* school holiday bar on the right edge */
.cal td.school::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 11px;
  background: var(--school);
}
.cal td.school.sa::after, .cal td.school.so::after { background: var(--school-soft); }

/* "off in a row" bar on the left edge */
.cal td.in-run::before, .cal td.in-sugg-run::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 4px;
  background: var(--run);
}
.cal td.in-sugg-run::before { background: var(--sugg-run); }

.cal .kw { position: absolute; top: 1px; right: 13px; font-size: 8px; font-weight: normal; }
.cal .line2 { display: flex; align-items: center; gap: 3px; padding-right: 10px; min-width: 0; }
.cal .dots { display: inline-flex; gap: 2px; flex: none; }
.cal .dots i { width: 6px; height: 6px; border-radius: 50%; box-shadow: 0 0 0 1px #fff; }
.cal .name {
  display: block;
  min-width: 0;
  font-size: 8px;
  font-weight: normal;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal td.has-title { overflow: visible; }
.cal .vtitle {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 2;
  writing-mode: vertical-rl;
  transform: translateX(-50%) rotate(180deg);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font: bold 11px Arial, Helvetica, sans-serif;
  letter-spacing: .3px;
  color: #1e3a8a;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff;
  pointer-events: none;
}
.cal .half { position: absolute; right: 13px; bottom: 1px; font-size: 10px; font-weight: bold; }

/* one marker segment per household member, bottom edge */

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; padding: 0; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 16px; height: 12px; border: 1px solid #0003; }
.sw-sa { background: var(--sat); }
.sw-so { background: var(--sun); }
.sw-free {
  background:
    repeating-linear-gradient(45deg, var(--free-line) 0 1.5px, transparent 1.5px 5px),
    repeating-linear-gradient(-45deg, var(--free-line) 0 1.5px, transparent 1.5px 5px),
    var(--free-bg);
}
.sw-school { background: var(--school); }
.sw-vac { background: var(--vac); }
.sw-preset { background: repeating-linear-gradient(135deg, var(--vac) 0 3px, #dce8ff 3px 6px); }
.sw-sugg { background: repeating-linear-gradient(135deg, var(--sugg) 0 3px, #fff4d1 3px 6px); }
.sw-run { width: 4px; background: var(--run); border: 0; }
.sw-dot { width: 8px; height: 8px; border-radius: 50%; border: 0; }

.head-actions { display: flex; gap: 6px; align-items: center; }

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
button.danger { color: #b42318; }
button.danger:hover { border-color: #b42318; }

.share { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.share p { margin: 6px 0; }
.share [data-share="create"] { width: 100%; }
.share-status { font-size: 12px; color: var(--muted); }
.share-status b { color: var(--text); font-weight: 600; }
.share-status.warn { color: #8a4b00; }
.share-notice { background: #fff4e5; border: 1px solid #f5c37a; color: #8a4b00; border-radius: 6px; padding: 6px 8px; }

.toast {
  position: fixed;
  inset: auto;
  margin: 0;
  border: 0;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 20px);
  background: #1f2328;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; padding: 16px; }
  .sidebar { position: static; max-height: none; order: 2; }
}

@media print {
  @page { size: A4 landscape; margin: 7mm; }
  body { background: #fff; }
  .app { display: block; padding: 0; }
  .sidebar, .no-print, .toast { display: none; }
  .cal-wrap { border: 0; padding: 0; }
  .cal { min-width: 0; font-size: 8px; }
  .cal th { font-size: 10px; }
  .cal td { height: 16.5px; padding-top: 0; }
  .cal .name, .cal .kw { font-size: 6px; }
  .cal .vtitle { font-size: 8px; }
  .cal .dots i { width: 4px; height: 4px; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
