@import url('https://fonts.googleapis.com/css2?family=Anton&display=swap');
:root {
  --bg: #f2f3f6;
  --header-bg: #1b2333;
  --header-text: #f5f6f8;
  --accent: #c9a227;
  --accent-dark: #a9861b;
  --card-bg: #ffffff;
  --border: #e3e5ea;
  --text: #1b2333;
  --text-muted: #6b7280;
  --shadow: 0 4px 16px rgba(20, 24, 35, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ヘッダーと機能タブはひとかたまりで画面上部に貼り付ける */
.app-chrome {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

header.app-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 14px 24px 0;
}

.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

header.app-header .brand {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

header.app-header .brand span {
  color: var(--accent);
}

header.app-header .brand span.brand-fsystem {
  font-family: 'Prata', serif;
  font-style: normal;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 25%, white), var(--accent), var(--accent-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
}

header.app-header .brand-smiley-eyes {
  vertical-align: 0.08em;
  margin-right: -0.06em;
}

header.app-header .brand-smiley-mouth {
  margin-left: 0;
}

header.app-header .brand-divider {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: var(--accent);
  opacity: 0.5;
  margin: 0 8px;
  vertical-align: middle;
}

header.app-header .brand-mark {
  display: inline-block;
  color: var(--accent);
  font-size: 14px;
  margin: 0 1px;
  vertical-align: 0.3em;
}

.app-header-side {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* スマホ幅ではブランド名と右側の情報が横一列に収まらず折り返して崩れるため、縦積みにする */
@media (max-width: 767px) {
  .app-header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  header.app-header .brand {
    font-size: 15px;
    white-space: nowrap;
  }

  .app-header-side {
    flex-wrap: wrap;
    justify-content: flex-end;
    width: 100%;
    row-gap: 6px;
  }
}

/* ヘッダーの地は3配色ともに濃色なので、ここだけは白の透過で濃さを決める
   （--text-muted はクラシックだと濃すぎて読めない） */
.hdr-updated {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
}

/* 分野タブ（売上・予約・アンケート・カウンセリング）。
   選択中の色は各タブが --field-color で持つ（fields.php で分野ごとに指定） */
.field-tabs {
  display: flex;
  gap: 28px;
  margin-top: 16px;
  overflow-x: auto;
  scrollbar-width: none;
}

/* 横スクロールはできるが、バーは出さない（下線と重なって見づらいため） */
.field-tabs::-webkit-scrollbar,
.view-bar::-webkit-scrollbar { display: none; }

.field-tabs a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding-bottom: 12px;
  color: rgba(255,255,255,0.64);
  text-decoration: none;
  font-size: 15px;
  white-space: nowrap;
  transition: color .15s ease;
}

.field-tabs a svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex: none;
  transition: fill .15s ease;
}

.field-tabs a:hover {
  color: rgba(255,255,255,0.92);
}

.field-tabs a.active {
  color: var(--field-color);
  font-weight: 600;
}

/* 選択中の分野を示すインジケーターライン。うっすら発光させて質感を出す */
.field-tabs a.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--field-color);
  box-shadow: 0 0 10px -1px var(--field-color);
}

/* 機能タブ（レポート・分析・取込・入力）。分野の直下に、窪んだ枠にまとめた
   セグメントコントロールとして置く。選択中だけ分野色でベタ塗り */
.view-bar {
  display: inline-flex;
  gap: 2px;
  margin: 14px 24px 16px;
  padding: 4px;
  max-width: calc(100% - 48px);
  background: color-mix(in srgb, var(--bg) 55%, var(--card-bg));
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.view-bar a {
  padding: 7px 16px;
  border-radius: 9px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .13s ease, color .13s ease;
}

.view-bar a:hover {
  color: var(--text);
}

.view-bar a.active {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  box-shadow: 0 2px 7px -1px color-mix(in srgb, var(--accent) 55%, transparent);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.card {
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 20px;
}

/* 売上入力：院・日付・分類の選択欄を、下の入力表をスクロールしてもヘッダーの直下に固定表示する */
.input-toolbar-card {
  position: sticky;
  top: var(--chrome-h, 96px);
  z-index: 40;
}

h2.page-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

/* タイトル行：左にページ名、右に税込の注記 */
.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.title-row .page-title {
  margin-bottom: 0;
}

.tax-note {
  font-size: 12px;
  color: var(--text-muted);
}

/* 表示結果の左上に置く税込の注記 */
.card .tax-note {
  margin: 0 0 10px;
}

/* リセットは絞り込み・比較どちらにも効くので、カードの外・データ最終更新の行に並べる */
.page-top-row {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.page-top-row .hint {
  margin: 0;
}

.page-top-row .btn-secondary {
  margin-left: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
}

.page-top-row .btn-secondary:hover {
  background: #f7f8fa;
}

/* 画面上部サマリーの開閉ボタンと、直近日の前後移動を同じ行に並べる */
.stats-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 8px;
}

.stats-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 13px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
}

.stats-toggle:hover {
  color: var(--text);
}

.stats-arrow {
  display: inline-block;
  width: 12px;
}

/* サマリーの直近日を前後に移動する矢印 */
.stats-daynav {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.stats-day-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.stats-day-btn:hover:not(:disabled) {
  background: #f2f4f8;
}

.stats-day-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.stats-day-label {
  min-width: 4em;
  text-align: center;
  cursor: pointer;
  border-bottom: 1px dashed var(--border);
}

.stats-day-label:hover {
  color: var(--text);
  border-bottom-color: var(--text-muted);
}

/* カレンダーを開くためだけの日付入力。画面には出さず、直近日の表示クリックで開く */
.stats-day-picker-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

/* 画面上部サマリー：4枠。3・4枠目は契約金額・役務消化金額の2段組み */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
}

.stat-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px 8px;
  margin-bottom: 6px;
}

.stat-head .label {
  margin-bottom: 0;
}

.stat .label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat .value {
  display: block;
  font-size: 22px;
  font-weight: 600;
  white-space: nowrap;
}

.stat .delta {
  display: inline-block;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  white-space: nowrap;
}

.stat .delta.up {
  color: #1a7f37;
}

.stat .delta.down {
  color: #c0392b;
}

.stat-multi .stat-row {
  margin-top: 10px;
}

.stat-multi .stat-row:first-of-type {
  margin-top: 0;
}

.stat-multi .stat-row .stat-head {
  margin-bottom: 2px;
}

.stat-multi .stat-row-label {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-multi .stat-row .value {
  font-size: 16px;
}

@media (min-width: 768px) {
  .stat-multi .stat-row .value {
    font-size: 20px;
  }
}

@media (max-width: 767px) {
  .stats {
    grid-template-columns: 1fr;
  }
}

/* 予約タブのサマリー：完了ブロックだけ、3期間を縦積みではなく横並びにする */
/* .stat は中身を上下中央寄せするため、中身の少ない完了ブロックだけ「完了」の見出しが下がってしまう。
   上下の余白を auto で吸わせて、見出しを他のカードと同じ高さまで上げる */
.stat-trio {
  display: flex;
  gap: 10px;
  margin-top: auto;
  margin-bottom: auto;
}

.stat-trio-item {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.stat-trio .stat-row-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  white-space: nowrap;
}

/* theme.css の .stat .value（clamp で最大34px）が後読みで勝ってしまうため、
   予約総数側の .stat-multi .stat-row .value と同じ詳細度（クラス3つ）にそろえて上書きする */
.stat-multi .stat-trio .value {
  display: block;
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}

@media (min-width: 768px) {
  .stat-multi .stat-trio .value {
    font-size: 20px;
  }
}

.toolbar {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.toolbar > button,
.toolbar > .compare-panel,
.toolbar > .field-pair,
.toolbar > .form-actions,
.filter-fields > .field-pair,
.filter-fields > .form-actions {
  flex-basis: 100%;
}

/* ボタンは改行させたいだけなので、横幅までは広げない（PC） */
.toolbar > button {
  max-width: 160px;
}

.form-actions {
  display: flex;
  gap: 12px;
}

.form-actions button[type=submit] {
  flex: none;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-secondary {
  background: #eceef2;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}

.btn-secondary:hover { background: #dfe2e8; }

.btn-compact {
  padding: 6px 14px;
  font-size: 12px;
}

.field-pair {
  display: flex;
  flex-wrap: nowrap;
  gap: 20px;
  align-items: flex-start;
}

/* 上部フィルター（開閉式）。中身は従来のツールバーと同じ並べ方 */
.filter-panel {
  width: 100%;
}

.filter-panel summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fafbfc;
  list-style: none;
}

.filter-panel summary::-webkit-details-marker { display: none; }

.filter-panel summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s ease;
}

.filter-panel[open] summary::before {
  transform: rotate(90deg);
}

.filter-fields {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 12px;
}

.category-list label.all-option,
.clinic-list label.all-option {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* 期間欄のボタン。上段が決め打ちの期間、下段が今の期間をずらす */
.period-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.period-quick button {
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.4;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.period-quick button:hover {
  background: var(--row-alt);
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.file-list:not(:empty) {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  max-height: 160px;
  overflow-y: auto;
}

.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
}

.file-list li span {
  overflow-wrap: anywhere;
}

.file-list li + li {
  border-top: 1px solid var(--border);
}

.file-remove {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

.file-remove:hover {
  color: #c0392b;
}

/* ファイル選択欄。ボタンで選ぶほかに、CSVをドラッグ＆ドロップでも置ける */
.dropzone {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  transition: border-color .15s, background .15s;
}

.dropzone.is-over {
  border-style: solid;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.dropzone-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.dropzone.is-over .dropzone-hint {
  color: var(--accent);
}

.import-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.import-overlay[hidden] {
  display: none;
}

.import-overlay-box {
  background: var(--card-bg);
  color: var(--text);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 32px;
  width: 300px;
  text-align: center;
}

.import-overlay-box p {
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

.progress-indeterminate {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-indeterminate-bar {
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  animation: progress-indeterminate-slide 1.1s ease-in-out infinite;
}

@keyframes progress-indeterminate-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

input[type=date], input[type=number], input[type=text], input[type=password], select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  background: #fff;
  color: #1b2333;
  height: 40px;
}

input[type=number] { width: 150px; }

/* 期間の日付欄と、その隣の契約／役務セレクトを同じ大きさに揃える */
input[type=date] { width: 150px; }
.compare-fields select { width: 150px; }

button {
  background: var(--accent);
  color: #1b2333;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

button:hover { background: var(--accent-dark); }

.message {
  background: #eef7ee;
  color: #2f7a3a;
  border: 1px solid #b9e0bd;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  display: inline-block;
}

.clinic-list {
  display: grid;
  grid-template-columns: repeat(5, max-content);
  gap: 4px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  width: fit-content;
  max-width: 100%;
  max-height: 118px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  background: #fafbfc;
}

.clinic-list label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
}

.clinic-list .caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.category-list {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 4px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  width: fit-content;
  max-width: 100%;
  max-height: 118px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  background: #fafbfc;
}

.category-list label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
}


table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin-top: 18px;
}

th, td {
  border: 1px solid var(--border);
  padding: 9px 12px;
  white-space: nowrap;
}

th {
  background: #f5f6f9;
  text-align: left;
  font-weight: 600;
  color: var(--text);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f5f6f9;
}

table th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #f5f6f9;
}

thead th:first-child {
  z-index: 4;
}

td.num { text-align: right; font-variant-numeric: tabular-nums; }

.total-row td, .total-col {
  font-weight: 700;
  background: #fbf6e8;
}

.scroll-wrap {
  overflow-x: auto;
  border-radius: 10px;
}

.pivot-scroll table {
  border-collapse: separate;
  border-spacing: 0;
}

.pivot-scroll {
  overflow: auto;
  max-height: 70vh;
  border-radius: 10px;
}

.pivot-scroll thead th {
  position: sticky;
  z-index: 3;
  background: #f5f6f9;
  height: 38px;
}

.pivot-scroll thead tr:nth-child(1) th {
  top: 0;
}

.pivot-scroll thead tr:nth-child(2) th {
  top: 38px;
}

/* 固有データは内訳が3段まであるため、3段目のヘッダーも固定する */
.pivot-scroll thead tr:nth-child(3) th {
  top: 76px;
}

.pivot-scroll tbody th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #f5f6f9;
}

/* ヘッダーは2段あるため、2段目の左端（院列の空セル）にも横固定と重なり順を効かせる。
   ここを tr:first-child に限定すると、2段目だけ隣の列に上書きされて貫通する */
.pivot-scroll thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--head-cell);
}

/* 分析タブの比較表は「院」を rowspan="2" にしているため、2段目の実際の先頭セルは
   「院」ではなく「今期」になる。上のルールがそれを誤って左固定してしまい、
   1段目の「院」と重なって表示されるため、目印クラスを付けたセルだけ左固定を解除する */
.pivot-scroll thead th.cmp-th-nofix {
  position: sticky !important;
  left: auto !important;
  z-index: 3 !important;
}

/* 比較表の「比較対象」列を背景色で区別する。合計行・偶数行の背景より優先させる。
   固定色ではなくテーマの背景色にアクセント色を混ぜることで、テーマ切替（midnight等）でも
   文字色（var(--text)）との組み合わせが崩れないようにする */
.pivot-scroll .cmp-b-col {
  background: color-mix(in srgb, var(--accent) 14%, var(--card-bg)) !important;
}

.pivot-scroll thead th {
  text-align: center;
}

.pivot-scroll tbody tr:nth-child(even):not(.total-row) td:not(.total-col),
.pivot-scroll tbody tr:nth-child(even):not(.total-row) th {
  background: #f7f8fb;
}

/* 一覧表（#pivotTable）は院の行を開くと年月・日付の行が間に挟まるため、
   縞模様は表示中の院の行だけを数える row-even クラス方式に切り替える。
   色は直接書かず、分析タブと同じテーマ変数だけを使う */

/* :nth-child(even) 由来の縞を打ち消し、分析タブと同じ素の配色に戻す。
   下の row-even・drill 行のルールと詳細度を揃え、後に書いた側が勝つようにする */
#pivotTable tbody tr:not(.total-row) td:not(.total-col) {
  background: transparent;
}
#pivotTable tbody tr:not(.total-row) th {
  background: var(--head-cell);
}

/* 表示中の院の行だけを数えた偶数行に縞を付ける */
#pivotTable tbody tr.row-even td:not(.total-col),
#pivotTable tbody tr.row-even th {
  background: var(--row-alt);
}

/* 内訳行（年・年月・日付）はドリル用の配色を優先する */
#pivotTable tbody tr.drill-year td:not(.total-col),
#pivotTable tbody tr.drill-year th,
#pivotTable tbody tr.drill-ym td:not(.total-col),
#pivotTable tbody tr.drill-ym th {
  background: var(--row-alt);
}
#pivotTable tbody tr.drill-day td:not(.total-col),
#pivotTable tbody tr.drill-day th {
  background: color-mix(in srgb, var(--row-alt) 55%, var(--card-bg));
}

/* 院・合計の行を開いた時に出る、年月・日付ごとの内訳行（テーマの配色変数に合わせる） */
.drill-arrow {
  cursor: pointer;
  display: inline-block;
  width: 14px;
  color: var(--text-muted, #6b7280);
  user-select: none;
}

.pivot-scroll tr.drill-year th,
.pivot-scroll tr.drill-year td,
.pivot-scroll tr.drill-year th:first-child,
.pivot-scroll tr.drill-ym th,
.pivot-scroll tr.drill-ym td,
.pivot-scroll tr.drill-ym th:first-child {
  background: var(--row-alt, #f0f1f5);
}

.pivot-scroll tr.drill-day th,
.pivot-scroll tr.drill-day td,
.pivot-scroll tr.drill-day th:first-child {
  background: color-mix(in srgb, var(--row-alt, #f9fafb) 55%, var(--card-bg, #ffffff));
}

.drill-sub {
  padding-left: 26px;
  font-weight: 400;
  color: var(--text-muted, #4b5261);
}

.drill-sub2 {
  padding-left: 42px;
  font-weight: 400;
  color: var(--text-muted, #6b7280);
}

/* 年をまたぐ時だけ使う、日付の段（年→年月→日付の3段目） */
.drill-sub3 {
  padding-left: 58px;
  font-weight: 400;
  color: var(--text-muted, #6b7280);
}

/* ブロックの境目を縦線で分ける */
.pivot-scroll th.sec-start,
.pivot-scroll td.sec-start {
  border-left: 3px solid #98a1b2;
}

/* 合計行は表の下端に固定して、下までスクロールしても見えるようにする */
.pivot-scroll tfoot tr.total-row td {
  position: sticky;
  bottom: 0;
  z-index: 3;
}

.pivot-scroll tfoot tr.total-row td:first-child {
  left: 0;
  z-index: 4;
}

/* 表の上のモード切替・コピーボタン */
.table-tools {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

/* モード切替はひと続きのタブ型。選んでいるものだけ色を反転させる */
.mode-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
}

.mode-switch label {
  display: block;
  cursor: pointer;
  border-left: 1px solid var(--border);
}

.mode-switch label:first-child {
  border-left: none;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.mode-switch span {
  display: block;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.mode-switch label:hover span {
  background: #f2f4f8;
}

.mode-switch input:checked + span {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.mode-switch input:focus-visible + span {
  outline: 2px solid var(--accent-dark);
  outline-offset: -2px;
}

/* リンクで切り替えるモードスイッチ（分析タブの契約／役務） */
.mode-switch.link-switch a {
  display: block;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  border-left: 1px solid var(--border);
}

.mode-switch.link-switch a:first-child {
  border-left: none;
}

.mode-switch.link-switch a:hover {
  background: #f2f4f8;
}

.mode-switch.link-switch a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* 人件費効率のアートメイク含む／含まないトグル（控えめな1個リンク） */
.an-le-art-toggle {
  display: inline-block;
  align-self: center;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.an-le-art-toggle:hover {
  background: #f2f4f8;
}

.an-le-art-toggle.on {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* モード専用のボタンは、そのモードの時だけ出す */
.table-tools .only-copy,
.table-tools .only-check {
  display: none;
}

.table-tools.mode-copy .only-copy,
.table-tools.mode-check .only-check {
  display: inline-block;
}

/* 別ウィンドウ表示は通常モードの時だけ出す */
.table-tools.mode-copy .only-normal,
.table-tools.mode-check .only-normal {
  display: none;
}

.copy-toast {
  font-size: 12px;
  color: var(--text-muted);
}

/* ツールバー内の小見出し（契約／役務の切替など） */
.tools-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* 表ツールバー共通：通常/コピー/チェックとコピー系ボタンを右寄せする */
.tools-mode-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-left: auto;
}

/* 大きく表示・CSVで保存を横並びにする */
.tools-btn-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 売上レポートの集計結果：1行目に条件と大きく表示・CSV、2行目にモード切替だけ */
.result-tools {
  display: block;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 10px;
}

/* 条件が長いときは条件の文を折り返し、ボタンは右端に残す */
.result-tools .result-cond {
  flex: 1 1 360px;
  margin: 0;
}

.result-head .tools-btn-row {
  flex: none;
  margin-left: auto;
}

.result-period {
  color: var(--text);
}

/* 「税込」の注記：PCはモード切替の行の右端、スマホは期間の行の右端に小さく出す */
.result-tax-note {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.result-mode .result-tax-note {
  margin-left: auto;
}

.result-tools .sp-only {
  display: none;
}

.result-cond .sep {
  margin: 0 1em;
}

.result-mode {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

@media (max-width: 767px) {
  /* スマホでは大きく表示だけを残し、モード切替・CSVは出さない */
  .result-tools .result-mode,
  .result-tools .result-csv {
    display: none !important;
  }

  .result-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
  }

  .result-tools .result-cond {
    display: contents;
  }

  .result-daynav {
    grid-column: 1;
    grid-row: 1;
  }

  .result-head .tools-btn-row {
    grid-column: 2;
    grid-row: 1;
  }

  .result-period {
    grid-column: 1;
    font-size: 13px;
  }

  .result-tools .sp-only {
    display: inline;
    grid-column: 2;
    align-self: center;
    text-align: right;
  }

  .result-rest {
    grid-column: 1 / -1;
    font-size: 11px;
    line-height: 1.5;
  }

  .result-rest .sep:first-child {
    display: none;
  }

  .result-cond .sep {
    margin: 0 .3em;
  }
}

/* ツールバーをフォームにした時も、通常のツールバーと同じ余白・並びにする */
form.table-tools {
  margin-bottom: 10px;
}

/* コピー・チェックモード中はセルが押せることを分かるようにする */
.mode-copy th, .mode-copy td,
.mode-check th, .mode-check td {
  cursor: pointer;
}

.pivot-scroll th.copied,
.pivot-scroll td.copied {
  outline: 2px solid #c9a227;
  outline-offset: -2px;
}

/* チェックした数字の色（クリックのたび 黄 → 青 → 無色） */
.pivot-scroll th.mark1,
.pivot-scroll td.mark1 {
  background: #fff2a8 !important;
}

.pivot-scroll th.mark2,
.pivot-scroll td.mark2 {
  background: #cfe3ff !important;
}

/* 表示結果の絞り込み条件 */
.cond-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: -4px 0 10px;
  line-height: 1.7;
}

/* 契約／役務の切替 */
.kind-list {
  display: flex;
  gap: 14px;
  font-size: 13px;
}

.kind-list label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
}

.closed-clinic {
  color: var(--text-muted);
}

.group-header td {
  background: #eef0f5;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 12px;
}

.mode-tabs {
  margin-bottom: 16px;
}

.mode-tabs a {
  display: inline-block;
  margin-right: 10px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}

.mode-tabs a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1b2333;
  font-weight: 600;
}

.compare-panel {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  width: 100%;
}

.compare-panel summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 10px;
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fafbfc;
  list-style: none;
}

.compare-panel summary::-webkit-details-marker {
  display: none;
}

.compare-panel summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s ease;
}

.compare-panel[open] summary::before {
  transform: rotate(90deg);
}

.compare-fields {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 12px;
}

.compare-result {
  margin-top: 18px;
}

.compare-result table {
  margin-top: 0;
}

.message.error {
  background: #fbeaea;
  color: #b3261e;
  border-color: #f0b8b8;
}

.diff-up { color: #2f7a3a; }
.diff-down { color: #b3261e; }

.main-chart {
  margin-top: 8px;
  max-width: 800px;
}

.chart-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.bar-a { background: var(--accent); }
.bar-b { background: #6b8fc7; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

/* グラフカードのヘッダー（タイトル＋表示ON/OFF） */
.chart-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.chart-card-head .page-title {
  margin: 0;
}

.chart-show-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

/* 補助線・凡例のON/OFF */
.chart-toggles {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.chart-toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* グラフの点・棒にカーソルを合わせた時に出る数値ツールチップ */
.chart-tooltip {
  position: fixed;
  z-index: 1000;
  background: #1f2430;
  color: #fff;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
}

/* ===== スマホ表示（PC用の横並び・固定幅をすべて解除して縦一列にする） ===== */
@media (max-width: 767px) {
  main { padding: 16px 12px 40px; }
  .card { padding: 16px 14px; border-radius: 10px; }

  /* 縦積みにするので、横並び用の flex-basis:100%（縦方向では高さ指定になる）を解除する */
  .toolbar > button,
  .toolbar > .compare-panel,
  .toolbar > .field-pair,
  .toolbar > .form-actions,
  .filter-fields > .field-pair,
  .filter-fields > .form-actions {
    flex-basis: auto;
  }

  /* スマホは従来どおり横いっぱいに広げる */
  .toolbar > button { max-width: none; }

  .toolbar,
  .filter-fields,
  .compare-fields,
  .field-pair {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .field-pair { flex-wrap: wrap; }

  /* チェックボックスは1列に積む */
  .category-list,
  .clinic-list {
    grid-template-columns: 1fr;
    width: auto;
  }

  input[type=date],
  input[type=number],
  select,
  .compare-fields select {
    width: 100%;
  }

  .date-nav { flex-wrap: wrap; }
  .date-nav input[type=date] { flex: 1 1 100%; order: -1; }
  .date-nav .btn-secondary { flex: 1; }

  .form-actions { flex-direction: column; }
  .form-actions button,
  .form-actions button[type=submit] { flex: none; width: 100%; }

  .page-top-row {
    gap: 8px;
  }
  .page-top-row .btn-secondary {
    margin-left: auto;
    width: auto;
    padding: 6px 14px;
    font-size: 13px;
  }

  .filter-panel summary,
  .compare-panel summary { display: block; text-align: center; }

  header.app-header { padding: 12px 14px 0; }
  .field-tabs { gap: 18px; margin-top: 12px; }
  .field-tabs a { font-size: 13px; }
  .view-bar { margin: 12px 14px 14px; max-width: calc(100% - 28px); }
  .hdr-updated { font-size: 11px; }

  table { font-size: 12px; }
  th, td { padding: 7px 9px; }

  .chart-card-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .chart-toggles { flex-wrap: wrap; gap: 10px 16px; }

  .mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .mode-tabs a {
    margin-right: 0;
    text-align: center;
  }
}

/* ===== 件数入力（input.php の「件数を入力」タブ） ===== */
.count-table input[type="number"] {
  width: 90px;
  text-align: right;
}
.count-table td:first-child,
.count-table th:first-child {
  white-space: nowrap;
}
.sub-title {
  margin: 22px 0 6px;
  font-size: 15px;
  font-weight: 600;
}
.sub-check {
  margin: 0 0 8px;
}
.sub-check.mismatch {
  color: #b3261e;
  font-weight: 600;
}

/* ===== 分析タブ（index.php + analysis.php） ===== */
/* 項目は表の上のタブで選ぶので、表は横幅いっぱいに使う */
.analysis-layout {
  display: block;
}
/* 分析画面の期間バー（日付を変えるとすぐ表示し直す） */
.an-period {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.an-period-label {
  font-size: 12px;
  color: var(--text-muted);
}
.an-period .an-period-quick {
  margin-top: 0;
}
/* 期間の箱を1行に収めるため、PC幅では日付欄とボタンを少し詰め、
   入りきらない時もボタン単位で折り返す（ボタンの塊ごと次の行へ落とさない） */
@media (min-width: 768px) {
  /* 間隔は画面幅に応じて広げる（1000pxで3px、1250px以上で8px） */
  .an-period {
    gap: clamp(3px, calc((100vw - 1000px) / 50 + 3px), 8px);
  }
  .an-period .an-period-label {
    font-size: 11px;
  }
  .an-period .an-period-quick {
    display: contents;
  }
  .an-period .an-period-quick button {
    padding: 4px 4px;
  }
  .an-period input[type=date] {
    width: 110px;
    height: 34px;
    padding: 5px 4px;
    font-size: 13px;
  }
}
/* リセット：期間のボタンと見分けるため、枠なしの文字だけのボタンにする。前後のボタンとは間を空ける */
.an-period .period-quick button.an-reset {
  margin-left: 6px;
  margin-right: 6px;
  padding: 4px 6px 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
}
.an-period .period-quick button.an-reset:hover {
  background: transparent;
  color: var(--text);
}
/* 絞り込み・比較：角の丸いボタンに▾。開いている間はアクセント色で塗りつぶして▴ */
.an-period .period-quick button.an-toggle {
  padding: 4px 12px;
  border-radius: 999px;
  border-color: var(--accent);
  background: var(--card-bg);
  color: var(--text);
}
.an-period .period-quick button.an-toggle:hover {
  background: var(--row-alt);
}
.an-period .period-quick button.an-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.an-toggle .an-toggle-mark {
  font-size: 10px;
  margin-left: 2px;
}
/* PC幅：比較まで1行に収めるため、リセット・絞り込み・比較の余白も詰める */
@media (min-width: 768px) {
  /* 日付／期間のボタン／リセット・絞り込み・比較の3つのまとまりに分け、余った幅をまとまりの間に等分する。
     リセット・絞り込み・比較は右端に揃う。幅が狭いときは余白0で今までどおり1行に収まる */
  .an-period .an-period-quick > button:first-child,
  .an-period .period-quick button.an-reset {
    margin-left: auto;
  }
  .an-period .period-quick button.an-toggle {
    padding: 4px 7px;
  }
}
/* 表の道具（モード切替・大きく表示・CSV）が1行だけの時は、表との間を空けすぎない */
.table-tools.result-tools .result-head:last-child {
  margin-bottom: 0;
}
.an-box .an-panels {
  gap: 0;
  margin-bottom: 0;
}
.an-box .filter-panel > summary,
.an-box .compare-panel > summary {
  display: none;
}
.an-box .compare-panel {
  margin-top: 0;
  border-top: none;
  padding-top: 0;
}
.an-box .filter-panel[open],
.an-box .compare-panel[open] {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
/* 項目のタブ（1段目＝区分、2段目＝その中の項目）。狭い画面では折り返して全部見えるようにする */
.an-tabs {
  margin-bottom: 12px;
}
.an-tabs .mode-switch {
  display: flex;
  flex-wrap: wrap;
  width: fit-content;
  max-width: 100%;
}
/* 2段目は1段目の中の項目なので、枠なしの文字タブにして下げる。選択中だけ下線と色（theme.css の配色より優先させる） */
.an-tabs .an-tabs-sub {
  margin: 6px 0 0 14px;
  border: none;
  border-radius: 0;
  background: none;
  gap: 2px 14px;
}
.an-tabs .an-tabs-sub a {
  padding: 5px 2px;
  font-size: 12px;
  border-left: none;
  border-bottom: 2px solid transparent;
}
.an-tabs .mode-switch.an-tabs-sub a:hover {
  background: none;
  color: var(--accent);
}
.an-tabs .mode-switch.an-tabs-sub a.active {
  background: none;
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.analysis-menu {
  flex: 0 0 190px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 10px;
}
.analysis-menu-head {
  margin: 8px 6px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.analysis-menu-head:first-child {
  margin-top: 0;
}
.analysis-menu-sub {
  margin: 10px 6px 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.analysis-menu a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.analysis-menu a:hover {
  background: var(--bg);
}
.analysis-menu a.active {
  background: var(--accent);
  color: #1b2333;
  font-weight: 600;
}
.analysis-body {
  flex: 1 1 auto;
  min-width: 0;
}
.analysis-title {
  margin: 4px 0 10px;
  font-size: 16px;
  font-weight: 600;
}
.analysis-body .mode-switch {
  margin-bottom: 12px;
}
/* 切り替えが複数ある時は横に並べる（契約／役務 と 件数／割合） */
.switch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.switch-row .mode-switch {
  margin-bottom: 0;
}
.an-csv-btn {
  margin-left: auto;
}
.analysis-table th {
  white-space: nowrap;
}
.analysis-table td.total-cell {
  font-weight: 600;
}

@media (max-width: 767px) {
  /* 注釈はスマホでは小さくする */
  .hint {
    font-size: 11px;
    line-height: 1.5;
  }
  .analysis-layout {
    flex-direction: column;
  }
  /* 期間バーは日付2つを1行に収める */
  .an-period-label { display: none; }
  .an-period input[type=date] {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }
  .analysis-menu {
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .analysis-menu-head,
  .analysis-menu-sub {
    width: 100%;
    margin: 4px 6px 0;
  }
  .count-table input[type="number"] { width: 68px; }
}

/* ログイン画面 */
.login-main {
  max-width: 360px;
  margin: 80px auto;
  padding: 0 20px;
}

.login-card { text-align: center; }

.login-brand {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 10px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-form input {
  width: 100%;
}

.login-form .form-actions {
  margin-top: 6px;
}

.login-form .form-actions button {
  width: 100%;
}

/* ヘッダー右側：ログイン中ユーザー名・ユーザー管理・ログアウト */
.hdr-user {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  white-space: nowrap;
}

.hdr-link {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  text-decoration: underline;
  white-space: nowrap;
}

.hdr-link:hover { color: #fff; }

/* ユーザー管理画面 */
.user-form label,
.user-card-head label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 12px;
}

.user-form input[type=text],
.user-form input[type=password],
.user-card-head input[type=text] {
  width: 260px;
  max-width: 100%;
}

.checkbox-label {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  margin: 0 16px 0 0;
}

.checkbox-label input[type=checkbox] {
  width: auto;
  height: auto;
}

.user-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 14px;
}

.user-card-username {
  font-weight: 700;
  font-size: 15px;
  align-self: center;
}

.perm-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 14px;
  background: #fafbfc;
  color: #1b2333;
}

.perm-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.perm-field-label {
  width: 100px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.perm-grid .checkbox-label {
  color: #1b2333;
}

.user-card { position: relative; }

.user-delete-form {
  position: absolute;
  top: 22px;
  right: 24px;
}

/* 週別カレンダー（直近4週の日別実績を曜日ごとに並べた表）。サマリー見出し行の小ボタンで開閉 */
.stats-weekly-btn,
.result-daynav button {
  padding: 3px 10px;
  font-size: 12px;
  line-height: 1.4;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.stats-weekly-btn:hover,
.result-daynav button:hover {
  background: var(--row-alt);
}

.stats-header .stats-weekly-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

/* 集計結果の［前日］［翌日］。条件行の先頭に並べる */
.result-daynav {
  display: inline-flex;
  gap: 14px;
  margin-right: 14px;
  vertical-align: middle;
}

.weekly-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.weekly-title {
  font-size: 16px;
  font-weight: 700;
  margin-right: auto;
}

.weekly-kind {
  display: flex;
  gap: 10px;
}

.weekly-kind label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}

.weekly-table-wrap {
  overflow-x: auto;
}

.weekly-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 860px;
}

.weekly-table th,
.weekly-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
  font-size: 13px;
}

.weekly-table th.weekly-dow {
  background: var(--head-cell);
  font-weight: 700;
  font-size: 13px;
}

/* 日曜と祝日は赤、土曜は青。明るい／暗いどちらのテーマでも読める色にする */
.weekly-red { color: #e05a5a; }
.weekly-blue { color: #5b8dd9; }

.weekly-day .weekly-date {
  display: block;
  font-weight: 700;
}

.weekly-day .weekly-amount {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 12px;
  min-height: 1em;
}

.weekly-total {
  font-weight: 700;
  white-space: nowrap;
}

.weekly-pct {
  white-space: nowrap;
}

/* 分析タブ「保険診療」の来院数カレンダー。週別カレンダーの見た目を流用し、マスに天気を小さく足す */
.hoken-monthnav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 10px;
}

.hoken-month {
  font-weight: 700;
  font-size: 15px;
}

.hoken-nav-off {
  opacity: 0.4;
  pointer-events: none;
}

/* マスは「左上に日付・右上に天気マーク・まん中に来院数」の3つだけ */
.hoken-table td.hoken-cell {
  position: relative;
  vertical-align: top;
}

.hoken-table .hoken-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 16px;
}

.hoken-table .hoken-head .weekly-date {
  font-size: 11px;
  font-weight: 600;
}

.hoken-table .hoken-mark {
  font-size: 14px;
  line-height: 1;
}

.hoken-table td.hoken-cell .weekly-amount {
  margin-top: 4px;
  font-family: 'Anton', sans-serif;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: .04em;
  text-shadow: -1px -1px 0 rgba(255,255,255,.55), 1px 1px 0 rgba(0,0,0,.9), 2px 2px 0 rgba(0,0,0,.75), 3px 4px 10px rgba(0,0,0,.85);
  line-height: 1.2;
}
[data-theme="classic"] .hoken-table td.hoken-cell .weekly-amount,
[data-theme="breeze"] .hoken-table td.hoken-cell .weekly-amount {
  text-shadow: -1px -1px 0 rgba(255,255,255,.95), 1px 1px 0 rgba(0,0,0,.35), 2px 2px 0 rgba(0,0,0,.2), 3px 4px 8px rgba(0,0,0,.3);
}

/* 指を当てる（マウスを乗せる）と、祝日名・天気概況・最高/最低気温をマスの上に重ねて出す */
.hoken-table .hoken-pop {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 4px;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 11px;
  line-height: 1.4;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.hoken-table td.hoken-cell:hover .hoken-pop,
.hoken-table td.hoken-cell:focus .hoken-pop {
  display: flex;
}

.hoken-table td.hoken-cell:focus {
  outline: none;
}

/* 詳細の箱の日付はスマホだけで出す（パソコンは触ったマスの上に重なるので不要） */
.hoken-table .hoken-pop-date {
  display: none;
}

/* 前月・翌月で埋めたマスは少し薄く（マスごと薄くすると詳細の箱まで薄くなり下に潜るので、中の文字だけ薄くする） */
.hoken-table td.hoken-out .hoken-head,
.hoken-table td.hoken-out .weekly-amount {
  opacity: 0.45;
}

/* 「画像として保存」のアイコン。パソコン幅では文字のボタンなので隠しておく */
.weekly-save-icon {
  display: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* スマホ幅では、文字のボタンをやめてダウンロードのアイコンだけを見出し行の右端に小さく出す */
@media (max-width: 767px) {
  .weekly-save-text {
    display: none;
  }
  .weekly-save-icon {
    display: block;
  }
  .weekly-save {
    margin-left: auto;
    padding: 4px;
    min-width: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--text-muted);
    line-height: 0;
  }
  .weekly-save:hover {
    background: transparent;
    color: var(--text);
  }
  /* スマホは表の中の詳細の箱を出さず、analysis.php の動きで表の外の箱（.hoken-pop-float）に写して出す */
  .hoken-table td.hoken-cell:hover .hoken-pop,
  .hoken-table td.hoken-cell:focus .hoken-pop {
    display: none;
  }
  .hoken-table td.hoken-cell[tabindex] {
    cursor: pointer;
  }
}

/* スマホで触ったマスの詳細。表の外に置き、画面のまん中の一番手前に文字が全部入る大きさで出す */
.hoken-pop-float {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: 80vw;
  padding: 10px 14px;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}
.hoken-pop-float[hidden] {
  display: none;
}
.hoken-pop-float .hoken-pop-date {
  display: block;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

/* ── アンケートレポート固有 ─────────────────────────
   共通クラス（.pivot-scroll / .table-tools / .mode-switch / .stats / .filter-panel）は
   売上・予約タブと共用。ここはアンケートだけで使う細部のみ。 */
.spark {
  display: inline-block;
  vertical-align: middle;
  color: var(--accent, #2e7d32);
}

/* 件数が平均の半分に満たないスタッフの氏名はグレーで表示する */
.pivot-scroll tbody tr.is-low th,
.pivot-scroll tbody tr.is-low td.name { color: var(--text-muted); }

/* スタッフ行：クリックで個票が開くことを示す */
.pivot-scroll tbody tr.staff-row { cursor: pointer; }
.pivot-scroll tbody tr.staff-row:hover th,
.pivot-scroll tbody tr.staff-row:hover td {
  background: color-mix(in srgb, var(--accent, #2e7d32) 10%, var(--card-bg, #fff));
}

/* アンケートのサマリ帯は3枠（施術後アンケート／術前問診／対象者数） */
.stats.stats-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) {
  .stats.stats-3 { grid-template-columns: 1fr; }
}

/* スタッフ・院ランキングの表：見出しクリックで並び替え */
.pivot-scroll thead th.sortable { cursor: pointer; white-space: nowrap; }
.pivot-scroll thead th.sortable:hover {
  background: color-mix(in srgb, var(--accent, #2e7d32) 12%, var(--card-bg, #fff));
}
.pivot-scroll thead th.sort-asc::after  { content: " ▲"; font-size: 10px; opacity: .8; }
.pivot-scroll thead th.sort-desc::after { content: " ▼"; font-size: 10px; opacity: .8; }

/* ③コメントの種別・満足度セレクタを横並びにする */
.sv-filter-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 10px;
}

/* ①スタッフ個票（行クリックで開く） */
.sv-detail {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
}
.sv-detail h4 { margin: 0 0 8px; }
.sv-detail-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}
.sv-detail-grid > div { min-width: 200px; }

.sv-mini {
  border-collapse: collapse;
  font-size: 12px;
}
.sv-mini th,
.sv-mini td {
  border: 1px solid var(--border);
  padding: 3px 8px;
}

/* ③コメント表の本文セル（一覧側） */
.sv-comment-text {
  white-space: normal;
  max-width: 480px;
}

/* 個票のコメントはカード形式。件数が多いので枠内スクロールで縦を抑える */
.sv-comment-wrap {
  margin-top: 6px;
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.sv-cmt {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.sv-cmt:last-child { border-bottom: 0; }
.sv-cmt-meta { color: var(--text-muted); margin-bottom: 2px; }
.sv-cmt-card { font-size: 11px; }
.sv-cmt-body { white-space: pre-wrap; word-break: break-word; }

/* スマホでは個票を詰めて表示する */
@media (max-width: 640px) {
  .sv-detail { padding: 10px; }
  .sv-detail-grid { gap: 12px; }
  .sv-detail-grid > div { min-width: 0; flex: 1 1 100%; }
  .sv-comment-wrap { max-height: 260px; }
}

/* ===== iPhone（スマホ幅）の表示直し ===== */
/* 分析タブの1段目のプルダウンは、PCでは出さない（タブを使う） */
.an-tabs-select { display: none; }

@media (max-width: 767px) {
  /* 1. 日付選択の箱：日付欄と期間のボタンを一回り小さくし、余白を詰める。並び方は今と同じ */
  .card.an-box { padding: 12px 10px; }
  .an-period { gap: 6px; }
  .an-period input[type=date],
  .an-period input[type=month] {
    height: 32px;
    padding: 4px 6px;
    font-size: 13px;
  }
  .an-period .an-period-quick { gap: 4px; }
  .an-period .an-period-quick button {
    padding: 3px 7px;
    font-size: 11px;
  }
  /* 前日・翌日（アンケートは前月・翌月）は今の大きさのまま */
  .an-period .an-period-quick > button:nth-child(-n+2):not(.an-reset):not(.an-toggle) {
    padding: 4px 10px;
    font-size: 12px;
  }
  .an-period .period-quick button.an-reset {
    margin-left: 2px;
    margin-right: 2px;
    padding: 3px 4px 3px 6px;
  }
  .an-period .period-quick button.an-toggle { padding: 3px 9px; }
  .an-period .mode-switch span {
    padding: 5px 10px;
    font-size: 12px;
  }

  /* 2. 検索結果の条件行：期間・法人・分類・院・区分を1行にまとめ、はみ出した分は指で横にずらす */
  .result-line {
    grid-column: 1 / -1;
    display: block;
    white-space: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    font-size: 12px;
    line-height: 1.6;
  }
  .result-line::-webkit-scrollbar { display: none; }
  /* 右に「税込」が並ぶ売上タブは左の列だけを使う */
  .result-line:has(+ .sp-only) { grid-column: 1; }
  .result-line .result-period,
  .result-line .result-rest {
    display: inline;
    font-size: inherit;
    line-height: inherit;
  }
  .result-line .result-rest .sep:first-child { display: inline; }
  /* 分析・比較・グラフの条件表示も同じく1行＋横スクロール */
  .cond-note:not(.result-cond) {
    white-space: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .cond-note:not(.result-cond)::-webkit-scrollbar { display: none; }

  /* 3. 売上・予約サマリ：直近1週間・今月の期間（9/21〜9/27 など）は出さない */
  .sum-range { display: none; }

  /* 4. 分析タブ：1段目のタブの代わりにプルダウンで選ぶ */
  .an-tabs .an-tabs-main { display: none; }
  .an-tabs .an-tabs-select {
    display: block;
    width: 100%;
    height: 36px;
    padding: 4px 8px;
    font-size: 14px;
  }
  .an-tabs .an-tabs-sub { margin-left: 4px; }

  /* 5. アンケートのサマリ：3つの枠を横1列に並べ、文字と余白を詰める */
  .stats.stats-3 {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .stats.stats-3 .stat { padding: 10px 8px; min-width: 0; }
  /* 枠が狭く見出しと％が横に並ばないので、3枠とも％は見出しの下に置いてそろえる */
  .stats.stats-3 .stat > .stat-head { flex-direction: column; align-items: flex-start; gap: 2px; }
  .stats.stats-3 .stat .label { font-size: 10.5px; white-space: nowrap; }
  .stats.stats-3 .stat .delta { font-size: 10px; }
  .stats.stats-3 .stat .value { font-size: 18px; }

  /* 6. 「スタッフ個人（対象者リストの○名）」の見出しは1行に収める */
  .sv-staff-title {
    font-size: min(15px, 4.1vw);
    white-space: nowrap;
  }
}
