:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --sidebar-w: 300px;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#app { display: flex; min-height: 100vh; }

/* ---------- サイドバー ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}
.sidebar-header { padding: 16px 16px 8px; }
.sidebar-header h1 { font-size: 16px; margin: 0 0 12px; }
.client-search { padding: 0 16px 8px; }
.client-search input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px;
}
.client-list { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.client-list li {
  padding: 10px 10px; border-radius: var(--radius); cursor: pointer; margin-bottom: 2px;
}
.client-list li:hover { background: #eef2ff; }
.client-list li.active { background: var(--primary); color: #fff; }
.client-list li .cl-name { font-weight: 600; font-size: 13.5px; }
.client-list li .cl-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.client-list li.active .cl-sub { color: #dbe4ff; }
/* 休止/終了はopacityだけに頼らずテキストラベル(.cl-status)で明示する（コントラスト比確保） */
.client-list li .cl-status { font-size: 10.5px; font-weight: 700; margin-left: 6px; }
.client-list li.status-paused .cl-status { color: var(--warn); }
.client-list li.status-ended .cl-status { color: var(--text-muted); }

/* ---------- メイン ---------- */
.main { flex: 1; padding: 24px 32px; min-width: 0; }
.empty-state { color: var(--text-muted); padding: 60px 0; text-align: center; }
.hidden { display: none !important; }

.detail-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px;
}
.detail-header h2 { margin: 0 0 4px; font-size: 22px; }
.detail-meta { color: var(--text-muted); font-size: 12.5px; line-height: 1.7; }
.detail-actions { display: flex; gap: 8px; }

.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border);
  margin-bottom: 20px; flex-wrap: wrap;
}
.tab-btn {
  background: none; border: none; padding: 10px 14px; cursor: pointer;
  font-size: 13.5px; color: var(--text-muted); border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-btn:hover { color: var(--text); }

.tab-panel { animation: fadein .12s ease-in; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 共通パーツ ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: var(--radius); cursor: pointer; font-size: 13px;
}
.btn:hover { background: #f5f6f8; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; }
tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.form-grid.single { grid-template-columns: 1fr; }
.form-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
  font-family: inherit;
}
.form-field textarea { resize: vertical; min-height: 60px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-bad { background: #fee2e2; color: #991b1b; }
.badge-muted { background: #eef0f3; color: var(--text-muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat-box { background: #fafbfc; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat-box .stat-label { font-size: 11.5px; color: var(--text-muted); }
.stat-box .stat-value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat-box .stat-delta { font-size: 12px; margin-top: 2px; }
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }

.icon-btn { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 13px; }
.icon-btn:hover { color: var(--danger); }

/* ---------- モーダル ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto; z-index: 50;
}
.modal {
  background: #fff; border-radius: 10px; padding: 22px 24px; width: 100%; max-width: 560px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 16px; }

/* ---------- ヒートマップ ---------- */
.heatmap-table td.rank-cell { text-align: center; font-weight: 700; color: #fff; border-radius: 4px; }

/* ---------- レポート ---------- */
.report-view { background: #fff; border: 1px solid var(--border); padding: 32px; border-radius: var(--radius); }
.report-view h2 { border-bottom: 3px solid var(--primary); padding-bottom: 8px; }
.report-section { margin: 22px 0; }
.report-section h4 {
  background: #eef2ff; color: var(--primary-dark); padding: 6px 10px; border-radius: 4px; font-size: 13px;
}
@media print {
  .sidebar, .tabs, .detail-actions, .report-controls, #btn-print-report { display: none !important; }
  .main { padding: 0; }
  .report-view { border: none; padding: 0; }
  /* 背景色付きセル(ヒートマップ/バッジ)がブラウザの既定設定で印刷時に消えるのを防ぐ */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.review-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.review-item .stars { color: #f59e0b; letter-spacing: 1px; }
.review-item .reply-box { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.template-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.template-pick button { font-size: 11.5px; }

/* ---------- SP幅対応（サイドバー固定幅による横崩れを防ぐ） ---------- */
@media (max-width: 768px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    max-height: 40vh;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main { padding: 16px; }
  .detail-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .detail-actions { justify-content: flex-end; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab-btn { flex-shrink: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; margin: 0 8px; }
  .report-view { padding: 16px; }
}

.section-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* ---------- サーバー版で追加: ログアウトリンク・ログイン画面 ---------- */
.sidebar-footer { padding: 8px 16px 16px; border-top: 1px solid var(--border); margin-top: auto; }
.sidebar-footer .btn { display: inline-block; text-decoration: none; width: 100%; text-align: center; }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.auth-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 320px; max-width: calc(100vw - 32px);
}
.auth-card h1 { font-size: 18px; margin: 0 0 20px; text-align: center; }
.auth-card label { display: block; font-size: 13px; margin: 12px 0 4px; }
.auth-card input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px;
}
.auth-card .btn-primary { width: 100%; margin-top: 18px; padding: 9px 14px; }
.auth-error { color: var(--danger); font-size: 12.5px; margin: 12px 0 0; text-align: center; }
.muted { color: var(--text-muted); font-size: 12.5px; }
