:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --ink: #1b1f3a;
  --muted: #6b7090;
  --line: #e3e5f0;
  --navy: #26306b;
  --navy-soft: #e8eaf7;
  --gold: #d9a21b;
  --gold-soft: #fcf3dc;
  --won: #17865a;
  --won-soft: #e2f5ec;
  --lost: #8a8fa6;
  --lost-soft: #eeeff4;
  --pend: #b7791f;
  --pend-soft: #fdf3e1;
  --danger: #c0392b;
  --radius: 14px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px;
  background: var(--navy); color: #fff;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: .02em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.login-card .brand { white-space: normal; }
@media (max-width: 440px) { .brand-sub { display: none; } }
.star { color: var(--gold); }
.role-badge { font-size: 12px; padding: 2px 10px; border-radius: 99px; background: rgba(255,255,255,.15); white-space: nowrap; }
.role-badge.admin { background: var(--gold); color: var(--ink); font-weight: 700; }

/* 下のタブ */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 10px 2px 12px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button .ico { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--navy); }
.tabs button.on .ico { color: var(--gold); }

.view { max-width: 720px; margin: 0 auto; padding: 16px; }
h2 { font-size: 22px; margin: 8px 0 12px; }
h3 { font-size: 17px; margin: 20px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.err { color: var(--danger); font-weight: 600; min-height: 1.6em; }

.card {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 14px 16px; margin-bottom: 12px;
}
.card.tight { padding: 10px 14px; }
.month { font-size: 14px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; letter-spacing: .05em; }

/* 公演カード */
.show-head { display: flex; gap: 12px; align-items: flex-start; }
.date-box {
  flex: none; width: 58px; text-align: center; border-radius: 10px;
  background: var(--navy-soft); color: var(--navy); padding: 6px 0; line-height: 1.2;
}
.date-box .d { font-size: 20px; font-weight: 800; display: block; }
.date-box .w { font-size: 12px; font-weight: 600; }
.date-box.weekend { background: var(--gold-soft); color: #8a5d00; }
.show-title { font-weight: 700; font-size: 16px; line-height: 1.4; }
.show-meta { font-size: 13px; color: var(--muted); }

/* チップ */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 99px; padding: 4px 12px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: #fff; color: var(--muted);
}
button.chip { cursor: pointer; min-height: 36px; }
.chip.must { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip.maybe { background: var(--navy-soft); border-color: #c9cdec; color: var(--navy); }
.chip.sel { background: var(--gold); border-color: var(--gold); color: var(--ink); }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 10px; }

/* 申込行 */
.apps { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.app-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.app-row:last-child { border-bottom: 0; }
.app-row .body { flex: 1; min-width: 0; font-size: 14px; }
.app-row .body b { font-weight: 700; }
.app-row.clickable { cursor: pointer; }
.status {
  flex: none; font-size: 13px; font-weight: 700; border-radius: 8px; padding: 2px 10px;
}
.status.pending { background: var(--pend-soft); color: var(--pend); }
.status.won { background: var(--won-soft); color: var(--won); }
.status.lost { background: var(--lost-soft); color: var(--lost); }
.tag { display: inline-block; font-size: 12px; font-weight: 700; background: var(--navy-soft); color: var(--navy); border-radius: 6px; padding: 0 6px; margin-right: 4px; }

/* 当落の切り替え（管理者） */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { border: 0; background: #fff; padding: 6px 10px; font-size: 13px; font-weight: 700; color: var(--muted); min-height: 36px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on.pending { background: var(--pend); color: #fff; }
.seg button.on.won { background: var(--won); color: #fff; }
.seg button.on.lost { background: var(--lost); color: #fff; }

/* フィルター */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; }
.filters .chip { white-space: nowrap; }

/* ボタン */
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 10px 16px; font-weight: 700; min-height: 44px; cursor: pointer;
}
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.danger { color: var(--danger); border-color: #f0c7c2; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* 精算 */
.pay-line { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.pay-line .arrow { color: var(--gold); }
.pay-line .amount { margin-left: auto; font-variant-numeric: tabular-nums; }
.settled { color: var(--won); font-weight: 700; }
.detail { font-size: 14px; margin-top: 8px; }
.detail li { margin: 2px 0; }
.warn { background: var(--pend-soft); border: 1px solid #f1d9a8; color: #7a4f00; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* メンバー選択 */
.me-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* フォーム・モーダル */
.modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(20, 24, 50, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal[hidden] { display: none; }
.sheet {
  background: #fff; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.field { margin-bottom: 14px; }
.field > label, .field > .label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; border: 1px solid #cfd2e3; border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 16px;
}
textarea { min-height: 70px; }
.qty { display: flex; gap: 6px; }
.qty button { flex: 1; }

.list-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.bad { background: var(--danger); }

/* ヘッダーのPDFボタン */
.hdr-right { display: flex; align-items: center; gap: 8px; }
.hdr-btn {
  border: 1px solid rgba(255,255,255,.5); background: transparent; color: #fff;
  border-radius: 8px; padding: 2px 10px; font-size: 13px; font-weight: 700; cursor: pointer; min-height: 30px;
}

/* 印刷・PDF用のまとめ */
body.reporting .tabs { display: none; }
body.reporting { padding-bottom: 16px; }
.report-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.report { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; overflow-x: auto; }
.report h1 { font-size: 20px; margin: 0 0 2px; }
.report h2 { font-size: 17px; margin: 22px 0 6px; padding-bottom: 4px; border-bottom: 2px solid var(--navy); color: var(--navy); }
.report h3 { font-size: 15px; margin: 14px 0 4px; }
.report p { margin: 4px 0; }
.report table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0 10px; }
.report th, .report td { border: 1px solid #d5d8e6; padding: 4px 6px; text-align: left; vertical-align: top; }
.report th { background: var(--navy-soft); font-weight: 700; white-space: nowrap; }
.report td.num { text-align: right; white-space: nowrap; }
.report td.c { text-align: center; }
.report .status { font-size: 12px; padding: 0 6px; }
.report table.matrix { font-size: 11.5px; }
.report table.matrix td { padding: 2px 5px; }
.report td.nw { white-space: nowrap; }
.report section { break-inside: avoid; }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; padding: 0; font-size: 12px; }
  .top, .tabs, .no-print, .toast, .modal { display: none !important; }
  .view { max-width: none; padding: 0; }
  .report { border: 0; padding: 0; overflow: visible; }
  .report h2.pb { break-before: page; }
  .report thead { display: table-header-group; }
  .report tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ログイン画面 */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; background: var(--navy); padding: 16px; }
.login-card { background: #fff; border-radius: 18px; padding: 28px 22px; width: 100%; max-width: 380px; }
.login-card .brand { color: var(--navy); }
.login-card h1 { margin: 4px 0 20px; font-size: 24px; }
.login-card label { font-weight: 700; font-size: 14px; display: block; margin-bottom: 4px; }
.login-card input { margin-bottom: 14px; }
