* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f5f5f5; color: #333; line-height: 1.6; }

header { background: #263238; color: #fff; padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; }
header h1 { font-size: 18px; }
header nav { display: flex; align-items: center; gap: 16px; }
header nav a { color: #80cbc4; font-size: 13px; text-decoration: none; }
header nav a:hover { text-decoration: underline; }

main { max-width: 1400px; margin: 0 auto; padding: 20px; }

section { background: #fff; border-radius: 8px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
h2 { font-size: 16px; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid #1a73e8; }

/* Controls */
.controls { background: #e8f5e9; position: sticky; top: 0; z-index: 100; }
.date-presets { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.date-preset { padding: 4px 12px; border: 1px solid #ddd; border-radius: 16px; background: #fff; font-size: 12px; cursor: pointer; transition: all 0.15s; }
.date-preset:hover { border-color: #1a73e8; color: #1a73e8; }
.date-preset.active { background: #1a73e8; color: #fff; border-color: #1a73e8; }
.control-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.control-row label { font-size: 14px; }
.control-row input[type="date"], .control-row select { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; }

.btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; font-size: 13px; font-weight: 500; background: #e0e0e0; color: #333; transition: background 0.2s; }
.btn:hover { background: #bdbdbd; }
.btn-primary { background: #1a73e8; color: #fff; }
.btn-primary:hover { background: #1565c0; }
.btn-danger { background: #d32f2f; color: #fff; }
.btn-danger:hover { background: #b71c1c; }

.status { margin-top: 10px; font-size: 13px; color: #666; }
.status.error { color: #d32f2f; }
.status.success { color: #2e7d32; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #eee; }
th { background: #fafafa; font-weight: 600; font-size: 13px; color: #666; }
td { font-variant-numeric: tabular-nums; }

/* Tier summary */
#tier-summary-table { min-width: 800px; }
#tier-summary-table tr:hover { background: #f5f9ff; }
#tier-summary-table th { font-size: 12px; white-space: nowrap; }
#tier-summary-table td:first-child { font-weight: 600; }
#tier-summary-section h2 { border-bottom-color: #ff9800; }

/* Page overview */
#page-overview-table { min-width: 900px; }
#page-overview-table tr:hover { background: #f5f9ff; }
#page-overview-table td:first-child { font-size: 13px; word-break: break-all; max-width: 240px; }
#page-overview-table th { font-size: 12px; white-space: nowrap; }
#page-overview-table th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 18px; }
#page-overview-table th.sortable:hover { color: #1a73e8; }
#page-overview-table th.sortable::after { content: '\2195'; position: absolute; right: 2px; top: 50%; transform: translateY(-50%); font-size: 10px; color: #bbb; }
#page-overview-table th.sort-asc::after { content: '\25B2'; color: #1a73e8; }
#page-overview-table th.sort-desc::after { content: '\25BC'; color: #1a73e8; }
.tip-popup { position: fixed; background: #333; color: #fff; font-size: 12px; font-weight: 400; padding: 5px 10px; border-radius: 4px; white-space: nowrap; pointer-events: none; z-index: 9999; }

/* Detail area */
.detail-header { background: #e3f2fd; }
.detail-header h2 { border-bottom-color: #1565c0; }

/* Param filters */
#param-filter-section { background: #fff8e1; }
#param-filter-section h2 { border-bottom-color: #f57c00; }
.param-filter-row { display: flex; flex-wrap: wrap; gap: 12px; }
.param-filter-item { display: flex; flex-direction: column; gap: 2px; }
.param-filter-item label { font-size: 12px; color: #666; font-weight: 600; }
.param-filter-item select { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; min-width: 140px; }
.active-filters { margin-top: 8px; font-size: 12px; color: #e65100; }

/* Funnel */
.funnel-bar-wrap { margin-bottom: 10px; }
.funnel-label { font-size: 13px; margin-bottom: 4px; display: flex; justify-content: space-between; }
.funnel-bar { height: 24px; background: #e3f2fd; border-radius: 4px; overflow: hidden; }
.funnel-bar-fill { height: 100%; background: #1a73e8; border-radius: 4px; transition: width 0.3s; min-width: 2px; }

/* Heatmap */
.heatmap-controls { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.heatmap-controls select { padding: 6px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; min-width: 200px; }
#heatmap-wrapper iframe { width: 100%; height: 600px; border: 1px solid #ddd; border-radius: 4px; }
.click-badge { position: absolute; background: rgba(255, 0, 0, 0.8); color: #fff; font-size: 11px; font-weight: bold; padding: 2px 6px; border-radius: 10px; pointer-events: none; z-index: 10; transform: translate(-50%, -50%); }

/* Raw data */
.raw-controls { margin-bottom: 12px; display: flex; align-items: center; gap: 12px; }
#event-count { font-size: 13px; color: #666; }
.event-card { background: #fafafa; border: 1px solid #eee; border-radius: 4px; padding: 10px; margin-bottom: 8px; font-size: 13px; cursor: pointer; }
.event-card:hover { background: #f0f0f0; }
.event-card .event-header { display: flex; gap: 12px; align-items: center; }
.event-card .event-type { background: #1a73e8; color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 11px; font-weight: 600; }
.event-card .event-type.pv { background: #2e7d32; }
.event-card .event-type.click { background: #e65100; }
.event-card .event-type.exit { background: #d32f2f; }
.event-card .event-type.duration { background: #6a1b9a; }
.event-card .event-type.section_reach { background: #0277bd; }
.event-card .event-type.section_leave { background: #78909c; }
.event-card .event-type.cta_reach { background: #f57c00; }
.event-detail { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid #eee; white-space: pre-wrap; font-family: monospace; font-size: 12px; color: #555; }
.event-detail.open { display: block; }

/* Site summary */
.site-summary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.site-summary-card { background: #f8f9fa; border-radius: 6px; padding: 12px; text-align: center; }
.site-summary-card .label { font-size: 11px; color: #888; margin-bottom: 4px; }
.site-summary-card .value { font-size: 20px; font-weight: 700; color: #333; font-variant-numeric: tabular-nums; }
.site-summary-card .value.highlight { color: #1a73e8; }
.site-summary-card .value.success { color: #2e7d32; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 14px; font-size: 13px; }
.pager button { min-width: 32px; height: 32px; border: 1px solid #ddd; border-radius: 4px; background: #fff; cursor: pointer; font-size: 13px; color: #333; }
.pager button:hover { background: #f0f0f0; }
.pager button.active { background: #1a73e8; color: #fff; border-color: #1a73e8; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager .pager-info { color: #888; font-size: 12px; margin: 0 8px; }

/* Modal dialogs */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.4); z-index: 9998; display: flex; align-items: center; justify-content: center; }
.modal-content { background: #fff; border-radius: 8px; width: 90%; max-width: 600px; box-shadow: 0 4px 20px rgba(0,0,0,.3); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 3px solid #1a73e8; }
.modal-header h3 { font-size: 15px; margin: 0; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: #999; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: #333; }
.modal-body { padding: 20px; }
.hm-modal { width: auto; max-width: 95vw; height: auto; max-height: 90vh; display: flex; flex-direction: column; }
.hm-modal .modal-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
#hm-dlg-wrapper { overflow: auto; display: flex; justify-content: center; flex-shrink: 0; }
#hm-dlg-wrapper iframe { width: 375px; height: 667px; border: 1px solid #ddd; border-radius: 4px; flex-shrink: 0; }
.hm-mode-toggle { display: inline-flex; border: 1px solid #c7cdd4; border-radius: 4px; overflow: hidden; background: #f8f9fa; }
.hm-mode-btn { border: 0; border-right: 1px solid #c7cdd4; padding: 6px 10px; background: transparent; color: #555; font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.hm-mode-btn:last-child { border-right: 0; }
.hm-mode-btn:hover { background: #eef1f4; }
.hm-mode-btn.active { background: #6a1b9a; color: #fff; }
.hm-period-notice { margin: -2px 0 10px; padding: 8px 10px; max-width: 640px; border-left: 3px solid #8e24aa; background: #faf5fb; color: #4a235a; font-size: 12px; line-height: 1.5; }
.hm-period-notice-emphasis { font-weight: 700; }
.hm-mapping-info { margin-left: 10px; color: #555; font-size: 12px; }

/* Section Analytics Sidebar */
.hm-sidebar { width: 300px; flex-shrink: 0; background: #fff; border: 1px solid #ddd; border-left: none; border-radius: 0 4px 4px 0; display: flex; flex-direction: column; overflow: hidden; font-size: 13px; }
.sa-mode-toggle { display: flex; border-bottom: 1px solid #ddd; flex-shrink: 0; background: #fafafa; }
.sa-mode-btn { flex: 1; padding: 8px 4px; border: none; background: transparent; font-family: inherit; font-size: 11px; font-weight: 500; color: #888; cursor: pointer; transition: all 0.15s; position: relative; letter-spacing: 0.02em; }
.sa-mode-btn:hover { color: #333; background: #f0f0f0; }
.sa-mode-btn.active { color: #1a73e8; background: #fff; font-weight: 600; }
.sa-mode-btn.active::after { content: ''; position: absolute; bottom: 0; left: 10%; right: 10%; height: 2px; background: #1a73e8; border-radius: 1px 1px 0 0; }
.sa-content { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
/* Analytics Main: section cards */
.sa-card { border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: background 0.12s; position: relative; }
.sa-card:last-child { border-bottom: none; }
.sa-card:hover { background: #f8f9fa; }
.sa-card.active { background: #e3f2fd; }
.sa-card.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: #1a73e8; }
.sa-card-inner { padding: 10px 14px; }
.sa-header-row { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; }
.sa-section-name { font-weight: 600; font-size: 11px; color: #555; text-transform: uppercase; letter-spacing: 0.04em; }
.sa-section-idx { font-size: 10px; color: #bbb; }
.sa-reach-row { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.sa-reach-num { font-size: 20px; font-weight: 600; color: #1a73e8; line-height: 1; }
.sa-reach-label { font-size: 10px; color: #888; letter-spacing: 0.03em; }
.sa-reach-pct { font-size: 12px; font-weight: 500; color: #888; margin-left: auto; }
.sa-reach-bar { height: 3px; background: #eee; border-radius: 1.5px; margin-bottom: 8px; overflow: hidden; }
.sa-reach-fill { height: 100%; border-radius: 1.5px; background: #1a73e8; transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
/* Flow tree */
.sa-flow { display: flex; flex-direction: column; margin-left: 2px; position: relative; }
.sa-flow::before { content: ''; position: absolute; left: 4px; top: 0; bottom: 0; width: 1px; background: #e0e0e0; }
.sa-flow-row { display: flex; align-items: center; gap: 6px; padding: 2px 0 2px 16px; position: relative; font-size: 11px; }
.sa-flow-row::before { content: ''; position: absolute; left: 4px; top: 50%; width: 8px; height: 1px; }
.sa-flow-action { color: #00897b; }
.sa-flow-action::before { background: #00897b; }
.sa-flow-drop { color: #ef6c00; }
.sa-flow-drop::before { background: #ef6c00; }
.sa-flow-next { color: #546e7a; }
.sa-flow-next::before { background: #b0bec5; }
.sa-flow-icon { flex-shrink: 0; font-size: 10px; width: 14px; text-align: center; }
.sa-flow-num { font-weight: 500; min-width: 24px; }
.sa-flow-pct { font-size: 10px; color: inherit; opacity: 0.7; }
.sa-flow-label { font-size: 10px; opacity: 0.65; margin-left: auto; letter-spacing: 0.02em; }
/* Connector between cards */
.sa-connector { display: flex; align-items: center; justify-content: center; height: 12px; background: #fafafa; position: relative; }
.sa-connector-line { width: 1px; height: 100%; background: #e0e0e0; }
.sa-connector-arrow { position: absolute; bottom: -1px; color: #d0d0d0; font-size: 8px; line-height: 1; }
/* HM Main: focus card */
.sa-focus { display: flex; flex-direction: column; height: 100%; }
.sa-focus-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: #ccc; font-size: 12px; text-align: center; padding: 20px; }
.sa-focus-card { padding: 16px 14px; animation: sa-fadein 0.15s ease; }
@keyframes sa-fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.sa-focus .sa-reach-num { font-size: 28px; }
.sa-minibar { display: flex; height: 18px; border-radius: 3px; overflow: hidden; margin: 8px 0; background: #f5f5f5; }
.sa-minibar-seg { height: 100%; transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.sa-minibar-seg.action { background: #00897b; }
.sa-minibar-seg.drop { background: #ef6c00; }
.sa-minibar-seg.next { background: #b0bec5; }
.sa-minibar-legend { display: flex; gap: 10px; margin-top: 4px; }
.sa-minibar-legend-item { display: flex; align-items: center; gap: 4px; font-size: 10px; color: #888; }
.sa-minibar-legend-dot { width: 6px; height: 6px; border-radius: 1px; flex-shrink: 0; }
.sa-focus-rows { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.sa-focus-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; font-size: 12px; }
.sa-focus-row.action { background: #e0f2f1; color: #00897b; }
.sa-focus-row.drop { background: #fff3e0; color: #ef6c00; }
.sa-focus-row.next { background: #eceff1; color: #546e7a; }
.sa-focus-row-icon { font-size: 12px; width: 16px; text-align: center; }
.sa-focus-row-label { font-size: 11px; }
.sa-focus-row-num { font-weight: 600; font-size: 14px; margin-left: auto; }
.sa-focus-row-pct { font-size: 11px; opacity: 0.75; min-width: 38px; text-align: right; }
.sa-focus-nav { display: flex; justify-content: space-between; padding: 8px 14px; border-top: 1px solid #f0f0f0; margin-top: auto; }
.sa-focus-nav-btn { background: none; border: 1px solid #ddd; border-radius: 4px; padding: 4px 10px; font-size: 11px; font-family: inherit; color: #888; cursor: pointer; transition: all 0.12s; }
.sa-focus-nav-btn:hover { border-color: #1a73e8; color: #1a73e8; background: #e3f2fd; }
.sa-focus-nav-btn:disabled { opacity: 0.3; cursor: default; }
.sa-focus-nav-btn:disabled:hover { border-color: #ddd; color: #888; background: none; }
/* FAQ */
.faq-item { border-bottom: 1px solid #eee; padding: 14px 0; }
.faq-item:last-child { border-bottom: none; }
.faq-q { font-weight: 700; color: #263238; font-size: 14px; margin-bottom: 6px; }
.faq-q::before { content: 'Q. '; color: #1a73e8; }
.faq-a { color: #555; }
.faq-a p { margin: 0 0 6px; }
.faq-a ul { margin: 4px 0 8px 20px; padding: 0; }
.faq-a li { margin-bottom: 4px; }
.faq-a code { background: #f0f0f0; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
/* Custom tooltip */
[data-tooltip] { position: relative; cursor: default; }
[data-tooltip]::after { content: attr(data-tooltip); position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); margin-bottom: 6px; background: #263238; color: #fff; font-size: 11px; font-weight: 400; line-height: 1.4; padding: 5px 10px; border-radius: 4px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity 0.12s; z-index: 100; }
[data-tooltip]:hover::after { opacity: 1; }
.sa-focus-row[data-tooltip]::after, .sa-flow-row[data-tooltip]::after { left: auto; right: 0; transform: none; }
.sa-reach-row[data-tooltip]::after { left: 0; transform: none; }

/* Keyword tooltip */
#kw-criteria-hint { cursor: help; font-size: 13px; }
#kw-tooltip { display: none; position: fixed; z-index: 10000; background: #263238; color: #fff; font-size: 12px; line-height: 1.5; padding: 6px 10px; border-radius: 4px; word-break: break-all; pointer-events: none; }
/* Keyword table layout */
#kw-table { table-layout: fixed; width: 100%; }
#kw-table th:nth-child(1) { width: 30%; }
#kw-table th:nth-child(2) { width: 6%; }
#kw-table th:nth-child(3) { width: 8%; }
#kw-table th:nth-child(4) { width: 9%; }
#kw-table th:nth-child(5) { width: 10%; }
#kw-table th:nth-child(6) { width: 10%; }
#kw-table th:nth-child(7) { width: 7%; }
#kw-table th:nth-child(8) { width: 11%; }
#kw-table td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#kw-table th.kw-sortable { cursor: pointer; user-select: none; position: relative; padding-right: 18px; }
#kw-table th.kw-sortable:hover { color: #1a73e8; }
#kw-table th.kw-sortable::after { content: '\2195'; position: absolute; right: 2px; top: 50%; transform: translateY(-50%); font-size: 10px; color: #bbb; }
#kw-table th.kw-sortable.sort-asc::after { content: '\25B2'; color: #1a73e8; }
#kw-table th.kw-sortable.sort-desc::after { content: '\25BC'; color: #1a73e8; }
/* Keyword conversion badges */
.kw-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; line-height: 1.4; }
.kw-badge-excellent { background: #e8f5e9; color: #2e7d32; }
.kw-badge-good { background: #e3f2fd; color: #1565c0; }
.kw-badge-below { background: #fff8e1; color: #f57f17; }
.kw-badge-poor { background: #ffebee; color: #c62828; }
/* CV rows inside action flow */
.sa-flow-cv-row { display: flex; align-items: center; gap: 4px; color: #e65100; font-size: 12px; margin-top: 2px; width: 100%; }
.sa-flow-cv-row .sa-flow-icon, .sa-flow-cv-row .sa-focus-row-icon { color: #e65100; }
.sa-flow-cv-row .sa-flow-num, .sa-flow-cv-row .sa-focus-row-num { font-weight: bold; }
.sa-flow-cv-row .sa-flow-label, .sa-flow-cv-row .sa-focus-row-label { font-size: 11px; }
/* Section value (HM main / focus mode bottom) */
.sa-section-value { text-align: right; font-size: 11px; color: #78909c; margin-top: 8px; padding: 6px 8px; border-top: 1px solid #e0e0e0; }
.sa-section-value span { display: block; font-size: 16px; font-weight: bold; color: #bf360c; margin-top: 2px; }
/* CV value in focus mode header */
.sa-section-cv-value { font-size: 12px; font-weight: bold; color: #bf360c; margin-left: auto; margin-right: 8px; }
.sa-flow-action { flex-wrap: wrap; }
.sa-focus-row.action { flex-wrap: wrap; }
/* CV filter toggle */
#hm-cv-filter.active { background: #c62828; color: #fff; border-color: #c62828; }
