:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --ink: #1f2937;
  --muted: #718096;
  --panel: #ffffff;
  --line: #dfe4ec;
  --green: #17745f;
  --green-soft: #eaf5f1;
  --blue: #2764a5;
  --amber: #9b6418;
  --red: #b83232;
  --rose-soft: #fbeaea;
  --shadow: 0 16px 48px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  display: grid;
  width: min(100%, 420px);
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0;
  font-size: 2.4rem;
  line-height: 1;
}

.login-error {
  margin: 0;
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 800;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  max-width: 100%;
  padding: 28px clamp(18px, 4vw, 56px) 18px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.5rem);
  font-weight: 760;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.header-actions,
.history-tools,
.section-heading,
.legend {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 10px;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.07);
}

.app-shell {
  display: grid;
  width: 100%;
  max-width: 100%;
  gap: 24px;
  padding: 0 clamp(18px, 4vw, 56px) 44px;
  overflow-x: clip;
}

.app-shell > *,
.summary-band > *,
.content-grid > *,
.metric-grid > * {
  min-width: 0;
}

.summary-band {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) 1.25fr;
  gap: 18px;
  align-items: stretch;
}

.latest-panel,
.metric,
.entry-form,
.trend-panel,
.history-section {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.latest-panel {
  padding: 24px;
}

.reading-line {
  margin: 8px 0 12px;
  font-size: clamp(3rem, 8vw, 6.25rem);
  font-weight: 780;
  line-height: 0.92;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 4px;
  background: #eef1f5;
  color: var(--muted);
  font-weight: 800;
}

.status-normal {
  background: var(--green-soft);
  color: var(--green);
}

.status-elevated,
.status-stage1 {
  background: #fff4dc;
  color: var(--amber);
}

.status-stage2,
.status-severe {
  background: var(--rose-soft);
  color: var(--red);
}

.muted,
.symptom-check p {
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  display: flex;
  min-height: 136px;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.metric strong {
  font-size: clamp(1.55rem, 3vw, 2.45rem);
  line-height: 1;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(0, 1.18fr);
  gap: 24px;
}

.entry-form,
.trend-panel,
.history-section {
  padding: 22px;
}

.section-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h2 {
  margin: 0;
  font-size: 1.16rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfcff;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 116, 95, 0.14);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 16px 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #eef1f5;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 36px;
  place-items: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.segmented input:checked + span {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(31, 41, 55, 0.07);
}

.symptom-check {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid #f0ceca;
  border-radius: 4px;
  background: #fff8f8;
}

.symptom-check label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.symptom-check input {
  width: 18px;
  height: 18px;
}

.symptom-check p {
  margin: 8px 0 0 28px;
  font-size: 0.82rem;
}

.primary-button,
.ghost-button,
.row-button {
  min-height: 42px;
  border-radius: 4px;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  border: 0;
  background: var(--green);
  color: white;
}

.ghost-button,
.row-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.chart-wrap {
  width: 100%;
  aspect-ratio: 2 / 1;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfcff;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.legend {
  justify-content: flex-end;
  gap: 18px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend i {
  display: inline-block;
  width: 22px;
  height: 4px;
  border-radius: 4px;
}

.legend-sys {
  background: var(--blue);
}

.legend-dia {
  background: var(--red);
}

.legend-pulse {
  border: 1px dashed #6a63e8;
  background: transparent;
}

.history-section {
  overflow: hidden;
}

.history-tools {
  gap: 10px;
}

.history-tools input {
  width: min(280px, 42vw);
}

.table-shell {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 10px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
}

.value-cell {
  font-weight: 850;
}

.notes-cell {
  max-width: 320px;
  color: var(--muted);
}

.action-cell {
  white-space: nowrap;
}

.row-button {
  min-width: 38px;
  margin-left: 6px;
}

.empty-state {
  display: grid;
  min-height: 150px;
  place-items: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 4px;
  background: var(--ink);
  color: white;
  opacity: 0;
  transform: translateY(12px);
  transition: 0.2s ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none;
}

@media (max-width: 1280px) {
  .summary-band,
  .content-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
  }

  .metric-grid,
  .field-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-tools {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .history-tools input {
    width: 100%;
  }

  .entry-form,
  .trend-panel,
  .history-section,
  .latest-panel {
    padding: 18px;
  }

  .chart-wrap {
    aspect-ratio: 1.25 / 1;
  }
}
