/* ============================================================
   みえるDM v2 顧客ダッシュボード 共通CSS
   version: v1
   GAS版デザイン維持 + CSS変数化 + モバイル対応
   ============================================================ */
:root {
  --c-bg: #eef1f6;
  --c-primary: #1478A5;
  --c-primary-dark: #0F5C84;
  --c-primary-light: #E6F1FB;
  --c-primary-border: #B5D4F4;
  --c-green: #48A868;
  --c-green-dark: #2E7D32;
  --c-text: #333;
  --c-text-light: #64748b;
  --c-text-muted: #94a3b8;
  --c-border: #e5e7eb;
  --c-border-light: #f1f5f9;
  --c-card: #fff;
  --c-error: #dc2626;
  --c-success: #16a34a;
  --c-warning: #f59e0b;
  --c-header-start: #1478A5;
  --c-header-end: #1A9AD5;
  --font-base: 9pt;
  --font-sm: 8pt;
  --font-xs: 7.5pt;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 10px;
  /* スキャン回数ハイライト */
  --c-hi-1: #EAF3DE;
  --c-hi-1-hover: #DCE9CE;
  --c-hi-2: #C0DD97;
  --c-hi-2-hover: #B0D080;
  --c-hi-3: #97C459;
  --c-hi-3-hover: #85B545;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: var(--font-base);
  background: var(--c-bg);
  color: var(--c-text);
}
.container { max-width: 1400px; margin: 0 auto; padding: 16px; }

/* --- ヘッダー --- */
.header {
  background: linear-gradient(135deg, var(--c-header-start) 0%, var(--c-header-end) 100%);
  color: #fff; padding: 10px 20px; margin-bottom: 16px;
  border-radius: var(--radius); display: flex;
  justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-left .logo-box {
  background: #fff; border-radius: var(--radius-sm);
  padding: 3px 8px; display: flex; align-items: center;
}
.header-left .logo-box img { height: 24px; }
.header-right { display: flex; align-items: center; gap: 10px; position: relative; }
.header-btn {
  background: rgba(255,255,255,.15); color: #fff; border: none;
  padding: 6px 14px; border-radius: 4px; cursor: pointer;
  font-size: var(--font-sm); font-family: inherit; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px;
}
.header-btn:hover { background: rgba(255,255,255,.25); }

/* --- ログイン画面 --- */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--c-bg);
}
.login-card {
  width: 380px; background: var(--c-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0,0,0,.08); overflow: hidden;
}
.login-header { padding: 32px 32px 0; text-align: center; }
.login-header img { height: 52px; margin-bottom: 8px; }
.login-header p { font-size: var(--font-base); color: #888; margin-top: 4px; }
.login-body { padding: 20px 32px 32px; }
.login-footer { font-size: var(--font-xs); color: var(--c-text-muted); text-align: center; margin-top: 8px; }

/* --- フォーム --- */
.fg { margin-bottom: 10px; }
.fg label { display: block; font-size: var(--font-sm); font-weight: 500; margin-bottom: 3px; color: #555; }
.fg input {
  width: 100%; padding: 8px 10px; border: 1px solid #ddd;
  border-radius: var(--radius-sm); font-size: var(--font-base); font-family: inherit;
}
.fg input:focus { border-color: var(--c-primary); outline: none; box-shadow: 0 0 0 3px rgba(20,120,165,.12); }

/* --- ボタン --- */
.btn {
  font-family: inherit; font-size: var(--font-base); font-weight: 500;
  border: none; padding: 8px 16px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all .15s;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-dark); }
.btn-ghost { background: transparent; color: #555; border: 1px solid #ddd; }
.btn-ghost:hover:not(:disabled) { background: #f5f5f5; }
.btn-sm { padding: 5px 10px; font-size: var(--font-sm); }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- メッセージ --- */
.error { color: var(--c-error); font-size: var(--font-sm); margin-top: 4px; }
.success { color: var(--c-success); font-size: var(--font-sm); margin-top: 4px; }

/* --- カード --- */
.card {
  background: var(--c-card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid var(--c-border);
}
.card h3 { font-size: 10pt; font-weight: 700; color: var(--c-primary); margin-bottom: 8px; }

/* --- イベントバナー --- */
.ev-banner {
  background: var(--c-primary-light); border: 1px solid var(--c-primary-border);
  border-radius: var(--radius); padding: 10px 16px; margin-bottom: 14px;
}
.ev-banner .ev-bn { font-size: 11pt; font-weight: 700; color: #185FA5; margin: 0; }
.ev-banner .ev-bsub { font-size: var(--font-sm); color: var(--c-text-light); margin: 3px 0 0; }

/* --- セッション警告バー --- */
.session-bar {
  background: #fff3cd; color: #856404; padding: 8px 16px;
  border-radius: 4px; margin-bottom: 10px;
  font-size: var(--font-sm); display: none; text-align: center;
}

/* --- プレビューバナー --- */
.preview-banner {
  display: none; background: var(--c-warning); color: #fff;
  text-align: center; padding: 6px 16px; border-radius: 4px;
  margin-bottom: 8px; font-size: var(--font-base); font-weight: 700;
}

/* --- サマリーカード --- */
.summary-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 100px; background: var(--c-card);
  border-radius: var(--radius); padding: 12px; text-align: center;
  border: 1px solid var(--c-border);
}
.stat-card .num { font-size: 18pt; font-weight: 700; color: var(--c-primary); }
.stat-card .label { font-size: var(--font-sm); color: var(--c-text-muted); margin-top: 2px; }

/* --- タブ --- */
.tab-bar { display: flex; gap: 6px; margin-bottom: 14px; }
.tab-btn {
  padding: 7px 18px; font-size: var(--font-base); font-weight: 500;
  color: var(--c-text-light); cursor: pointer; font-family: inherit;
  background: #f1f5f9; border: 1px solid var(--c-border);
  border-radius: 20px; display: inline-flex; align-items: center;
  gap: 5px; transition: all .15s;
}
.tab-btn.active { color: #fff; background: var(--c-primary); border-color: var(--c-primary); }
.tab-btn:hover:not(.active) { color: var(--c-text); background: #e2e8f0; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* --- コントロール --- */
.controls { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.search-box {
  padding: 6px 10px; border: 1px solid #ddd; border-radius: var(--radius-sm);
  font-size: var(--font-base); width: 200px; font-family: inherit;
}
.search-box:focus { border-color: var(--c-primary); outline: none; }

/* --- テーブル --- */
.tbl-wrap { overflow-x: auto; overflow-y: auto; max-height: 500px; }
table { width: 100%; border-collapse: collapse; font-size: var(--font-sm); table-layout: auto; }
th {
  padding: 7px 8px; text-align: left; background: #f8fafc;
  color: var(--c-text-light); font-weight: 500; font-size: var(--font-sm);
  border-bottom: 2px solid #e2e8f0; cursor: pointer;
  white-space: nowrap; user-select: none; position: sticky; top: 0; z-index: 4;
}
th:hover { background: #eef2f7; }
th .sort-icon { color: #c0c8d4; font-size: 7pt; margin-left: 2px; }
th .sort-icon.active { color: var(--c-primary); }
td {
  padding: 6px 8px; border-bottom: 1px solid var(--c-border-light);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
tr:hover td { background: #eef2f7; }
tr:hover td.fix-col,
tr:hover td.no-col { background: #eef2f7; }

/* スキャン回数ハイライト */
tr.hi-1 { background: var(--c-hi-1); }
tr.hi-2 { background: var(--c-hi-2); }
tr.hi-3 { background: var(--c-hi-3); }
tr.hi-1:hover td,
tr.hi-1:hover td.no-col,
tr.hi-1:hover td.fix-col { background: var(--c-hi-1-hover) !important; }
tr.hi-2:hover td,
tr.hi-2:hover td.no-col,
tr.hi-2:hover td.fix-col { background: var(--c-hi-2-hover) !important; }
tr.hi-3:hover td,
tr.hi-3:hover td.no-col,
tr.hi-3:hover td.fix-col { background: var(--c-hi-3-hover) !important; }

/* 固定列 */
.no-col {
  background: #f8fafc; color: var(--c-text-muted); font-size: var(--font-sm);
  text-align: center; min-width: 36px; max-width: 40px; font-weight: 500;
  border-right: 1px solid var(--c-border-light);
  position: sticky; left: 0; z-index: 5;
}
th.no-col { cursor: default; border-right: 1px solid var(--c-border-light); z-index: 6; background: #f8fafc; }
th.no-col:hover { background: #f8fafc; }
.fix-col { position: sticky; z-index: 5; border-right: 1px solid #e2e8f0; background: #fff; }
th.fix-col { z-index: 6; background: #f8fafc; }
tr.hi-1 .no-col, tr.hi-1 .fix-col { background: var(--c-hi-1) !important; }
tr.hi-2 .no-col, tr.hi-2 .fix-col { background: var(--c-hi-2) !important; }
tr.hi-3 .no-col, tr.hi-3 .fix-col { background: var(--c-hi-3) !important; }

/* 列フィルター */
.filter-input {
  width: 100%; padding: 3px 5px; border: 1px solid #ddd;
  border-radius: 3px; font-size: var(--font-sm); margin-top: 3px; font-family: inherit;
}
.filter-input:focus { border-color: var(--c-primary); outline: none; }

/* --- ページネーション --- */
.pagi {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; font-size: var(--font-sm); color: var(--c-text-light);
  flex-wrap: wrap; gap: 8px;
}
.pagi-btns { display: flex; gap: 3px; }
.pagi-btn {
  padding: 4px 10px; border: 1px solid #ddd; border-radius: 4px;
  background: #fff; font-size: var(--font-sm); cursor: pointer; font-family: inherit;
}
.pagi-btn.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.pagi-btn:hover:not(.active) { background: #f5f5f5; }

/* --- 列設定パネル --- */
.col-panel {
  background: #f8fafc; border: 1px solid var(--c-border);
  border-radius: var(--radius-sm); padding: 10px; margin-bottom: 10px;
  font-size: var(--font-sm);
}
.col-panel summary { cursor: pointer; font-weight: 500; color: var(--c-primary); }
.col-panel .note { color: var(--c-text-muted); font-size: var(--font-xs); margin-top: 4px; }
.col-panel .col-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.col-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 8px; border-radius: 4px; font-size: var(--font-sm);
  border: 1px solid #ddd; background: #fff; cursor: pointer; user-select: none;
}
.col-chip.hidden { opacity: .4; text-decoration: line-through; }
.col-chip .arrows { display: inline-flex; gap: 1px; margin-left: 3px; }
.col-chip .arrows span { cursor: pointer; color: var(--c-text-light); font-size: var(--font-base); line-height: 1; }
.col-chip .arrows span:hover { color: var(--c-primary); }

/* --- チャート --- */
.chart-row { display: flex; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.chart-half { flex: 1; min-width: 260px; }
.chart-full { width: 100%; }
.chart-wrap { position: relative; height: 260px; margin: 8px 0; }
.chart-wrap-sm { position: relative; height: 240px; margin: 8px 0; }
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-scroll-inner { min-width: 600px; position: relative; height: 260px; }
.chart-center { max-width: 600px; margin: 0 auto; }

/* --- イベント選択画面 --- */
.sel-wrap { max-width: 500px; margin: 0 auto; padding: 20px 0; }
.sel-title { font-size: 14pt; font-weight: 500; color: var(--c-text); margin: 0 0 4px; }
.sel-sub { font-size: var(--font-base); color: #888; margin: 0 0 20px; }
.ev-item {
  border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; background: var(--c-card);
  cursor: pointer; display: flex; align-items: center; gap: 12px; transition: all .15s;
}
.ev-item:hover { background: #f8fafc; border-color: var(--c-primary); }
.ev-item.disabled { opacity: .6; cursor: default; }
.ev-item.disabled:hover { background: var(--c-card); border-color: var(--c-border); }
.ev-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-active { background: var(--c-primary); }
.dot-sched { background: #378ADD; }
.dot-closed { background: #888780; }
.ev-body { flex: 1; }
.ev-pj { font-size: 10pt; font-weight: 500; color: var(--c-text); }
.ev-meta { font-size: var(--font-sm); color: var(--c-text-light); margin-top: 2px; }
.ev-msg { font-size: var(--font-sm); color: var(--c-text-muted); margin-top: 2px; font-style: italic; }
.ev-arrow { font-size: 18px; color: #ccc; }

/* --- モーダル --- */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.4); z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-card {
  width: 460px; max-height: 85vh; overflow-y: auto;
  background: var(--c-card); border-radius: var(--radius-lg);
  padding: 24px; box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.modal-card h3 { font-size: 12pt; font-weight: 500; margin: 0; color: var(--c-text); }
.modal-section {
  background: #f8fafc; border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.modal-section h3 { font-size: 10pt; font-weight: 700; color: var(--c-primary); margin: 0 0 10px; }
.modal-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.modal-row label { font-size: var(--font-sm); font-weight: 500; min-width: 100px; }
.modal-row select {
  padding: 4px 8px; font-size: var(--font-sm); border: 1px solid #ddd;
  border-radius: 4px; font-family: inherit;
}

/* --- ローディング --- */
.loading-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(255,255,255,.85); z-index: 9999;
  align-items: center; justify-content: center; flex-direction: column;
}
.loading-spinner {
  width: 36px; height: 36px; border: 3px solid var(--c-border);
  border-top: 3px solid var(--c-primary); border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 12px; font-size: 10pt; color: var(--c-text-light); }

/* --- トースト --- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  padding: 10px 20px; border-radius: var(--radius-sm); font-size: var(--font-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,.15); opacity: 0; transition: all .3s; z-index: 9999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-info { background: var(--c-primary); color: #fff; }
.toast-success { background: var(--c-success); color: #fff; }
.toast-error { background: var(--c-error); color: #fff; }

/* --- 凡例 --- */
.legend {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--font-xs); color: var(--c-text-light);
}
.legend-swatch {
  display: inline-block; width: 14px; height: 14px;
  border: 1px solid #ccc; border-radius: 2px; vertical-align: middle;
}

/* --- レスポンシブ --- */
@media (max-width: 768px) {
  .container { padding: 10px; }
  .header { padding: 8px 12px; }
  .summary-row { gap: 6px; }
  .stat-card { min-width: 70px; padding: 8px; }
  .stat-card .num { font-size: 14pt; }
  .controls { gap: 6px; }
  .search-box { width: 100%; }
  .login-card { width: 95%; max-width: 380px; }
  .modal-card { width: 95%; max-width: 460px; padding: 16px; }
  .sel-wrap { padding: 10px; }
}
