*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  background: #f0f2f5;
  color: #333;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ヘッダー */
#header {
  background: #1e3a5f;
  color: white;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
}
#header h1 { font-size: 15px; font-weight: 600; white-space: nowrap; }
#header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#file-input { display: none; }

.enc-label { color: rgba(255,255,255,0.75); font-size: 12px; }
select.encoding-sel {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 12px;
  cursor: pointer;
}
select.encoding-sel option { color: #333; background: white; }

.btn {
  padding: 5px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.btn-white { background: white; color: #1e3a5f; }
.btn-white:hover { background: #dde6f0; }

/* レイアウト */
#main { display: flex; flex: 1; overflow: hidden; }

/* 左パネル */
#left-panel {
  width: 264px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid #dde3ea;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #999;
  padding: 0 4px 5px;
}

.quick-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  margin-bottom: 4px;
  border: 1px solid #dde3ea;
  border-radius: 5px;
  cursor: pointer;
  background: white;
  font-size: 12px;
  color: #333;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.quick-btn:hover  { background: #e8f0fe; border-color: #4285f4; color: #1557b0; }
.quick-btn.active { background: #1557b0; color: white; border-color: #1557b0; }
.quick-icon { font-size: 14px; }

.divider { height: 1px; background: #dde3ea; margin: 8px 4px 10px; }

/* フィルターセクション */
.filter-section {
  border: 1px solid #dde3ea;
  border-radius: 5px;
  margin-bottom: 5px;
}
.filter-header {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  cursor: pointer;
  user-select: none;
  border-radius: 5px;
  background: #f8f9fa;
  gap: 4px;
}
.filter-section.open .filter-header {
  border-radius: 5px 5px 0 0;
  border-bottom: 1px solid #dde3ea;
  background: #e8f0fe;
}
.filter-title { font-weight: 600; font-size: 11px; flex: 1; color: #444; }
.filter-badge {
  font-size: 10px;
  background: #1557b0;
  color: white;
  padding: 1px 5px;
  border-radius: 10px;
  display: none;
}
.filter-badge.show { display: inline; }
.filter-chevron {
  font-size: 9px;
  color: #aaa;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.filter-section.open .filter-chevron { transform: rotate(180deg); }

.filter-body { display: none; padding: 5px 7px 7px; }
.filter-section.open .filter-body { display: block; }

.filter-search {
  width: 100%;
  padding: 3px 6px;
  border: 1px solid #dde3ea;
  border-radius: 3px;
  font-size: 11px;
  margin-bottom: 4px;
  outline: none;
}
.filter-search:focus { border-color: #4285f4; }

.filter-actions { display: flex; gap: 8px; padding: 2px 0 4px; }
.link-btn {
  font-size: 11px;
  color: #1557b0;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.filter-items { max-height: 180px; overflow-y: auto; }
.filter-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 1px;
}
.filter-item input[type=checkbox] { cursor: pointer; flex-shrink: 0; accent-color: #1557b0; }
.filter-item label {
  font-size: 11px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.fi-count { font-size: 10px; color: #bbb; flex-shrink: 0; }

/* リサイズハンドル */
#resize-handle {
  width: 10px;
  flex-shrink: 0;
  cursor: col-resize;
  background: #dde3ea;
  transition: background 0.15s;
  position: relative;
  z-index: 10;
}
#resize-handle:hover, #resize-handle.dragging { background: #4285f4; }

/* 右パネル */
#right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  position: relative;
}

/* フィルター中オーバーレイ (右パネルのみ) */
#right-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.65);
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: all;
}
#right-overlay.show { display: flex; }

/* ステータスバー */
#status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  background: white;
  border-bottom: 1px solid #dde3ea;
  font-size: 12px;
  color: #666;
  flex-shrink: 0;
}
.hl { font-weight: 700; color: #1e3a5f; }
#reset-btn {
  font-size: 10px;
  padding: 2px 6px;
  background: #444;
  border: 1px solid #666;
  color: #ccc;
  border-radius: 3px;
  cursor: pointer;
}
#reset-btn:hover { background: #555; color: #fff; }

/* チャート */
#chart-area {
  flex-shrink: 0;
  background: white;
  border-bottom: 1px solid #dde3ea;
  padding: 7px 14px 0;
  height: 150px;
}
#chart-label { font-size: 11px; color: #999; margin-bottom: 2px; }
#chart-svg { width: 100%; height: 128px; display: block; }

/* テーブル */
#table-area { flex: 1; overflow: auto; background: white; }

table { table-layout: fixed; width: max-content; min-width: 100%; border-collapse: collapse; font-size: 12px; }
thead tr { position: sticky; top: 0; z-index: 5; }
th {
  position: relative;
  background: #1e3a5f;
  color: white;
  padding: 0;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  overflow: hidden;
}
.th-inner {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 14px 5px 8px;
  height: 100%;
}
.col-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.col-collapse-btn {
  flex-shrink: 0;
  opacity: 0;
  width: 14px; height: 14px;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 2px;
  cursor: pointer;
  color: white;
  font-size: 9px;
  line-height: 1;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s, background 0.1s;
}
th:hover .col-collapse-btn { opacity: 1; }
.col-collapse-btn:hover { background: rgba(255,255,255,0.4); }
th.col-collapsed { background: #2d4e78; }
th.col-collapsed .th-inner { padding: 0; justify-content: center; }
th.col-collapsed .col-label  { display: none; }
th.col-collapsed .col-resizer { display: none; }
th.col-collapsed .col-collapse-btn {
  opacity: 1;
  width: 100%; height: 100%;
  border-radius: 0;
  background: transparent;
}
td {
  padding: 5px 10px;
  border-bottom: 1px solid #edf0f3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-resizer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 1;
  user-select: none;
}
.col-resizer:hover, .col-resizer.dragging { background: rgba(255,255,255,0.35); }
tr:nth-child(even) td { background: #f8f9fa; }
tr:hover td { background: #dce8fc !important; }

.tag-s {
  display: inline-block;
  padding: 1px 6px;
  background: #e6f4ea;
  color: #137333;
  border-radius: 3px;
  font-weight: 700;
  font-size: 11px;
}
.tag-f {
  display: inline-block;
  padding: 1px 6px;
  background: #fce8e6;
  color: #c5221f;
  border-radius: 3px;
  font-weight: 700;
  font-size: 11px;
}
.row-wknd td { background: #fffde7 !important; }
.row-wknd:hover td { background: #fff8c4 !important; }

/* ページネーション */
#pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 7px;
  background: white;
  border-top: 1px solid #dde3ea;
  flex-shrink: 0;
}
.page-btn {
  padding: 4px 14px;
  border: 1px solid #dde3ea;
  border-radius: 4px;
  cursor: pointer;
  background: white;
  font-size: 12px;
}
.page-btn:hover:not(:disabled) { background: #e8f0fe; border-color: #4285f4; }
.page-btn:disabled { opacity: 0.35; cursor: default; }
#page-info { font-size: 12px; color: #666; min-width: 150px; text-align: center; }

/* 空状態 */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #ccc;
  gap: 10px;
}
#empty-state .ei { font-size: 52px; }
#empty-state p { font-size: 14px; color: #bbb; }

/* ローディング */
#loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.28);
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#loading.show { display: flex; }
.loading-box {
  background: white;
  padding: 28px 44px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #e0e0e0;
  border-top-color: #1557b0;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box p { color: #666; font-size: 13px; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c5cdd4; border-radius: 3px; }
