/* ================================================================
   MAK 収益レポート — ライト/ダーク対応・レスポンシブ
   経営が数字を読むための画面。装飾より可読性を優先する。
   ================================================================ */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #c0392b;      /* いちもんの赤 */
  --accent-weak: #fdecea;
  --up: #0f7b3f;
  --down: #b3261e;
  --chart-grid: rgba(0,0,0,.07);
  --c1: #f39c12;
  --c2: #34495e;
  --c3: #2980b9;
  --c4: #16a085;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --panel: #1c1f24;
  --border: #2b3037;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --accent: #e05a4a;
  --accent-weak: #3a2320;
  --up: #4ade80;
  --down: #f87171;
  --chart-grid: rgba(255,255,255,.08);
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
               "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.r { text-align: right; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------------- ログイン ---------------- */
.login-view {
  min-height: 100svh;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-logo { width: 84px; height: auto; margin-bottom: 12px; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card p { margin: 4px 0 0; }
.login-card input {
  width: 100%;
  margin: 20px 0 12px;
  padding: 12px 14px;
  font-size: 18px;
  letter-spacing: .3em;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.login-card button {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.login-card button:disabled { opacity: .6; cursor: default; }
.error { color: var(--down); font-size: 13px; min-height: 1.4em; }

/* ---------------- 全体レイアウト ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.brand { font-size: 15px; }
.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}
.ghost:hover { background: var(--bg); }

.tabs { display: flex; gap: 4px; padding: 10px 16px 0; flex-wrap: wrap; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.custom-range, .store-picker { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.custom-range input, .store-picker select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
}
.period-label { margin-left: auto; color: var(--muted); font-size: 13px; }

.panel { padding: 16px; max-width: 1400px; margin: 0 auto; }
.panel > h2 { font-size: 17px; margin: 0 0 12px; }

.loading { padding: 16px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.spin {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty, .warn {
  margin: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--accent-weak);
  border: 1px solid var(--border);
  font-size: 13px;
}

/* ---------------- KPIカード ---------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 12px; color: var(--muted); }
.card-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 6px; }
.card-subs { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; }
.card-subs .s i { font-style: normal; color: var(--muted); margin-right: 5px; }
.card-subs .note { color: var(--muted); }

/* ---------------- 構成比バー ---------------- */
.mixes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 16px; }
.mix { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.mix-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.mix-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--bg); }
.seg { display: block; height: 100%; }
.seg.c1 { background: var(--c1); } .seg.c2 { background: var(--c2); }
.seg.c3 { background: var(--c3); } .seg.c4 { background: var(--c4); }
.seg.empty { background: var(--border); }
.mix-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.dot.c1 { background: var(--c1); } .dot.c2 { background: var(--c2); }
.dot.c3 { background: var(--c3); } .dot.c4 { background: var(--c4); }

/* ---------------- グラフ・表 ---------------- */
.chart-box, .table-box, .notes-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.chart-box h2, .table-box h2, .notes-box h2 { font-size: 14px; margin: 0 0 10px; }
.chart { position: relative; height: 300px; }

.scroll-x { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.grid thead th { color: var(--muted); font-weight: 600; text-align: left; position: sticky; top: 0; background: var(--panel); }
table.grid thead th.r { text-align: right; }
table.grid tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
.tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 4px;
}

.notes { margin: 0; padding-left: 1.2em; font-size: 12px; color: var(--muted); }
.notes li { margin-bottom: 4px; }

.foot { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* ---------------- スマホ ---------------- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .topbar { padding: 8px 12px; }
  .topbar-right .ghost { padding: 4px 8px; }
  .panel { padding: 12px; }
  .card-value { font-size: 22px; }
  .chart { height: 240px; }
  .period-label { margin-left: 0; width: 100%; }
}

/* ---------------- 収益／業績の使い分け ---------------- */
.badge-line {
  display: inline-block;
  margin: 2px 0 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.pill {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.switcher {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.switcher-self { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dot-now {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
  display: inline-block;
}
.switcher-other {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
}
.switcher-other:hover { background: var(--bg); }
.switcher-other .arrow { color: var(--muted); }
.switcher-detail {
  padding: 12px 16px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
table.compare { max-width: 900px; white-space: normal; }
table.compare th.rowhead { color: var(--muted); font-weight: 600; width: 90px; }
table.compare thead th { text-align: left; }

/* ---------------- セクション見出し・待ちカード ---------------- */
h3.sec {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 8px;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  line-height: 1.5;
}
.card.pending { border-style: dashed; }
.card.pending .card-value { color: var(--muted); }

@media (max-width: 640px) {
  .switcher { padding: 8px 12px; gap: 8px; }
  .switcher-other { margin-left: 0; width: 100%; justify-content: space-between; }
  /* 説明文は畳む。詳細は「違いを見る」で開ける */
  #swSelfDesc, #swOtherDesc { display: none; }
}

/* ---------------- 最初の読み込みの進捗 ---------------- */
.progress { padding: 32px 16px; max-width: 520px; margin: 0 auto; text-align: center; }
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width .2s linear;
}
.progress p { margin: 10px 0 0; }

/* ---------------- 人件費単価の指定 ---------------- */
.rate-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.rate-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 0 14px;
  background: var(--panel);
}
.rate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px 16px;
  margin: 10px 0;
}
.rate-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.rate-row label { font-size: 13px; }
.rate-row input {
  width: 96px;
  padding: 5px 8px;
  text-align: right;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.rate-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.rate-actions input {
  width: 96px; padding: 5px 8px; text-align: right;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}

/* 前期比に添える実数 */
.card-subs .base {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
  margin-top: 1px;
}

/* ---------------- 日次一覧：見出しと左2列を固定 ----------------
   .scroll-x は overflow-x:auto だが、CSSの仕様上そのとき overflow-y も auto 扱いになり、
   thead の position:sticky が「ページ」ではなく「この枠」に対して効く。
   枠の高さ＝表の高さだと動かないので見出しが流れてしまっていた。
   枠に高さを与えて縦もスクロールさせることで、見出しが枠の上に張り付く。 */
#dailyTable {
  max-height: calc(100vh - 260px);
  overflow: auto;
}
#dailyTable table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--panel);
  box-shadow: 0 1px 0 var(--border);
}
/* 右へスクロールしても、どの日・どの店の行かを見失わない */
#dailyTable table.grid th:nth-child(1),
#dailyTable table.grid td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);
}
#dailyTable table.grid th:nth-child(2),
#dailyTable table.grid td:nth-child(2) {
  position: sticky;
  left: 84px;
  z-index: 2;
  background: var(--panel);
}
#dailyTable table.grid thead th:nth-child(1),
#dailyTable table.grid thead th:nth-child(2) { z-index: 4; }
#dailyTable table.grid td:nth-child(2) { box-shadow: 1px 0 0 var(--border); }

/* 店舗別一覧も、横に長いので店舗名を固定する */
#storeTable table.grid th:nth-child(1),
#storeTable table.grid td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--border);
}

@media (max-width: 640px) {
  #dailyTable { max-height: calc(100vh - 200px); }
  #dailyTable table.grid th:nth-child(2),
  #dailyTable table.grid td:nth-child(2) { position: static; box-shadow: none; }
}
