/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-growing-bg: #d4edda;
  --color-growing-border: #28a745;
  --color-at-risk-bg: #f8d7da;
  --color-at-risk-border: #dc3545;
  --color-middle-bg: #f8f9fa;
  --color-middle-border: #adb5bd;
  --color-header-bg: #343a40;
  --color-header-fg: #fff;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 6px;
}

body {
  font-family: var(--font);
  background: #f0f2f5;
  color: #212529;
  min-height: 100vh;
}

/* ===== Header ===== */
header {
  background: var(--color-header-bg);
  color: var(--color-header-fg);
  padding: 1.25rem 1rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

header p {
  font-size: 0.8rem;
  opacity: 0.7;
}

/* ===== Main container ===== */
main {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

/* ===== Controls ===== */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.search-wrap {
  position: relative;
  flex: 1 1 220px;
}

.search-wrap svg {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  opacity: 0.45;
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2rem;
  border: 1px solid #ced4da;
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: #fff;
}

#search:focus { outline: none; border-color: #495057; box-shadow: 0 0 0 2px rgba(73,80,87,.2); }

.filter-tabs {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.filter-tabs button {
  padding: 0.4rem 0.9rem;
  border: 1px solid #ced4da;
  border-radius: 999px;
  background: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.filter-tabs button:hover { background: #e9ecef; }
.filter-tabs button.active { background: #343a40; color: #fff; border-color: #343a40; }
.filter-tabs button.active.tab-growing { background: #28a745; border-color: #28a745; }
.filter-tabs button.active.tab-at_risk { background: #dc3545; border-color: #dc3545; }
.filter-tabs button.active.tab-middle  { background: #6c757d; border-color: #6c757d; }

.actions {
  margin-left: auto;
}

#csv-btn {
  padding: 0.45rem 1rem;
  background: #495057;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#csv-btn:hover { background: #343a40; }

/* ===== Summary bar ===== */
.summary {
  font-size: 0.82rem;
  color: #6c757d;
  margin-bottom: 0.6rem;
}

/* ===== Table wrapper ===== */
.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead th {
  background: var(--color-header-bg);
  color: var(--color-header-fg);
  padding: 0.65rem 0.9rem;
  text-align: left;
  white-space: nowrap;
  user-select: none;
}

thead th.sortable { cursor: pointer; }
thead th.sortable:hover { background: #495057; }

thead th .sort-icon { margin-left: 0.3rem; font-size: 0.75em; opacity: 0.5; }
thead th.asc .sort-icon::after  { content: '▲'; opacity: 1; }
thead th.desc .sort-icon::after { content: '▼'; opacity: 1; }
thead th:not(.asc):not(.desc) .sort-icon::after { content: '⇅'; }

tbody tr {
  border-bottom: 1px solid #dee2e6;
  transition: filter 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { filter: brightness(0.96); }

/* ===== Row colors by category ===== */
tr.growing { background: var(--color-growing-bg); }
tr.at_risk  { background: var(--color-at-risk-bg); }
tr.middle   { background: var(--color-middle-bg); }

td {
  padding: 0.55rem 0.9rem;
  vertical-align: middle;
}

/* ===== Info box ===== */
.info-box {
  background: #f8f9fa;
  border-left: 4px solid #6c757d;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.2rem;
  font-size: 0.87rem;
  color: #495057;
}

.info-box-title {
  font-weight: 700;
  font-size: 0.85rem;
  color: #343a40;
  margin-bottom: 0.4rem;
  letter-spacing: 0.02em;
}

.info-box-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.info-box-list li::before {
  content: '–';
  margin-right: 0.4rem;
  color: #adb5bd;
}

/* ===== Column header tooltip hint ===== */
.th-label { cursor: default; }
.th-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  font-size: 0.65rem;
  font-weight: 700;
  vertical-align: middle;
  margin-left: 2px;
  opacity: 0.8;
}

/* ===== Category dot ===== */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.dot-growing { background: #28a745; }
.dot-at_risk  { background: #dc3545; }
.dot-middle   { background: #adb5bd; }

/* ===== Name cell ===== */
.name-cell .name-ja { font-weight: 500; }
.name-cell .name-en { display: block; font-size: 0.78rem; color: #6c757d; margin-top: 1px; padding-left: 14px; }

a.occ-link { color: inherit; text-decoration: none; border-bottom: 1px dotted currentColor; }
a.occ-link:hover { border-bottom-style: solid; }

/* ===== BLS growth cell ===== */
.bls-positive { color: #1a7a36; font-weight: 600; }
.bls-negative { color: #b02a37; font-weight: 600; }
.bls-zero     { color: #495057; }

/* ===== AI score bar ===== */
.ai-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-bar-bg {
  width: 60px;
  height: 7px;
  background: #dee2e6;
  border-radius: 999px;
  flex-shrink: 0;
}

.ai-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: #6c757d;
}

.ai-bar-fill.high { background: #dc3545; }
.ai-bar-fill.mid  { background: #fd7e14; }
.ai-bar-fill.low  { background: #28a745; }

/* ===== Category badge ===== */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.badge-growing { background: #c3e6cb; color: #155724; border-color: #b1dfbb; }
.badge-at_risk  { background: #f5c6cb; color: #721c24; border-color: #f1b0b7; }
.badge-middle   { background: #e2e3e5; color: #383d41; border-color: #d6d8db; }

/* ===== No results ===== */
#no-results {
  text-align: center;
  padding: 2.5rem;
  color: #6c757d;
  font-size: 0.95rem;
  display: none;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  font-size: 0.78rem;
  color: #6c757d;
  padding: 1.5rem 1rem 2rem;
}

footer a { color: #6c757d; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  header h1 { font-size: 1.05rem; }
  .controls { gap: 0.5rem; }
  .actions { margin-left: 0; width: 100%; }
  #csv-btn { width: 100%; justify-content: center; }
  .ai-bar-bg { display: none; }
  th:last-child, td:last-child { display: none; }
}
