:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --ok: #2e9e5b;
  --warn: #d99a26;
  --danger: #d03b3b;
  --lock-wash: rgba(217, 154, 38, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --border: rgba(255, 255, 255, 0.12);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --ok: #45b374;
    --warn: #e0a83e;
    --danger: #e05555;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", sans-serif;
  background: var(--page);
  color: var(--ink);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main { max-width: 640px; margin: 0 auto; padding: 0 12px 48px; }

.app-header {
  max-width: 640px; margin: 0 auto;
  padding: 14px 12px 8px;
  display: flex; align-items: baseline; gap: 10px;
}
.app-title { font-size: 20px; margin: 0; font-weight: 700; }
.app-sub { font-size: 12px; color: var(--muted); }

/* ---- tabs ---- */
.tabs {
  max-width: 640px; margin: 0 auto 12px;
  padding: 0 12px;
  display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 6px;
}
.tab {
  padding: 10px 4px;
  font-size: 14px; font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.tab.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- cards & forms ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}
.card-title { font-size: 15px; margin: 0 0 10px; font-weight: 700; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; }
.entry-count { font-size: 12px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.6; }

.form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.form-row:last-child { margin-bottom: 0; }
.form-row label { font-size: 13px; color: var(--ink-2); min-width: 6.5em; }
.form-row input[type="text"], .form-row select {
  flex: 1;
  font-size: 15px; padding: 8px 10px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink);
  min-width: 0;
}

input[type="date"], input[type="time"] {
  font-size: 15px; padding: 7px 8px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink);
}

.primary-btn {
  background: var(--accent); color: #fff;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 600;
  padding: 10px 16px; cursor: pointer;
}
.big-btn { width: 100%; padding: 14px; font-size: 16px; }
.ghost-btn {
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 12px;
  font-size: 14px; padding: 9px 14px; cursor: pointer;
}
.small-btn { padding: 6px 12px; font-size: 13px; }
.danger-btn {
  background: none; color: var(--danger);
  border: 1px solid var(--danger); border-radius: 12px;
  font-size: 14px; padding: 9px 14px; cursor: pointer;
}
.icon-btn {
  width: 32px; height: 32px;
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2);
  font-size: 14px; cursor: pointer; flex: none;
}
.lock-btn {
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
  font-size: 11px; padding: 7px 9px;
  cursor: pointer; flex: none; white-space: nowrap;
  font-family: inherit;
}
.lock-btn.is-on {
  background: var(--warn); border-color: var(--warn);
  color: #fff; font-weight: 700;
}

/* ---- days ---- */
.day-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.day-item {
  padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--page);
}
.day-main { display: flex; align-items: center; gap: 10px; }
.day-main .d-date { font-weight: 700; font-size: 15px; }
.day-main .d-time { font-size: 13px; color: var(--ink-2); }
.day-main .d-slots { font-size: 12px; color: var(--muted); margin-left: auto; }
.day-ex {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.ex-label { font-size: 12px; color: var(--muted); }
.ex-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 4px 6px 4px 9px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.ex-del {
  border: none; background: none; color: var(--muted);
  font-size: 14px; line-height: 1; padding: 2px 4px;
  cursor: pointer;
}
.ex-time { font-size: 13px; padding: 4px 5px; }
.day-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tilde { color: var(--muted); }

.data-tools { display: flex; gap: 8px; }
.data-note { font-size: 11px; color: var(--muted); margin: 8px 2px 0; }

/* ---- families ---- */
.fam-add { display: flex; gap: 8px; }
.fam-add input { flex: 1; font-size: 15px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--page); color: var(--ink); min-width: 0; }
.bulk-add { margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.bulk-add textarea {
  width: 100%; margin: 8px 0;
  font-size: 15px; padding: 8px 10px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink);
  font-family: inherit;
}

.pref-legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin: 8px 0 10px; }
.p-o { color: var(--ok); font-style: normal; }
.p-d { color: var(--warn); font-style: normal; }
.p-x { color: var(--danger); font-style: normal; }

.pref-wrap { overflow-x: auto; margin: 0 -4px; }
.pref-table { border-collapse: collapse; width: 100%; }
.pref-table th, .pref-table td {
  border: 1px solid var(--border);
  padding: 0; text-align: center;
  font-size: 14px;
}
.pref-table th { font-weight: 600; font-size: 12px; color: var(--ink-2); padding: 6px 4px; background: var(--page); }
.pref-table th.name-col { text-align: left; padding-left: 8px; }
.pref-name {
  display: block; width: 100%;
  border: none; background: none; color: var(--ink);
  font-size: 14px; font-weight: 600; text-align: left;
  padding: 10px 8px; cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.pref-name .fam-meta { display: block; font-size: 10px; font-weight: 400; color: var(--muted); }
.pref-cell {
  width: 100%; min-width: 44px; min-height: 44px;
  border: none; background: none;
  font-size: 18px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 4px 2px;
}
.cell-time {
  font-size: 9px; font-weight: 500; color: var(--muted);
  font-variant-numeric: tabular-nums; line-height: 1.2;
  white-space: nowrap;
}
.pref-cell.v-o { color: var(--ok); }
.pref-cell.v-d { color: var(--warn); background: rgba(217, 154, 38, 0.08); }
.pref-cell.v-x { color: var(--danger); background: rgba(208, 59, 59, 0.08); }

.empty-note { font-size: 13px; color: var(--muted); padding: 12px 4px; }

/* ---- schedule ---- */
.assign-summary { font-size: 13px; color: var(--ink-2); margin-top: 10px; }
.assign-summary b { font-size: 16px; }
.unassigned-box {
  margin-top: 10px; padding: 10px;
  border: 1px dashed var(--danger); border-radius: 12px;
}
.unassigned-title { font-size: 12px; color: var(--danger); font-weight: 600; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 600;
  padding: 7px 12px; cursor: pointer;
}
.chip.is-sel { background: var(--accent); border-color: var(--accent); color: #fff; }

.sel-bar {
  position: sticky; top: 8px; z-index: 10;
  max-width: 616px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--accent); color: #fff;
  border-radius: 12px; padding: 10px 12px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
}
.sel-bar .ghost-btn { background: rgba(255,255,255,0.15); color: #fff; border-color: rgba(255,255,255,0.4); }

.sched-day { margin-bottom: 14px; }
.sched-day-title { font-size: 15px; font-weight: 700; margin: 0 0 8px 4px; }
.slot-list { display: flex; flex-direction: column; gap: 5px; }
.slot {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface);
  padding: 8px 10px;
  min-height: 46px;
}
.slot-time { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; flex: none; width: 7.2em; }
.slot-body {
  flex: 1; text-align: left;
  border: none; background: none; color: var(--ink);
  font-size: 15px; font-weight: 600;
  padding: 6px 4px; cursor: pointer; font-family: inherit;
  border-radius: 8px;
  min-width: 0;
}
.slot-body .placeholder { color: var(--muted); font-weight: 400; font-size: 13px; }
.slot.is-target .slot-body { background: var(--accent-wash); outline: 2px dashed var(--accent); }
.slot.is-sel { outline: 2px solid var(--accent); }
.slot.is-blocked { background: none; border-style: dashed; }
.slot.is-blocked .slot-body { color: var(--muted); font-weight: 400; cursor: default; }
.slot.is-locked { background: var(--lock-wash); }
.slot.is-cont { border-style: dotted; }
.slot.is-cont .slot-body { color: var(--ink-2); font-weight: 400; }
.pref-badge { font-size: 12px; font-weight: 700; margin-left: 6px; }
.slot-note { font-size: 11px; color: var(--muted); font-weight: 400; }

.print-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.collect-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- dialog ---- */
dialog {
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--ink);
  padding: 16px; width: min(92vw, 420px);
}
dialog::backdrop { background: rgba(0,0,0,0.4); }
.fam-form h3 { margin: 0 0 14px; font-size: 16px; }
.seg { display: flex; gap: 6px; flex: 1; }
.seg button {
  flex: 1; padding: 8px 4px;
  font-size: 13px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--page); color: var(--ink-2); cursor: pointer;
  font-family: inherit;
}
.seg button.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.fam-form-btns { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.spacer { flex: 1; }

.day-pref-head { font-size: 13px; color: var(--ink-2); margin: 14px 0 8px; font-weight: 600; }
.day-pref-note { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.day-pref-list { display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.dp-row {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 10px; background: var(--page);
}
.dp-head { display: flex; align-items: center; gap: 10px; }
.dp-date { font-size: 13px; font-weight: 700; min-width: 5em; }
.dp-seg { max-width: 180px; }
.dp-seg button { padding: 6px 2px; font-size: 15px; font-weight: 700; }
.dp-times { display: flex; align-items: center; gap: 6px; margin-top: 8px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: var(--page);
  font-size: 13px; font-weight: 600;
  padding: 10px 16px; border-radius: 999px;
  z-index: 100; max-width: 88vw;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

/* ---- print ---- */
.print-area { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }

  .pr-title { font-size: 16pt; font-weight: 700; margin: 0 0 2mm; }
  .pr-sub { font-size: 10pt; margin: 0 0 5mm; color: #333; }

  .pr-table { border-collapse: collapse; width: 100%; }
  .pr-table th, .pr-table td {
    border: 1pt solid #000; padding: 1.6mm 2.5mm;
    font-size: 10.5pt; text-align: left;
    vertical-align: middle;
  }
  .pr-table th { background: #eee; font-size: 9.5pt; text-align: center; }
  .pr-table .t-col { width: 26mm; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .pr-table .blocked-cell { color: #999; text-align: center; }
  .pr-table .off { background: #e6e6e6; }
  .pr-table .span-cell { background: #fafafa; }
  .pr-table thead { display: table-header-group; }

  .slips { display: grid; grid-template-columns: 1fr 1fr; }
  .slip {
    border: 1pt dashed #666;
    padding: 5mm; break-inside: avoid;
    font-size: 10.5pt; line-height: 1.7;
  }
  .slip h3 { font-size: 12pt; margin: 0 0 2mm; text-align: center; }
  .slip .s-name { font-size: 13pt; font-weight: 700; }
  .slip .s-dt { font-size: 12pt; font-weight: 700; }
  .slip .s-foot { font-size: 8.5pt; color: #444; margin-top: 2mm; }

  /* 希望調査票 */
  .survey {
    break-inside: avoid;
    border-bottom: 1pt dashed #999;
    padding: 4mm 0 5mm;
    margin-bottom: 4mm;
  }
  .sv-title { font-size: 13pt; font-weight: 700; margin: 0 0 2.5mm; text-align: center; }
  .sv-name { font-size: 11pt; margin: 0 0 2mm; }
  .sv-name-label { font-size: 9pt; color: #333; }
  .sv-name b { font-size: 13pt; border-bottom: 0.6pt solid #000; padding: 0 6mm; }
  .sv-lead { font-size: 9pt; line-height: 1.6; margin: 0 0 2.5mm; color: #222; }
  .sv-table { border-collapse: collapse; width: 100%; }
  .sv-table th, .sv-table td {
    border: 0.8pt solid #000; padding: 2mm 2.5mm;
    font-size: 10pt; vertical-align: middle;
  }
  .sv-table th { background: #eee; font-size: 9pt; text-align: center; }
  .sv-table .sv-date { width: 46mm; }
  td.sv-date { font-weight: 700; }
  .sv-table .sv-time { display: block; font-size: 8.5pt; font-weight: 400; color: #333; }
  .sv-table .sv-mark { width: 22mm; text-align: center; }
  td.sv-mark, td.sv-memo { height: 11mm; }
  .sv-foot {
    display: flex; justify-content: space-between;
    font-size: 9pt; color: #222; margin-top: 2.5mm;
  }
}
