/* ============================================================
   売上係数管理 共通スタイル（スマホ優先）
   ============================================================ */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --fg: #1f2328;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #1f5fa8;
  --accent-fg: #ffffff;
  --danger: #c0262d;
  --ok: #1d7a3a;
  --blue: #d9e1f2;
  --blue-strong: #2f5597;
  --orange: #fce4d6;
  --orange-strong: #c55a11;
  --green: #e2efda;
  --green-strong: #548235;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --card: #1f2227;
    --fg: #e8e9eb;
    --muted: #9aa1ab;
    --line: #343840;
    --accent: #6ea8ff;
    --accent-fg: #0b1220;
    --danger: #ff6b6b;
    --ok: #5fd08a;
    --blue: #1e2a40;
    --blue-strong: #8fb0ff;
    --orange: #3a271b;
    --orange-strong: #ffa36b;
    --green: #1f2e1f;
    --green-strong: #9ed27b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

/* ---------- ヘッダー ---------- */
#app-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 8px 16px;
}
.brand { font-weight: bold; color: var(--fg); text-decoration: none; }
.who { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 0 12px 8px;
  -webkit-overflow-scrolling: touch;
}
.nav a {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  border: 1px solid var(--line);
}
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

#app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 16px 40px;
}

/* ---------- レイアウト ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 420px; }
h1 { font-size: 1.3rem; margin: 8px 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.muted { color: var(--muted); font-size: 14px; }
.error-card { border-color: var(--danger); color: var(--danger); }

/* ---------- フォーム ---------- */
label { display: block; font-size: 14px; margin: 12px 0 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px; /* スマホで勝手に拡大されないように16px */
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
}
textarea { min-height: 96px; resize: vertical; }
.row { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.row > * { flex: 1 1 180px; }

button, .button {
  display: inline-block;
  padding: 10px 16px;
  font-size: 15px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  text-decoration: none;
}
button.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.link-button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 13px;
  text-decoration: underline;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.form-error { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 1em; }

/* ---------- 表 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: normal; font-size: 13px; }
td.number { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: var(--muted); }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

/* ---------- 仮パスワード表示 ---------- */
.temp-password {
  background: var(--blue);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.temp-password code {
  display: block;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  margin: 8px 0;
  user-select: all;
}

/* ---------- お知らせ ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(120px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  color: #fff;
  background: var(--ok);
  transition: transform 0.2s;
  z-index: 100;
}
#toast.error { background: var(--danger); }
#toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- 日次入力 ---------- */
.group-card { border-top-width: 6px; }
.group-blue { border-top-color: var(--blue-strong); }
.group-blue h2 { color: var(--blue-strong); }
.group-orange { border-top-color: var(--orange-strong); }
.group-orange h2 { color: var(--orange-strong); }
.group-green { border-top-color: var(--green-strong); }
.group-green h2 { color: var(--green-strong); }
.group-gray { border-top-color: var(--muted); }
.group-purple { border-top-color: #7b5cc4; }
.group-purple h2 { color: #7b5cc4; }
@media (prefers-color-scheme: dark) {
  .group-purple { border-top-color: #b49cff; }
  .group-purple h2 { color: #b49cff; }
}

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; }
.kpi-field label { margin-top: 8px; }
.input-with-unit { display: flex; align-items: center; gap: 6px; }
.input-with-unit input { text-align: right; }
.input-with-unit span { color: var(--muted); font-size: 14px; flex: 0 0 auto; }

.score-field { border: none; padding: 0; margin: 0 0 16px; }
.score-field legend { font-weight: bold; margin-bottom: 6px; }
.score-options { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.score-pill { margin: 0; cursor: pointer; }
.score-pill input { position: absolute; opacity: 0; pointer-events: none; }
.score-pill span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; font-size: 16px;
}
.score-pill input:checked + span { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.score-pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.check-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; margin: 0; border-bottom: 1px solid var(--line); font-size: 16px; cursor: pointer;
}
.check-row input { width: 24px; height: 24px; flex: 0 0 auto; }

.day-strip { display: flex; gap: 6px; overflow-x: auto; margin-top: 12px; padding-bottom: 4px; }
.day-chip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center;
  padding: 6px 10px; border-radius: 8px; font-size: 13px;
  background: var(--card); color: var(--fg); border: 1px solid var(--line);
}
.day-chip small { font-size: 11px; }
.day-chip.entered small { color: var(--ok); }
.day-chip.missing small { color: var(--danger); }
.day-chip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }

.sticky-actions {
  position: sticky; bottom: 0; background: var(--bg);
  padding: 12px 0; margin: 0; border-top: 1px solid var(--line);
}
.sticky-actions button { width: 100%; }

/* ---------- 集計 ---------- */
.period-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.period-nav strong { text-align: center; flex: 1; }
.row.compact > * { flex: 0 1 260px; }

.kpi-table th:first-child, .kpi-table td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
.kpi-table tr.group-row td { font-weight: bold; padding-top: 14px; border-bottom: 2px solid var(--line); }
.kpi-table tr.group-row.sales td { color: var(--blue-strong); }
.kpi-table tr.group-row.process td { color: var(--orange-strong); }
.kpi-table tr.group-row.referral td { color: var(--green-strong); }
.kpi-table .good { color: var(--ok); }
.kpi-table .bad { color: var(--danger); }

.chart-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 820px) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-card.wide { grid-column: 1 / -1; }
}
.chart-card { min-width: 0; }
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 320px; }
.chart-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}

/* ---------- MVV ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab {
  background: none; color: var(--muted); border: none; border-bottom: 3px solid transparent;
  border-radius: 0; padding: 10px 16px; font-size: 15px;
}
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: bold; }
.mvv-field { margin-bottom: 20px; }
.mvv-field label { font-weight: bold; font-size: 15px; }
.mvv-field .hint { margin: 0 0 4px; }
.mvv-field textarea[readonly] { background: var(--bg); }
.advice { margin-top: 8px; }
.advice-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 6px; }
.advice-card {
  background: var(--bg); border-left: 4px solid #7b5cc4; border-radius: 6px;
  padding: 10px 12px; margin-top: 6px; font-size: 14px;
}
.advice-card.past summary { cursor: pointer; color: var(--muted); }
.advice-meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.advice-text { white-space: pre-wrap; line-height: 1.7; }
.action-items { list-style: none; padding: 0; margin: 0 0 12px; }
.action-item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.action-item .action-title { flex: 1 1 220px; }
.action-item.inactive .action-title { color: var(--muted); text-decoration: line-through; }
.action-buttons { display: flex; gap: 4px; }
.ai-notice { margin-top: 8px; }
