/* 明るい配色のみ（弔事では黒い背景は縁起が悪いとされるため、ダークモードは用意しない） */
:root {
  --bg: #f6f4ee;
  --panel: #ffffff;
  --ink: #2b2a27;
  --muted: #77736a;
  --line: #d9d4c7;
  --accent: #6b5b3e;
  --accent-soft: #efe9dc;
  --ok: #2f7a4b;
  --ng: #b3412e;
  --warn: #9a6a00;
  --view: #3d6aa6;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5;
  display: flex; flex-direction: column; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, .btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--ng); border-color: #e3b8ae; }
button.mini { padding: 2px 8px; }
input, select, textarea { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; }
.muted { color: var(--muted); font-size: 13px; }
.note { color: var(--muted); font-size: 13px; }

header.top { display: flex; align-items: baseline; gap: 12px; padding: 10px 16px 6px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; }
.beta { font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 4px; vertical-align: 2px; }
.event { color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.on { border-bottom-color: var(--accent); font-weight: 700; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tabpanel { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px 16px 16px; }
.tabpanel[hidden], [hidden] { display: none !important; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar input[type=search] { flex: 1; min-width: 140px; }
.btnrow { display: flex; gap: 8px; margin-top: 12px; }
.btnrow.wrap { flex-wrap: wrap; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.box h2 { font-size: 15px; margin: 0 0 8px; }
.box summary { cursor: pointer; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.field input, .field select, .field textarea { color: var(--ink); font-size: 15px; }
.check { display: flex; gap: 6px; align-items: center; font-size: 14px; }
#shareUrl { width: 100%; margin-top: 10px; font-size: 12px; word-break: break-all; }

/* はじめに */
.welcome { max-width: 560px; margin: 24px auto; padding: 0 16px; }
.welcome h1 { font-size: 22px; }

/* 家系図 */
#tab-tree { position: relative; padding-bottom: 0; }
.stage { position: relative; flex: 1; min-height: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; touch-action: none; }
svg.tree { width: 100%; height: 100%; position: absolute; inset: 0; user-select: none; }
.zoom { position: absolute; right: 8px; top: 8px; z-index: 2; display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.zoom button { padding: 4px 10px; background: rgba(255,255,255,.92); }
.edge { fill: none; stroke: #a59d8b; stroke-width: 1.5; }
.wed { stroke: #a59d8b; stroke-width: 2; }
.card rect { fill: #fff; stroke: var(--line); stroke-width: 1.5; }
.card { cursor: pointer; }
.card .nm { font-size: 14px; font-weight: 700; fill: var(--ink); }
.card .rel { font-size: 12px; fill: var(--accent); }
.card .tag { font-size: 11px; fill: var(--muted); }
.card.dead rect { fill: #f1efea; stroke-dasharray: 4 3; }
.card.subject rect { fill: #f3eee2; stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: none; }
.card.viewer rect { stroke: var(--view); stroke-width: 2.5; }
.card.viewer .rel { fill: var(--view); font-weight: 700; }
.card.sel rect { stroke: #d08a2c; stroke-width: 3; }
.sheet {
  position: absolute; right: 24px; top: 60px; width: min(360px, calc(100% - 48px)); max-height: calc(100% - 80px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: 0 6px 24px rgba(60,50,30,.15); z-index: 3;
}
.sheet h2 { margin: 0; font-size: 19px; }
.sheet .yomi { color: var(--muted); font-size: 13px; }
.sheet .big { margin: 8px 0 4px; }
.sheet .big b { font-size: 18px; color: var(--accent); }
.sheet .close { position: absolute; right: 8px; top: 8px; padding: 2px 9px; }
.chain { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; background: var(--accent-soft); border-radius: 8px; padding: 6px 8px; }
.chain .ar { color: var(--muted); }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; }
.sheet dt { color: var(--muted); }
.sheet dd { margin: 0; }
@media (max-width: 700px) {
  .sheet { left: 16px; right: 16px; width: auto; top: auto; bottom: 12px; max-height: 55%; }
}

/* 人物 */
.list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: auto; }
.list li { padding: 9px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.list li:last-child { border-bottom: none; }
.list li:hover { background: var(--accent-soft); }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 16px; width: min(640px, calc(100% - 24px)); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(60, 50, 30, .25); }
dialog h2 { margin: 0 0 10px; font-size: 17px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
.grid .wide { grid-column: 1 / -1; }

/* 香典台帳 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 10px; }
.cards .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.cards .k { font-size: 12px; color: var(--muted); }
.cards .k.warn { color: var(--warn); }
.cards .v { font-size: 18px; font-weight: 700; }
.cards .v input { width: 100%; font-size: 16px; }
.cards .card.ok { border-color: var(--ok); } .cards .card.ok .v { color: var(--ok); }
.cards .card.ng { border-color: var(--ng); } .cards .card.ng .v { color: var(--ng); font-size: 15px; }
.tablewrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; font-size: 14px; }
th { background: var(--accent-soft); font-size: 12px; white-space: nowrap; position: sticky; top: 0; }
table.ledger input, table.ledger select { width: 100%; padding: 4px 6px; border-color: transparent; background: transparent; }
table.ledger input:focus, table.ledger select:focus { border-color: var(--accent); background: #fff; }
table.ledger select { width: auto; min-width: 6.5em; }
table.ledger input.s { width: 3.5em; } table.ledger input.m { width: 8em; } table.ledger input.l { width: 11em; } table.ledger input.xl { width: 18em; }
.num, input.num { text-align: right; }
tfoot td { font-weight: 700; background: #fff8e6; }
table.gifts input { width: 100%; }
table.gifts tr.sum td { font-weight: 700; background: #fff8e6; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 14px; z-index: 10; }

/* 出欠・食事 */
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
#orderText { width: 100%; font-size: 15px; line-height: 1.6; background: #fffdf7; }
table.attend select { min-width: 4.5em; font-weight: 700; }
table.attend select.yes { color: var(--ok); }
table.attend select.no { color: var(--ng); }
table.attend select.maybe { color: var(--warn); }

/* 印刷: 香典台帳だけを出す */
@media print {
  body.print-ledger header.top, body.print-ledger .tabs, body.print-ledger .toolbar,
  body.print-ledger #giftBox, body.print-ledger .tabpanel:not(#tab-ledger) { display: none !important; }
  body.print-ledger .tablewrap { border: none; overflow: visible; }
  body.print-ledger table.ledger th:last-child, body.print-ledger table.ledger td:last-child { display: none; }
  body.print-ledger table.ledger input, body.print-ledger table.ledger select { border: none; appearance: none; padding: 0; }
  @page { size: A4 landscape; margin: 10mm; }
  /* 出欠・食事だけを出す */
  body.print-attend header.top, body.print-attend .tabs, body.print-attend .toolbar,
  body.print-attend .tabpanel:not(#tab-attend), body.print-attend #copyOrder, body.print-attend .order .note,
  body.print-attend .order .grid3 { display: none !important; }
  body.print-attend .tablewrap { border: none; overflow: visible; }
  body.print-attend table.attend th:last-child, body.print-attend table.attend td:last-child { display: none; }
  body.print-attend table.ledger input, body.print-attend table.ledger select { border: none; appearance: none; padding: 0; }
}
