:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --panel: #fffdf8;
  --ink: #221e1d;
  --muted: #756967;
  --line: rgba(73, 55, 51, .16);
  --blood: #9f3041;
  --blood-dark: #5f2130;
  --teal: #497b78;
  --amber: #b57b42;
  --band: rgba(73, 123, 120, .11);
  --shadow: 0 18px 45px rgba(53, 42, 38, .08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 78% -10%, rgba(159, 48, 65, .13), transparent 36%),
    linear-gradient(180deg, #f5eee8 0%, var(--bg) 46%, #fbfaf6 100%);
  color: var(--ink);
  font: 15px/1.42 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
}

button {
  font: inherit;
  letter-spacing: 0;
}

.suite-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 8px;
}

.suite-brand-cluster,
.suite-app-brand,
.suite-topbar-actions {
  display: inline-flex;
  align-items: center;
}

.suite-brand-cluster {
  gap: 8px;
  min-width: 0;
}

.suite-ao-home,
.suite-app-brand,
.suite-topbar-actions a {
  text-decoration: none;
}

.suite-ao-home {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
}

.suite-ao-home img {
  display: block;
  width: 38px;
  height: 38px;
}

.suite-app-brand {
  gap: 8px;
  min-width: 0;
  font-size: 15px;
  font-weight: 780;
  text-transform: lowercase;
}

.suite-app-mark {
  width: 32px;
  height: 32px;
}

.suite-topbar-actions {
  gap: 4px;
}

.suite-topbar-actions a {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  color: var(--blood-dark);
}

.readings-icon,
.sync-icon {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
}

.readings-icon {
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.readings-icon::before {
  content: "";
  position: absolute;
  left: 3px;
  bottom: 4px;
  width: 12px;
  height: 8px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: skew(-18deg);
}

.sync-icon {
  border: 2px solid currentColor;
  border-radius: 50%;
}

.sync-icon::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-top: 2px solid currentColor;
  transform: rotate(35deg);
}

.shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 10px 0 48px;
}

.graph-surface,
.readings-section,
.sync-section,
.import-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 94%, white);
  box-shadow: var(--shadow);
}

.graph-surface {
  min-height: calc(100vh - 120px);
  padding: 22px;
}

.surface-head,
.section-head,
.sync-section {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(34px, 6vw, 72px);
  line-height: .96;
  font-weight: 780;
}

h2 {
  font-size: 20px;
  line-height: 1.12;
  font-weight: 760;
}

.surface-head p,
.sync-section p,
.import-section p,
.latest-strip span,
.chart-note,
.section-head span {
  color: var(--muted);
}

.surface-head p,
.sync-section p,
.import-section p {
  max-width: 690px;
  margin-top: 8px;
  font-size: 15px;
  font-weight: 560;
}

#refresh-button,
.range-controls button,
.download-link,
.data-form input,
.data-form select,
.data-form button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf2;
  color: var(--ink);
}

#refresh-button,
.range-controls button,
.data-form button {
  cursor: pointer;
}

#refresh-button {
  min-width: 94px;
  padding: 10px 14px;
  font-weight: 720;
}

.download-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  margin-top: 14px;
  padding: 9px 13px;
  background: var(--blood);
  color: #fffaf2;
  font-weight: 760;
  text-decoration: none;
}

#refresh-button:disabled,
.data-form button:disabled {
  cursor: wait;
  opacity: .68;
}

.latest-strip {
  display: grid;
  grid-template-columns: minmax(128px, .74fr) minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 16px;
  margin: 22px 0 14px;
  padding: 14px;
  border: 1px solid rgba(159, 48, 65, .18);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(159, 48, 65, .08), rgba(73, 123, 120, .05));
}

.latest-strip.is-boundary {
  grid-template-columns: minmax(150px, .8fr) minmax(0, 1.3fr) minmax(0, 1fr);
}

.latest-strip > div {
  min-width: 0;
}

.latest-strip strong,
.latest-strip span,
.latest-strip small {
  display: block;
}

.latest-value {
  display: flex;
  align-items: baseline;
  gap: 7px;
  color: var(--blood-dark);
}

.latest-strip .latest-value span {
  color: inherit;
  font-size: clamp(34px, 7vw, 80px);
  line-height: .86;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.latest-strip.is-boundary .latest-value span {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
}

.latest-value small {
  font-size: 15px;
  font-weight: 760;
}

.latest-strip strong {
  margin-top: 8px;
  font-size: 21px;
  line-height: 1.08;
  font-weight: 780;
}

.latest-strip span {
  margin-top: 5px;
  font-size: 13px;
  font-weight: 650;
}

.range-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.range-controls button {
  min-width: 64px;
  min-height: 36px;
  padding: 7px 12px;
  font-weight: 750;
}

.range-controls button.is-active {
  border-color: color-mix(in srgb, var(--blood) 48%, var(--line));
  background: var(--blood);
  color: #fffaf2;
}

.chart-frame {
  min-height: 430px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf2;
}

.chart {
  min-height: 430px;
}

.glucose-chart {
  display: block;
  width: 100%;
  height: auto;
}

.plot-bg {
  fill: #fffdf8;
}

.reference-band {
  fill: var(--band);
}

.gridline line,
.x-tick line {
  stroke: rgba(34, 30, 29, .12);
  stroke-width: 1;
}

.gridline text,
.x-tick text,
.axis-label {
  fill: rgba(34, 30, 29, .56);
  font-size: 13px;
  font-weight: 700;
}

.gridline text {
  text-anchor: end;
}

.x-tick text {
  text-anchor: middle;
}

.trend-area {
  fill: rgba(159, 48, 65, .08);
}

.trend-line {
  fill: none;
  stroke: var(--blood);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.point {
  fill: #fffaf2;
  stroke: var(--blood-dark);
  stroke-width: 2;
}

.latest-marker circle {
  fill: var(--blood);
  stroke: #fffaf2;
  stroke-width: 3;
}

.latest-marker text {
  fill: var(--blood-dark);
  font-size: 18px;
  font-weight: 800;
}

.chart-boundary {
  display: grid;
  min-height: 430px;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.chart-boundary strong {
  font-size: 24px;
  line-height: 1.1;
}

.chart-boundary p {
  max-width: 560px;
  color: var(--muted);
  font-weight: 620;
}

.chart-note {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 9px;
  font-size: 12px;
  font-weight: 700;
}

.readings-section {
  margin-top: 18px;
  padding: 18px;
}

.section-head {
  margin-bottom: 12px;
}

.section-head span {
  font-size: 13px;
  font-weight: 720;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  background: #fffdf8;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(73, 55, 51, .1);
  text-align: left;
  vertical-align: top;
}

th {
  color: #5d514e;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  font-size: 14px;
  font-weight: 610;
}

td strong {
  color: var(--blood-dark);
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.sync-section {
  margin-top: 18px;
  padding: 18px;
}

.sync-section > div:first-child {
  max-width: 640px;
}

.sync-steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: min(430px, 100%);
}

.sync-steps span {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-left: 3px solid var(--teal);
  background: rgba(73, 123, 120, .08);
  color: #314b49;
  font-size: 13px;
  font-weight: 760;
}

.import-section {
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
  gap: 18px;
  margin-top: 18px;
  padding: 18px;
}

.entry-tools {
  display: grid;
  gap: 14px;
}

.fallback-tools {
  min-width: 0;
}

.fallback-tools summary {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf2;
  color: var(--blood-dark);
  cursor: pointer;
  font-weight: 760;
}

.fallback-tools[open] summary {
  margin-bottom: 14px;
}

.data-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.manual-entry {
  grid-template-columns: minmax(86px, .42fr) minmax(170px, .76fr) minmax(132px, .58fr) minmax(160px, .72fr) auto;
}

.data-form label,
.data-form label span,
.data-form p {
  min-width: 0;
}

.data-form label span {
  display: block;
  margin-bottom: 5px;
  color: #5d514e;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.data-form input,
.data-form select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

.data-form button {
  min-height: 40px;
  padding: 8px 13px;
  background: var(--blood);
  color: #fffaf2;
  font-weight: 760;
}

.data-form p {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 760px) {
  .suite-topbar,
  .shell {
    width: min(100% - 20px, 1180px);
  }

  .suite-topbar {
    padding-top: 12px;
  }

  .suite-topbar-actions {
    display: none;
  }

  .graph-surface {
    min-height: auto;
    padding: 15px;
  }

  .surface-head,
  .sync-section,
  .import-section {
    display: block;
  }

  #refresh-button {
    margin-top: 14px;
  }

  .latest-strip {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .latest-strip.is-boundary {
    grid-template-columns: 1fr;
  }

  .latest-strip strong {
    margin-top: 0;
  }

  .chart-frame,
  .chart {
    min-height: 0;
  }

  .chart-frame {
    overflow: hidden;
  }

  .glucose-chart {
    min-width: 0;
  }

  .chart-note {
    display: block;
  }

  .chart-note span {
    display: block;
  }

  .chart-boundary {
    min-height: 280px;
  }

  table {
    min-width: 0;
    table-layout: fixed;
  }

  th,
  td {
    padding: 10px 9px;
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  th:nth-child(1),
  td:nth-child(1) {
    width: 37%;
  }

  th:nth-child(2),
  td:nth-child(2) {
    width: 19%;
  }

  th:nth-child(3),
  td:nth-child(3),
  th:nth-child(4),
  td:nth-child(4) {
    width: 22%;
  }

  .sync-steps {
    grid-template-columns: 1fr;
    margin-top: 14px;
  }

  .data-form,
  .manual-entry {
    grid-template-columns: 1fr;
    margin-top: 14px;
  }
}
