/* ================================================================
   鮨いちもん 業績レポート — スタイル
   カラーは dataviz 検証済みパレット（両モードで全チェックPASS）
   ================================================================ */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: #e1e0d9;

  /* 店舗カテゴリ（順序固定・循環させない） */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;

  /* ステータス（固定・シリーズ色に転用しない） */
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-ink: #046b04; --critical-ink: #a82626;

  /* 連続量ヒートマップ（青・単一色相 light→dark） */
  --seq-0: transparent;
  --seq-1: #eaf2fd; --seq-2: #cde2fb; --seq-3: #b7d3f6; --seq-4: #9ec5f4; --seq-5: #86b6ef;

  --shadow: 0 1px 2px rgba(11,11,11,.06), 0 1px 8px rgba(11,11,11,.04);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: #2c2c2a;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --good-ink: #4fc24f; --critical-ink: #ef7676;
    --seq-1: #13253a; --seq-2: #16304c; --seq-3: #184063; --seq-4: #1a4f7c; --seq-5: #1c5cab;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: #2c2c2a;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --good-ink: #4fc24f; --critical-ink: #ef7676;
  --seq-1: #13253a; --seq-2: #16304c; --seq-3: #184063; --seq-4: #1a4f7c; --seq-5: #1c5cab;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }

/* ---------- ログイン ---------- */
#loginView {
  min-height: 100svh; min-height: 100vh;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 32px 28px; width: 100%; max-width: 360px; text-align: center;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; letter-spacing: .02em; }
.login-card .sub { color: var(--muted); font-size: 12px; }
.login-card .sub:last-of-type { margin-bottom: 24px; }
.login-logo { max-height: 56px; max-width: 200px; margin: 0 auto 10px; display: block; }
.app-logo { height: 26px; width: auto; margin-right: 2px; align-self: center; }
.login-card input[type="password"] {
  width: 100%; padding: 12px 14px; font-size: 20px; letter-spacing: .3em; text-align: center;
  border: 1px solid var(--border); border-radius: 8px; background: var(--page); color: var(--ink);
}
.login-card input:focus { outline: 2px solid var(--s1); outline-offset: 1px; }
.btn-primary {
  width: 100%; margin-top: 14px; padding: 12px; border: none; border-radius: 8px;
  background: var(--s1); color: #fff; font-weight: 600;
}
.btn-primary:disabled { opacity: .5; cursor: default; }
.login-err { color: var(--critical-ink); font-size: 13px; margin-top: 12px; min-height: 1.2em; }

/* ---------- ヘッダー ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand strong { font-size: 15px; white-space: nowrap; }
.brand span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.appbar .spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; white-space: nowrap;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- タブ ---------- */
.tabs {
  display: flex; gap: 4px; padding: 8px 16px 0; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto; position: sticky; top: 49px; z-index: 29;
}
.tab {
  border: none; background: none; color: var(--ink-2); padding: 8px 12px 10px;
  border-bottom: 2px solid transparent; white-space: nowrap; font-size: 13px;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--s1); font-weight: 600; }
.tab:disabled { color: var(--muted); opacity: .55; cursor: default; }

/* ---------- フィルタ（1行にまとめる） ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 16px; background: var(--page);
}
.filters .group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filters label { color: var(--muted); font-size: 12px; }
.filters input[type="date"] {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 7px; padding: 6px 8px; font-size: 13px;
}
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 5px 11px; font-size: 12px;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip.store[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); border-color: currentColor; }
.chip.store .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px;
}
.chip.store[aria-pressed="false"] { opacity: .45; }

/* ---------- レイアウト ---------- */
main { padding: 0 16px 48px; max-width: 1400px; margin: 0 auto; }
.section-title {
  font-size: 14px; font-weight: 700; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px;
}
.section-title::before { content: "◆"; color: var(--s1); font-size: 11px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- KPIカード ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 10px 0 4px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow);
}
.kpi .k-label { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.kpi .k-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .k-sub { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.kpi.is-good .k-value { color: var(--good-ink); }
.kpi.is-bad .k-value { color: var(--critical-ink); }

/* ---------- テーブル ---------- */
table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; text-align: right; white-space: nowrap; font-size: 13px; }
thead th {
  background: var(--surface-2); color: var(--ink-2); font-size: 11px; font-weight: 600;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
}
th.col-store, td.col-store {
  text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 2;
  border-right: 1px solid var(--border);
}
thead th.col-store { background: var(--surface-2); z-index: 3; }
tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:hover td.col-store { background: var(--surface-2); }
tfoot td {
  border-top: 2px solid var(--axis); font-weight: 700; background: var(--surface);
}
.store-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; }
.num-dim { color: var(--muted); }

/* 達成率セル（バー＋ステータス。数字がラベルを兼ねる） */
.rate-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.rate-bar { width: 46px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; flex: none; }
.rate-bar > i { display: block; height: 100%; border-radius: 3px; }
.is-good .rate-bar > i, i.bar-good { background: var(--good); }
.is-bad .rate-bar > i, i.bar-bad { background: var(--critical); }
td.is-good { color: var(--good-ink); }
td.is-bad { color: var(--critical-ink); }

/* 構成比セル（内訳バー） */
.ratio-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.ratio-bar { width: 54px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; flex: none; }
.ratio-bar > i { display: block; height: 100%; border-radius: 3px; background: var(--s1); }
.ratio-bar.dinner > i { background: var(--s2); }

/* デルタ（アイコン＋数値。色だけに頼らない） */
.delta { font-size: 12px; }
.delta.up { color: var(--good-ink); }
.delta.down { color: var(--critical-ink); }

/* ---------- グラフ ---------- */
.chart-card { padding: 14px 14px 8px; }
.chart-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.chart-head h3 { font-size: 13px; margin: 0; font-weight: 700; }
.chart-head .note { font-size: 11px; color: var(--muted); }
.chart-head .warn-note {
  font-size: 11px; color: var(--critical-ink); background: color-mix(in srgb, var(--critical) 12%, transparent);
  border-radius: 999px; padding: 2px 9px;
}
.chart-head .warn-note:empty { display: none; }
.chart-box { position: relative; height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin: 8px 0 2px; }
.legend button {
  display: inline-flex; align-items: center; gap: 6px; border: none; background: none;
  color: var(--ink-2); font-size: 12px; padding: 2px 0;
}
.legend button[aria-pressed="false"] { opacity: .38; text-decoration: line-through; }
.legend .swatch { width: 12px; height: 3px; border-radius: 2px; }

/* ---------- 状態表示 ---------- */
.state {
  padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px;
}
.state.err { color: var(--critical-ink); }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 999px;
  font-size: 13px; z-index: 60; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.footer-note { color: var(--muted); font-size: 11px; margin: 24px 0 0; text-align: center; }

/* ---------- 今月タブ ---------- */
.progress-card { padding: 16px 18px; }
.progress-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.bigbar {
  flex: 1 1 260px; height: 14px; background: var(--surface-2);
  border-radius: 7px; position: relative; overflow: visible;
}
.bigbar .fill {
  display: block; height: 100%; border-radius: 7px;
  background: var(--s1); min-width: 4px; max-width: 100%;
}
.bigbar .fill.is-good { background: var(--good); }
.bigbar .marker {
  position: absolute; top: -4px; width: 2px; height: 22px; background: var(--ink-2);
}
.bigbar .marker::after {
  content: attr(data-label); position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: var(--muted); white-space: nowrap;
}
.progress-pct { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.progress-note { color: var(--muted); font-size: 12px; margin-top: 14px; }
.alert-card {
  background: color-mix(in srgb, var(--critical) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--critical) 30%, var(--border));
  border-radius: var(--radius); padding: 10px 14px; margin: 10px 0;
  color: var(--critical-ink); font-size: 13px;
}

/* ---------- 印刷（PDF） ---------- */
.print-header { display: none; }
@media print {
  :root { color-scheme: light; }
  body { background: #fff !important; color: #000; font-size: 11px; }
  .appbar, .tabs, .filters, .legend, .icon-btn, #loginView,
  .footer-note button, .state { display: none !important; }
  .print-header {
    display: block; padding: 0 0 10px; margin-bottom: 12px;
    border-bottom: 2px solid #000;
  }
  .print-header .ph-title { font-size: 16px; font-weight: 700; }
  .print-header .ph-sub { font-size: 11px; color: #444; margin-top: 2px; }
  main { padding: 0; max-width: none; }
  .card, .kpi {
    box-shadow: none !important; border-color: #bbb !important;
    break-inside: avoid;
  }
  .section-title { break-after: avoid; }
  .scroll-x { overflow: visible !important; }
  table { font-size: 10px; }
  th, td { padding: 5px 7px; }
  th.col-store, td.col-store { position: static; }
  thead th { position: static; }
  .chart-box { height: 230px !important; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .chart-head .warn-note { border: 1px solid #c00; }
}

/* ---------- スマホ ---------- */
@media (max-width: 640px) {
  main { padding: 0 10px 40px; }
  .appbar { padding: 8px 10px; }
  .brand span { display: none; }
  .tabs { padding: 6px 10px 0; top: 45px; }
  .filters { padding: 10px; gap: 6px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi .k-value { font-size: 17px; }
  .chart-box { height: 220px; }
  th, td { padding: 8px 10px; font-size: 12px; }
}
