:root {
  --bg: #0f1c1a;
  --surface: #182b27;
  --text: #eaf2ee;
  --muted: #9db3ac;
  --border: #24382f;
  --header-bg: #16241f;
  --row-alt: #142522;
  --accent: #4f8272;
  --accent-soft: #1f332c;
  --sd-text: #d7b676;
  --low: #ff8080;
  --low-soft: #3a2020;
  --high: #6fbf94;
  --high-soft: #16302a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

/* the site nav (.site-header/.header-row/.brand/nav) comes from
   ../styles.css — this file only adds the data-page-specific toolbar and
   table/report/modal styling below. */
.data-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  padding-bottom: 10px;
}

.data-toolbar {
  max-width: 760px;
  margin: 14px auto 0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.data-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.data-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.refresh-btn {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
}
.refresh-btn-secondary {
  color: var(--muted);
  background: transparent;
  border-color: var(--border);
}
.refresh-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

#meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.refresh-status {
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 1.1em;
}

.reauth-link {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.reauth-link:hover { color: var(--accent); text-decoration: underline; }

/* segmented toggle */
.seg {
  display: flex;
  gap: 4px;
  max-width: 760px;
  margin: 12px auto 0;
  padding: 0 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.seg-btn {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* report */
.report {
  display: none;
  padding: 14px 16px 40px;
  max-width: 640px;
  height: calc(100vh - 150px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.report-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 16px;
}

.report-section {
  margin-bottom: 22px;
}
.report-section h2 {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 7px;
}

.report-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.report-row:last-child { border-bottom: none; }

.report-label {
  flex: 1 1 auto;
  min-width: 0;
}

.report-badge {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.report-badge.high {
  background: var(--high-soft);
  color: var(--high);
}
.report-badge.low {
  background: var(--low-soft);
  color: var(--low);
}

.report-value {
  flex: 0 0 auto;
  min-width: 64px;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.report-date {
  flex: 0 0 auto;
  min-width: 84px;
  text-align: right;
  font-size: 0.72rem;
  color: var(--muted);
}

.report-empty {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  padding: 8px 0;
}

@media (max-width: 480px) {
  .report-row {
    flex-wrap: wrap;
  }
  .report-value, .report-date {
    min-width: 0;
  }
}

/* table */
.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  height: calc(100vh - 150px);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--header-bg);
  color: var(--muted);
  font-weight: 600;
  text-align: right;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th:hover { color: var(--text); }
thead th.txt { text-align: left; }
thead th.sd { color: var(--sd-text); font-style: italic; }
thead th.contrib { background: var(--accent-soft); color: var(--accent); }

tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tbody td.txt { text-align: left; color: var(--muted); }
tbody td.sd { color: var(--sd-text); }
tbody td.contrib { background: var(--accent-soft); font-weight: 700; }
/* estimated: value derived from a chosen-percentile fallback, not real
   recorded data — muted to signal lower confidence, same colour as the Day
   column. */
tbody td.estimated { color: var(--muted); font-weight: 400; }
/* clickable: Sleep Duration cells in the Daily table, opens the sleep
   source popup (Recorded vs. Estimated) on tap. */
tbody td.clickable { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; cursor: pointer; }

tbody tr:nth-child(even) { background: var(--row-alt); }

/* sticky first column (Date) */
th:first-child, td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  font-weight: 600;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
thead th:first-child { z-index: 4; background: var(--header-bg); }
tbody tr:nth-child(even) td:first-child { background: var(--row-alt); }

/* sleep source modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-panel {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modal-header span {
  font-weight: 650;
  font-size: 0.95rem;
}
.modal-close {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
.modal-close:hover { color: var(--text); }
.modal-value {
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 14px;
}
.modal-seg {
  margin-top: 0;
  margin-bottom: 10px;
}
.modal-seg .seg-btn { flex: 1 1 0; text-align: center; }
.modal-seg .seg-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.modal-slider-wrap {
  display: none;
  margin-bottom: 12px;
}
.modal-slider-wrap input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 4px 0 6px;
}
.modal-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--muted);
}
.modal-slider-labels span.active {
  color: var(--accent);
  font-weight: 650;
}
.modal-hint {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

/* password gate */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-panel {
  max-width: 280px;
  width: 100%;
  text-align: center;
}
.auth-panel img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin-bottom: 16px;
}
.auth-panel .auth-label {
  font-size: 0.95rem;
  margin-bottom: 14px;
}
.auth-panel input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}
.auth-panel .auth-error {
  color: var(--low);
  font-size: 0.78rem;
  margin-top: 8px;
  min-height: 1em;
}
.auth-panel button {
  margin-top: 14px;
  width: 100%;
  padding: 10px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
