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

body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', system-ui, sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1565c0 0%, #1e88e5 100%);
  color: #fff;
  padding: 22px 32px;
  box-shadow: 0 2px 10px rgba(0,0,0,.22);
}
header h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: .03em; }
header .subtitle { font-size: .9rem; opacity: .85; margin-top: 5px; }

/* ===== Main ===== */
main { padding: 24px 16px; }

/* ===== Table Section ===== */
.table-section {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 14px rgba(0,0,0,.09);
  overflow: hidden;
}

.table-wrapper {
  overflow-x: auto;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

/* ===== Loading / Error ===== */
#loading {
  text-align: center;
  padding: 56px 24px;
  color: #777;
  font-size: 1.05rem;
}
.error-msg {
  color: #b71c1c;
  background: #ffebee;
  border-left: 4px solid #e53935;
  padding: 14px 20px;
  margin: 16px;
  border-radius: 4px;
  font-size: .95rem;
}

/* ===== Table ===== */
table {
  border-collapse: collapse;
  width: 100%;
  min-width: max-content;
  font-size: .91rem;
}

/* Sticky header rows */
thead th, thead td {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1565c0;
  color: #fff;
  padding: 10px 16px;
  text-align: center;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,.18);
  border-bottom: none;
}

/* 2nd row: units */
thead .unit-row td {
  top: 41px; /* height of header row */
  background: #1976d2;
  font-size: .78rem;
  color: rgba(255,255,255,.88);
  padding: 5px 16px;
}

/* 3rd row: reference range */
thead .ref-row td {
  top: 67px; /* header + units */
  background: #1e88e5;
  font-size: .78rem;
  color: rgba(255,255,255,.88);
  padding: 5px 16px;
}

thead .unit-row td.row-label,
thead .ref-row td.row-label {
  font-weight: 600;
  color: #fff;
}

/* Sticky date column */
.date-col {
  position: sticky !important;
  left: 0;
  z-index: 3 !important;
  background: #1565c0 !important;
  text-align: left !important;
  min-width: 108px;
  font-weight: 600;
  border-right: 2px solid rgba(255,255,255,.3) !important;
}

tbody .date-col {
  background: #f5f5f5 !important;
  color: #333;
  border-right: 2px solid #ddd !important;
}

/* Clickable item headers */
.item-header {
  cursor: pointer;
  transition: background .15s;
  min-width: 78px;
}
.item-header:hover { background: #0d47a1 !important; }
.item-header::after { content: ' 📈'; font-size: .72rem; opacity: .75; }

/* Body rows */
tbody tr { border-bottom: 1px solid #e8e8e8; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #e3f2fd; }
tbody tr:hover .date-col { background: #e3f2fd !important; }

tbody td {
  padding: 7px 16px;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Value states */
.out-range {
  color: #b71c1c;
  font-weight: 700;
  background: rgba(244, 67, 54, .08);
}
.in-range { color: #2e7d32; }
.no-value { color: #bbb; }

/* ===== Modal ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.52);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.open { display: flex; }

.modal-content {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 48px rgba(0,0,0,.28);
  width: min(940px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp .18s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 1.2rem; color: #1565c0; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.9rem;
  line-height: 1;
  cursor: pointer;
  color: #888;
  padding: 0 6px;
  transition: color .15s;
}
.modal-close:hover { color: #333; }

.chart-container {
  padding: 20px 24px 24px;
  flex: 1;
  min-height: 360px;
  position: relative;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  header { padding: 14px 16px; }
  header h1 { font-size: 1.3rem; }
  main { padding: 12px 8px; }
  .chart-container { min-height: 260px; padding: 14px; }
}
