:root {
  color-scheme: light;
  --paper: #f4f7f4;
  --surface: #ffffff;
  --ink: #182b29;
  --muted: #667772;
  --line: #dce5e0;
  --teal: #08796f;
  --teal-soft: #e4f2ee;
  --coral: #d76549;
  --shadow: 0 12px 36px rgb(25 54 47 / 5%);
  font-family: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image: linear-gradient(rgb(34 76 67 / 2%) 1px, transparent 1px), linear-gradient(90deg, rgb(34 76 67 / 2%) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
}

button { font: inherit; }

.topbar {
  min-height: 64px;
  padding: 0 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.brand-mark {
  width: 29px;
  height: 29px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--ink);
  color: white;
  font-family: Georgia, serif;
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0;
}

.brand-divider { color: var(--coral); }
.topbar-right, .region-label { display: flex; align-items: center; }
.topbar-right { gap: 22px; }

.region-label {
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.refresh-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 5px;
  background: var(--ink);
  color: white;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.refresh-button:hover:not(:disabled) { background: var(--teal); border-color: var(--teal); }
.refresh-button:disabled { opacity: 0.65; cursor: wait; }
.signout-button { min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 650; cursor: pointer; }
.signout-button:hover { border-color: var(--coral); color: var(--coral); }
.avatar-control { position: relative; }
.avatar-button { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; border: 2px solid #fff; border-radius: 50%; background: var(--teal); color: #fff; box-shadow: 0 0 0 1px var(--line); font-size: 13px; font-weight: 750; cursor: pointer; }
.avatar-button:hover, .avatar-button[aria-expanded="true"] { background: var(--ink); box-shadow: 0 0 0 2px var(--teal-soft); }
.profile-popover { position: absolute; z-index: 5; top: calc(100% + 10px); right: 0; width: min(280px, calc(100vw - 28px)); padding: 17px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: var(--shadow); }
.profile-popover .eyebrow { margin-bottom: 4px; }
.profile-popover h2 { margin-bottom: 14px; font-size: 16px; }
.profile-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 650; }
.profile-popover input { width: 100%; min-height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); font: inherit; font-size: 12px; }
.profile-save { width: 100%; min-height: 34px; margin-top: 10px; border: 1px solid var(--teal); border-radius: 4px; background: var(--teal); color: #fff; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.profile-save:disabled { opacity: .6; cursor: wait; }
.profile-status { min-height: 16px; margin: 7px 0 0; color: var(--muted); font-size: 10px; }
.profile-status.error-text { color: var(--coral); }

.dashboard {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 34px 0 28px;
}

.login-section {
  width: min(440px, 100%);
  margin: clamp(24px, 8vh, 76px) auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--teal);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-section h1 { font-size: 23px; }
.login-copy { margin: 12px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login-form { display: grid; gap: 9px; }
.login-form label { margin-top: 5px; color: var(--ink); font-size: 12px; font-weight: 650; }
.login-form input, .login-form select { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink); font: inherit; font-size: 13px; }
.login-form input:focus, .login-form select:focus { border-color: var(--teal); outline: 2px solid var(--teal-soft); }
.login-form .remember-login { display: flex; align-items: center; gap: 9px; min-height: 32px; cursor: pointer; }
.login-form .remember-login input { width: 18px; height: 18px; min-height: 18px; margin: 0; padding: 0; flex: 0 0 18px; accent-color: var(--teal); }
.optional-label { color: var(--muted); font-weight: 400; }
.login-button { min-height: 42px; margin-top: 9px; border: 1px solid var(--ink); border-radius: 5px; background: var(--ink); color: white; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.login-button:hover:not(:disabled) { border-color: var(--teal); background: var(--teal); }
.login-button:disabled { opacity: .65; cursor: wait; }
.login-status { min-height: 18px; margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.login-status.error-text { color: var(--coral); }
.login-footnote { margin: 19px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.6; }
.community-section { margin-top: 30px; padding: 21px 22px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.community-heading { margin-bottom: 15px; }
.community-heading h2 { font-size: 19px; }
.community-status { margin: 0; color: var(--muted); font-size: 11px; }
.community-status.error-text { color: var(--coral); }
.community-intro { margin: 0 0 15px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.community-consent-row { width: min(360px, 100%); margin-top: 10px; }
.community-consent-row label { display: block; margin-bottom: 6px; color: var(--ink); font-size: 11px; font-weight: 700; }
.community-consent-row input[type="text"] { width: 100%; min-height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); font: inherit; font-size: 12px; }
.share-consent { margin-top: 14px; display: flex; align-items: start; gap: 9px; color: var(--muted); font-size: 11px; line-height: 1.55; cursor: pointer; }
.share-consent input { width: 16px; height: 16px; flex: 0 0 16px; margin: 1px 0 0; accent-color: var(--teal); }
.community-actions { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 9px; }
.community-primary { min-height: 35px; padding: 0 12px; border: 1px solid var(--teal); border-radius: 5px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.community-primary { background: var(--teal); color: #fff; }
.community-primary:hover { background: #06675e; }
.community-primary:disabled { opacity: .55; cursor: wait; }
.community-room-header { padding-bottom: 15px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.community-room-header .eyebrow { margin-bottom: 4px; }
.community-room-copy { margin: 0; color: var(--muted); font-size: 12px; }
.community-member-list { margin-top: 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 9px; }
.community-member { min-height: 78px; padding: 12px; border: 1px solid var(--line); border-left: 3px solid var(--member-color, var(--teal)); border-radius: 5px; background: #fff; }
.community-member-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.community-member-name { overflow: hidden; color: var(--ink); font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.community-member-value { color: var(--member-color, var(--teal)); font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 750; white-space: nowrap; }
.community-member-meta { margin-top: 5px; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; }
.community-footer { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 10px; }
.leave-community { min-height: 30px; padding: 0 9px; border: 1px solid #ead2ca; border-radius: 4px; background: #fff; color: var(--coral); font: inherit; font-size: 11px; font-weight: 650; cursor: pointer; }
.leave-community:hover { background: #fbefeb; }

.page-heading, .section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.page-heading { margin-bottom: 24px; }
.eyebrow, .section-label { margin: 0 0 7px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: 0.07em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1, h2 { margin-bottom: 0; color: var(--ink); font-weight: 650; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 20px; line-height: 1.3; }
.updated-label, .table-note { margin: 0; color: var(--muted); font-size: 12px; }

.current-section {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  align-items: center;
  min-height: 194px;
  padding: 24px 30px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.reading-line { display: flex; align-items: baseline; gap: 12px; }
.reading-value { color: var(--ink); font-size: 58px; font-variant-numeric: tabular-nums; font-weight: 620; line-height: 1.05; }
.reading-unit { color: var(--muted); font-size: 15px; font-weight: 600; }
.trend-line { min-height: 22px; margin-top: 10px; display: flex; align-items: center; gap: 9px; color: var(--teal); font-size: 14px; font-weight: 650; }
.trend-indicator { color: var(--teal); font-size: 10px; }

.reading-details {
  margin: 0;
  padding-left: 26px;
  display: grid;
  gap: 15px;
  border-left: 1px solid var(--line);
}

.reading-details div { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.reading-details dt { color: var(--muted); font-size: 12px; }
.reading-details dd { margin: 0; color: var(--ink); font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; }
.history-section, .readings-section { margin-top: 34px; padding-top: 24px; border-top: 1px solid var(--line); }
.section-heading { margin-bottom: 20px; align-items: center; }
.control-groups { display: flex; align-items: center; flex-wrap: wrap; justify-content: end; gap: 10px; }
.chart-tools { display: flex; gap: 4px; }
.chart-tools button { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink); cursor: pointer; }
.chart-tools button:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.chart-tools button:disabled { opacity: .4; cursor: default; }
.chart-tools svg { width: 18px; height: 18px; }
.chart-tools button:focus-visible, #glucose-chart:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

.segmented-control {
  padding: 3px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #e9efeb;
}

.segmented-control button { min-height: 29px; padding: 0 9px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 650; white-space: nowrap; cursor: pointer; }
.segmented-control button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(25 54 47 / 12%); }
.chart-wrap { position: relative; height: 300px; padding: 5px 4px 0 0; }
.chart-wrap canvas { cursor: grab; touch-action: none; }
.chart-wrap canvas:active { cursor: grabbing; }
.chart-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; pointer-events: none; }
.chart-state.is-hidden { display: none; }
.validation-strip { min-height: 45px; margin-top: 8px; padding: 10px 0; display: flex; flex-wrap: wrap; gap: 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.validation-strip strong { margin-left: 5px; color: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums; }
.table-heading { margin-bottom: 14px; }
.table-scroll { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { height: 39px; padding: 0 12px; border-bottom: 1px solid var(--line); font-size: 12px; }
th { height: 34px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: 0.04em; }
td { color: var(--ink); font-variant-numeric: tabular-nums; }
td:first-child, th:first-child { padding-left: 4px; }
.numeric { text-align: right; }
td.numeric { color: var(--teal); font-weight: 700; }
.trend-cell { color: var(--muted); }
.empty-cell { height: 72px; color: var(--muted); text-align: center; }
.page-footer { margin-top: 23px; padding-top: 13px; display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.error-text { color: var(--coral); }

@media (max-width: 760px) {
  .topbar { padding: 0 18px; }
  .topbar-right { gap: 12px; }
  .region-label { font-size: 0; }
  .status-dot { width: 8px; height: 8px; }
  .dashboard { width: min(100% - 32px, 600px); padding-top: 26px; }
  .current-section { grid-template-columns: 1fr; gap: 23px; padding: 22px; }
  .community-section { padding: 17px; }
  .community-consent-row { width: 100%; }
  .community-room-header { align-items: start; flex-direction: column; }
  .community-member-list { grid-template-columns: 1fr; }
  .reading-details { padding: 17px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .section-heading { align-items: start; flex-direction: column; }
  .control-groups { width: 100%; justify-content: start; }
  .segmented-control { max-width: 100%; overflow-x: auto; }
  .chart-wrap { height: 250px; }
}

@media (max-width: 420px) {
  .brand { gap: 7px; font-size: 10px; }
  .brand > span:last-child { white-space: nowrap; }
  .page-heading { align-items: start; flex-direction: column; gap: 8px; }
  .refresh-button { width: 36px; min-height: 34px; padding: 0; overflow: hidden; font-size: 0; }
  .refresh-button::before { content: "↻"; font-size: 20px; }
  .dashboard { width: calc(100% - 24px); }
  .login-section { margin: 26px auto; padding: 21px; }
  .reading-value { font-size: 52px; }
  .control-groups { align-items: start; flex-direction: column; }
  .page-footer { flex-direction: column; }
}