:root {
  --hp-heat-0: var(--bg-tertiary, #2d333b);
  --hp-heat-1: #0e4429;
  --hp-heat-2: #006d32;
  --hp-heat-3: #26a641;
  --hp-heat-4: #39d353;
}
@media (prefers-color-scheme: light) {
  :root {
    --hp-heat-0: #ebedf0;
    --hp-heat-1: #9be9a8;
    --hp-heat-2: #40c463;
    --hp-heat-3: #30a14e;
    --hp-heat-4: #216e39;
  }
}

/* shared */
.hp-hm-wrap,
.hp-dh-wrap,
.hp-hourly-wrap,
.hp-stats-grid,
.hp-table-wrap {
  margin-bottom: 2.5rem;
}
.hp-sec-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}

/* 52-week heatmap */
.hp-hm-wrap   { overflow-x: auto; }
.hp-hm-months { display: flex; align-items: flex-end; margin-bottom: 3px; }
.hp-hm-month  { font-size: .72rem; color: var(--text-secondary); overflow: hidden; white-space: nowrap; flex-shrink: 0; }
.hp-hm-body   { display: flex; }
.hp-hm-days   { display: flex; flex-direction: column; gap: 2px; margin-right: 4px; width: 24px; flex-shrink: 0; }
.hp-hm-day    { font-size: .68rem; color: var(--text-secondary); height: 11px; line-height: 11px; white-space: nowrap; }
.hp-hm-grid   { display: flex; gap: 2px; }
.hp-hm-col    { display: flex; flex-direction: column; gap: 2px; }
.hp-hm-cell   { width: 11px; height: 11px; border-radius: 2px; flex-shrink: 0; cursor: default; }
.hp-hm-legend { display: flex; align-items: center; gap: 3px; margin-top: 8px; font-size: .72rem; color: var(--text-secondary); }
.hp-hm-legend span { margin: 0 2px; }

/* daily heatmap */
.hp-dh-nav       { display: flex; align-items: center; gap: .75rem; margin-bottom: .6rem; flex-wrap: wrap; }
.hp-dh-btn       { padding: .3rem .8rem; border: 1px solid var(--border-primary); border-radius: 4px; background: var(--bg-secondary); color: var(--text-primary); font-size: .82rem; cursor: pointer; }
.hp-dh-btn:disabled                { opacity: .35; cursor: default; }
.hp-dh-btn:not(:disabled):hover    { background: var(--bg-hover); }
.hp-dh-nav-label  { font-size: .85rem; color: var(--text-secondary); }
.hp-dh-grid-wrap  { overflow-x: auto; }
.hp-dh-grid       { display: inline-flex; flex-direction: column; gap: 2px; }
.hp-dh-row        { display: flex; align-items: center; gap: 2px; }
.hp-dh-date-lbl   { width: 88px; font-size: .68rem; color: var(--text-secondary); flex-shrink: 0; white-space: nowrap; }
.hp-dh-hour-lbl   { width: 14px; height: 14px; font-size: .6rem; color: var(--text-secondary); text-align: center; line-height: 14px; flex-shrink: 0; }
.hp-dh-cell       { width: 14px; height: 14px; border-radius: 2px; flex-shrink: 0; cursor: default; }

/* hourly pattern */
.hp-hourly-chart { display: flex; align-items: flex-end; gap: 3px; height: 100px; }
.hp-hourly-col   { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; cursor: default; }
.hp-hourly-bar   { width: 20px; border-radius: 2px 2px 0 0; min-height: 2px; flex-shrink: 0; transition: opacity .1s; }
.hp-hourly-col:hover .hp-hourly-bar { opacity: .75; }
.hp-hourly-lbl   { font-size: .6rem; color: var(--text-secondary); height: 12px; line-height: 12px; }

/* toolbar */
.hp-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
#hp-filter {
  flex: 1;
  min-width: 200px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.88rem;
}
.hp-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.hp-toolbar-right label { white-space: nowrap; }
.hp-toolbar-right select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
}
#hp-last-updated { white-space: nowrap; font-size: 0.78rem; }

/* top stats */
.hp-stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2rem; }
.hp-bar-row    { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; font-size: .82rem; }
.hp-bar-label  { width: 130px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp-bar-track  { flex: 1; height: 12px; background: var(--bg-tertiary, #2d333b); border-radius: 2px; overflow: hidden; }
.hp-bar-fill   { height: 100%; background: var(--hp-heat-3); border-radius: 2px; transition: width .4s ease; }
.hp-bar-count  { width: 36px; text-align: right; flex-shrink: 0; color: var(--text-secondary); font-size: .78rem; }

/* tooltip */
.hp-tt {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  background: var(--bg-secondary, #1c2128);
  border: 1px solid var(--border-primary, #444c56);
  border-radius: 6px;
  padding: .5rem .65rem;
  font-size: .8rem;
  min-width: 140px;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .45);
}
.hp-tt-header { font-weight: 700; margin-bottom: .2rem; white-space: nowrap; }
.hp-tt-count  { color: var(--hp-heat-4); font-size: .88rem; margin-bottom: .3rem; }
.hp-tt-ips    { display: flex; flex-direction: column; gap: 1px; }
.hp-tt-ip     { font-family: monospace; font-size: .75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp-tt-more   { font-style: italic; }
.hp-tt-x      { color: var(--hp-heat-3); margin-left: 3px; }

/* country / org columns */
.hp-country   { white-space: nowrap; }
.hp-org       { font-size: 0.78rem; color: var(--text-secondary); white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.hp-unknown   { color: var(--text-secondary); }

/* org lines inside tooltip */
.hp-tt-orgs   { margin-top: 0.25rem; display: flex; flex-direction: column; gap: 1px; }
.hp-tt-org    { font-size: 0.72rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* hourly chart: always scrollable (24 bars × ~23px overflows small screens) */
.hp-hourly-wrap  { overflow-x: auto; }
.hp-hourly-chart { min-width: max-content; }

/* ── DataTables 2.x theme ────────────────────────────────────────────────── */

/* layout rows (info top-left, length/paging bottom) */
.dt-layout-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.6rem 0;
}
.dt-layout-cell { flex: 0 0 auto; }

/* info text */
.dt-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* length selector */
.dt-length {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.dt-length select {
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.82rem;
  margin: 0 0.25rem;
  cursor: pointer;
}

/* pagination */
.dt-paging { display: flex; align-items: center; gap: 2px; }
button.dt-paging-button {
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1.4;
}
button.dt-paging-button:not(.disabled):hover { background: var(--bg-hover); }
button.dt-paging-button.current {
  background: var(--hp-heat-3);
  border-color: var(--hp-heat-3);
  color: #fff;
  font-weight: 600;
}
button.dt-paging-button.disabled { opacity: 0.35; cursor: default; }

/* sort indicators on th */
table.dataTable thead th.dt-orderable-asc span.dt-column-order,
table.dataTable thead th.dt-orderable-desc span.dt-column-order {
  position: relative;
  display: inline-block;
  width: 1rem;
  height: 0;
  text-indent: -9999px;
  overflow: hidden;
  vertical-align: middle;
  margin-left: 4px;
  user-select: none;
}
table.dataTable thead th.dt-orderable-asc  span.dt-column-order::before,
table.dataTable thead th.dt-orderable-desc span.dt-column-order::before,
table.dataTable thead th.dt-orderable-asc  span.dt-column-order::after,
table.dataTable thead th.dt-orderable-desc span.dt-column-order::after {
  position: absolute;
  display: block;
  text-indent: 0;
  font-size: 0.65em;
  line-height: 8px;
  height: 8px;
  overflow: hidden;
}
table.dataTable thead th.dt-orderable-asc  span.dt-column-order::before,
table.dataTable thead th.dt-orderable-desc span.dt-column-order::before {
  bottom: 0;
  content: "▲";
  color: var(--text-secondary);
  opacity: 0.4;
}
table.dataTable thead th.dt-orderable-asc  span.dt-column-order::after,
table.dataTable thead th.dt-orderable-desc span.dt-column-order::after {
  top: 0;
  content: "▼";
  color: var(--text-secondary);
  opacity: 0.4;
}
table.dataTable thead th.dt-ordering-asc  span.dt-column-order::before { opacity: 1; color: var(--text-primary); }
table.dataTable thead th.dt-ordering-desc span.dt-column-order::after  { opacity: 1; color: var(--text-primary); }

/* column visibility button */
div.dt-buttons { display: flex; gap: 4px; }
button.dt-button {
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1.4;
}
button.dt-button:hover { background: var(--bg-hover); }

/* colvis dropdown panel */
.dt-button-collection {
  position: absolute;
  z-index: 2000;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.dt-button-collection button.dt-button {
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 4px;
  background: transparent;
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
}
.dt-button-collection button.dt-button:hover { background: var(--bg-hover); }
.dt-button-collection button.dt-button.dt-button-active::before {
  content: "✓ ";
  color: var(--hp-heat-3);
  font-weight: 700;
}

/* cursor on sortable headers */
table.dataTable thead th.dt-orderable-asc,
table.dataTable thead th.dt-orderable-desc { cursor: pointer; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* toolbar: stack search + controls vertically */
  .hp-toolbar { flex-direction: column; align-items: stretch; }
  #hp-filter  { min-width: unset; width: 100%; }
  .hp-toolbar-right { justify-content: space-between; }

  /* stats: single column, narrower bar label */
  .hp-stats-grid { grid-template-columns: 1fr; gap: 1.5rem; }
  .hp-bar-label  { width: 90px; }

  /* table: hide ID (#) and Org columns to free up horizontal space */
  .hp-table thead th:nth-child(1),
  .hp-table tbody td:nth-child(1),
  .hp-table thead th:nth-child(5),
  .hp-table tbody td:nth-child(5) { display: none; }
}
