:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1d2330;
  --muted: #7a8598;
  --line: #e6eaf1;
  --brand: #e8552d;
  --brand-dark: #c8431f;
  --green: #1fae67;
  --blue: #3b7ddd;
  --purple: #8a63d2;
  --shadow: 0 1px 3px rgba(20,30,60,.06), 0 8px 24px rgba(20,30,60,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; }

/* サイドバー */
.sidebar {
  width: 240px; flex: 0 0 240px;
  background: #151b2b; color: #cdd5e4;
  display: flex; flex-direction: column;
  padding: 20px 16px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
.brand-title { font-weight: 700; font-size: 18px; color: #fff; }
.brand-sub { font-size: 12px; color: #8b96ac; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  text-align: left; border: 0; background: transparent; color: #b7c0d3;
  padding: 11px 14px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.nav-item:hover { background: #1e2740; color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }

.sidebar-foot { margin-top: auto; }
.status-line { font-size: 11px; color: #8b96ac; margin-top: 10px; text-align: center; }

/* メイン */
.main { flex: 1; overflow-y: auto; padding: 28px 32px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.view-head h1 { font-size: 24px; margin: 0 0 4px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.hidden { display: none; }

/* カード */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.cards.cards-3 { grid-template-columns: repeat(3, 1fr); }

/* 利益カード（粗利・純利）を強調 */
.kpi-profit { background: linear-gradient(180deg, #ffffff, #f6fbf7); border: 1px solid #d8efe0; }
.kpi-profit .kpi-value { color: var(--green); }
.kpi-profit .kpi-value.neg { color: #b93a22; }
.card {
  background: var(--panel); border-radius: 14px; padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card-title { font-weight: 700; font-size: 15px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }

.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.kpi-value { font-size: 27px; font-weight: 800; letter-spacing: -.5px; }
.kpi-sub { font-size: 12px; color: var(--green); margin-top: 6px; }
.kpi-sub.muted { color: var(--muted); }

/* テーブル */
.mini-table, .data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.mini-table td { padding: 9px 4px; border-bottom: 1px solid var(--line); }
.mini-table td:last-child { text-align: right; font-weight: 700; }
.mini-table .pct { font-size: 11px; font-weight: 600; color: var(--muted); background: #eef1f6; padding: 1px 6px; border-radius: 20px; }
.data-table th, .data-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--muted); font-size: 12px; font-weight: 600; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.empty { text-align: center; color: var(--muted); padding: 22px; }

/* テーブルカード：横に広い時は横スクロール（切れないように） */
.table-card { padding: 0; overflow-x: auto; }
.table-card .data-table { padding: 6px 12px 12px; }
.table-card .data-table thead th {
  background: #f7f9fc; border-bottom: 2px solid var(--line);
  padding: 12px 10px;
}

/* 日別テーブル（午前/午後つき） */
.daily-table { font-variant-numeric: tabular-nums; min-width: 760px; }
.daily-table td, .daily-table th { padding: 11px 10px; }
.daily-table tbody tr:nth-child(even of :not(.month-head):not(.subtotal)) { background: #fbfcfe; }
.daily-table .col-day { text-align: left; font-weight: 600; white-space: nowrap; }
.daily-table .col-day .dow { color: var(--muted); font-size: 12px; font-weight: 500; margin-left: 3px; }
.daily-table .col-day.weekend { color: var(--brand); }
.daily-table .col-sub { color: var(--muted); font-size: 13px; }
.daily-table td.strong { font-weight: 700; }
.daily-table .cell-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.daily-table thead .col-sub { color: #9aa4b5; font-weight: 500; }
.daily-table .month-head td {
  background: #eef2f8; font-weight: 700; font-size: 13px; color: var(--ink);
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.daily-table .subtotal td {
  background: #fff6f2; font-weight: 700; border-top: 1px solid #f2d4c8;
  border-bottom: 2px solid var(--line);
}
.daily-table tbody tr.subtotal:hover { background: #fff6f2; }

/* 曜日ごとのまとめ */
.weekday-table { font-variant-numeric: tabular-nums; min-width: 940px; }
.weekday-table td, .weekday-table th { padding: 11px 10px; }
.weekday-table .col-day { text-align: left; font-weight: 600; white-space: nowrap; }
.weekday-table .col-day.weekend { color: var(--brand); }
.weekday-table .col-sub { color: var(--muted); font-size: 13px; }
.weekday-table thead .col-sub { color: #9aa4b5; font-weight: 500; }
.weekday-table tbody tr:hover { background: #f8fafc; }

/* 業者・科目 × 月 のクロス集計表 */
.pivot-table { font-variant-numeric: tabular-nums; min-width: 640px; }
.pivot-table th, .pivot-table td { padding: 10px 12px; white-space: nowrap; }
.pivot-table thead th { background: #f7f9fc; border-bottom: 2px solid var(--line); }
.pivot-table .col-day { text-align: left; font-weight: 600; }
.pivot-table tbody tr:hover { background: #f8fafc; }
/* 1列目（名前）は横スクロールしても左に固定 */
.pivot-table th.col-day, .pivot-table td.col-day {
  position: sticky; left: 0; background: #fff; z-index: 1;
}
.pivot-table thead th.col-day { background: #f7f9fc; }
.pivot-table tbody tr:hover td.col-day { background: #f8fafc; }
.pivot-table tbody tr.subtotal td {
  background: #fff6f2; font-weight: 700; border-top: 2px solid #f2d4c8;
}
.pivot-table tbody tr.subtotal:hover td { background: #fff6f2; }
/* 支払い先の1列目を少し広めに（並べ替えボタン＋カテゴリ選択が入る） */
.pivot-table th.vcol, #vendorPivot td.col-day { min-width: 260px; }
/* カテゴリ見出し行 */
.pivot-table tbody tr.cat-head td {
  background: #eef2f8; font-weight: 700; color: var(--ink);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.pivot-table tbody tr.cat-head:hover td { background: #eef2f8; }
.pivot-table tbody tr.cat-head td.cat-name { background: #eef2f8; }
/* 支払い先の行内コントロール */
.vrow { display: flex; align-items: center; gap: 8px; }
.vmove { display: inline-flex; flex-direction: column; line-height: 0; }
.vmove button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  width: 22px; height: 15px; font-size: 9px; cursor: pointer; padding: 0;
}
.vmove button:first-child { border-radius: 5px 5px 0 0; }
.vmove button:last-child { border-radius: 0 0 5px 5px; margin-top: -1px; }
.vmove button:hover { background: #f4f6fa; color: var(--brand); border-color: var(--brand); }
.vname { flex: 1; }
.vcat {
  border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe;
  font-size: 12px; padding: 3px 6px; color: var(--ink); cursor: pointer;
}
.vcat:focus { outline: none; border-color: var(--brand); }

/* 月別比較テーブル */
.compare-table { font-variant-numeric: tabular-nums; min-width: 1040px; }
.compare-table td, .compare-table th { padding: 11px 10px; }
.compare-table .col-day { text-align: left; font-weight: 600; white-space: nowrap; }
.compare-table tbody tr:hover { background: #f8fafc; }
.compare-table tbody tr.subtotal td {
  background: #fff6f2; font-weight: 700; border-top: 2px solid #f2d4c8;
}
.compare-table tbody tr.subtotal:hover { background: #fff6f2; }

/* ヘッダーのツール（期間セレクタ＋ボタン） */
.head-tools { display: flex; align-items: center; gap: 14px; }

/* 設定 */
.settings-card { max-width: 720px; }
.settings-group { margin-bottom: 18px; }
.settings-label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.settings-help { font-size: 12px; color: var(--muted); margin: 0 0 8px; line-height: 1.6; }
.settings-help code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; background: #fbfcfe;
}
.input:focus { outline: none; border-color: var(--brand); background: #fff; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
.req { color: var(--brand); font-size: 11px; font-weight: 600; margin-left: 4px; }
.soon { color: var(--muted); font-size: 11px; background: #eef1f6; padding: 2px 7px; border-radius: 20px; margin-left: 4px; }
.settings-actions { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.save-msg { font-size: 13px; color: var(--green); }

/* ボタン */
.btn { border: 0; border-radius: 10px; padding: 11px 18px; font-size: 14px; cursor: pointer; font-weight: 600; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-block { width: 100%; }
.btn-outline { background: #fff; border: 1.5px solid var(--brand); color: var(--brand); }
.btn-outline:hover { background: #fff4f0; }

/* マネフォ連携 */
.field-label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.mf-connect-row { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
.mf-status { font-size: 13px; font-weight: 600; color: var(--muted); }
.mf-status.ok { color: var(--green); }
.mf-status.err { color: #b93a22; }
.mf-status.loading { color: var(--blue); }

/* 期間セレクタ */
.period-picker { display: flex; align-items: center; gap: 10px; }
.select {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.select:focus { outline: none; border-color: var(--brand); }
textarea.input { resize: vertical; font-family: inherit; line-height: 1.5; }

/* 状態表示 */
.banner { padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.banner-error { background: #fdecea; color: #b93a22; }
.banner-info { background: #eaf2fd; color: #2b5fa8; }
