* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color: #222;
  background: #f7f5f2;
  line-height: 1.6;
  padding-bottom: 64px;
}
h1 { font-size: 1.2rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
button, .btn {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  display: inline-block;
}
button:hover:not(:disabled), .btn:hover { background: #f0ede8; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: #3d6f9e; border-color: #3d6f9e; color: #fff; }
button.primary:hover:not(:disabled) { background: #2f5a82; }
button.danger { color: #b3261e; border-color: #e3b4b0; }
button.link { border: none; background: none; color: #3d6f9e; padding: 0 4px; font-size: .85rem; text-decoration: underline; }
input[type="text"], input[type="number"], select {
  font: inherit;
  padding: 4px 6px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #fff;
  max-width: 100%;
}
input.num { width: 4.8em; }
input:disabled, select:disabled { background: #eee; color: #888; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: #777; }
.nowrap { white-space: nowrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

.app-header {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid #ddd;
}
.header-menu { display: flex; gap: 6px; flex-wrap: wrap; }
.banner { margin: 8px 16px; padding: 8px 12px; border-radius: 6px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.banner.warn { background: #fdecea; border: 1px solid #f1b0a8; }
.banner.hint { background: #eef5fb; border: 1px solid #b6d3ec; }
.banner.info { background: #fff8e1; border: 1px solid #f0d58a; margin: 8px 0; }

.tabs { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; white-space: nowrap; border-bottom: 1px solid #ddd; background: #fff; }
.tab { border-radius: 6px 6px 0 0; border-bottom: none; background: #f0ede8; flex: 0 0 auto; }
.tab.active { background: #3d6f9e; color: #fff; border-color: #3d6f9e; }
main { padding: 16px; max-width: 1280px; margin: 0 auto; }
.box { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 10px 14px; margin: 12px 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 8px 0; }
.empty { padding: 16px; background: #fff; border: 1px dashed #ccc; border-radius: 8px; text-align: center; color: #666; }
.warn-text { color: #b3261e; margin: 6px 0 0; }
.card { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 10px 14px; margin: 8px 0; }

/* ① メンバー */
.member-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.member-row input[type="color"] { width: 40px; height: 34px; padding: 0; border: none; background: none; }
.fld { display: flex; flex-direction: column; font-size: .85rem; }
.fld span { color: #555; }
.target-out { min-width: 120px; }
.target-out small { display: block; color: #777; }

/* ② 家事リスト */
.add-form { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.table-scroll { overflow-x: auto; }
.chore-table, .data-table { border-collapse: collapse; background: #fff; width: 100%; font-size: .9rem; }
.chore-table th, .chore-table td, .data-table th, .data-table td { border: 1px solid #e0ddd8; padding: 4px 6px; vertical-align: middle; text-align: left; }
.chore-table th, .data-table th { background: #f3f0eb; white-space: nowrap; }
.chore-table input[type="text"] { width: 13em; }
.chore-table tr.locked { background: #f4f7fb; }
.num-cell { text-align: right; white-space: nowrap; }
.dislike { display: inline-flex; align-items: center; margin-right: 4px; }
.days { white-space: nowrap; font-size: .8rem; }
.day { display: inline-flex; flex-direction: column; align-items: center; margin-right: 1px; }
.actions { white-space: nowrap; }
.actions button { margin: 2px; padding: 4px 8px; }
.data-table tr.gap-warn td { background: #fdecea; font-weight: bold; }
.gap-warn { color: #b3261e; font-weight: bold; }

/* プリセット */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 12px; }
.modal-body { background: #fff; border-radius: 10px; padding: 16px; width: min(860px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal-body.small { width: min(420px, 100%); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.preset-list { overflow-y: auto; flex: 1; margin-top: 8px; }
.preset-list fieldset { border: 1px solid #ddd; border-radius: 8px; margin: 0 0 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 2px 10px; }
.preset-list legend { font-weight: bold; }
.preset-item.added { color: #999; }
.badge { font-size: .7rem; background: #fff2cc; border: 1px solid #e8cf7a; border-radius: 8px; padding: 0 6px; }
.badge.done { background: #e6e6e6; border-color: #ccc; }

/* ③ グラフ */
.chart-wrap { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 10px; overflow: hidden; }
.chart-wrap canvas { display: block; }
.gap-message { font-weight: bold; }

/* ④ 提案 */
.minibar-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.minibar-label { width: 3.5em; font-size: .8rem; color: #555; flex: 0 0 auto; }
.minibar { flex: 1; display: flex; height: 18px; border-radius: 4px; overflow: hidden; background: #eee; }
.minibar span { display: block; height: 100%; color: #fff; font-size: .7rem; text-align: center; line-height: 18px; overflow: hidden; white-space: nowrap; }
.suggest-card .step { display: inline-block; width: 1.6em; height: 1.6em; line-height: 1.6em; text-align: center; border-radius: 50%; background: #3d6f9e; color: #fff; margin-right: 6px; font-size: .8rem; }
.suggest-card button { margin-top: 6px; }

/* ⑤ 分担表 */
.print-head h2 { margin-bottom: 0; }
.week-table td { min-width: 120px; font-size: .85rem; }
.member-lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.member-card { border-left: 6px solid #999; margin: 0; }
.member-card h4 { margin: 0 0 4px; }
.member-card ul { margin: 0; padding-left: 1.2em; font-size: .85rem; }
.plain-text { width: 100%; font-family: inherit; font-size: .85rem; padding: 8px; border: 1px solid #bbb; border-radius: 6px; }

/* ⑥ 履歴 */
.history-item { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }

/* フッター・トースト */
.app-footer { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid #ddd; padding: 8px 16px; font-size: .85rem; z-index: 40; overflow-x: auto; white-space: nowrap; }
.toast-container { position: fixed; bottom: 56px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; width: max-content; max-width: 92vw; }
.toast { background: #333; color: #fff; padding: 8px 14px; border-radius: 6px; font-size: .9rem; transition: opacity .4s; }
.toast.error { background: #b3261e; }
.toast.hide { opacity: 0; }

/* スマホ：家事一覧をカード表示 */
@media (max-width: 760px) {
  main { padding: 10px; }
  .chore-table thead { display: none; }
  .chore-table, .chore-table tbody, .chore-table tr, .chore-table td { display: block; width: 100%; }
  .chore-table tr { border: 1px solid #ddd; border-radius: 8px; margin-bottom: 10px; padding: 6px; background: #fff; }
  .chore-table tr.locked { background: #f4f7fb; }
  .chore-table td { border: none; padding: 3px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .chore-table td::before { content: attr(data-label); flex: 0 0 5.5em; font-size: .78rem; color: #666; }
  .chore-table td.actions::before { content: ""; }
  .chore-table input[type="text"] { width: auto; flex: 1; min-width: 0; }
  .num-cell { text-align: left; }
  .days { white-space: normal; }
}

/* 印刷：A4縦1枚の分担表 */
@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #fff; padding: 0; font-size: 10pt; }
  .no-print, .app-header, .tabs, .app-footer, .banner, .modal, .toast-container { display: none !important; }
  main { padding: 0; max-width: none; }
  .tab-panel { display: none !important; }
  #tab-schedule { display: block !important; }
  #print-area h3 { margin: 8px 0 4px; font-size: 11pt; }
  .table-scroll { overflow: visible; }
  .week-table td { min-width: 0; font-size: 8.5pt; }
  .data-table th, .data-table td { padding: 2px 4px; }
  .member-lists { grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .member-card { padding: 4px 8px; break-inside: avoid; }
  .member-card ul { font-size: 8.5pt; }
  .dot, .member-card { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
