:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f7f9;
  color: #17202a;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: #f6f7f9;
  color: #17202a;
}
img, svg { max-width: 100%; }
header {
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 18px max(16px, env(safe-area-inset-left));
  background: #111827;
  color: white;
}
header h1 {
  margin: 0 0 6px;
  font-size: clamp(20px, 5vw, 28px);
  line-height: 1.2;
  overflow-wrap: anywhere;
}
header p { margin: 0; color: #cbd5e1; font-size: 13px; line-height: 1.45; }

.ptl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 12px;
  padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
  width: 100%;
}
.panel {
  margin: 0 12px 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.ptl-grid > .panel { margin: 0; }
.ptl-card h2 {
  font-size: clamp(15px, 4vw, 17px);
  line-height: 1.3;
  margin: 0 0 10px;
  overflow-wrap: anywhere;
}

.pie-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 8px;
}
.pie-svg {
  width: 132px;
  height: 132px;
  aspect-ratio: 1;
  flex: 0 0 auto;
}
.pie-label { font-weight: 700; font-size: 10px; fill: #111827; pointer-events: none; }
.pie-svg path, .pie-svg circle { cursor: pointer; outline: none; }
.pie-svg path:hover, .pie-svg circle:hover,
.pie-svg g:focus-visible path, .pie-svg g:focus-visible circle { filter: brightness(.93); }

.legend { font-size: 12px; flex: 1 1 140px; min-width: 0; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  padding: 5px 6px;
  border-radius: 8px;
  line-height: 1.35;
}
.legend-row > span:not(.dot) { min-width: 0; overflow-wrap: anywhere; }
.legend-row b { margin-left: auto; }
.legend-row.clickable { cursor: pointer; }
.legend-row.clickable:hover, .legend-row.clickable:focus-visible { background: #f3f4f6; }
.legend-row.clickable:focus-visible { outline: 2px solid #2563eb; outline-offset: 1px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

/* Popup / modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.modal.hidden { display: none; }
.modal-box {
  background: white;
  border-radius: 14px;
  max-width: 900px;
  width: 100%;
  max-height: min(88vh, 88dvh);
  overflow: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; font-size: clamp(15px, 4vw, 17px); overflow-wrap: anywhere; }
.modal-head button {
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 10px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  cursor: pointer;
  font-size: 20px;
}
.detail-meta { color: #6b7280; font-size: 12px; margin-bottom: 8px; }

.table-wrap {
  overflow: auto;
  max-height: 70vh;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}
table { border-collapse: collapse; width: 100%; font-size: 12px; min-width: 600px; }
th, td {
  border-bottom: 1px solid #eef0f2;
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
}
th { position: sticky; top: 0; background: #f9fafb; z-index: 1; }
tr:hover td { background: #f8fafc; }

/* Small phones */
@media (max-width: 599px) {
  header { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: 14px; }
  .ptl-grid { grid-template-columns: 1fr; gap: 10px; padding: 10px; }
  .panel { padding: 12px; border-radius: 12px; }
  .pie-wrap { flex-direction: column; align-items: stretch; gap: 10px; }
  .pie-svg { width: min(132px, 60vw); height: min(132px, 60vw); margin: 0 auto; }
  .legend { width: 100%; }
  .legend-row { padding: 8px; font-size: 12px; }
  .table-wrap { max-height: none; }
  table { min-width: 560px; }
  .modal { padding: 8px; }
  .modal-box { max-height: 92dvh; padding: 12px; }
}

/* Laptop/desktop */
@media (min-width: 600px) and (max-width: 1023px) {
  .ptl-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
}
@media (min-width: 1024px) {
  .ptl-grid { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; padding: 16px; }
  .panel { margin: 0 16px 16px; padding: 16px; }
  .ptl-grid > .panel { margin: 0; }
}

.toolbar { display: flex; gap: 10px; align-items: center; padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left)); background: rgba(246,247,249,.96); backdrop-filter: blur(8px); }
.toolbar.sticky { position: sticky; top: 0; z-index: 5; border-bottom: 1px solid #e5e7eb; }
.toolbar input { flex: 1; min-width: 0; padding: 11px 12px; border: 1px solid #d1d5db; border-radius: 10px; font-size: 15px; background: white; }
.toolbar button { min-height: 44px; padding: 0 14px; border: 0; border-radius: 10px; background: #111827; color: white; font-weight: 600; cursor: pointer; }
.toolbar button.secondary { background: white; color: #111827; border: 1px solid #d1d5db; }
@media (max-width: 599px) { .toolbar { flex-wrap: wrap; } .toolbar input { flex-basis: 100%; } .toolbar button { flex: 1; } }
