:root {
  --bg: #f7f8f5;
  --panel: #ffffff;
  --text: #18201f;
  --muted: #69736d;
  --border: #dfe5dd;
  --accent: #0f8b7f;
  --accent-strong: #0a6b62;
  --mint: #dff4ec;
  --amber: #f2b84b;
  --rose: #df6a63;
  --shadow: 0 16px 40px rgba(32, 45, 41, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1.02;
  font-weight: 760;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

.status-pill {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
}

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

.metric,
.panel,
.chart-section,
.history-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.metric.primary {
  background: var(--mint);
  border-color: #c6eadf;
}

.metric span,
.metric small,
.section-head p,
.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  padding: 18px;
}

.panel-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(180px, 1.1fr) minmax(120px, 0.65fr) auto;
  align-items: end;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.form-grid > *,
.settings-grid > * {
  min-width: 0;
}

input,
select {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 139, 127, 0.14);
}

input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
}

.unit-field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.unit-field input {
  border: 0;
  border-radius: 0;
  min-width: 0;
}

.unit-field span {
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.primary-button,
.ghost,
.quick-row button,
.record button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 750;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost,
.quick-row button,
.record button {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.icon-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.quick-row button {
  min-height: 38px;
  padding: 0 12px;
  color: var(--accent-strong);
}

.chart-section,
.history-section {
  padding: 18px;
  margin-bottom: 16px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

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

.line {
  display: block;
  width: 22px;
  height: 3px;
  border-radius: 999px;
}

.line.caffeine {
  background: var(--accent);
}

.line.sleep {
  background: var(--amber);
}

.chart-scroll {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(#fff, #fbfcfa);
}

canvas {
  display: block;
  width: 1800px;
  max-width: none;
  height: 440px;
  touch-action: pan-x;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 112px;
  padding: 9px 10px;
  border: 1px solid rgba(24, 32, 31, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 26px rgba(24, 32, 31, 0.14);
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 120ms ease;
}

.chart-tooltip.visible {
  opacity: 1;
}

.chart-tooltip strong {
  display: block;
  font-size: 18px;
  line-height: 1;
}

.chart-tooltip span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.records {
  display: grid;
  gap: 8px;
}

.record {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.record strong {
  display: block;
  font-size: 15px;
}

.record span {
  color: var(--muted);
  font-size: 13px;
}

.record .dose {
  color: var(--accent-strong);
  font-weight: 800;
}

.record button {
  min-width: 44px;
  padding: 0;
  color: var(--rose);
}

@media (max-width: 900px) {
  .topbar,
  .section-head {
    align-items: start;
    flex-direction: column;
  }

  .metrics,
  .workspace,
  .form-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 108px;
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .panel,
  .chart-section,
  .history-section,
  .metric {
    padding: 14px;
  }

  .record {
    grid-template-columns: 1fr auto;
  }

  .record .dose {
    grid-row: 1;
    grid-column: 2;
  }
}
