
:root {
  --blue: #2563EB; --blue-light: #DBEAFE; --blue-bg: #EFF6FF;
  --green: #059669; --green-light: #D1FAE5; --green-bg: #ECFDF5;
  --purple: #7C3AED; --purple-light: #EDE9FE;
  --pink: #DB2777; --pink-light: #FCE7F3;
  --orange: #D97706; --orange-light: #FEF3C7; --orange-bg: #FFFBEB;
  --red: #DC2626; --red-light: #FEE2E2; --red-bg: #FEF2F2;
  --gray-50: #F8FAFC; --gray-100: #F1F5F9; --gray-200: #E2E8F0; --gray-300: #CBD5E1;
  --gray-400: #94A3B8; --gray-500: #64748B; --gray-600: #475569; --gray-700: #334155; --gray-800: #1E293B; --gray-900: #0F172A;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif; background: #F0F4F8; color: var(--gray-900); line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Loading ── */
#loading { position:fixed; inset:0; background:#F0F4F8; display:flex; align-items:center; justify-content:center; z-index:9999; transition: opacity 0.4s; }
#loading.hide { opacity:0; pointer-events:none; }
.spinner { width:40px; height:40px; border:4px solid var(--gray-200); border-top-color:var(--blue); border-radius:50%; animation:spin 0.7s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
@keyframes fadeUp { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }

/* ── Header ── */
.header { background: linear-gradient(135deg, #0F172A, #1E293B); padding: 0 16px; height: 56px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 12px rgba(0,0,0,0.2); }
.header-left { display: flex; align-items: center; gap: 10px; }
.header-icon { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--blue), var(--purple)); display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.header-title { color: white; font-weight: 700; font-size: 14px; white-space: nowrap; }
.header-link { color:#d9fbe7; border:1px solid rgba(255,255,255,.22); border-radius:9px; padding:6px 10px; font-size:11px; font-weight:700; text-decoration:none; }
.header-link:hover { background:rgba(255,255,255,.1); }

/* ── Controls bar ── */
.controls { background: white; border-bottom: 1px solid var(--gray-200); padding: 8px 16px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; position: sticky; top: 56px; z-index: 90; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.control-group { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.control-label { font-size: 11px; font-weight: 600; color: var(--gray-500); white-space: nowrap; }
select.ctrl { appearance: none; background: var(--gray-50) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 8px center; border: 1px solid var(--gray-200); border-radius: 8px; padding: 6px 26px 6px 8px; font-size: 12px; font-family: inherit; cursor: pointer; color: var(--gray-700); }
select.ctrl:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); }
.period-btn { padding: 5px 10px; border-radius: 7px; border: 1px solid var(--gray-200); background: white; font-size: 11px; font-family: inherit; cursor: pointer; color: var(--gray-600); transition: all 0.15s; white-space: nowrap; }
.period-btn:hover { background: var(--gray-50); }
.period-btn.active { background: var(--blue); color: white; border-color: var(--blue); }
input[type="date"].ctrl { border: 1px solid var(--gray-200); border-radius: 8px; padding: 5px 6px; font-size: 11px; font-family: inherit; color: var(--gray-700); background: var(--gray-50); }
input[type="date"].ctrl:focus { outline: none; border-color: var(--blue); }

/* ── Tab navigation ── */
.tab-bar { display: flex; background: white; border-bottom: 1px solid var(--gray-200); overflow-x: auto; -webkit-overflow-scrolling: touch; position: sticky; top: 56px; z-index: 89; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.tab-bar::-webkit-scrollbar { display: none; }
.tab-item { flex: none; padding: 12px 18px; font-size: 13px; font-weight: 500; color: var(--gray-400); cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.15s; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.tab-item:hover { color: var(--gray-600); }
.tab-item.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 700; }

/* ── Main ── */
.main { max-width: 1200px; margin: 0 auto; padding: 16px 14px 60px; }
.section-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.section-desc { font-size: 12px; color: var(--gray-500); margin-bottom: 14px; line-height: 1.5; }

/* ── Card ── */
.card { background: white; border-radius: var(--radius); padding: 18px; box-shadow: var(--card-shadow); margin-bottom: 14px; animation: fadeUp 0.3s ease; }
.card-head { font-size: 14px; font-weight: 700; color: var(--gray-700); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-help { font-size: 11px; color: var(--gray-400); font-weight: 400; margin-left: 4px; }

/* ── Grid ── */
.g { display: grid; gap: 12px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: 1fr 1fr 1fr; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g21 { grid-template-columns: 2fr 1fr; }

/* ── KPI ── */
.kpi { border-left: 4px solid var(--blue); padding: 16px 18px; position: relative; }
.kpi-emoji { position: absolute; top: 12px; right: 14px; font-size: 24px; opacity: 0.12; }
.kpi-label { font-size: 11px; font-weight: 600; color: var(--gray-500); margin-bottom: 4px; }
.kpi-val { font-size: 28px; font-weight: 800; line-height: 1.1; }
.kpi-sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.kpi-change { margin-top: 5px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 3px; }
.kpi-change.up { color: var(--green); }
.kpi-change.down { color: var(--red); }

/* ── Table ── */
.tw { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; min-width: 400px; }
th, td { text-align: left; padding: 9px 10px; font-size: 13px; }
th { background: var(--gray-50); color: var(--gray-500); font-weight: 600; font-size: 11px; letter-spacing: 0.03em; border-bottom: 2px solid var(--gray-200); white-space: nowrap; }
td { border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
tr:hover td { background: var(--gray-50); }
.mono { font-family: 'SF Mono', 'Menlo', monospace; font-size: 12px; }
.page-link { color: var(--blue); font-weight: 500; display: inline-flex; align-items: center; gap: 3px; }
.page-link::after { content: '↗'; font-size: 10px; }
.page-link:hover { text-decoration: underline; }

/* ── Badge ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge-g { background: var(--green-light); color: var(--green); }
.badge-y { background: var(--orange-light); color: var(--orange); }
.badge-r { background: var(--red-light); color: var(--red); }

/* ── Inline bar ── */
.ibar { height: 6px; background: var(--gray-100); border-radius: 3px; }
.ibar-fill { height: 100%; border-radius: 3px; }

/* ── Funnel ── */
.funnel-s { margin-bottom: 12px; }
.funnel-h { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.funnel-b { height: 28px; background: var(--gray-100); border-radius: 6px; position: relative; overflow: hidden; }
.funnel-f { height: 100%; border-radius: 6px; }
.funnel-p { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 11px; font-weight: 700; }
.journey { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:10px; align-items:stretch; }
.journey-step { position:relative; border:1px solid var(--gray-200); border-radius:12px; padding:14px 12px; background:linear-gradient(180deg,#fff,var(--gray-50)); min-height:130px; }
.journey-step:not(:last-child)::after { content:'→'; position:absolute; right:-17px; top:45%; color:var(--gray-400); font-size:20px; font-weight:800; z-index:2; }
.journey-num { font-size:28px; font-weight:900; line-height:1.1; color:var(--gray-900); }
.journey-label { font-size:13px; font-weight:800; color:var(--gray-700); margin:5px 0 8px; }
.journey-rate { font-size:11px; color:var(--gray-500); line-height:1.6; }
.journey-meter { height:6px; background:var(--gray-200); border-radius:99px; overflow:hidden; margin-top:8px; }
.journey-meter-fill { height:100%; border-radius:99px; }

/* ── Alert ── */
.alert { border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; }
.alert-hi { background: var(--red-bg); border: 1px solid #FCA5A5; }
.alert-md { background: var(--orange-bg); border: 1px solid #FCD34D; }
.alert-lo { background: var(--green-bg); border: 1px solid #86EFAC; }
.alert-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.alert-msg { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 5px; }
.alert-hi .alert-msg { color: #991B1B; } .alert-md .alert-msg { color: #92400E; } .alert-lo .alert-msg { color: #166534; }
.alert-det { font-size: 12px; margin-top: 5px; padding-left: 22px; opacity: 0.85; }
.alert-hi .alert-det { color: #991B1B; } .alert-md .alert-det { color: #92400E; } .alert-lo .alert-det { color: #166534; }

/* ── Proposal ── */
.prop { padding: 16px; margin-bottom: 10px; background: var(--gray-50); border-radius: 10px; border: 1px solid var(--gray-200); }
.prop-title { font-weight: 700; font-size: 14px; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; }
.prop-body { font-size: 13px; color: var(--gray-600); line-height: 1.9; }

/* ── AB Test ── */
.ab { padding: 16px; margin-bottom: 10px; background: var(--blue-bg); border-radius: 10px; border: 1px solid var(--blue-light); }
.ab-title { font-weight: 700; font-size: 14px; color: #1E3A5F; margin-bottom: 8px; }
.ab-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 13px; }
.ab-box { background: white; padding: 10px 12px; border-radius: 8px; }
.ab-label { font-weight: 600; font-size: 11px; color: var(--gray-500); margin-bottom: 3px; }
.ab-meta { margin-top: 8px; font-size: 12px; display: flex; flex-wrap: wrap; gap: 12px; color: var(--gray-600); }

/* ── Campaign bar ── */
.camp { margin-bottom: 10px; }
.camp-h { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.camp-b { height: 8px; background: var(--gray-100); border-radius: 4px; }
.camp-f { height: 100%; border-radius: 4px; }

/* ── Flow ── */
.flow-g { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.flow-col-title { font-size: 12px; font-weight: 700; text-align: center; padding: 6px; border-radius: 8px; margin-bottom: 8px; }
.flow-item { margin-bottom: 5px; }
.flow-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--gray-500); margin-bottom: 2px; }
.flow-row span:last-child { font-weight: 700; }

/* ── Heatmap ── */
.hm-cell { text-align: center !important; font-weight: 700 !important; }

/* ── Site comparison mini cards ── */
.site-mini { border-radius: 10px; padding: 12px 14px; background: white; box-shadow: var(--card-shadow); }
.site-mini-name { font-size: 12px; font-weight: 700; color: var(--gray-500); margin-bottom: 4px; }
.site-mini-stats { display: flex; gap: 12px; font-size: 11px; color: var(--gray-400); flex-wrap: wrap; }
.site-mini-stats strong { color: var(--gray-800); }

/* ── Tooltip / help icon ── */
.help-tip { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: var(--gray-200); color: var(--gray-500); font-size: 10px; font-weight: 700; cursor: help; position: relative; flex-shrink: 0; }
.help-tip:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--gray-800); color: white; padding: 6px 10px; border-radius: 6px; font-size: 11px; font-weight: 400; white-space: nowrap; max-width: 260px; white-space: normal; z-index: 50; margin-bottom: 4px; line-height: 1.4; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

/* ── Chart canvas ── */
.chart-c { position: relative; }
canvas { display: block; width: 100% !important; }

/* ── Signal light KPI backgrounds ── */
.kpi-green { background: linear-gradient(135deg, #F0FDF4 0%, #DCFCE7 100%) !important; border-left-color: #059669 !important; }
.kpi-yellow { background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%) !important; border-left-color: #D97706 !important; }
.kpi-red { background: linear-gradient(135deg, #FEF2F2 0%, #FEE2E2 100%) !important; border-left-color: #DC2626 !important; }
.kpi-face { font-size: 32px; line-height: 1; }
.kpi-summary { font-size: 12px; font-weight: 700; margin-top: 4px; padding: 4px 8px; border-radius: 6px; display: inline-block; }
.kpi-summary-up { background: #DCFCE7; color: #166534; }
.kpi-summary-down { background: #FEE2E2; color: #991B1B; }
.kpi-summary-flat { background: #FEF3C7; color: #92400E; }

/* ── Help modal ── */
.help-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9998; display: flex; align-items: center; justify-content: center; animation: fadeIn 0.2s ease; padding: 16px; }
.help-modal { background: white; border-radius: 16px; padding: 28px 24px; max-width: 420px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,0.2); position: relative; animation: scaleIn 0.2s ease; }
.help-modal-close { position: absolute; top: 12px; right: 14px; background: var(--gray-100); border: none; border-radius: 50%; width: 32px; height: 32px; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--gray-500); }
.help-modal-close:hover { background: var(--gray-200); }
.help-modal-title { font-size: 16px; font-weight: 800; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.help-modal-body { font-size: 14px; line-height: 1.9; color: var(--gray-600); }
.help-modal-example { background: var(--gray-50); border-radius: 10px; padding: 12px 14px; margin-top: 12px; font-size: 13px; color: var(--gray-500); line-height: 1.7; border: 1px dashed var(--gray-200); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* ── Help button (❓これって何？) ── */
.help-btn { display: inline-flex; align-items: center; gap: 3px; background: var(--blue-light); color: var(--blue); border: 1px solid #93C5FD; border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all 0.15s; white-space: nowrap; }
.help-btn:hover { background: #BFDBFE; }

/* ── Action button ── */
.action-btn { display: inline-flex; align-items: center; gap: 4px; background: linear-gradient(135deg, #EDE9FE, #DBEAFE); color: #5B21B6; border: 1px solid #C4B5FD; border-radius: 8px; padding: 6px 12px; font-size: 11px; font-weight: 700; cursor: pointer; font-family: inherit; transition: all 0.15s; margin-top: 6px; }
.action-btn:hover { background: linear-gradient(135deg, #DDD6FE, #BFDBFE); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(124,58,237,0.15); }

/* ── Evidence button (根拠ボタン) ── */
.evidence-btn { display: inline-flex; align-items: center; gap: 3px; background: var(--gray-50); color: var(--gray-500); border: 1px solid var(--gray-200); border-radius: 6px; padding: 2px 8px; font-size: 10px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all 0.15s; white-space: nowrap; }
.evidence-btn:hover { background: var(--gray-100); color: var(--gray-700); }

/* ── Action popup ── */
.action-popup-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9998; display: flex; align-items: center; justify-content: center; animation: fadeIn 0.2s ease; padding: 16px; }
.action-popup { background: white; border-radius: 16px; padding: 28px 24px; max-width: 480px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,0.2); position: relative; animation: scaleIn 0.2s ease; max-height: 80vh; overflow-y: auto; }
.action-popup-close { position: absolute; top: 12px; right: 14px; background: var(--gray-100); border: none; border-radius: 50%; width: 32px; height: 32px; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--gray-500); }
.action-popup-close:hover { background: var(--gray-200); }
.action-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.action-item:last-child { border-bottom: none; }
.action-icon { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; }
.action-text { font-size: 13px; color: var(--gray-700); line-height: 1.7; }
.action-text strong { color: var(--gray-900); }

/* ── Floating help button ── */
.floating-help { position: fixed; bottom: 20px; right: 20px; width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, #2563EB, #7C3AED); color: white; border: none; font-size: 24px; cursor: pointer; box-shadow: 0 4px 16px rgba(37,99,235,0.35); z-index: 500; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.floating-help:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(37,99,235,0.45); }

/* ── Top3 summary ── */
.top3-bar { background: linear-gradient(135deg, #FFFBEB, #FEF3C7); border: 2px solid #FDE68A; border-radius: 14px; padding: 16px 20px; margin-bottom: 16px; }
.top3-title { font-size: 15px; font-weight: 800; color: #92400E; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.top3-items { display: flex; gap: 10px; flex-wrap: wrap; }
.top3-item { flex: 1; min-width: 200px; background: white; border-radius: 10px; padding: 12px; border: 1px solid #FDE68A; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.top3-num { font-size: 20px; font-weight: 800; color: #D97706; margin-right: 6px; }
.top3-text { font-size: 12px; color: var(--gray-700); line-height: 1.6; }

/* ── Footer ── */
.footer { background: var(--gray-800); color: var(--gray-500); text-align: center; padding: 14px; font-size: 11px; }

/* ══ Responsive ══ */
@media (max-width: 900px) {
  .g4 { grid-template-columns: 1fr 1fr; }
  .g3, .g2, .g21 { grid-template-columns: 1fr; }
  .flow-g { grid-template-columns: 1fr; }
  .ab-grid { grid-template-columns: 1fr; }
  #siteCompareGrid { grid-template-columns: 1fr !important; }
  .journey { grid-template-columns:1fr 1fr; }
  .journey-step::after { display:none; }
}
@media (max-width: 600px) {
  .g4 { grid-template-columns: 1fr 1fr; }
  #siteCompareGrid { grid-template-columns: 1fr !important; }
  .header { padding: 0 10px; height: 48px; }
  .header-icon { width: 28px; height: 28px; font-size: 13px; }
  .header-title { font-size: 13px; }
  .main { padding: 10px 8px 40px; }
  .controls { padding: 6px 8px; gap: 4px; top: 48px; }
  .control-group { gap: 3px; }
  .control-label { font-size: 10px; }
  select.ctrl { padding: 5px 22px 5px 6px; font-size: 11px; }
  .period-btn { padding: 4px 7px; font-size: 10px; }
  input[type="date"].ctrl { padding: 4px 4px; font-size: 10px; }
  .tab-bar { top: 48px; }
  .tab-item { padding: 8px 10px; font-size: 11px; gap: 3px; }
  .kpi-val { font-size: 22px; }
  .kpi-label { font-size: 10px; }
  .kpi-face { font-size: 24px; }
  .card { padding: 12px 10px; margin-bottom: 10px; }
  .card-head { font-size: 13px; }
  .section-title { font-size: 15px; }
  .section-desc { font-size: 11px; }
  th, td { padding: 7px 6px; font-size: 11px; }
  th { font-size: 10px; }
  .site-mini { padding: 8px 10px; }
  .site-mini-name { font-size: 11px; }
  .site-mini-stats { font-size: 10px; }
  .prop { padding: 12px; }
  .prop-title { font-size: 13px; }
  .prop-body { font-size: 12px; }
  .alert { padding: 10px 12px; }
  .alert-msg { font-size: 12px; }
  .alert-det { font-size: 11px; }
  .help-btn { font-size: 10px; padding: 1px 5px; }
  .action-btn { font-size: 10px; padding: 4px 8px; }
  .evidence-btn { font-size: 9px; padding: 1px 5px; }
  .top3-items { flex-direction: column; }
  .top3-item { min-width: unset; }
  .floating-help { width: 46px; height: 46px; font-size: 20px; bottom: 14px; right: 14px; }
  .journey { grid-template-columns:1fr; }
}
@media (max-width: 380px) {
  .g4 { grid-template-columns: 1fr; }
  .period-btn { padding: 3px 5px; font-size: 9px; }
  .kpi-val { font-size: 20px; }
  .controls { gap: 3px; }
}
