/* ===========================================================================
   秘書アプリ スタイル
   色は :root のトークンにまとめ、ダークモードはトークンだけを差し替える
   =========================================================================== */

:root {
  /* 地をひと段暗くして、白い面が浮いて見えるようにする */
  --bg: #eceef3;
  --bg-glow: rgba(52, 76, 200, 0.07);
  --surface: #ffffff;
  --surface-sunken: #f4f6fa;
  --surface-hover: #e9edf4;

  --text: #0f1219;
  --text-2: #49515f;
  --muted: #868e9d;

  /* 罫線は細く薄く。囲うのではなく「そっと区切る」 */
  --border: #e8eaef;
  --border-strong: #d6dae2;

  --accent: #3a55d9;
  --accent-hover: #2b43bd;
  --accent-soft: rgba(58, 85, 217, 0.09);
  --accent-ring: rgba(58, 85, 217, 0.20);

  /* 主役のボタンとタブは濃いインク色。青は数字とリンクのために取っておく */
  --ink: #161a23;
  --ink-hover: #262c38;
  --on-ink: #ffffff;

  --open: #c9821c;
  --open-soft: rgba(201, 130, 28, 0.11);
  --info: #2b76cc;
  --info-soft: rgba(43, 118, 204, 0.11);
  --done: #21875a;
  --done-soft: rgba(33, 135, 90, 0.11);
  --danger: #d0484c;
  --danger-soft: rgba(208, 72, 76, 0.10);
  --neutral-soft: rgba(134, 142, 157, 0.13);
  /* グラフの3本目（システム＝青、Ocho＝緑、ロボペイ＝この色） */
  --review: #6b57c9;
  --review-soft: rgba(107, 87, 201, 0.11);

  /* Excel 風の表 */
  --sheet-bg: #ffffff;
  --sheet-line: #dcdfe6;
  --sheet-text: #14171d;
  --sheet-hover: #f0f4fb;
  /* 「◯月から契約が変わる」の塗りつぶし（Excel の黄色と同じ役目） */
  --change: #ffe75c;
  --change-text: #4a3a00;
  --change-line: #b58a00;
  --sheet-head: #427fc2;
  --sheet-head-line: #326196;

  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 8px;

  /* 影は「1枚の濃い影」ではなく、近い影と遠い影を重ねる。そのほうが厚みが出る */
  --shadow-sm:
    0 1px 1px rgba(15, 18, 25, 0.04),
    0 2px 4px -1px rgba(15, 18, 25, 0.06);
  --shadow-md:
    0 1px 1px rgba(15, 18, 25, 0.04),
    0 4px 8px -2px rgba(15, 18, 25, 0.08),
    0 16px 32px -12px rgba(15, 18, 25, 0.16);
  --shadow-lift:
    0 1px 1px rgba(15, 18, 25, 0.05),
    0 8px 16px -4px rgba(15, 18, 25, 0.12),
    0 24px 44px -16px rgba(15, 18, 25, 0.22);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12;
    --bg-glow: rgba(110, 136, 255, 0.10);
    --surface: #14171e;
    --surface-sunken: #1a1e27;
    --surface-hover: #222733;

    --text: #e9ecf3;
    --text-2: #b4bcca;
    --muted: #7f8899;

    --border: #232834;
    --border-strong: #333a49;

    --accent: #8299ff;
    --accent-hover: #9aabff;
    --accent-soft: rgba(130, 153, 255, 0.14);
    --accent-ring: rgba(130, 153, 255, 0.28);

    --ink: #e9ecf3;
    --ink-hover: #ffffff;
    --on-ink: #0f1219;

    --open: #e3a850;
    --open-soft: rgba(227, 168, 80, 0.15);
    --info: #6fb2f2;
    --info-soft: rgba(111, 178, 242, 0.15);
    --done: #4cc08c;
    --done-soft: rgba(76, 192, 140, 0.15);
    --danger: #ef7472;
    --danger-soft: rgba(239, 116, 114, 0.15);
    --neutral-soft: rgba(127, 136, 153, 0.16);
    --review: #a394f0;
    --review-soft: rgba(163, 148, 240, 0.15);

    --sheet-bg: #171b23;
    --sheet-line: #333a48;
    --sheet-text: #e9ecf3;
    --sheet-hover: #212734;
    --change: #6b5714;
    --change-text: #ffe75c;
    --change-line: #ffd12e;
    --sheet-head: #3a6ea8;
    --sheet-head-line: #2a5280;

    /* 暗い背景では影が効きにくいので、上辺の細い光で縁を立てる */
    --shadow-sm:
      inset 0 1px 0 rgba(255, 255, 255, 0.04),
      0 2px 4px -1px rgba(0, 0, 0, 0.45);
    --shadow-md:
      inset 0 1px 0 rgba(255, 255, 255, 0.05),
      0 4px 8px -2px rgba(0, 0, 0, 0.45),
      0 16px 32px -12px rgba(0, 0, 0, 0.6);
    --shadow-lift:
      inset 0 1px 0 rgba(255, 255, 255, 0.07),
      0 8px 16px -4px rgba(0, 0, 0, 0.5),
      0 24px 44px -16px rgba(0, 0, 0, 0.75);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 44px 24px 72px;
  background:
    radial-gradient(1100px 520px at 8% -18%, var(--bg-glow), transparent 68%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI", "Yu Gothic UI",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, system-ui, sans-serif;
  font-size: 15.5px;
  line-height: 1.65;
  letter-spacing: 0.004em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.shell { max-width: 1240px; margin: 0 auto; }

::selection { background: var(--accent-ring); color: var(--text); }

/* スクロールバーを細くして、表の中でも主張しないようにする */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

svg { width: 100%; height: 100%; display: block; }

/* --- ヘッダー ------------------------------------------------------------ */

/* ヘッダー。事務所の写真を横いっぱいに敷いて、その上に題字を置く */
.topbar {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 152px;
  margin-bottom: 26px;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  /* 写真が届かない間も文字が読めるように、下地は濃い色にしておく */
  background: var(--ink);
}

.topbar-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* 机と窓のあたりが帯に入るように、上寄りを見せる */
  object-position: 50% 42%;
  /* 写真は重ねて置いて、表に出ている1枚だけを見せる */
  opacity: 0;
  transition: opacity 1.6s ease;
}

.topbar-photo.is-on { opacity: 1; }

/* 富士山と空が帯に収まるように、こちらはもう少し上を見せる */
.topbar-photo-mountain { object-position: 50% 24%; }

@media (prefers-reduced-motion: reduce) {
  .topbar-photo { transition: none; }
}

/* 写真の上に文字を置くので、暗い膜を1枚かける。左ほど濃くして題字を読みやすく */
.topbar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(8, 10, 16, 0.86) 0%,
    rgba(8, 10, 16, 0.58) 38%,
    rgba(8, 10, 16, 0.26) 66%,
    rgba(8, 10, 16, 0.58) 100%
  );
}

/* 写真と膜より前に出す */
.topbar > *:not(.topbar-photo) { position: relative; z-index: 1; }

.brand-mark {
  width: 38px;
  height: 38px;
  padding: 9px;
  flex: none;
  border-radius: 11px;
  color: var(--on-ink);
  background: var(--ink);
  box-shadow: none;
}
/* 写真の上では、すりガラス風にして浮かせる */
.topbar .brand-mark {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.brand-text h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 640;
  letter-spacing: -0.015em;
  line-height: 1.3;
}
.brand-text .sub {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.topbar .brand-text h1 { color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); }
.topbar .brand-text .sub { color: rgba(255, 255, 255, 0.8); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); }

/* ヘッダーのボタンも、写真の上で読めるように白く抜く */
.topbar .ghost {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.32);
}
.topbar .ghost:hover:not(:disabled) {
  color: #fff;
  background: rgba(255, 255, 255, 0.26);
  border-color: rgba(255, 255, 255, 0.5);
}
.topbar .undo-btn:disabled { opacity: 0.6; }

/* スマホの幅では、題字とボタンを2段にする（1段だと題字が縦一列に潰れる） */
@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 12px;
    min-height: 128px;
    padding: 16px 18px;
  }
  /* 幅いっぱいの隙間を挟んで、ボタンを次の段へ送る */
  .topbar-spacer { flex: 1 0 100%; height: 0; }
  .brand-text { flex: 1 1 auto; min-width: 0; }
  .brand-text h1 { font-size: 19px; }
  .brand-text .sub { font-size: 12.5px; }
}

/* --- ダッシュボード ------------------------------------------------------ */

/* 5枚が1行に収まる幅にしておく（4枚＋1枚に折り返すと落ち着かない） */
/* 件数のカード。経営サマリーの一番下に置く（以前はヘッダーに常時出していた） */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
/* パネルの中に入るので、カード自身の枠と影は落として平らに見せる */
.dashboard-panel .stat {
  background: var(--surface-sunken);
  box-shadow: none;
}
.dashboard-panel .stat:hover { box-shadow: var(--shadow-sm); }
.dashboard-panel .stat-icon { background: var(--surface); }
.dashboard-panel .stat.is-open .stat-icon { background: var(--open-soft); }
.dashboard-panel .stat.is-alert .stat-icon { background: var(--danger-soft); }

.stat {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 15px 17px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lift); transform: translateY(-2px); }
/* カードは押すと対応する表へ飛ぶボタン。見た目はカードのままにする */
.stat { font: inherit; text-align: left; color: inherit; cursor: pointer; width: 100%; }
.stat:hover { border-color: var(--accent); }
.stat:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

/* 飛んだ先の表を、しばらく光らせて目印にする */
.panel.is-spotlight {
  animation: panel-spotlight 2s ease-out;
}
@keyframes panel-spotlight {
  0%, 45% { box-shadow: 0 0 0 3px var(--accent-ring), var(--shadow-md); }
  100% { box-shadow: var(--shadow-md); }
}

.stat-icon {
  width: 34px;
  height: 34px;
  padding: 8px;
  flex: none;
  border-radius: 10px;
  color: var(--text-2);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}
.stat.is-open .stat-icon { color: var(--open); background: var(--open-soft); border-color: transparent; }
.stat.is-alert .stat-icon { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

.stat-body { display: flex; flex-direction: column; min-width: 0; }

/* 見出しは小さく、間隔を空けて。数字を主役にする */
.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.09em;
  line-height: 1.5;
  /* 折り返すとカードの高さが揃わないので、狭いときは末尾を省く */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: 33px;
  font-weight: 660;
  line-height: 1.2;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}
.stat.is-open .stat-value { color: var(--open); }
.stat.is-alert .stat-value { color: var(--danger); }

/* --- タブ ---------------------------------------------------------------- */

/* 件数のカードを経営サマリーへ移したぶん、ここを主役にして大きく取る */
.tabs {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-bottom: 22px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  width: fit-content;
  max-width: 100%;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font: inherit;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: 0.005em;
  cursor: pointer;
  /* 7つを1行に収めたいので、右の余白はここまで詰める */
  padding: 10px 15px 10px 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  transition: background 0.16s ease, color 0.16s ease;
}
.tab:hover { color: var(--text); background: var(--surface-sunken); }

/* 選択中は濃いインク色。派手な原色より落ち着いて見える */
.tab.is-active {
  color: var(--on-ink);
  background: var(--ink);
  box-shadow: none;
}
.tab.is-active:hover { background: var(--ink-hover); color: var(--on-ink); }

/* タブの絵柄。ページごとに色を変えて、字を読まなくても探せるようにする */
.tab-icon {
  --tab-color: var(--accent);
  width: 34px;
  height: 34px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--tab-color);
  background: var(--surface-sunken); /* color-mix が使えないときの受け皿 */
  background: color-mix(in srgb, var(--tab-color) 13%, transparent);
  transition: background 0.16s ease, color 0.16s ease;
}
.tab-icon svg { width: 21px; height: 21px; }

/* 選択中は絵柄を塗りつぶして、いま見ているページをはっきりさせる */
.tab.is-active .tab-icon { color: #fff; background: var(--tab-color); }

#tab-private  .tab-icon { --tab-color: #c9821c; }
#tab-overview .tab-icon { --tab-color: #3a55d9; }
#tab-business .tab-icon { --tab-color: #1d7a8c; }
#tab-sales    .tab-icon { --tab-color: #21875a; }
#tab-ocho     .tab-icon { --tab-color: #e8541f; }
#tab-robopay  .tab-icon { --tab-color: #d0295a; }
#tab-expense  .tab-icon { --tab-color: #6b57c9; }

/* 暗い背景では同じ色だと沈むので、明るめに振る */
@media (prefers-color-scheme: dark) {
  .tab.is-active .tab-icon { color: var(--on-ink); }
  #tab-private  .tab-icon { --tab-color: #e3a850; }
  #tab-overview .tab-icon { --tab-color: #8299ff; }
  #tab-business .tab-icon { --tab-color: #5cb6c7; }
  #tab-sales    .tab-icon { --tab-color: #4cc08c; }
  #tab-ocho     .tab-icon { --tab-color: #ff8556; }
  #tab-robopay  .tab-icon { --tab-color: #f2749a; }
  #tab-expense  .tab-icon { --tab-color: #a394f0; }
}

/* --- レイアウト ---------------------------------------------------------- */

.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 22px 22px 24px;
}

.panel-gap { margin-top: 14px; }

.panel-head { margin-bottom: 15px; }
.panel-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.012em;
  line-height: 1.4;
}
.panel-head h2 .count { margin-left: 7px; vertical-align: 2px; }
.panel-sub { margin: 3px 0 0; font-size: 13px; color: var(--muted); letter-spacing: 0.005em; }

.panel-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* 前月コピー（◯月 → ◯月 にまとめて写す） */
.copy-month {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.copy-month select { width: auto; padding: 3px 6px; font-size: 12.5px; background: var(--surface); }
.copy-arrow { color: var(--muted); font-size: 12px; }
.copy-month .ghost { padding: 5px 11px; font-size: 12.5px; }

/* 開閉する入力フォーム（一覧を主役にするため、ふだんは閉じている） */
.form-block {
  padding: 14px;
  margin-bottom: 16px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
/* display:flex が [hidden] より強いので明示的に打ち消す */
.form-block[hidden] { display: none; }
.form-block input, .form-block textarea, .form-block select { background: var(--surface); }

.list-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.list-head h3 {
  margin: 0;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.12em;
}

.spacer { flex: 1; }

.count {
  font-size: 11.5px;
  font-weight: 650;
  color: var(--text-2);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

.filter { display: flex; align-items: center; gap: 6px; }
.filter .field-label { white-space: nowrap; }
.filter select { padding: 4px 8px; font-size: 12.5px; }

/* --- 入力フォーム -------------------------------------------------------- */

.composer { display: flex; flex-direction: column; gap: 10px; }

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.hint { font-size: 11.5px; color: var(--muted); }
.button-row { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 11.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.07em; }

input[type="text"], input[type="date"], textarea, select {
  width: 100%;
  padding: 10px 13px;
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

select { cursor: pointer; }
input[type="date"] { cursor: text; }
input::placeholder, textarea::placeholder { color: var(--muted); }

input:hover, textarea:hover, select:hover { border-color: var(--border-strong); }

input:focus, textarea:focus, select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input:disabled, select:disabled { opacity: 0.6; cursor: default; }

/* --- ボタン -------------------------------------------------------------- */

button {
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.005em;
  cursor: pointer;
  white-space: nowrap;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 15px;
  background: var(--ink);
  color: var(--on-ink);
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}
button:hover { background: var(--ink-hover); box-shadow: var(--shadow-lift); }
button:active { transform: translateY(1px); box-shadow: none; }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.ghost {
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  box-shadow: none;
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 13px;
}
.ghost:hover { background: var(--surface-sunken); color: var(--text); border-color: var(--muted); box-shadow: none; }

/* --- 一覧 ---------------------------------------------------------------- */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

/* 顧客カードは横に並べる */
.grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 10px;
}

.item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  overflow: hidden;
  padding: 12px 14px 12px 16px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

/* 左端の色帯で種類・状態を示す */
.item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
}

.item:hover { background: var(--surface-hover); box-shadow: var(--shadow-md); transform: translateY(-1px); }

.item-main { flex: 1; min-width: 0; }
.item-actions { display: flex; align-items: center; gap: 2px; flex: none; }

.item-title { font-weight: 600; line-height: 1.5; word-break: break-word; }

.item-body {
  margin: 5px 0 0;
  font-size: 14px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
}

.item-meta {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

/* プライベートのメモ：本文が主役なので大きめに */
.note-text { margin-top: 0; font-size: 14.5px; color: var(--text); }

/* ===========================================================================
   顧客マスタの表（Excel「訪問履歴」シートの見た目に合わせる）
   ヘッダー #427FC2 / Good=黄 / 要注意=赤 / 見出し行は固定
   =========================================================================== */

/* 表の中では縦スクロールさせない。全行そのまま並べて、ページごとスクロールする */
.sheet-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--sheet-bg);
  box-shadow: var(--shadow-sm);
  scrollbar-width: thin;
}

/* 横にも収まっている表は、はみ出しの制御ごと外す。
   そうすると見出しがページのスクロールに追従して、行数が多くても列名を見失わない
   （.fits は app.js が幅を測ってつける） */
.sheet-wrap.fits { overflow: visible; }
.sheet-wrap.fits .sheet-total td { position: static; }

.sheet {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 940px;
  font-family: "Segoe UI Variable Text", "Segoe UI", "Yu Gothic UI",
    "Hiragino Sans", "Meiryo UI", Meiryo, sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
  letter-spacing: 0.002em;
  color: var(--sheet-text);
  background: var(--sheet-bg);
  font-variant-numeric: tabular-nums;
}

/* 見出しは Excel と同じ青のまま。固定したときに影で浮かせる */
.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--sheet-head);
  color: #fff;
  font-weight: 650;
  font-size: 12.5px;
  letter-spacing: 0.05em;
  text-align: center;
  white-space: nowrap;
  padding: 8px 8px;
  border-right: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom: 1px solid var(--sheet-head-line);
  box-shadow: 0 4px 10px -6px rgba(15, 18, 25, 0.5);
}
.sheet thead th:last-child { border-right: none; }

.sheet td {
  padding: 5px 9px;
  border-right: 1px solid var(--sheet-line);
  border-bottom: 1px solid var(--sheet-line);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet td:last-child { border-right: none; }

/* Excel の列幅に合わせる */
.col-expand { width: 26px; text-align: center; padding: 0 !important; }
.col-kind { width: 96px; text-align: center; }
.col-content { width: auto; min-width: 220px; }
.col-status { width: 96px; text-align: center; }
.col-latest { width: 150px; color: var(--muted); }
.col-division { width: 70px; text-align: center; }
.col-month { width: 76px; text-align: center; }
.col-money { width: 108px; text-align: right; font-variant-numeric: tabular-nums; }
.col-note { width: auto; min-width: 160px; }
.col-check { width: 84px; text-align: center; }
.col-summary-label { width: 120px; font-weight: 600; white-space: nowrap; }
.col-no { width: 40px; text-align: center; }
.col-expense-name { width: 160px; }

/* 販管費が経費の肝から自動連動しているセル */
.is-linked-cell { color: var(--info); }

/* スポットは訪問管理の対象外なので控えめに */
.sheet-row.is-spot .col-kind { color: var(--muted); }
.sheet-row.is-spot .cs-none { background: repeating-linear-gradient(135deg, transparent, transparent 4px, var(--sheet-line) 4px, var(--sheet-line) 5px); }

/* 提案の表 */
.proposal-row.status-open .col-status { color: var(--open); }
.proposal-row.status-review .col-status { color: var(--review); }
.proposal-row.status-info .col-status { color: var(--info); }
.proposal-row.status-done .col-status { color: var(--done); }
.proposal-row.status-neutral .col-name { color: var(--muted); }
.proposal-row.is-due .col-date.due-over { color: var(--danger); font-weight: 700; }
.status-cell { font-weight: 700; }

/* 売上の表 */
.cell-money { text-align: right; }
.cell-check { text-align: center; cursor: pointer; }
.cell-check.is-checked { color: var(--done); font-weight: 700; font-size: 14px; line-height: 1; }
.is-readonly { background: var(--surface-sunken); color: var(--text-2); }
.col-money.is-profit { font-weight: 600; }
.col-money.is-minus { color: var(--danger); }
.col-name.is-linked { font-weight: 600; }
/* 見込案件を売上明細へ移すボタン。提案が「受注」になっていたら押しどきなので目立たせる */
#prospect-sheet .col-actions { width: 84px; }
.delete.win:hover { color: var(--done); background: var(--done-soft); }
.delete.win.is-ready {
  opacity: 1;
  color: var(--done);
  background: var(--done-soft);
  box-shadow: inset 0 0 0 1px var(--done);
}

/* 月の切れ目。その月の最後の明細の下に、少し濃い線を引く */
.sales-row.is-month-end td { border-bottom: 2px solid var(--sheet-head-line); }

.sales-row.division-endo .col-division { color: var(--info); font-weight: 600; }
.sales-row.division-ec .col-division { color: var(--done); font-weight: 600; }
.sales-row.division-x .col-division { color: var(--muted); }

.sheet-total td {
  position: sticky;
  bottom: 0;
  background: var(--surface-hover);
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
}
.is-total { font-weight: 700; }

/* 月次集計 */
.summary-sheet { min-width: 1000px; }
#overview-sheet { min-width: 640px; }
/* 月次の内訳は列が14本あるので、左右の余白を詰めて横に収める */
#overview-sheet td, #overview-sheet th { padding-left: 5px; padding-right: 5px; }
#overview-sheet .col-summary-label { width: 104px; }
#overview-sheet .col-money { width: 66px; }
.summary-sheet .col-money { width: 82px; }
.summary-heading td {
  background: var(--surface-hover);
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
}
.summary-row.is-profit td { font-weight: 700; }

.target-input { width: 120px; padding: 4px 8px; font-size: 12.5px; text-align: right; }

.target-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.target-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 150px;
}
.target-label { font-size: 11.5px; color: var(--muted); }
.target-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.target-item.is-done .target-value { color: var(--done); }
.col-name { width: 158px; font-weight: 600; }
.col-person { width: 100px; }
.col-date { width: 92px; text-align: center; font-variant-numeric: tabular-nums; }
.col-rank { width: 62px; text-align: center; }
.col-cs { width: 92px; text-align: center; font-weight: 700; }
.col-proposal { width: 84px; text-align: center; }

/* 提案中の案件があるか。無い顧客をひと目で拾えるようにする */
.proposal-flag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 9px;
  white-space: nowrap;
}
.has-proposal .proposal-flag { color: var(--done); background: var(--done-soft); }
.no-proposal .proposal-flag { color: var(--muted); background: var(--neutral-soft); font-weight: 500; }
.col-karte { width: 74px; text-align: center; }
.col-actions { width: 62px; text-align: right; white-space: nowrap; }

/* カルテを開くボタン。日報の件数も出しておく */
.karte-btn {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}
.karte-btn:hover { background: var(--accent-soft); }
.karte-btn.is-empty { color: var(--muted); border-color: var(--border); font-weight: 500; }

.sheet-row:hover td { background: var(--sheet-hover); }
.sheet-row.is-attention .col-name { color: var(--danger); }
.sheet-row.is-current td { background: var(--accent-soft); }

/* CS満足度：Excel の条件付き書式と同じ配色 */
.cs-good { background: #ffff00; color: #4a4300; }
.cs-alert { background: #ff0000; color: #fff; }
.sheet-row:hover .cs-good { background: #f7f000; }
.sheet-row:hover .cs-alert { background: #ec0000; }

/* --- 「◯月から契約が変わる」の印（ロボペイの肝） ------------------------- */
/* Excel ではその月のマスを黄色に塗り、コメントで中身を書いていた。同じ見え方にする */
.cell-change { position: relative; }
.cell-change.has-change,
.sheet-row:hover .cell-change.has-change {
  background: var(--change);
  color: var(--change-text);
  font-weight: 650;
}

/* 角の小さな三角。メモがあるときは常に、無いときはマスに触れたときだけ出す */
.change-mark {
  position: absolute;
  top: 0;
  right: 0;
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.14s ease;
}
.change-mark::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  border-top: 9px solid var(--muted);
  border-left: 9px solid transparent;
}
.cell-change:hover .change-mark { opacity: 0.5; }
.has-change .change-mark { opacity: 1; }
.has-change .change-mark::before { border-top-color: var(--change-line); }
.change-mark:hover { opacity: 1; }
.change-mark:focus-visible { opacity: 1; outline: 2px solid var(--accent-ring); outline-offset: 1px; }

/* セルの編集 */
.cell { cursor: cell; }
.cell.is-empty::after { content: "\00a0"; }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.cell-input {
  width: 100%;
  padding: 2px 4px;
  font: inherit;
  color: var(--sheet-text);
  background: var(--sheet-bg);
  border: 2px solid #217346;   /* Excel の編集中セルと同じ緑の枠 */
  border-radius: 0;
  box-shadow: none;
}
.cell-input:focus { outline: none; box-shadow: none; border-color: #217346; background: var(--sheet-bg); }

.expand {
  width: 24px;
  height: 22px;
  padding: 0;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 3px;
}
.expand:hover { background: var(--sheet-hover); color: var(--text); box-shadow: none; }
.expand.is-open { color: var(--accent); }

/* --- パスワード金庫 ------------------------------------------------------- */

/* 閉じているあいだの画面。中身も件数も出さない */
.vault-gate { display: flex; justify-content: center; padding: 46px 24px; }
/* display:flex は [hidden] より強いので、明示的に打ち消す（.form-block と同じ理由） */
.vault-gate[hidden] { display: none; }
.vault-gate-inner { max-width: 460px; text-align: center; }
.vault-lock {
  display: inline-flex;
  width: 56px;
  height: 56px;
  padding: 13px;
  margin-bottom: 12px;
  border-radius: 16px;
  color: var(--on-ink);
  background: var(--ink);
}
.vault-gate h2 { margin: 0 0 4px; font-size: 20px; }
.vault-gate .panel-sub { margin-bottom: 18px; }
#vault-form { display: flex; gap: 8px; justify-content: center; }
#vault-password { flex: 1; max-width: 280px; }
/* 間違えたときのメッセージ。入力欄のすぐ下に出す */
.vault-error {
  margin: 12px auto 0;
  max-width: 360px;
  text-align: center;
}
.vault-hint {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

/* さがす欄。区分のプルダウンと並べて置く */
#vault-search {
  width: 200px;
  padding: 5px 10px;
  font: inherit;
  font-size: 13px;
}

/* 開いているあいだの残り時間 */
.vault-timer {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-sunken);
  white-space: nowrap;
}
.vault-timer.is-soon { color: var(--danger); background: var(--danger-soft); }

.col-vault-group { width: 110px; }
.col-vault-service { width: 158px; }
.col-vault-account { width: 200px; }
.col-vault-secret { width: 200px; white-space: nowrap; }
.col-vault-url { width: 150px; }

/* サイトの列。文字を押すと書き換え、矢印を押すと開く */
.vault-url-text {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vault-url-text.is-empty { color: var(--muted); }
.vault-url-text:hover { color: var(--accent); }
.sheet .vault-url-open {
  width: 24px;
  height: 22px;
  padding: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.delete.vault-url-open:hover { color: var(--accent); background: var(--accent-soft); }

/* パスワードとサイトの列は、中身を横並びにする。
   td そのものを flex にすると表の列がずれるので、中に1枚かぶせて並べる */
.cell-row { display: flex; align-items: center; gap: 2px; }
.secret-text {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.08em;
}
.secret-text.is-shown {
  font-family: "Consolas", "SFMono-Regular", "Menlo", monospace;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}
.sheet .secret-toggle, .sheet .secret-copy { width: 24px; height: 22px; padding: 2px; }
.delete.secret-toggle:hover, .delete.secret-copy:hover { color: var(--accent); background: var(--accent-soft); }

/* --- 運営指導情報（カルテの右カラム） ------------------------------------- */
/* 幅が狭いので表にはせず、1件を「日付＋事業所」と「本文2つ」の2段で見せる */
.guidance-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.guidance-item {
  padding: 10px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.guidance-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.guidance-date {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  white-space: nowrap;
}
.guidance-office {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  overflow-wrap: anywhere;
}
.guidance-office.is-empty { color: var(--muted); font-style: italic; }
.guidance-head .delete { width: 26px; height: 26px; padding: 4px; }

.guidance-block + .guidance-block { margin-top: 8px; }
.guidance-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 2px;
}
/* 指摘事項は通知書をそのまま貼るので、改行を残して折り返す */
.guidance-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
  font-size: 12.5px;
  padding: 5px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  /* 長いものはここで抑えて、中でスクロールさせる（右カラムが伸びすぎないように） */
  max-height: 14em;
  overflow-y: auto;
}
.guidance-body.is-empty { color: var(--muted); font-style: italic; }
.guidance-body:hover, .guidance-office:hover, .guidance-date:hover { color: var(--accent); }

/* 長い文の書き込み欄 */
textarea.cell-input {
  min-height: 7em;
  resize: vertical;
  line-height: 1.55;
}

/* 区分の見出し行（クライアント／スポットの境目） */
.sheet-group td {
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-2);
  background: var(--surface-sunken);
  border-top: 2px solid var(--sheet-line);
  border-bottom: 1px solid var(--sheet-line);
  white-space: nowrap;
}
.sheet-group:first-child td { border-top: none; }

/* 展開行 */
.sheet-detail td { background: var(--surface-sunken); white-space: normal; padding: 10px 14px 12px 34px; }
.detail-box { max-width: 720px; }
.detail-line { font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; }

.sheet-detail .history { margin-top: 6px; }

/* 新規行。列に沿って並べ、そのまま最後まで打てるようにする */
.sheet-new td {
  background: var(--surface-sunken);
  border-bottom: none;
  border-top: 2px solid var(--sheet-line);
  padding: 0;
}
/* 先頭に置く追加行は、線を下側に引く（見出しのすぐ下に来るため） */
.sheet-new.is-first td {
  border-top: none;
  border-bottom: 2px solid var(--sheet-line);
}
.sheet-new input,
.sheet-new select,
.sheet-new textarea {
  width: 100%;
  padding: 7px 6px;
  font: inherit;
  color: var(--sheet-text);
  background: transparent;
  border: none;
  border-radius: 0;
  text-align: inherit;
}
.sheet-new select { appearance: none; text-align: center; cursor: pointer; }
.sheet-new .col-money input { text-align: right; }
/* 数字の増減ボタンは幅を食うので出さない */
.sheet-new input[type='number']::-webkit-outer-spin-button,
.sheet-new input[type='number']::-webkit-inner-spin-button { appearance: none; margin: 0; }
.sheet-new input[type='number'] { appearance: textfield; }
.sheet-new input[type='checkbox'] { width: auto; accent-color: var(--accent); cursor: pointer; }
.sheet-new .col-check { text-align: center; padding: 4px 0; }
.sheet-new textarea { resize: vertical; line-height: 1.5; min-height: 4.5em; }
.sheet-new textarea::placeholder { color: var(--muted); }
.sheet-new input:focus,
.sheet-new select:focus,
.sheet-new textarea:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent-ring);
  background: var(--sheet-bg);
}
.sheet-new input::placeholder { color: var(--muted); }
/* EC のように相手先が要らないときは、欄そのものを控えめにする */
.sheet-new input.is-optional { background: var(--surface-sunken); }
.sheet-new input.is-optional::placeholder { font-style: italic; }
/* 打っている途中の粗利。確定前なので少し控えめに見せる */
.sheet-new .is-profit { text-align: right; padding-right: 6px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.sheet-new .is-profit.is-minus { color: var(--danger); }

.row-add {
  width: 100%;
  padding: 6px 4px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--on-ink);
  background: var(--ink);
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.row-add:hover { background: var(--ink-hover); }
.row-add:disabled { opacity: 0.5; cursor: default; }
.sheet-new .col-actions { padding: 4px 6px; }

/* 見込案件と「提案中」の連動を見せる列 */
.col-proposal-link { width: 78px; text-align: center; }
.col-proposal-link.is-empty { color: var(--muted); }
.proposal-link {
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-2);
  background: var(--neutral-soft);
}
.proposal-link.open { color: var(--open); background: var(--open-soft); }
.proposal-link.review { color: var(--review); background: var(--review-soft); }
.proposal-link.info { color: var(--info); background: var(--info-soft); }
.proposal-link.done { color: var(--done); background: var(--done-soft); }
.proposal-link:hover { box-shadow: inset 0 0 0 1px currentColor; }

/* 見込案件から飛んで来たときに、その提案の行をしばらく光らせる */
.proposal-row.is-spotlight { animation: spotlight 2.4s ease-out; }
@keyframes spotlight {
  0%, 55% { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
  100% { background: transparent; box-shadow: none; }
}

.sheet .delete { width: 26px; height: 24px; padding: 3px; }

/* 顧客（旧カード表示。展開行の中で使う） */
.client::before { background: var(--done); }
.client.is-attention::before { background: var(--danger); }
.client-detail { margin-top: 3px; font-size: 12.5px; color: var(--muted); word-break: break-word; }
.client.is-current { border-color: var(--accent); }

.client-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0 8px;
  white-space: nowrap;
}
.chip.closeness { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.timeline-more { margin: 0 0 4px 14px; font-size: 11.5px; color: var(--muted); }
.history-form .visit-visitor { width: 90px; flex: none; padding: 5px 10px; font-size: 13px; }

/* 提案：ステータスで色帯を変える */
.proposal.status-open::before { background: var(--open); }
.proposal.status-review::before { background: var(--review); }
.proposal.status-info::before { background: var(--info); }
.proposal.status-done::before { background: var(--done); }
.proposal.status-neutral::before { background: var(--muted); }
.proposal.status-neutral .item-title { color: var(--muted); }
.proposal.is-due { border-color: var(--danger); }

.proposal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.proposal-head .item-title { flex: 1; min-width: 0; }

.status-select {
  width: auto;
  flex: none;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--neutral-soft);
  color: var(--text-2);
}
.status-select.open { color: var(--open); background: var(--open-soft); }
.status-select.review { color: var(--review); background: var(--review-soft); }
.status-select.info { color: var(--info); background: var(--info-soft); }
.status-select.done { color: var(--done); background: var(--done-soft); }

/* 提案の履歴（提案開始 → デモ → 見積提出 …） */

.history { margin-top: 10px; }

.timeline {
  list-style: none;
  margin: 0 0 6px;
  padding: 0 0 0 14px;
  position: relative;
}
/* 縦のつなぎ線 */
.timeline::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 7px;
  bottom: 7px;
  width: 1px;
  background: var(--border-strong);
}

.timeline-item {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
  font-size: 13px;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
}
.timeline-item.is-latest::before { background: var(--accent); }

.timeline-date {
  flex: none;
  min-width: 34px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.timeline-text { color: var(--text-2); word-break: break-word; }
.timeline-item.is-latest .timeline-text { color: var(--text); font-weight: 600; }

.timeline-del {
  margin-left: auto;
  flex: none;
  padding: 0 5px;
  font-size: 14px;
  line-height: 1.4;
  background: transparent;
  color: var(--muted);
  border: none;
  box-shadow: none;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.timeline-item:hover .timeline-del, .timeline-del:focus-visible { opacity: 1; }
.timeline-del:hover { background: transparent; color: var(--danger); box-shadow: none; }

/* 文字だけの控えめなボタン */
.link-btn {
  padding: 2px 0;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: var(--accent);
  border: none;
  box-shadow: none;
}
.link-btn:hover { background: transparent; color: var(--accent-hover); box-shadow: none; text-decoration: underline; }
.link-btn:active { transform: none; }

.history-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.history-form .history-date { width: auto; flex: none; padding: 5px 9px; font-size: 12.5px; }
.history-form .history-text { flex: 1; min-width: 140px; padding: 5px 10px; font-size: 13px; }
.history-form .ghost { padding: 5px 12px; font-size: 12.5px; }

/* 次アクション日 */
.due {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 9px;
}
.due::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.due-over { color: var(--danger); background: var(--danger-soft); }
.due-soon { color: var(--open); background: var(--open-soft); }
.due-far { color: var(--info); background: var(--info-soft); }
.due-none { color: var(--muted); background: var(--neutral-soft); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 9px;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.open { color: var(--open); background: var(--open-soft); }
.badge.review { color: var(--review); background: var(--review-soft); }
.badge.info { color: var(--info); background: var(--info-soft); }
.badge.done { color: var(--done); background: var(--done-soft); }
.badge.neutral { color: var(--muted); background: var(--neutral-soft); }
.badge.alert { color: var(--danger); background: var(--danger-soft); }

/* アイコンボタン（削除・編集） */
.delete {
  flex: none;
  align-self: center;
  padding: 5px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  box-shadow: none;
  opacity: 0.75;
  transition: color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.delete:hover {
  opacity: 1;
  color: var(--danger);
  background: var(--danger-soft);
  box-shadow: none;
}
.delete.edit:hover { color: var(--accent); background: var(--accent-soft); }
.delete:focus-visible { opacity: 1; box-shadow: 0 0 0 3px var(--accent-ring); }

/* --- 経営サマリーのレイアウト（左＝数字とグラフ／右＝言葉とリンク） ------ */

.overview-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}
/* 中の表やグラフに引きずられて横に広がらないようにする */
.overview-main, .overview-side { min-width: 0; }

/* ---- 顧客カルテ ---- */
/* 経営サマリーと同じ考え方で、左に日報（いちばん見るもの）、右に台帳を置く */
.karte-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}
.karte-main, .karte-side { min-width: 0; }
.karte-side.is-sticky {
  position: sticky;
  top: 12px;
}
/* カルテの見出しは書類のタイトルらしく大きく */
.karte-head-panel { padding: 18px 22px; }
.karte-head-panel .panel-head { margin-bottom: 0; }
.karte-head-panel .panel-head-row { align-items: center; }
.karte-head-panel h2 { font-size: 24px; font-weight: 660; letter-spacing: -0.03em; }
.karte-head-panel .panel-sub { margin-top: 1px; }

/* カルテの表は Excel の訪問履歴ほど列が多くないので、幅の下限を下げる */
.karte-sheet { min-width: 0; }
.karte-main .karte-sheet { min-width: 520px; }
/* 右側は幅が狭いので、URL や長い備考は折り返して収める */
.karte-side .sheet td { white-space: normal; overflow-wrap: anywhere; }
.karte-side .col-actions { width: 28px; }
.karte-sheet td { vertical-align: top; }
.karte-sheet .col-staff { width: 68px; }
.karte-sheet .col-place { width: 110px; }
.karte-sheet .col-kind2 { width: 68px; text-align: center; }
.karte-sheet .col-body { white-space: normal; line-height: 1.5; }
/* 元の Excel に「場所」の列が無い顧客では、この列を出さない */
.karte-sheet.no-place .col-place { display: none; }
.karte-profile-sheet .col-label { width: 116px; color: var(--muted); }
.karte-profile-sheet .col-value { font-weight: 600; }

/* 訪問の行は最終訪問にも効くので、少し目立たせる */
.karte-sheet .report-visit .col-kind2 { color: var(--accent); font-weight: 700; }
.karte-sheet .report-other .col-kind2 { color: var(--muted); }

.karte-folder-input {
  width: 100%;
  font-size: 12px;
  font-family: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text);
}
.karte-folder-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.karte-folder-actions .panel-sub { margin: 0; }

/* 日報の内容が読める幅を確保できないときは、上下に積む */
@media (max-width: 1100px) {
  .karte-layout { grid-template-columns: 1fr; }
  .karte-side.is-sticky { position: static; }
}

/* 右カラムは画面に収まるときだけ貼り付ける（.is-sticky は app.js がつける）。
   はみ出す長さのときに貼り付けると下が読めなくなるので、そのときはページと一緒に流す */
.overview-side.is-sticky {
  position: sticky;
  top: 12px;
}

.headline-panel { padding-bottom: 20px; }

/* 1段目に 営業利益 → 年商 → 利益率、2段目に残り3枚。
   auto-fit だと列数が変わるたびに2段目が1枚だけ取り残されて崩れる */
.headline {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.headline-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 15px 17px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius);
  /* 数字の大きさをカードの幅に合わせるための基準にする */
  container-type: inline-size;
}
.headline-card.is-hero {
  background: linear-gradient(135deg, var(--accent-soft), transparent 62%), var(--surface-sunken);
}
.headline-card.is-revenue { border-left-color: var(--accent); }
.headline-card.is-margin.is-plus .headline-icon { color: var(--done); background: var(--done-soft); }
.headline-card.is-margin.is-minus .headline-icon { color: var(--danger); background: var(--danger-soft); }
.headline-card.is-expense { border-left-color: var(--danger); }
.headline-card.is-plus { border-left-color: var(--done); }
.headline-card.is-minus { border-left-color: var(--danger); }

.headline-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.09em;
}

.headline-icon {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  color: var(--accent);
  background: var(--accent-soft);
}
.headline-icon svg { width: 14px; height: 14px; }

/* 幅が狭いときは、8〜9桁でもカードからはみ出さない大きさまで縮める */
.headline-value {
  font-size: min(30px, 18cqi);
  font-weight: 660;
  line-height: 1.2;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}
.headline-card.is-hero .headline-value { font-size: min(44px, 18cqi); letter-spacing: -0.045em; }
.headline-card.is-plus .headline-value { color: var(--done); }
.headline-card.is-minus .headline-value { color: var(--danger); }
.headline-unit { font-size: 0.5em; font-weight: 600; color: var(--muted); margin-left: 2px; }

.headline-note {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: auto;   /* 下端で揃える。数字の位置がカードごとにずれないように */
  padding-top: 6px;
}

/* リンク集（中身はショートカットと同じアイコンボタン） */
.link-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

/* --- ページ上部のショートカットボタン ------------------------------------ */
/* よく開く外部サイトへ、ひと目でわかる大きさで飛べるようにする */

.shortcuts {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.shortcuts:empty { display: none; }

.shortcut-item { position: relative; display: flex; align-items: center; }

.shortcut {
  --brand: var(--accent);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 16px 10px 11px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}
.shortcut:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
}
.shortcut:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
/* ファイルへのショートカットは <button> なので、見た目をリンクに揃える */
.shortcut.is-file { font: inherit; text-align: left; cursor: pointer; }

/* サイトの色で塗った四角。短い印を入れて見分けやすくする */
.shortcut-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.shortcut-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.shortcut-label { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.35; }
.shortcut-host {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shortcut-arrow { color: var(--muted); margin-left: 2px; transition: color 0.16s ease; }
.shortcut:hover .shortcut-arrow { color: var(--brand); }

/* 編集と削除はふだん隠しておく */
.shortcut-edit, .shortcut-del {
  position: absolute;
  top: -7px;
  width: 24px;
  height: 24px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.shortcut-edit { right: 20px; }
.shortcut-del { right: -7px; }
.shortcut-item:hover .shortcut-edit, .shortcut-item:hover .shortcut-del,
.shortcut-edit:focus-visible, .shortcut-del:focus-visible { opacity: 1; }

.shortcut-add { align-self: center; border-style: dashed; }

/* リンク集のように縦に積むとき（経営サマリーの右カラム） */
.link-list { gap: 8px; }
.shortcut-item.is-block { display: block; }
.shortcut-item.is-block .shortcut { width: 100%; }
.shortcut-item.is-block .shortcut-label { white-space: normal; }

/* --- グラフ -------------------------------------------------------------- */

/* 構成比と月次の内訳は左に寄せ、空いた右に「いまの状況」を縦に並べる。
   リンク集との間の余白を、件数カードの置き場にあてている */
.chart-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 248px;
  gap: 14px;
  /* 左のグラフと同じ高さまで伸ばして、カードを等間隔に散らす */
  align-items: stretch;
}
/* 上の「推移」との間は、左の構成比と同じだけ空ける（.panel-gap の 14px）。
   ここを 0 にすると、右側だけ推移にくっついて見える */
.chart-area .dashboard-panel {
  display: flex;
  flex-direction: column;
}
/* 右に縦置きするので1列（4行）。余った高さは4枚で等分する */
.chart-area .dashboard {
  flex: 1;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: repeat(4, minmax(74px, 1fr));
  gap: 12px;
}

/* 画面が狭いとグラフ側が潰れるので、そのときは件数カードをグラフの下へ回す
   （右のリンク集と合わせて3列ぶんの幅が要るため、早めに折り返す） */
@media (max-width: 1240px) {
  .chart-area { grid-template-columns: minmax(0, 1fr); }
  .chart-area .dashboard {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    grid-template-rows: auto;
  }
  .chart-area .dashboard-panel { margin-top: 14px; }
}

/* 構成比と月次の内訳は上下に積む。
   横に並べると月次の内訳が狭くなるので、どちらも横幅いっぱい使わせる */
.chart-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.chart { width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-zero { stroke: var(--border-strong); stroke-width: 1.5; }
.chart-axis { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; }
.chart-dot { fill: var(--surface); stroke: var(--text); stroke-width: 1.6; }

.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* 円は左に大きく、3事業は右に縦3行。横に3つ並べるより字が大きく取れる */
.donut-wrap { display: flex; align-items: center; gap: 26px; }
.chart-donut { flex: none; width: clamp(190px, 30%, 268px); max-width: 268px; }
.donut-value { font-size: 20px; font-weight: 700; fill: var(--text); }
.donut-label { font-size: 10px; fill: var(--muted); }

.share-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
  gap: 10px;
}
.share-list li {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  grid-template-areas: 'swatch name amount rate';
  align-items: center;
  gap: 0 16px;
  padding: 14px 18px;
  border-radius: 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}
.share-list li .legend-swatch { grid-area: swatch; width: 12px; height: 12px; border-radius: 3px; }
.share-name { grid-area: name; color: var(--text); font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.share-amount { grid-area: amount; color: var(--text-2); font-variant-numeric: tabular-nums; font-size: 13.5px; }
.share-rate {
  grid-area: rate;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 21px;
  letter-spacing: -0.02em;
  min-width: 2.6em;
  text-align: right;
}

/* 幅が足りないときは、円を上・一覧を下にして折り返す */
@media (max-width: 720px) {
  .donut-wrap { flex-direction: column; align-items: stretch; gap: 16px; }
  .chart-donut { width: 200px; align-self: center; }
}

/* --- ドット絵のオフィス -------------------------------------------------- */

.office-panel { padding: 14px 14px 12px; }

.office-canvas {
  display: block;
  width: 100%;
  height: auto;
  /* 押すと次の場面へ送れる */
  cursor: pointer;
  /* 引き伸ばしてもドットがぼやけないようにする */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-sunken);
}

.office-caption {
  margin: 11px 2px 0;
  min-height: 34px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-2);
  text-align: center;
  letter-spacing: 0.01em;
}

/* 言葉の出どころ（著名人の名前） */
.office-by {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

/* --- 大事にしている言葉 -------------------------------------------------- */

.motto-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.motto {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius);
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: -0.005em;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.motto:hover { background: var(--surface-hover); }
.motto-star { color: var(--open); flex: none; }
.motto-text { flex: 1; cursor: text; word-break: break-word; font-weight: 700; }
.motto-text:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.motto:hover .timeline-del, .motto .timeline-del:focus-visible { opacity: 1; }

.motto-input {
  flex: 1;
  padding: 4px 8px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 6px;
}

/* --- ログイン画面 -------------------------------------------------------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 22px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card button { width: 100%; padding: 10px; font-size: 14px; }
.login-card .error { margin: 16px 0 0; }
.login-note { margin: 16px 0 0; font-size: 11.5px; color: var(--muted); text-align: center; }

/* ヘッダーの右端（元に戻す・やり直す・ログアウト） */
.topbar-spacer { flex: 1; }
.logout { flex: none; }

.undo-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}
.undo-btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: var(--surface);
  color: var(--muted);
  border-color: var(--border);
}
.undo-btn:disabled:hover { background: var(--surface); color: var(--muted); border-color: var(--border); }

/* --- 空の状態・エラー ---------------------------------------------------- */

.empty {
  margin: 0;
  padding: 22px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.error[hidden] { display: none; }

/* エラーではない一言（「元に戻しました」など） */
.error.is-notice {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.error {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 18px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 13.5px;
  box-shadow: var(--shadow-sm);
}

/* --- レスポンシブ -------------------------------------------------------- */

@media (max-width: 900px) {
  .dashboard { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* 1段に積むときは必ず minmax(0, 1fr) にする。
   ただの 1fr だと「列は中身より狭くならない」という決まりが効いて、
   表の min-width にページごと引き伸ばされてしまう（スマホで横スクロールになる） */
@media (max-width: 820px) {
  body { padding: 28px 14px 48px; }
  .columns, .business-columns { grid-template-columns: minmax(0, 1fr); }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 8px 12px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 24px; }
  .field-row { flex-direction: column; }
  .chart-columns { grid-template-columns: minmax(0, 1fr); }
  /* 幅が足りないときは、件数カードもグラフの下へ回して横並びに戻す */
  .chart-area { grid-template-columns: minmax(0, 1fr); }
  .chart-area .dashboard {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    grid-template-rows: auto;
  }
  .chart-area .dashboard-panel { margin-top: 14px; }
  .donut-wrap { flex-direction: column; }
  .share-list { grid-template-columns: minmax(0, 1fr); }
  .overview-layout { grid-template-columns: minmax(0, 1fr); }
  .overview-side.is-sticky { position: static; }
  .karte-layout { grid-template-columns: minmax(0, 1fr); }
  .karte-side.is-sticky { position: static; }
  .headline { grid-template-columns: minmax(0, 1fr); }
  .headline-card.is-hero { grid-column: 1 / -1; }

  /* 表は枠の中で横に送る。ページごと横に伸びると他のページまで読みにくくなる */
  .sheet-wrap, .sheet-wrap.fits { overflow-x: auto; }
  .sheet-wrap.fits { overflow-y: visible; }
}

@media (max-width: 480px) {
  .dashboard { grid-template-columns: minmax(0, 1fr); gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ページ下部まで進んだときに出る「先頭へ」ボタン */
.to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease, color 0.18s ease,
    border-color 0.18s ease, background 0.18s ease;
}

.to-top.is-shown { opacity: 1; transform: translateY(0); }

.to-top:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.to-top:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.to-top[hidden] { display: none; }

.to-top-arrow { font-size: 15px; line-height: 1; }

@media (max-width: 720px) {
  .to-top { right: 14px; bottom: 14px; padding: 9px 12px; }
  .to-top-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .to-top { transition: opacity 0.18s ease; transform: none; }
}

/* --- 特別経費の内容メモ ------------------------------------------------- */

.expense-notes-head {
  margin: 22px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.expense-notes-head h3 {
  margin: 0;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.12em;
}

.expense-note-sheet .col-note-month { width: 64px; }
.expense-note-sheet .col-expense-name { width: 160px; }
.expense-note-sheet .col-money { width: 120px; }
.expense-note-sheet .col-note-body { min-width: 280px; white-space: pre-wrap; }
.expense-note-sheet .is-month-end td { border-bottom: 2px solid var(--sheet-head-line); }
/* まだ書いていない欄には、押せば書けることを薄く出しておく（書いている最中は消す） */
.expense-note-sheet .col-note-body.is-empty:not(:focus-within)::before {
  content: '＋ 内容を書く';
  color: var(--muted);
}

/* 内容メモがある月のセル。Excel のコメントのように右上へ小さな三角を付ける */
.sheet td.has-note { position: relative; }
.sheet td.has-note::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  border-style: solid;
  border-width: 0 7px 7px 0;
  border-color: transparent var(--accent) transparent transparent;
  pointer-events: none;
}

/* --- 顧客別集計（システム売上の肝） ------------------------------------------
   左に円グラフ、右に上位10社の順位。円の色は、色覚の違いがあっても隣り合う色を
   見分けられることを検証した8色を、順位の順に固定で使う（9社目以降は灰色の「その他」）。
   ライトで背景との差が小さい色もあるので、名前と金額は必ず一覧の文字で添える */

:root {
  --cat-1: #2a78d6;
  --cat-2: #eb6834;
  --cat-3: #1baf7a;
  --cat-4: #eda100;
  --cat-5: #e87ba4;
  --cat-6: #008300;
  --cat-7: #4a3aa7;
  --cat-8: #e34948;
  --cat-other: #c3c7cf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --cat-1: #3987e5;
    --cat-2: #d95926;
    --cat-3: #199e70;
    --cat-4: #c98500;
    --cat-5: #d55181;
    --cat-6: #008300;
    --cat-7: #9085e9;
    --cat-8: #e66767;
    --cat-other: #4b5160;
  }
}

.client-sales-chart { position: relative; margin-top: 8px; }

.cs-layout {
  display: grid;
  grid-template-columns: minmax(200px, 280px) minmax(0, 1fr);
  gap: 32px;
  align-items: center;
}

.cs-donut { width: 100%; max-width: 280px; height: auto; justify-self: center; }
/* 一切れの間は 2px、面の色の隙間で分ける */
.cs-slice { stroke: var(--surface); stroke-width: 2px; stroke-linejoin: round; cursor: default; transition: opacity 0.15s ease; }
.cs-slice.is-dim, .rank-row.is-dim { opacity: 0.35; }

.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.rank-row {
  display: grid;
  grid-template-columns: 1.6em 12px minmax(0, 1fr) auto 3.6em;
  grid-template-areas:
    "no swatch name value share"
    ". . sub sub sub";
  align-items: center;
  column-gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: opacity 0.15s ease;
}
.rank-row:last-child { border-bottom: none; }
.rank-row:hover, .rank-row:focus-visible { background: var(--surface-hover); }
.rank-row:focus-visible { box-shadow: 0 0 0 2px var(--accent-ring); }

.rank-no { grid-area: no; font-size: 12px; font-weight: 650; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.rank-row .legend-swatch { grid-area: swatch; width: 12px; height: 12px; border-radius: 3px; }
.rank-name {
  grid-area: name;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rank-value { grid-area: value; font-size: 14px; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.rank-share { grid-area: share; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; }
.rank-sub { grid-area: sub; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-value.is-minus, .cs-tip-value.is-minus { color: var(--danger); }

.rank-total {
  margin: 10px 0 0;
  padding: 8px 8px 0;
  border-top: 1px solid var(--border-strong);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.rank-note { margin: 6px 8px 0; font-size: 12px; color: var(--muted); }

/* マウスを乗せたときの吹き出し */
.cs-tip {
  position: absolute;
  z-index: 5;
  min-width: 200px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 12.5px;
  pointer-events: none;
}
.cs-tip[hidden] { display: none; }
.cs-tip-title { display: flex; align-items: center; gap: 6px; font-weight: 650; margin-bottom: 4px; color: var(--text); }
.cs-tip-line { display: flex; align-items: center; gap: 6px; line-height: 1.7; }
.cs-tip-label { color: var(--text-2); }
.cs-tip-value { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }

/* 狭い幅では、円を上、順位を下に積む */
@media (max-width: 860px) {
  .cs-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .cs-donut { max-width: 240px; }
}
