:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e2e5ea;
  --border-strong: #cdd2da;
  --text: #1f2430;
  --text-sub: #5b6370;
  --text-muted: #8a92a0;
  --accent: #2f6fed;
  --weekend-bg: #f0f1f4;
  --sat-text: #1f5fd0;
  --sun-text: #c23a3a;
  --today-bg: #fff7e0;
  --today-line: #f0b429;
  --empty: #adb3bd;
  /* 消化率の色（凡例と行背景） */
  --rate-high-bg: #e3f3e6;
  --rate-high-text: #1f7a37;
  --rate-high-bar: #3aa35a;
  --rate-mid-bg: #fdeccd;
  --rate-mid-text: #8a5a00;
  --rate-mid-bar: #e8a93a;
  --rate-low-bg: #fbd9d1;
  --rate-low-text: #a4382b;
  --rate-low-bar: #e06a55;
  --rate-none-bg: #e9ebee;
  --rate-none-text: #8a92a0;
  --warn-color: #b57700;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.06), 0 1px 2px rgba(20, 30, 50, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI",
    "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ===== ヘッダー ===== */
.app-header {
  background: linear-gradient(135deg, #233252, #2f6fed);
  color: #fff;
  padding: 16px 0;
}
.app-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}
.app-header__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.app-header__basis {
  margin: 6px 0 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
}
.app-header__note {
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.72);
}

/* ===== メイン ===== */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* ===== 不完全警告バナー ===== */
.banner-incomplete {
  background: #fff3cd;
  border: 2px solid #e8a93a;
  color: #7a5200;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 12px;
  font-size: 13.5px;
  font-weight: 600;
}

/* ===== 週ナビ ===== */
.weeknav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 5;
}
.weeknav__btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.weeknav__btn:hover:not(:disabled) { background: #f0f4ff; border-color: var(--accent); }
.weeknav__btn:disabled { opacity: 0.4; cursor: not-allowed; }
.weeknav__btn--today { background: #eef3ff; border-color: var(--accent); color: var(--accent); font-weight: 600; }
.weeknav__select {
  appearance: auto;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  max-width: 220px;
}
.weeknav__range {
  margin-left: auto;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
}

/* ===== 凡例 ===== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 12px 2px 4px;
  font-size: 11.5px;
  color: var(--text-sub);
}
.legend__item { display: inline-flex; align-items: center; gap: 5px; }
.legend__swatch {
  width: 13px; height: 13px; border-radius: 3px; border: 1px solid var(--border-strong);
  display: inline-block;
}
.legend__swatch--high { background: var(--rate-high-bg); }
.legend__swatch--mid { background: var(--rate-mid-bg); }
.legend__swatch--low { background: var(--rate-low-bg); }
.legend__swatch--none { background: var(--rate-none-bg); }

/* ===== エラー ===== */
.error-box {
  background: #fff3f3;
  border: 1px solid #f3b9b9;
  color: #a4282b;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 13px;
}

/* ===== エリアセクション ===== */
.area {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin: 16px 0;
  overflow: hidden;
}
.area__head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.area__name {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}
.area__weekrate {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  margin-left: auto;
}
.area__weekrate-label { font-size: 12px; color: var(--text-sub); }
.area__weekrate-num { font-size: 28px; font-weight: 800; line-height: 1; }
.area__weekrate-num--high { color: var(--rate-high-text); }
.area__weekrate-num--mid { color: var(--rate-mid-text); }
.area__weekrate-num--low { color: var(--rate-low-text); }
.area__weekrate-num--none { color: var(--rate-none-text); }
.area__weekrate-sub { font-size: 12px; color: var(--text-sub); }

.area__scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== テーブル ===== */
table.grid {
  border-collapse: collapse;
  width: 100%;
  min-width: 640px;
  font-size: 13px;
}
table.grid th, table.grid td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
  white-space: nowrap;
}
table.grid thead th {
  background: #f3f5f9;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-sub);
  position: sticky;
  top: 0;
  z-index: 2;
}

.col-date { text-align: left !important; min-width: 96px; }
.col-date .d-date { font-weight: 600; }
td.col-wd { font-size: 12px; }
td.col-wd.wd-sat { color: var(--sat-text); font-weight: 700; }
td.col-wd.wd-sun { color: var(--sun-text); font-weight: 700; }

td.num { font-variant-numeric: tabular-nums; }
td.empty { color: var(--empty); }
.col-breakdown { text-align: left !important; font-size: 12px; }
.bd-muted { color: var(--text-muted); }

/* 消化率セル: バッジ + 横棒バー */
.col-rate { min-width: 140px; }
.ratecell {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ratecell__badge {
  display: inline-block;
  min-width: 52px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border-strong);
}
.ratecell__bar {
  flex: 1;
  height: 8px;
  min-width: 56px;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 4px;
  overflow: hidden;
}
.ratecell__fill {
  height: 100%;
  border-radius: 4px;
}

/* 消化率クラス別の行背景・バッジ・バー色 */
tr.rate-high td { background: var(--rate-high-bg); }
tr.rate-high .ratecell__badge { color: var(--rate-high-text); border-color: var(--rate-high-bar); }
tr.rate-high .ratecell__fill { background: var(--rate-high-bar); }

tr.rate-mid td { background: var(--rate-mid-bg); }
tr.rate-mid .ratecell__badge { color: var(--rate-mid-text); border-color: var(--rate-mid-bar); }
tr.rate-mid .ratecell__fill { background: var(--rate-mid-bar); }

tr.rate-low td { background: var(--rate-low-bg); }
tr.rate-low .ratecell__badge { color: var(--rate-low-text); border-color: var(--rate-low-bar); }
tr.rate-low .ratecell__fill { background: var(--rate-low-bar); }

/* 総枠数未登録（グレーアウト） */
tr.rate-none td { background: var(--rate-none-bg); color: var(--rate-none-text); }
tr.rate-none td.col-wd.wd-sat,
tr.rate-none td.col-wd.wd-sun { opacity: 0.65; }

/* 今日のハイライト */
tr.today td.col-date { box-shadow: inset 3px 0 0 var(--today-line); }
tr.today .col-date .d-date { color: #9a6a00; }

/* 枠パース警告アイコン */
.warn-icon {
  color: var(--warn-color);
  cursor: help;
  margin-left: 4px;
  font-size: 13px;
}

/* 週合計行 */
table.grid tfoot td {
  background: #f3f5f9;
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
}
table.grid tfoot td.col-date { font-weight: 700; }
tfoot tr.rate-high td { background: var(--rate-high-bg); }
tfoot tr.rate-mid td { background: var(--rate-mid-bg); }
tfoot tr.rate-low td { background: var(--rate-low-bg); }
tfoot tr.rate-none td { background: var(--rate-none-bg); color: var(--rate-none-text); }

/* ===== 警告 ===== */
.warnings {
  margin: 16px 0 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
}
.warnings__summary { cursor: pointer; color: var(--text-sub); font-weight: 600; }
.warnings__list { margin: 8px 0 4px; padding-left: 20px; color: var(--text-sub); }
.warnings__list li { margin: 3px 0; }

.empty-week {
  padding: 20px 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* ===== レスポンシブ ===== */
@media (max-width: 640px) {
  .app-header__title { font-size: 16px; }
  .weeknav__range { width: 100%; margin-left: 0; text-align: right; }
  .weeknav__select { max-width: 160px; }
  .area__weekrate-num { font-size: 24px; }
  .app-main { padding: 12px; }
}
