/* ============================================================
 * Aladdin v600 — clean single-source-of-truth UI
 * 設計方針: 入力したものが消えないことを最優先。装飾より確実性。
 * ============================================================ */

:root {
  /* v616: iOS Safari 等の自動ダークモードを止めて常にライト固定 */
  color-scheme: light only;
  --bg: #f5f4f0;
  --paper: #ffffff;
  --card: #ffffff;
  --ink: #0f1418;
  --ink-soft: #2b3138;
  --ink-mute: #61686f;
  --line: #d9d6cf;
  --line-soft: #ebe8e0;
  --accent: #1d5f56;
  --accent-soft: #e0edea;
  --accent-ink: #0f4842;
  --warn: #b83228;
  --warn-soft: #f7e4e0;
  --ok: #2f6b4a;
  --ok-soft: #d9ecdd;
  --info: #1d4e89;
  --info-soft: #e1eaf3;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic Medium", "Meiryo", sans-serif;
  --font-mono: "SF Mono", Menlo, "Cascadia Mono", "Consolas", "MS Gothic", monospace;
}

/* v616: prefers-color-scheme:dark override は撤廃。全端末で白基調に固定。 */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  /* v612: 画面外にスクロールバー出さない (テーブル内で完結) */
  overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.hdr { flex-shrink: 0; }

/* ------- Loader ------- */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 100vh;
  color: var(--ink-mute);
  font-size: 13px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------- Login ------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.v-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  border-radius: 4px;
  letter-spacing: 0.05em;
  vertical-align: middle;
  margin-left: 4px;
}
.login-sub {
  color: var(--ink-soft);
  font-size: 12px;
  margin: 0 0 24px;
  line-height: 1.6;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  color: var(--ink-mute);
  margin-bottom: 4px;
  letter-spacing: 0.03em;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  margin-top: 6px;
}
.btn-primary:hover { background: var(--accent-ink); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }
.btn-secondary {
  padding: 8px 16px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.btn-secondary:hover { background: var(--bg); }
.err-msg {
  color: var(--warn);
  font-size: 12px;
  margin-top: 10px;
  min-height: 16px;
}
.login-foot {
  margin-top: 20px;
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}
.login-foot a {
  color: var(--ink-mute);
  text-decoration: none;
  font-size: 12px;
}
.login-foot a:hover { color: var(--accent); }

/* ------- Header ------- */
.hdr {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  /* v626: 1 行固定 (幅が足りない時は横スクロール) */
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: visible;
  min-height: 52px;
}
.hdr-nav {
  flex-wrap: nowrap;
  flex-shrink: 0;
}
.hdr-brand { flex-shrink: 0; }
.hdr-right {
  flex-shrink: 0;
  flex-wrap: nowrap;
}
.hdr-right * { white-space: nowrap; }
.hdr-brand {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hdr-logo { font-size: 20px; }
.hdr-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.hdr-nav {
  display: flex;
  gap: 4px;
}
.nav-btn {
  padding: 8px 14px;
  background: transparent;
  color: var(--ink-soft);
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  /* v626: 1 行固定 (これがないと狭い時に「来」「院」が縦積みされる) */
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-btn:hover { background: var(--line-soft); color: var(--ink); }
.nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}
/* v600 fix #8: 外部リンク (Google Sheets) 用のナビリンク */
.nav-btn.nav-ext {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  color: var(--ink);
}
.nav-btn.nav-ext:hover { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent); }
.nav-btn.nav-ext .ext-arrow { font-size: 10px; color: var(--ink-mute); }
.nav-btn.nav-ext:hover .ext-arrow { color: var(--accent-ink); }
.hdr-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.hdr-right button, .hdr-right .link-btn {
  padding: 6px 10px;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.hdr-right button:hover, .hdr-right .link-btn:hover {
  background: var(--line-soft);
  color: var(--ink);
}
.user-email {
  font-size: 11px;
  color: var(--ink-mute);
  font-family: var(--font-mono);
}
.save-status {
  font-size: 11px;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  min-width: 100px;
  text-align: right;
}
.save-status.saving { color: var(--info); }
.save-status.saved { color: var(--ok); }
.save-status.failed { color: var(--warn); font-weight: 600; }

/* ------- Main ------- */
main {
  padding: 16px 20px;
  flex: 1;
  min-height: 0;   /* flex + overflow の必須お作法 */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* v612: view と table-wrap を flex 化して残りの高さを埋める (下枠余白の原因除去) */
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.view .toolbar { flex-shrink: 0; }

/* ------- Toolbar ------- */
.toolbar {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.tb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.tb-row + .tb-row { margin-top: 10px; }
.tb-summary {
  padding-top: 8px;
  border-top: 1px dashed var(--line-soft);
  color: var(--ink-mute);
  font-size: 11px;
}
.tb-search {
  flex: 1;
  min-width: 160px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
}
.tb-select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}
.link-btn {
  padding: 7px 12px;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
}
/* v607: 今月/先月 のクイックボタン */
.quick-period-btn {
  padding: 6px 12px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.quick-period-btn:hover { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent); }
.quick-period-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
/* v710 重複ボタン: 未選択=柔ピンク、active=濃ピンク */
.quick-dup-btn {
  padding: 6px 12px; background: #fff5f5; color: #c2185b; border: 1px solid #f8bbd0;
  border-radius: 5px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.quick-dup-btn:hover { background: #fce4ec; border-color: #f48fb1; }
.quick-dup-btn.active { background: #c2185b; color: #fff; border-color: #c2185b; }
/* 重複バッジ: 名前列の右に小さく ×N */
.dup-badge {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  background: #fce4ec; color: #c2185b; border: 1px solid #f48fb1;
  border-radius: 8px; font-size: 10px; font-weight: 700; vertical-align: middle;
}
.link-btn:hover {
  background: var(--line-soft);
}
.count-chip, .update-chip {
  display: inline-block;
  padding: 3px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--ink-soft);
}
.count-chip strong { color: var(--accent-ink); }
/* v611: ヘッダー右側に格納した count/updated chip */
.hdr-count, .hdr-updated {
  font-size: 10.5px;
  padding: 2px 8px;
  white-space: nowrap;
}
/* v611: 期間の date/month 入力 (hidden 属性が効くように inline style を撤廃) */
.v-range-wrap { display: inline-flex; align-items: center; gap: 4px; }
.v-range-wrap[hidden], .v-period-extra[hidden] { display: none !important; }
.v-date-inp { width: 130px; }
.v-range-sep { color: var(--ink-soft); font-size: 12px; }

/* ------- Table ------- */
/* v609/v612: .table-wrap を flex-1 の scroll container 化 → 残り高さを埋める */
.table-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;   /* flex 子で overflow を効かせる */
}
.v-table {
  table-layout: fixed;
  width: 100%;
  min-width: 1180px;
  border-collapse: separate;   /* sticky + border-collapse:collapse で border が消える対策 */
  border-spacing: 0;
  font-size: 13px;
}
.v-table thead th {
  position: sticky;
  top: 0;                       /* container 内で先頭固定 */
  background: var(--bg);
  padding: 10px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--line);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  z-index: 5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.v-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  color: var(--ink);
  overflow: hidden;         /* 列幅を守る */
  text-overflow: ellipsis;
}
.v-table tbody tr:hover td { background: var(--bg); }
.v-table tbody tr:last-child td { border-bottom: none; }

/* v600 fix #4: 全列に絶対幅を指定 (table-layout: fixed と組み合わせ) */
.c-book     { width: 58px;  font-family: var(--font-mono); font-size: 11px; white-space: nowrap; color: var(--ink); font-weight: 600; }
/* v707 UI調整: 名前6字/プロモ6字が入るよう拡大 */
.c-name     { width: 124px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-treatment{ width: 88px; }
.c-facility { width: 82px; font-size: 12px; color: var(--ink); font-weight: 500; white-space: nowrap; }
.c-promo    { width: 108px; font-size: 11px; }
.c-status   { width: 118px; }
.c-next     { width: 118px; }
.c-cs       { width: 118px; }
.c-cmonth   { width: 118px; }
.c-amount   { width: 100px; }
.c-memo     {
  width: auto; min-width: 140px;
  /* v613: メモは折り返して全文表示 (行高が伸びる) */
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  vertical-align: middle;
}
.c-updated  { width: 82px;  font-size: 10.5px; color: var(--ink-soft); font-family: var(--font-mono); white-space: nowrap; }

.promo-chip {
  display: inline-block;
  padding: 3px 9px;
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.promo-chip.select-type { background: #fde68a; color: #78350f; border-color: #fbbf24; }
.promo-chip.empty { background: transparent; border-color: transparent; color: var(--ink-mute); }

.treatment-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;   /* v600 fix #7: 「インプラント」が縦に折れないよう */
}
.treatment-chip[data-t="BF"]         { background: #1a1a1a; color: #fff; }
.treatment-chip[data-t="矯正"]       { background: #fed7aa; color: #7c2d12; }
.treatment-chip[data-t="インプラント"] { background: #c7d2fe; color: #1e1b4b; }
.treatment-chip[data-t="ラブリエ"]    { background: #fbcfe8; color: #500724; }
/* v706 新カテゴリ */
.treatment-chip[data-t="保険"]       { background: #bae6fd; color: #0c4a6e; }
.treatment-chip[data-t="WT"]         { background: #fef9c3; color: #713f12; }
.treatment-chip[data-t="審美"]       { background: #ddd6fe; color: #4c1d95; }
.treatment-chip[data-t="補綴"]       { background: #d1fae5; color: #064e3b; }
.treatment-chip[data-t="転院"]       { background: #fecaca; color: #7f1d1d; }
/* v706: 該当なし (service 空) は淡いダッシュ表示、badge なし */
.tx-empty { color: var(--ink-mute); font-size: .95em; }   /* v709 fix: --muted 未定義 → --ink-mute */

.field-input {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  background: var(--paper);
  color: var(--ink);
}
.field-input.saving { border-color: var(--info); }
.field-input.saved  { border-color: var(--ok); background: var(--ok-soft); }
.field-input.failed { border-color: var(--warn); background: var(--warn-soft); }
.field-input[type=date], .field-input[type=month] {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
}

.status-sel {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  font-family: inherit;
  background: var(--paper);
  cursor: pointer;
}
.status-sel[data-value="要確認"]     { background: #ffe5b4; color: #a24800; font-weight: 700; border: 1px solid #d17b00; }
.status-sel[data-value="キャンセル"] { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.status-sel[data-value="成約"]       { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.status-sel[data-value="来院済"]     { background: var(--info-soft); color: var(--info); font-weight: 600; }
.status-sel[data-value="検討中"]     { background: #fff5d6; color: #8a6d1a; font-weight: 600; }
.status-sel[data-value="除外"]       { background: var(--line-soft); color: var(--ink-mute); }
.status-sel[data-value="重複削除"]   { background: #e5e7eb; color: #6b7280; text-decoration: line-through; }
.status-sel.saving { outline: 2px solid var(--info); }
.status-sel.saved  { outline: 2px solid var(--ok); }
.status-sel.failed { outline: 2px solid var(--warn); }

.amount-input {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  background: var(--paper);
  color: var(--ink);
  text-align: right;
}
.amount-input.saving { border-color: var(--info); }
.amount-input.saved  { border-color: var(--ok); }
.amount-input.failed { border-color: var(--warn); background: var(--warn-soft); }

.memo-cell {
  cursor: pointer;
  padding: 5px 9px;
  border: 1px dashed var(--line);
  border-radius: 4px;
  min-height: 24px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  /* v613: 折り返して複数行表示 (最大 4 行、それ以上は省略) */
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.memo-cell:hover { background: var(--bg); border-style: solid; }
.memo-cell.has-value {
  background: #fff8e1;
  border-color: #f9a825;
  color: var(--ink);
}
.memo-cell.empty { color: var(--ink-mute); }

.empty-msg {
  padding: 40px;
  text-align: center;
  color: var(--ink-mute);
  font-size: 13px;
}

/* ------- Modal ------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}
.modal-hdr {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-hdr h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  flex: 1;
}
.modal-close {
  width: 28px; height: 28px;
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--ink-mute);
  cursor: pointer;
  line-height: 1;
  border-radius: 4px;
}
.modal-close:hover { background: var(--line-soft); color: var(--ink); }
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
}
.modal-body textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}
.modal-body textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line-soft);
}
.modal-foot .btn-primary,
.modal-foot .btn-secondary {
  width: auto;
  margin: 0;
  min-width: 80px;
}
.modal-hint {
  flex: 1;
  font-size: 11px;
  color: var(--ink-mute);
}

/* ------- Toast ------- */
.toast-host {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  max-width: 380px;
  animation: slideIn 0.2s ease-out;
  pointer-events: auto;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--warn); font-weight: 500; }
.toast.info { background: var(--info); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ------- Slots view ------- */
.slots-view { padding-bottom: 40px; }
.slots-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 18px;
}
.slots-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}
.slots-source {
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.slots-source h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}
.slots-source .badge-ok {
  padding: 3px 10px;
  background: var(--ok-soft);
  color: var(--ok);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.slots-source .badge-none {
  padding: 3px 10px;
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.slots-source .meta {
  font-size: 11px;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  margin-left: auto;
}
.slots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.slot-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.slot-card.has-slots { border-color: var(--ok); background: var(--ok-soft); }
.slot-card.empty { opacity: 0.6; }
.slot-clinic {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}
.slot-mark { font-size: 10px; }
.slot-mark.ok { color: var(--ok); font-weight: 700; }
.slot-mark.none { color: var(--warn); font-weight: 700; }
.slot-count {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--font-mono);
}
.slot-count .num {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
}
.slot-count .unit { font-size: 11px; color: var(--ink-soft); }
.slot-count .days { margin-left: 6px; font-size: 11px; color: var(--ink-soft); }
.slot-meta { font-size: 10px; color: var(--ink-mute); font-family: var(--font-mono); }

/* v622: 更新確認ボタン (旧 🔄 の代替) */
.ver-check-btn {
  font-size: 11px !important;
  padding: 4px 8px !important;
  white-space: nowrap;
}

/* v627: 絞込ボタンはモバイル専用 (デスクトップでは常時フィルタ表示なので隠す) */
.tb-filter-toggle { display: none; }

/* v700: 初診管理シート 同期バッジ + 手動ボタン */
.sheet-sync-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px !important;
  padding: 4px 10px !important;
  white-space: nowrap;
  border: 1px solid var(--line) !important;
  background: var(--accent-soft) !important;
  color: var(--accent-ink) !important;
  border-radius: 12px !important;
}
.sheet-sync-btn:hover { background: var(--accent) !important; color: #fff !important; }
.sheet-sync-btn.syncing { opacity: .6; cursor: wait; }
.sheet-sync-btn.error { background: var(--warn-soft) !important; color: var(--warn) !important; border-color: var(--warn) !important; }
.ss-icon { font-size: 12px; }
.ss-label { font-family: var(--font-mono); letter-spacing: .02em; }
@media (max-width: 720px) { .sheet-sync-btn .ss-label { display: none; } }

/* ------- v614: アクティビティビュー ------- */
.activity-summary {
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
  align-items: center;
  flex-shrink: 0;
}
.activity-chip {
  display: inline-block;
  padding: 4px 12px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
}
.activity-chip strong { font-size: 14px; margin: 0 2px; }
.activity-table tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line-soft);
}
.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 10.5px;
}

/* ============================================================
 * v611: Responsive — desktop / tablet / mobile 3 段階
 * ============================================================ */

/* ------- Tablet (< 1100px) ------- */
@media (max-width: 1100px) {
  .hdr-right .user-email { display: none; }
}

/* ------- Small tablet / large mobile (< 900px) ------- */
@media (max-width: 900px) {
  .hdr {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 6px;
    row-gap: 6px;
  }
  .hdr-brand { flex-shrink: 0; }
  .hdr-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .hdr-nav::-webkit-scrollbar { height: 3px; }
  .hdr-nav .nav-btn { flex-shrink: 0; white-space: nowrap; }
  .hdr-right { margin-left: auto; }
  main { padding: 10px 12px; }
  .tb-search { min-width: 140px; flex: 1 1 100%; }
  .toolbar { padding: 10px 12px; }
}

/* ============================================================
 * v618: Mobile (< 720px) — 超コンパクトカード + フィルタ折りたたみ
 *   - 1 患者 = 1 カード (2〜3 行だけ)
 *   - 医院/治療/名前/status/次回/メモ を凝縮
 *   - 成約商材・売上等は 詳細ボタンで開く (WIP: 現状は小さく inline 表示)
 *   - フィルタ群はデフォ折りたたみ → 検索と一覧に集中
 * ============================================================ */
@media (max-width: 720px) {
  /* v618: フィルタ折りたたみ (来院/予約タブ用) */
  .tb-row-filters { display: none; }
  body.filters-open .tb-row-filters { display: flex; margin-top: 8px; }
  /* v731: 分析タブは絞込トグル無し → 常に表示 (医院/治療 select が押せない問題 fix) */
  .analytics-view .tb-row-filters { display: flex !important; margin-top: 0; }
  .tb-filter-toggle {
    display: inline-block;   /* v627: モバイルでは表示 (デスクトップ用 display:none を上書き) */
    flex: 0 0 auto;
    padding: 8px 10px;
    font-size: 12px;
    white-space: nowrap;
  }
  .tb-row-search .tb-search { flex: 1; }
  /* ---- Header ---- */
  .hdr {
    padding: 6px 10px;
    gap: 4px;
  }
  .hdr-title { font-size: 14px; }
  .v-badge { font-size: 9px; padding: 1px 4px; }
  .hdr-right { gap: 4px; }
  .hdr-right .link-btn, .hdr-right button {
    padding: 6px 8px;
    font-size: 11px;
    min-height: 36px;
  }
  .hdr-count, .hdr-updated {
    font-size: 10px;
    padding: 2px 6px;
  }
  .hdr-updated { display: none; }
  .save-status { min-width: auto; font-size: 10px; }
  .nav-btn { padding: 7px 10px; font-size: 12px; min-height: 36px; }
  .nav-btn.nav-ext { padding: 7px 8px; }
  .ext-arrow { display: none; }

  /* ---- Main / Toolbar ---- */
  main { padding: 8px 10px; }
  .toolbar {
    padding: 8px 10px;
    margin-bottom: 8px;
    border-radius: 6px;
  }
  .tb-row { gap: 6px; }
  .tb-search {
    flex: 1 1 100%;
    min-width: 0;
    font-size: 14px;
    padding: 8px 10px;
  }
  .tb-select {
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    font-size: 13px;
    padding: 8px 10px;
  }
  .quick-period-btn {
    flex: 1 1 calc(50% - 3px);
    padding: 8px 10px;
    font-size: 13px;
  }
  .link-btn { padding: 8px 10px; font-size: 12px; min-height: 36px; }
  .v-date-inp { flex: 1 1 40%; width: auto; min-width: 0; }

  /* ---- ★ v619 モバイル: mockup 準拠の 2 段カード ----
     Row1: 日付 名前 医院 治療tag プロモpill
     Row2: [ステータス▼]  [売上]  [メモボタン] */
  .visits-view .table-wrap,
  .bookings-view .table-wrap {
    background: transparent;
    border: none;
    padding: 2px;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .visits-view .v-table,
  .bookings-view .v-table {
    display: block;
    min-width: 0;
    width: 100%;
  }
  .visits-view .v-table thead,
  .bookings-view .v-table thead,
  .visits-view .v-table tbody,
  .bookings-view .v-table tbody { display: block; width: 100%; }
  .visits-view .v-table thead,
  .bookings-view .v-table thead { display: none; }

  /* ---- v621 スマホ 2 段 flex カード (再) ----
     Row 1: [date] [name flex] [clinic small] [treat tag] [promo pill]
     Row 2: [status(min 100)] [amount 78] [memo flex]
     tr::after で強制改行 (order で行を分離) */
  .visits-view .v-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    column-gap: 6px;
    row-gap: 7px;
    align-items: center;
    background: #ffffff;
    border: 1px solid #dfe3df;
    border-radius: 12px;
    padding: 10px 12px;
    margin: 0 0 7px;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    width: 100%;
  }
  .visits-view .v-table tbody tr::after {
    content: '';
    flex: 0 0 100%;
    height: 0;
    order: 50;   /* Row 1 items order 1-9, Row 2 items order 60+ */
    margin: 0;
  }
  .visits-view .v-table tbody td {
    display: block;
    padding: 0;
    border: none;
    min-height: 0;
    width: auto !important;
    min-width: 0 !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
  }
  .visits-view .v-table tbody td::before { content: none; }

  /* Row 1: date name (flex) clinic treat promo */
  .visits-view .v-table tbody td.c-book {
    order: 1;
    flex: 0 0 auto;
    font-size: 12px;
    color: #62706a;
    font-variant-numeric: tabular-nums;
  }
  .visits-view .v-table tbody td.c-name {
    order: 2;
    /* v623 fix: flex-basis を 0 に (auto だと content 幅が加算されオーバーフロー→ promo が折り返す)
       これで名前は残り幅ぴったりに固定され、医院/治療/プロモの x が全行で揃う */
    flex: 1 1 0;
    min-width: 0;
    font-size: 14.5px;
    font-weight: 600;
    color: #17201d;
  }
  .visits-view .v-table tbody td.c-facility {
    order: 3;
    /* v623: 医院を固定 56px 幅 → インプラント行と矯正行で BF銀座/大森 が同じ x 位置 */
    flex: 0 0 56px;
    font-size: 12px;
    color: #35443e;
    font-weight: 600;
    text-align: right;
  }
  .visits-view .v-table tbody td.c-treatment {
    order: 4;
    /* v623: 治療タグを固定 84px 幅 → インプラント(6文字) が余裕で入る */
    flex: 0 0 84px;
    overflow: visible;
    text-align: center;
  }
  .visits-view .v-table tbody td.c-treatment > span {
    font-size: 11px !important;
    font-weight: 500;
    padding: 3px 7px !important;
    border-radius: 5px !important;
    display: inline-block;
    white-space: nowrap;
    max-width: 100%;
  }
  .visits-view .v-table tbody td.c-promo {
    order: 5;
    /* v623: プロモも固定 78px 幅 → 全行で末尾位置が揃う */
    flex: 0 0 78px;
    overflow: hidden;
    text-align: right;
  }
  .visits-view .v-table tbody td.c-promo > span {
    display: inline-block;
    max-width: 100%;
    padding: 3px 8px;
    background: #e0efff;
    color: #24527d;
    border-radius: 999px;
    font-size: 10.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
  }

  /* Row 2: status amount memo — v622: status/amount 短く、memo 長く */
  .visits-view .v-table tbody td.c-status {
    order: 60;
    flex: 0 0 88px;              /* 100 → 88 */
  }
  .visits-view .v-table tbody td.c-amount {
    order: 61;
    flex: 0 0 82px;   /* ¥999,999 (7 桁) が切れないよう確保 */
  }
  .visits-view .v-table tbody td.c-memo {
    order: 62;
    /* v624: flex-basis を 0 に (auto だと長文memo の content 幅で折り返しが起きる) */
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
  }
  /* status select 内部の padding も詰める */
  .visits-view .v-table tbody td.c-status select {
    padding: 8px 22px 8px 8px;
    font-size: 12px !important;
  }
  .visits-view .v-table tbody td.c-amount input {
    font-size: 12px !important;
    padding: 7px 6px;
  }

  /* モバイル非表示 (詳細編集は デスクトップで) */
  .visits-view .v-table tbody td.c-next,
  .visits-view .v-table tbody td.c-cs,
  .visits-view .v-table tbody td.c-cmonth,
  .visits-view .v-table tbody td.c-updated { display: none; }

  /* v709 UX BUG#1 修正: status select の色は data-value 別ルールに任せる。
     以前は border/background/color を blanket 指定 → specificity で全ステータス赤色になっていた。
     ここでは寸法・padding のみ調整。 */
  .visits-view .v-table tbody td.c-status select {
    width: 100%;
    font-size: 13px !important;
    font-weight: 500;
    min-height: 34px;
    padding: 8px 22px 8px 8px;
    border-radius: 8px;
    box-sizing: border-box;
  }
  /* status 別の色を PC 用 rule と同 specificity 以上でモバイルでも上書き適用 */
  .visits-view .v-table tbody td.c-status .status-sel[data-value="未対応"] { background: #fff5f3; color: #9d2f25; border: 1px solid #e4a39d; }
  .visits-view .v-table tbody td.c-status .status-sel[data-value="キャンセル"] { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }
  .visits-view .v-table tbody td.c-status .status-sel[data-value="成約"] { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok); }
  .visits-view .v-table tbody td.c-status .status-sel[data-value="来院済"] { background: var(--info-soft); color: var(--info); border: 1px solid var(--info); }
  .visits-view .v-table tbody td.c-status .status-sel[data-value="検討中"] { background: #fff5d6; color: #8a6d1a; border: 1px solid #d1a933; }
  .visits-view .v-table tbody td.c-status .status-sel[data-value="除外"] { background: var(--line-soft); color: var(--ink-mute); border: 1px solid var(--line); }
  .visits-view .v-table tbody td.c-status .status-sel[data-value="重複削除"] { background: #e5e7eb; color: #6b7280; border: 1px solid #9ca3af; }

  /* 売上: 数字だけ表示 */
  .visits-view .v-table tbody td.c-amount input {
    width: 100%;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 13px !important;
    min-height: 34px;
    padding: 7px 8px;
    border: 1px solid #dfe3df;
    border-radius: 8px;
    background: #fafbfa;
    color: #17201d;
    box-sizing: border-box;
  }

  /* v624: memo は 1 行厳密 (nowrap+ellipsis)。カード高さを 92px に固定
     長文はタップでモーダルを開いて全文表示 (既存の click delegation) */
  .visits-view .v-table tbody td .memo-cell {
    width: 100%;
    height: 34px;
    max-height: 34px;
    font-size: 12px;
    font-weight: 500;
    padding: 7px 10px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #ffffff;
    color: #35443e;
    border: 1px dashed #bdc7c2;
    border-radius: 8px;
    text-align: left;
    box-sizing: border-box;
    cursor: pointer;
  }
  /* has-value に「👀 全部見る」ヒント色を付与 (タップ可視化) */
  .visits-view .v-table tbody td .memo-cell.has-value::after {
    content: '';
  }
  .visits-view .v-table tbody td .memo-cell.has-value {
    background: #eef6f2;
    border-style: solid;
    border-color: #b3d8c8;
    color: #214e3c;
  }
  .visits-view .v-table tbody td .memo-cell.empty {
    color: #6e7975;
    text-align: left;
  }

  /* Bookings は単純カード維持 (ラベル付き) */
  .bookings-view .v-table tbody tr {
    display: block;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    margin: 0 0 6px;
    box-shadow: var(--shadow-sm);
  }
  .bookings-view .v-table tbody td {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px dashed var(--line-soft);
    font-size: 12px;
    width: auto !important;
    min-width: 0 !important;
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
  }
  .bookings-view .v-table tbody td:last-child { border-bottom: none; }
  .bookings-view .v-table tbody td::before {
    flex: 0 0 60px;
    font-size: 10px;
    color: var(--ink-mute);
    font-weight: 700;
  }
  .bookings-view .v-table tbody td.c-book::before     { content: '来院'; }
  .bookings-view .v-table tbody td.c-facility::before { content: '医院'; }
  .bookings-view .v-table tbody td.c-promo::before    { content: 'プロモ'; }
  .bookings-view .v-table tbody td.c-name {
    display: block;
    padding: 4px 0 6px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
    font-size: 15px;
    font-weight: 700;
  }
  .bookings-view .v-table tbody td.c-name::before { display: none; }

  /* ---- Modal ---- */
  .modal {
    max-width: calc(100vw - 20px);
    margin: 10px;
    border-radius: 8px;
  }
  .modal-body textarea { font-size: 14px; }
  .modal-foot { flex-wrap: wrap; gap: 6px; }
  .modal-foot .btn-primary, .modal-foot .btn-secondary {
    flex: 1 1 40%;
    min-height: 40px;
  }

  /* ---- Toast ---- */
  .toast-host { bottom: 10px; right: 10px; left: 10px; }
  .toast { max-width: 100%; font-size: 13px; }

  /* ---- Slots ---- */
  .slots-header { flex-wrap: wrap; gap: 8px; }
  .slots-title { font-size: 16px; }
  .slot-card { padding: 12px; }
  .slot-count { font-size: 22px; }

  /* activity-view は table のまま (別スコープなので card 化されない) */
  .activity-view .table-wrap { overflow-x: auto; }
  .activity-view .v-table { font-size: 12px; min-width: 700px; }
}

/* ------- Very small (< 480px) ------- */
@media (max-width: 480px) {
  .hdr-right .link-btn[title="v521 に戻る"] { display: none; }
  .user-email { display: none; }
  .tb-select { flex: 1 1 100%; }
  .quick-period-btn { flex: 1 1 calc(50% - 3px); }
  /* カード内のラベル幅を少し詰める */
  .v-table tbody td::before { flex: 0 0 58px; font-size: 10px; }
}

/* ==================== v719 Analytics view ==================== */
.analytics-view { padding: 16px; }
.a2-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.a2-card { padding: 14px 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.a2-card-lbl { font-size: 11px; color: var(--ink-mute); font-weight: 600; letter-spacing: .05em; }
.a2-card-num { font-size: 22px; font-weight: 700; color: var(--ink); margin-top: 4px; font-family: var(--font-mono); }
.a2-card-sub { font-size: 12px; color: var(--info); margin-top: 2px; font-weight: 600; }
.a2-section { margin-bottom: 28px; }
.a2-title { font-size: 14px; font-weight: 700; margin: 0 0 8px 0; color: var(--ink); border-left: 3px solid var(--accent); padding-left: 8px; }
.a2-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
.a2-table { width: 100%; border-collapse: collapse; font-size: 12px; background: var(--paper); }
.a2-table th, .a2-table td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.a2-table th { background: var(--bg); font-weight: 700; color: var(--ink); font-size: 11px; }
.a2-table tr:last-child td { border-bottom: none; }
.a2-num { font-family: var(--font-mono); text-align: right; }
.a2-yen { color: var(--accent-ink); font-weight: 600; }
.a2-pct { display: inline-block; padding: 1px 8px; background: var(--info-soft); color: var(--info); border-radius: 10px; font-size: 11px; font-weight: 700; }
.a2-total td { background: var(--bg); border-top: 2px solid var(--line); font-weight: 700; }

/* v723 分析タブ 追加スタイル */
.a2-filter-line { margin-bottom: 12px; font-size: 12px; color: var(--ink-mute); }
.a2-chip { display: inline-block; padding: 2px 10px; background: var(--accent-soft); color: var(--accent-ink); border-radius: 12px; font-size: 11px; font-weight: 600; margin-right: 6px; }
.a2-badge-walkin { display: inline-block; padding: 1px 6px; background: #fff5e6; color: #9a5a00; border: 1px solid #ffcf8f; border-radius: 8px; font-size: 10px; font-weight: 700; margin-left: 4px; vertical-align: middle; }
.a2-empty { color: var(--ink-mute); font-size: 11px; }
.a2-card-alert { border-color: #f8bbd0; background: #fff5f8; }
.a2-card-alert .a2-card-num { color: #c2185b; }

/* v726 相談数 注記 */
.a2-notice { background: #fff9e6; border: 1px solid #f4d78e; color: #7a5a0f; padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 12px; line-height: 1.5; }
.a2-notice strong { color: #a36f00; }

/* body/app が overflow:hidden なので、分析ビュー自体を縦スクロール可能にする */
.analytics-view {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  height: 100%;
  box-sizing: border-box;
}

/* ============================================================
 * v732 分析タブ モバイル 全面再設計
 *   - 期間クイック 3等分 横並び (今月/先月/先々月)
 *   - 期間 select + リセット は独立 1行
 *   - 医院/治療/プロモ は 3列 横並び (小型 chip 風)
 *   - Toolbar sticky で操作性↑
 *   - サマリーカード 2列固定 + アラート全幅
 *   - テーブル 分類列 sticky + 12px 詰め
 * ============================================================ */
@media (max-width: 720px) {
  .analytics-view { padding: 8px 8px 32px; }
  .analytics-view .a2-toolbar {
    padding: 8px;
    background: var(--paper);
    position: sticky; top: 0; z-index: 5;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
    margin: -8px -8px 12px;
  }

  /* [v732] 今月/先月/先々月 → 3等分 横並び */
  .analytics-view .a2-quick-row {
    display: flex; gap: 6px;
  }
  .analytics-view .a2-quick-row .quick-period-btn {
    flex: 1 1 0; min-width: 0;
    min-height: 44px;
    font-size: 14px; font-weight: 600;
    padding: 0 4px;
    border-radius: 8px;
  }
  .analytics-view .a2-quick-row .quick-period-btn.active {
    background: var(--accent); color: #fff; border-color: var(--accent);
  }

  /* [v732] 期間セレクト + リセット: [7:3] */
  .analytics-view .a2-period-row {
    display: flex; gap: 8px; align-items: stretch;
  }
  .analytics-view .a2-period-row #a2-period {
    flex: 1 1 auto;
    min-height: 40px; font-size: 13px;
    padding: 6px 10px;
    -webkit-appearance: menulist; appearance: menulist;
  }
  .analytics-view .a2-period-row #a2-reset {
    flex: 0 0 auto;
    min-height: 40px; padding: 0 12px;
    font-size: 12px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  }

  /* [v732] 医院/治療/プロモ: 3列 横並び (chip 風) */
  .analytics-view .a2-filter-grid {
    display: flex !important;
    flex-direction: row !important;
    gap: 6px; margin: 0;
  }
  .analytics-view .a2-filter-grid .tb-select {
    flex: 1 1 0; min-width: 0; width: auto !important;
    min-height: 38px; font-size: 12px; padding: 4px 6px;
    -webkit-appearance: menulist; appearance: menulist;
  }

  /* サマリーカード: 2列 + 数字大きく */
  .a2-summary { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
  .a2-card { padding: 10px 12px; }
  .a2-card-lbl { font-size: 10px; }
  .a2-card-num { font-size: 20px; margin-top: 2px; font-weight: 700; }
  .a2-card-sub { font-size: 10px; }
  .a2-card-alert { grid-column: 1 / -1; }

  /* テーブル: 横スクロール + font 縮小 + セル padding 減 + 分類列 sticky */
  .a2-section { margin-bottom: 18px; }
  .a2-title { font-size: 13px; padding-left: 6px; }
  .a2-table { font-size: 11px; }
  .a2-table th, .a2-table td { padding: 5px 6px; }
  .a2-table th { font-size: 10px; }
  .a2-pct { padding: 1px 5px; font-size: 10px; }
  .a2-filter-line { font-size: 11px; margin-bottom: 8px; }
  .a2-chip { padding: 2px 8px; font-size: 10px; }
  .a2-table thead th:first-child,
  .a2-table tbody td:first-child { position: sticky; left: 0; background: var(--paper); z-index: 1; }
  .a2-table thead th:first-child { background: var(--bg); }
  .a2-table tr.a2-total td:first-child { background: var(--bg); }
}

/* [v732] デスクトップは従来レイアウト維持 (period-row と quick-row は 1行に流し込み) */
@media (min-width: 721px) {
  .analytics-view .a2-toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px; }
  .analytics-view .a2-quick-row,
  .analytics-view .a2-period-row,
  .analytics-view .a2-filter-grid { display: flex; gap: 8px; flex-wrap: wrap; }
}

/* ============================================================
 * v730 モバイル UX 全面 fix
 * ============================================================ */

/* [Finding 14] iOS のアドレスバー可変吸収 (100dvh 対応) */
@supports (height: 100dvh) {
  html, body, #app { height: 100dvh; }
}

/* [Finding 7] iOS notch / safe-area */
.hdr {
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  padding-top: max(6px, env(safe-area-inset-top));
}
.toast-host {
  bottom: max(10px, env(safe-area-inset-bottom));
}

/* [Finding 1] slots-view / patients-view / activity-view にスクロール救済 */
.slots-view, .patients-view, .activity-view {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  height: 100%;
  box-sizing: border-box;
  overscroll-behavior: contain;
}

@media (max-width: 720px) {
  /* [Finding 5] 患者/アクティビティ view の table min-width を狭める */
  .patients-view .v-table, .activity-view .v-table { min-width: 0; }
  .patients-view .v-table th, .activity-view .v-table th,
  .patients-view .v-table td, .activity-view .v-table td {
    font-size: 12px; padding: 6px 8px;
  }

  /* [Finding 4] nav 横スクロールのエッジフェード + 右端ヒント */
  .hdr-nav {
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 20px), transparent);
    mask-image: linear-gradient(to right, black calc(100% - 20px), transparent);
    position: relative;
  }
  .hdr-nav::-webkit-scrollbar { height: 4px; }
  .hdr-nav::after {
    content: '▶';
    position: sticky; right: 0;
    color: var(--accent);
    font-size: 12px;
    padding: 6px 4px 6px 6px;
    background: linear-gradient(to right, transparent, var(--paper) 40%);
    pointer-events: none;
    align-self: center;
  }

  /* [Finding 8] モーダル close 44x44 */
  .modal-close { width: 44px; height: 44px; font-size: 26px; }

  /* [Finding 9] hdr 内ボタンを 40px 確保 (!important 上書き) */
  .sheet-sync-btn, .ver-check-btn {
    padding: 8px 10px !important;
    min-height: 40px;
    font-size: 12px !important;
  }

  /* [Finding 10] 「重複」トグルを 38px */
  .quick-dup-btn {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 38px;
  }

  /* [Finding 13] modal をキーボードで隠れない配置 (iOS 対応) */
  .modal-backdrop { align-items: flex-start; padding-top: 10px; }
  .modal {
    max-height: calc(100dvh - 20px);
    max-height: 90vh; /* fallback */
    margin-top: 0;
  }
  .modal-body textarea { min-height: 80px; }
  /* footer はキーボード横まで安全に */
  .modal-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }

  /* [補足] メモセル 40px タップターゲット */
  .memo-cell { min-height: 40px; }

  /* [補足] status select 等の user-select 制御 */
  .status-sel, .field-input, .amount-input { touch-action: manipulation; }

  /* [補足] update-banner を safe-area top に */
  #update-banner {
    padding-top: max(10px, calc(env(safe-area-inset-top) + 4px)) !important;
  }
}

/* [Finding 15] toast err はデフォルト長め + タップで消せる */
.toast { cursor: pointer; }


/* v733: 予約一覧 sort ヘッダ */
.bookings-view .b-sortable {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}
.bookings-view .b-sortable:hover { background: var(--bg); }
.bookings-view .b-sortable.b-sort-active { color: var(--accent); }
.bookings-view .b-sort-ind { font-size: 10px; margin-left: 2px; }

/* v734: 分析タブ ドリルダウンリンク */
.a2-drill {
  color: var(--accent-ink);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}
.a2-drill:hover { background: var(--accent-soft); color: var(--accent); text-decoration-style: solid; border-radius: 3px; }

/* v738: 要確認 名前セル → 初診シートジャンプ link */
.name-sheet-link {
  color: #a24800;
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: pointer;
  font-weight: 700;
}
.name-sheet-link:hover { background: #ffe5b4; border-radius: 3px; text-decoration-style: solid; }
