/*
 * 月次レポート（Mapミル）の紙面。店主がスマホで開く画面と、A4 印刷 / 共有リンクの納品物を兼ねる。
 * アプリのテーマ（shadcn）ではなく、Mapミルのブランドで組む。
 *
 * design plan（web-page-design skill・2026-10-11）
 * - ブランド: mapmiru.jp。正本は docs/mapmiru/lp-draft.html の :root（色と書体をそのまま写した）
 *   地の紙 #f7f8f5 / 墨 #14201b / 地図の緑 #1b6b4c（良い変化・店の数字）/ 旗の錆 #a0521b（要対応）/ 罫 #dce2da
 * - 書体: 表題・本文・数字ともに LINE Seed JP（2026-11-10 智翔決定）
 * - レイアウト: 上に数字の帯 → 順位 → 口コミ → 検索の言葉 → やること。スマホ幅（40rem）が正、印刷も同じ順
 * - 参照:
 *   Plausible（plausible.io/docs/guided-tour）… 上で概況・下で内訳の順番、途中の期間は明示する
 *   SmartHR Design System（smarthr.design/products/design-tokens/color/）… 日本語の表の密度、色だけに頼らない（▲▼も文字で出す）
 *   Ramp（refero b38702a0-…）… 影なし・罫線で区切る、強調色は意味のある所だけ
 * - 数値: 表題 26→38px / 型は 4 段（ラベル 12・本文 15・小見出し 20・表題）/ 話題の区切り 56〜72px / 角丸 3px の 1 種類・影なし
 *
 * 色はここでだけ定義する。他所に hex を散らさない。
 */
.report {
  --paper: #f7f8f5;
  --card: #ffffff;
  --ink: #14201b;
  --soft: #4c5a53;
  --faint: #7c8a82;
  --map: #1b6b4c;
  --map-weak: #e6efe9;
  --flag: #a0521b;
  --flag-weak: #f6ece3;
  --rule: #dce2da;

  --mincho: 'LINE Seed JP', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --gothic: 'LINE Seed JP', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --mono:
    'LINE Seed JP', 'Hiragino Sans', sans-serif; /* 名前は旧来のまま。数字は等幅にせず tabular-nums で桁を揃える */

  --t-label: 0.75rem;
  --t-body: 0.9375rem;
  --t-h2: 1.25rem;
  --t-headline: clamp(1.625rem, 6.4vw, 2.375rem);
  --t-num: 1.75rem;

  --gap-section: clamp(3.5rem, 8vw, 4.5rem);
  --radius: 3px;

  max-width: 40rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--gothic);
  font-size: var(--t-body);
  line-height: 1.8;
  font-feature-settings: 'palt' 1;
}

/* ── 共通の部品 ─────────────────────────────────────────── */

.report__label {
  margin: 0;
  font-size: var(--t-label);
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.report__num {
  font-family: var(--mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.report__note {
  margin: 0.75rem 0 0;
  font-size: var(--t-label);
  line-height: 1.7;
  color: var(--soft);
}

.report__change {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--t-label);
  font-weight: 500;
  white-space: nowrap;
  color: var(--faint);
}

.report__change[data-dir='up'] {
  color: var(--map);
}

.report__change[data-dir='down'] {
  color: var(--flag);
}

.report__button {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  text-decoration: none;
  cursor: pointer;
}

.report__button--primary {
  border-color: var(--map);
  background: var(--map);
  color: var(--card);
}

.report__button:disabled {
  opacity: 0.5;
}

/* ── ツールバー（画面だけ）──────────────────────────────── */

.report__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  font-size: 0.875rem;
  color: var(--soft);
}

.report__toolbar a {
  color: inherit;
}

.report__toolbar nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ── マストヘッドと表題 ─────────────────────────────────── */

.report__masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--ink);
}

.report__wordmark {
  margin: 0;
  font-size: 1.375rem;
}

.report__lede {
  margin-top: 2rem;
}

.report__headline {
  margin: 0.5rem 0 0;
  font-family: var(--mincho);
  font-size: var(--t-headline);
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.01em;
  /* 日本語を文節で折り返す（「です。」だけが次の行に落ちるのを防ぐ）。 */
  word-break: auto-phrase;
  text-wrap: pretty;
}

/* ── 節 ──────────────────────────────────────────────── */

.report__section {
  margin-top: var(--gap-section);
  break-inside: avoid;
}

.report__h2 {
  margin: 0 0 1rem;
  font-size: var(--t-h2);
  font-weight: 700;
  line-height: 1.4;
}

/* ── 数字のタイル（見られ方・口コミ）──────────────────────── */

.report__tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.report__tile {
  padding: 0.875rem 1rem 1rem;
  background: var(--card);
}

.report__tile dd {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
  margin: 0.25rem 0 0;
}

.report__tile .report__num {
  font-size: var(--t-num);
  line-height: 1.2;
}

.report__tile small {
  font-size: var(--t-label);
  color: var(--soft);
}

.report__tile[data-attention='true'] {
  background: var(--flag-weak);
}

.report__tile[data-attention='true'] .report__num {
  color: var(--flag);
}

.report__tiles--3 .report__tile:first-child {
  grid-column: 1 / -1;
}

.report__section > .report__button {
  margin-top: 1rem;
}

/* ── キーワードの順位（行ごとに推移線）──────────────────── */

.report__ranks {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

/*
 * スマホ: 1 行目 = 語 / 順位・前月比、2 行目 = 推移線 / ベスト・圏外日。
 * 表（table）にすると 390px で列が潰れるので grid で 2 段に組む。
 */
.report__rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas:
    'kw rank change'
    'spark spark sub';
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--rule);
}

.report__kw {
  grid-area: kw;
  font-weight: 500;
  line-height: 1.5;
}

.report__rank {
  grid-area: rank;
  white-space: nowrap;
  color: var(--map);
}

.report__rank .report__num {
  font-size: 1.5rem;
  line-height: 1.1;
}

.report__rank small {
  margin-left: 0.125rem;
  font-size: var(--t-label);
}

.report__out {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--faint);
}

.report__rank-row .report__change {
  grid-area: change;
  min-width: 4.5em;
  text-align: right;
}

.report__spark {
  grid-area: spark;
  align-self: center;
  width: 100%;
  max-width: 12rem;
  height: 1.75rem;
  overflow: visible;
  /* 下地が無いと、1 位の水平線が下線に見える。 */
  border-radius: var(--radius);
  background: var(--map-weak);
}

.report__spark path {
  fill: none;
  stroke: var(--map);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.report__sub {
  grid-area: sub;
  align-self: center;
  font-size: var(--t-label);
  text-align: right;
  white-space: nowrap;
  color: var(--soft);
}

/* ── 検索の言葉（行の中の棒）──────────────────────────────── */

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

.report__bars li {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  /* 棒どうしの隙間（地の色で切る）。罫線ではない。 */
  border-bottom: 2px solid var(--paper);
}

.report__bar {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  border-radius: var(--radius);
  background: var(--map-weak);
}

.report__bar-label,
.report__bar-value {
  position: relative;
}

.report__bar-value {
  font-size: 0.875rem;
}

/* ── 今月やること ───────────────────────────────────────── */

.report__actions {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: report-action;
  border-top: 1px solid var(--rule);
}

.report__actions li {
  position: relative;
  padding: 0.875rem 0 0.875rem 2.5rem;
  border-bottom: 1px solid var(--rule);
  counter-increment: report-action;
}

/* 番号は mono の数字を緑で。行頭に記号を重ねない（二重マーカー禁止）。 */
.report__actions li::before {
  content: counter(report-action);
  position: absolute;
  top: 0.875rem;
  left: 0;
  width: 1.75rem;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--map);
  text-align: center;
}

/* ── 計測条件・フッター ─────────────────────────────────── */

.report__scope {
  margin-top: var(--gap-section);
  padding: 1rem 1.125rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  break-inside: avoid;
}

.report__scope ul {
  margin: 0.375rem 0 0;
  padding-left: 1.125rem;
  font-size: var(--t-label);
  line-height: 1.8;
}

.report__scope-change {
  margin: 0.5rem 0 0;
  font-size: var(--t-label);
  font-weight: 700;
  line-height: 1.7;
}

.report__footer {
  margin-top: 2rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
  font-size: 0.6875rem;
  line-height: 1.7;
  color: var(--faint);
}

/* ── 運用側だけ ─────────────────────────────────────────── */

.report__ops {
  margin-top: 2.5rem;
  padding: 1rem 1.125rem;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.report__ops label {
  display: block;
  margin: 0.75rem 0 0;
  font-size: var(--t-label);
  color: var(--soft);
}

.report__ops textarea,
.report__ops input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
}

.report__ops input {
  font-family: var(--mono);
  font-size: var(--t-label);
}

.report__ops .report__button {
  margin-top: 0.75rem;
}

.report__ops-warn {
  margin: 0.5rem 0 0;
  font-size: var(--t-label);
  font-weight: 700;
  line-height: 1.6;
  color: var(--flag);
}

.report__ops-said {
  margin-left: 0.75rem;
  font-size: var(--t-label);
  color: var(--soft);
}

/* 口コミの要約（担当が直したもの）。改行をそのまま見せる。 */
.report__review-summary {
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
  border-left: 3px solid var(--map);
  background: var(--card);
}

.report__review-summary p {
  margin-top: 0.5rem;
  white-space: pre-line;
  line-height: 1.8;
}

/* ── 直近 3 か月の表 ─────────────────────────────────────── */

.report__table-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.report__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.report__table th:first-child {
  padding-left: 0.75rem;
}

/* 狭い画面では項目名と前年比（率の行は「a → b」）だけ折り返し、数字の列は折らない。 */
.report__table th[scope='row'],
.report__table td:last-child {
  white-space: normal;
  word-break: keep-all;
  /* 空白の無い長い店名は、はみ出す前にどこででも折る。 */
  overflow-wrap: anywhere;
}

.report__table th:last-child,
.report__table td:last-child {
  padding-right: 0.75rem;
}

.report__table th,
.report__table td {
  padding: 0.5rem 0.375rem;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  white-space: nowrap;
}

.report__table td {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.report__table th[scope='row'],
.report__table thead th:first-child {
  text-align: left;
  font-weight: 500;
}

.report__table thead th {
  font-size: var(--t-label);
  font-weight: 500;
  color: var(--soft);
}

.report__table tr[data-level='1'] {
  font-weight: 700;
}

.report__table tr[data-level='2'] th {
  padding-left: 1.25rem;
  color: var(--soft);
}

.report__table tbody tr:last-child > * {
  border-bottom: 0;
}

/* ── アクション数の 12 か月（縦の棒）──────────────────────────── */

.report__cols {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 2px;
  height: 10rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.report__cols li {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-width: 0;
  text-align: center;
}

.report__cols li > .report__col {
  align-self: end;
  min-height: 1px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--map);
}

.report__col-value {
  /* スマホでは 12 本の数字が重なる。数は上の表にあるので、広い画面と紙でだけ出す。 */
  visibility: hidden;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.625rem;
}

.report__col-label,
.report__col-rate {
  font-size: 0.625rem;
  color: var(--soft);
}

/* ── PC: 同じものを広げるだけ ──────────────────────────────── */

@media (min-width: 40rem) {
  .report {
    padding-top: 2.5rem;
  }

  .report__tiles {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .report__tiles--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .report__tiles--3 .report__tile:first-child {
    grid-column: auto;
  }

  .report__rank-row {
    grid-template-columns: minmax(0, 1fr) 9rem 3.5rem 4.5rem 10.5rem;
    grid-template-areas: 'kw spark rank change sub';
    align-items: center;
  }

  .report__rank {
    text-align: right;
  }

  .report__table {
    font-size: 0.875rem;
  }

  .report__table th,
  .report__table td {
    padding-inline: 0.75rem;
  }

  .report__col-value {
    visibility: visible;
  }
}

/* ── 印刷（A4・内容は欠かさない。収まらなければ 2 枚目へ）──────── */

@page {
  size: A4;
  margin: 14mm;
}

@media print {
  .report {
    --gap-section: 1.25rem;
    --t-headline: 17pt;
    --t-num: 16pt;

    max-width: none;
    padding: 0;
    background: var(--card);
    font-size: 9.5pt;
    line-height: 1.6;
  }

  .report__no-print {
    display: none !important;
  }

  .report__table {
    font-size: 8.5pt;
  }

  .report__table th,
  .report__table td {
    padding-block: 0.2rem;
  }

  .report__col-value {
    visibility: visible;
  }

  .report__cols {
    height: 7rem;
  }

  .report__lede {
    margin-top: 0.75rem;
  }

  .report__h2 {
    margin-bottom: 0.5rem;
    font-size: 11pt;
  }

  .report__tiles {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .report__tiles--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .report__tiles--3 .report__tile:first-child {
    grid-column: auto;
  }

  .report__tile {
    padding: 0.4rem 0.6rem 0.5rem;
  }

  .report__rank-row {
    grid-template-columns: minmax(0, 1fr) 9rem 3.5rem 4.5rem 10.5rem;
    grid-template-areas: 'kw spark rank change sub';
    align-items: center;
  }

  .report__rank {
    text-align: right;
  }

  .report__rank-row,
  .report__actions li {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
  }

  .report__actions li::before {
    top: 0.35rem;
  }

  .report__rank .report__num {
    font-size: 13pt;
  }

  .report__bars li {
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
  }

  .report__bar {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .report__scope {
    padding: 0.5rem 0.75rem;
  }

  .report__footer {
    margin-top: 0.75rem;
    padding-top: 0.4rem;
  }
}

/* 画面で開いたときは「1 枚の用紙」に見せる（台紙の上に紙を置く）。印刷には効かせない。 */
@media screen and (min-width: 48rem) {
  body:has(.report) {
    background: #eceee9;
  }

  .report {
    /* 内側に 3rem 取るぶん広げて、紙面の本文幅は 40rem のまま保つ */
    max-width: 46rem;
    margin: 2rem auto 4rem;
    padding: 2.5rem 3rem 4rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
  }
}

/* ── 口コミのお願い（店頭に置く 1 枚・stores.$id.review-card）──────── */

.review-card {
  padding: 3rem 1.5rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  text-align: center;
}

.review-card__store {
  color: var(--map);
  font-size: 1rem;
  font-weight: 700;
}

.review-card__title {
  margin-top: 1rem;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.4;
}

.review-card__qr {
  width: min(16rem, 70%);
  margin: 2rem auto 0;
}

.review-card__qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.review-card__how {
  margin-top: 1.5rem;
  color: var(--soft);
  line-height: 1.8;
}

.review-card__url {
  margin-top: 1.5rem;
  color: var(--faint);
  font-size: 0.75rem;
  word-break: break-all;
}

@media print {
  /* A4 の真ん中に大きく。枠線は切り取り線を兼ねる。 */
  .review-card {
    margin-top: 20mm;
    padding: 24mm 12mm;
  }

  .review-card__title {
    font-size: 26pt;
  }

  .review-card__qr {
    width: 80mm;
  }

  .review-card__how {
    font-size: 13pt;
  }
}
