:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --accent: #1f6f4a;
  --warn: #b45309;
  --border: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1f2229;
    --text: #f0f0f0;
    --muted: #9ca3af;
    --border: #33363d;
  }
}

* { box-sizing: border-box; }

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

header {
  padding: 24px clamp(16px, 4vw, 40px) 8px;
}

header h1 {
  margin: 0 0 4px;
  font-size: clamp(20px, 3vw, 28px);
}

.updated-at {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

main {
  padding: 8px clamp(16px, 4vw, 40px) 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.company-card h2, .branch-card h3 {
  margin: 0 0 12px;
}

.company-top-figures {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.figure-lg {
  display: flex;
  flex-direction: column;
}

.figure-lg .label {
  color: var(--muted);
  font-size: 14px;
}

.value-lg {
  font-size: 36px;
  font-weight: 800;
}

.value-blue { color: #2f7fd1; }

.company-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 24px;
}

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

.branch-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

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

.forecast-note {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

.donut-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  flex: none;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
}

.company-figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px 24px;
  flex: 1 1 320px;
}

.figure {
  display: flex;
  flex-direction: column;
}

.figure .label {
  color: var(--muted);
  font-size: 13px;
}

.figure .value {
  font-size: 22px;
  font-weight: 700;
}

.figure-subnote {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
}

.branch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  background: none;
  border: none;
  padding: 0;
}

.branch-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.branch-card-top {
  display: flex;
  align-items: center;
  gap: 16px;
}

.branch-donut-wrap {
  position: relative;
  width: 84px;
  height: 84px;
  flex: none;
}

.branch-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}

.branch-name {
  font-size: 18px;
  font-weight: 700;
}

.branch-figures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  font-size: 14px;
}

.branch-figures .label {
  color: var(--muted);
}

.branch-figures .value {
  font-weight: 700;
}

.value.positive { color: var(--accent); }
.value.negative { color: var(--warn); }

.focus-box {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  font-size: 14px;
}

.focus-box .focus-label {
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.focus-box p {
  margin: 0;
  line-height: 1.5;
}

.forecast-box {
  border-top: none;
  padding-top: 0;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.forecast-row {
  display: flex;
  justify-content: space-between;
  gap: 2px;
  text-align: center;
  font-size: 11px;
  overflow: hidden;
}

.forecast-day {
  flex: 1 1 0;
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
}

.section-title {
  margin: 8px 0 0;
  font-size: 18px;
}

.fes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  background: none;
  border: none;
  padding: 0;
}

.fes-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fes-name {
  font-size: 18px;
  font-weight: 700;
}

.fes-not-started {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.fes-bar-wrap {
  width: 100%;
}

.fes-bar {
  position: relative;
  display: flex;
  width: 100%;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
}

.fes-bar-segment {
  height: 100%;
}

.fes-target-line {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--text);
}

.fes-reapproach-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 6px;
}

.fes-reapproach-table th,
.fes-reapproach-table td {
  text-align: right;
  padding: 3px 6px;
  border-bottom: 1px solid var(--border);
}

.fes-reapproach-table th:first-child,
.fes-reapproach-table td:first-child {
  text-align: left;
}

footer {
  padding: 16px clamp(16px, 4vw, 40px) 32px;
  color: var(--muted);
  font-size: 12px;
}

.previous-month-card {
  border-style: dashed;
  background: transparent;
}

.previous-month-title {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

.previous-month-figures {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}

/* previousMonthSummaryが無い日（16日以降、または前月データ欠落時）は<section>が空のまま残る。
   `section {}` の汎用ルールで箱が見えてしまわないよう、空の間はCSSだけで確実に非表示にする。
   flexアイテムにdisplay:noneを適用すると、mainのgapレイアウトからも除外されるため、空箱はもちろん
   前後の要素との余分な隙間(phantom gap)も発生しない。 */
#previous-month-card:empty {
  display: none;
}
