/* freee_Manager — ダッシュボード型 / APP_Design.md 共通デザイントークン準拠 */

:root {
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe4ef;
  --panel: #ffffff;
  --canvas: #f5f7fb;
  --brand: #2563eb;
  --brand-dark: #1e40af;
  --brand-soft: #dbeafe;
  --danger: #a44343;
  --warning: #9b6a18;
  --warning-soft: #f7ecd8;
  --ok-soft: #ddf0e2;
  --ok-ink: #1f6b3a;
  --app-accent: #2563eb;
  --app-accent-soft: #dbeafe;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 14px;
  line-height: 1.65;
}

.hidden { display: none !important; }

/* ---- ヘッダー ---- */

.app-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.header-inner {
  max-width: 1360px; margin: 0 auto;
  padding: 10px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  background: var(--app-accent); color: #fff;
  font-weight: 700; font-size: 13px; letter-spacing: .02em;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.3; }
.brand-sub { font-size: 11px; color: var(--muted); }

.header-actions { display: flex; align-items: center; gap: 10px; }
.main-nav { display: flex; gap: 4px; }
.nav-link {
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--muted); background: transparent;
  border: 1px solid transparent; border-radius: 999px;
  padding: 6px 14px; cursor: pointer;
}
.nav-link:hover { color: var(--ink); background: var(--canvas); }
.nav-link.is-active { color: var(--brand-dark); background: var(--brand-soft); border-color: #bfdbfe; }
.user-email { font-size: 11px; color: var(--muted); }

/* ---- レイアウト ---- */

.app-main { max-width: 1360px; margin: 0 auto; padding: 22px 24px 48px; }
.view { animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}
.panel + .panel { margin-top: 16px; }
.panel-title { margin: 0 0 14px; font-size: 15px; font-weight: 700; }

.page-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 0 2px 16px;
}
.page-title { font-size: 21px; margin: 0; font-weight: 700; }
.head-spacer { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }

/* ---- 指標チップ ---- */

.summary-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; }
.summary-item {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 14px;
  display: flex; align-items: baseline; gap: 8px;
}
.summary-label { font-size: 12px; color: var(--muted); }
.summary-item strong { font-size: 20px; font-weight: 700; line-height: 1; }
.summary-item.tone-action { border-color: #f0c987; background: #fffaf0; }

/* ---- 入力 ---- */

.btn {
  font-family: inherit; font-size: 13px; font-weight: 600;
  border-radius: 9px; border: 1px solid transparent;
  padding: 8px 14px; cursor: pointer; transition: background .15s ease;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--brand-dark); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--brand-soft); }
.btn-ghost { background: transparent; color: var(--muted); border: none; }
.btn-ghost:hover:not(:disabled) { color: var(--ink); }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-large { padding: 12px 24px; font-size: 15px; width: 100%; max-width: 320px; }

input[type="month"], select {
  font-family: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 11px; background: #fff; color: var(--ink);
}
input[type="month"]:focus, select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

/* ---- テーブル ---- */

/* スクロール枠内でヘッダーを固定する（ページ側の sticky ヘッダーと干渉させない） */
.table-scroll { overflow: auto; max-height: calc(100vh - 300px); min-height: 120px; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: var(--panel);
  position: sticky; top: 0; z-index: 1;
}
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: var(--ink); }
.data-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-size: 13px; white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table tbody tr.clickable:hover { background: var(--canvas); cursor: pointer; }
.data-table .sorted::after { content: " ▼"; font-size: 9px; }
.data-table .sorted.asc::after { content: " ▲"; }
.cell-strong { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 11px; margin-left: 4px; }
.empty-cell { color: var(--muted); text-align: center; padding: 24px; }

.tone-bad { color: var(--danger); font-weight: 700; }
.tone-warn { color: var(--warning); }
.tone-ok { color: var(--ok-ink); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 2px 9px; white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok-ink); }
.badge-none { background: var(--warning-soft); color: var(--warning); }

/* ---- チャート ---- */

.chart-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px;
}

/* デモモード切替（顧客名等を仮名表示）*/
.demo-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: #fff;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.demo-toggle .demo-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1;
}
.demo-toggle.is-on { border-color: #b45309; background: #fffbeb; color: #b45309; }
.demo-toggle.is-on .demo-dot { background: #f59e0b; }
.demo-toggle.hidden { display: none; }
/* 解除し忘れに気づけるよう、画面全体に細い枠を出す */
body.demo-on { box-shadow: inset 0 0 0 3px #f59e0b; }

/* 事業所詳細：グラフ3列 ＋ 下段のテーブル2枚 */
.chart-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
/* テーブルは列数が多く3列に収まらないため、下段だけ2列にして可読性を確保する */
.detail-tables { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 16px; }
@media (max-width: 1500px) { .chart-grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 1100px) { .detail-tables { grid-template-columns: 1fr; } }
@media (max-width: 820px) { .chart-grid-3 { grid-template-columns: 1fr; } }

/* HOME 上段：分析グラフ3枚 */
.analysis-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
/* ラベルをグラフ内に描くため、凡例ぶんの高さを本体に回す */
.chart-holder.chart-mid { height: 320px; }
.chart-holder.chart-mid canvas { cursor: pointer; }
@media (max-width: 1500px) { .analysis-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 820px) { .analysis-grid { grid-template-columns: 1fr; } }

/* 下部テーブルの見出し（グラフクリックでランキングへ差し替わる） */
.board-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.board-head .panel-title { margin: 0; flex: 1; }
/* 差し替わったことが分かる程度の軽いフェードイン */
.is-swapping { animation: boardSwap .22s ease-out; }
@keyframes boardSwap {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .is-swapping { animation: none; } }

/* 顧客一覧の構成比バー */
.mixbar-col { min-width: 220px; }
.mixbar-cell { width: 240px; }
.mixbar {
  display: flex; width: 220px; height: 14px; border-radius: 4px; overflow: hidden;
  background: var(--canvas);
}
.mixbar > span { display: block; height: 100%; }
.board-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 2px 8px; font-size: 11px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-item i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px;
}
.chart-card h3 {
  margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--muted);
}
.chart-holder { position: relative; height: 260px; }
.chart-holder.chart-tall { height: 360px; }
.chart-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* 件数／構成比 切替 */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.seg-btn {
  font-family: inherit; font-size: 12px; font-weight: 600;
  border: none; background: transparent; color: var(--muted);
  padding: 7px 14px; cursor: pointer;
}
.seg-btn.is-active { background: var(--brand-soft); color: var(--brand-dark); }

/* 絞り込みチップ */
.chip {
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--brand-dark); background: var(--brand-soft);
  border: 1px solid #bfdbfe; border-radius: 999px;
  padding: 6px 12px; cursor: pointer;
}
.chip:hover { background: #cfe0fd; }

/* ランキング・要注意先リスト */
.rank-list { display: flex; flex-direction: column; }
.rank-row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  font-family: inherit; font-size: 13px; text-align: left;
  background: transparent; border: none; border-bottom: 1px solid var(--line);
  padding: 10px 6px; cursor: pointer; color: inherit;
}
.rank-row:last-child { border-bottom: none; }
.rank-row:hover { background: var(--canvas); }
.rank-name { flex: 1; font-weight: 600; display: flex; flex-direction: column; }
.rank-metric { flex: none; }
.rank-metric strong { font-size: 16px; }
.rank-sub { font-size: 11px; color: var(--muted); font-weight: 400; }

.data-table.mini td { padding: 6px 10px; }

/* ---- 設定 ---- */

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.settings-grid .panel { margin-top: 0; }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.progress { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.progress-bar { flex: 1; height: 8px; background: var(--canvas); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar > div { height: 100%; width: 0; background: var(--brand); transition: width .3s ease; }

/* ---- ログイン ---- */

.center-panel { text-align: center; padding: 40px 24px; margin: 48px auto 0; max-width: 420px; }
.center-panel h1 { font-size: 20px; margin: 0 0 8px; }
.center-panel p { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 14px; }

/* ---- その他 ---- */

.app-footer { text-align: center; font-size: 11px; color: var(--muted); padding: 8px 0 28px; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 13px;
  border-radius: 999px; padding: 10px 20px; z-index: 100; max-width: 90vw;
}
.toast.is-error { background: var(--danger); }

@media (max-width: 860px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 8px; }
  .app-main { padding: 16px 14px 40px; }
  .table-scroll { max-height: none; }
  .data-table th { position: static; }
}
