:root {
  --bg: #f7f4ef;
  --panel: #fffdf8;
  --text: #222831;
  --muted: #68707a;
  --line: #d8d0c4;
  --green: #2f7d66;
  --blue: #2f80c7;
  --red: #c24b5a;
  --amber: #d99a2b;
  --teal: #2f8f95;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 12px max(12px, calc((100vw - 1180px) / 2));
  background: rgba(255, 253, 248, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 800;
  font-size: 1.2rem;
}

nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

nav a,
.inline-form a,
button,
.primary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
}

.logout-form {
  margin: 0;
}

.primary {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
  padding: 28px 0;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4rem);
  margin-bottom: 8px;
}

h2 {
  font-size: 1rem;
}

.eyebrow,
.muted,
article span {
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 22px 0;
}

article,
fieldset,
.detail-list,
.recent-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

article {
  padding: 16px;
}

article strong {
  display: block;
  margin-top: 6px;
  font-size: 1.7rem;
}

.stat-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.section-title {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 14px;
}

.section-title h1,
.section-title h2 {
  margin: 0;
}

.title-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.title-actions a,
.section-title > a {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-weight: 650;
}

.auth-panel {
  max-width: 420px;
  margin: 42px auto;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-panel h1 {
  font-size: 2rem;
}

.login-form {
  display: grid;
  gap: 10px;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.message {
  padding: 12px;
  border-radius: 8px;
  background: #e8f4ef;
  border: 1px solid #b8d8cb;
}

.message.error {
  background: #f8e8ea;
  border-color: #e6b6bd;
}

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

fieldset {
  margin: 0;
  padding: 16px;
}

legend {
  padding: 0 6px;
  font-weight: 800;
}

label {
  display: block;
  margin: 10px 0 6px;
  font-weight: 650;
}

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 8px;
}

.choice {
  margin: 0;
}

.choice input {
  position: absolute;
  opacity: 0;
}

.choice span {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f1;
}

.choice input:checked + span {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.choice.empty input:checked + span {
  background: #777;
  border-color: #777;
}

.text-input,
textarea,
select,
.inline-form input,
.config-list input {
  width: 100%;
  min-height: 42px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

.detail-list {
  display: grid;
  margin-bottom: 16px;
}

.detail-list div,
.day-line,
.config-list label {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.detail-list div:last-child,
.day-line:last-child {
  border-bottom: 0;
}

.detail-list span {
  color: var(--muted);
}

.recent-list {
  overflow: hidden;
}

.day-line {
  grid-template-columns: 120px 1fr 1fr 1fr;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.inline-form input,
.inline-form select {
  width: auto;
}

.month-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.month-table {
  min-width: 980px;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  table-layout: fixed;
}

.month-table th,
.month-table td {
  min-width: 44px;
  height: 42px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: center;
  padding: 4px;
}

.month-table th:first-child {
  min-width: 130px;
  width: 130px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);
  text-align: left;
}

.month-table thead th {
  background: #f1ede4;
  vertical-align: middle;
  z-index: 3;
}

.month-table thead th:first-child {
  z-index: 4;
}

.month-table small {
  display: block;
  color: var(--muted);
}

.weekend {
  background: #f2eadc;
}

.week-start {
  border-left: 3px solid #827466;
}

.month-table .hydration {
  color: var(--blue);
}

.month-table .alcohol {
  color: var(--red);
}

.month-table .sleep {
  color: #4b5aa8;
}

.month-table .sport {
  color: var(--green);
}

.month-table .travel {
  color: var(--teal);
}

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.chart-card {
  min-height: 0;
  overflow: hidden;
}

.chart-frame {
  position: relative;
  width: 100%;
  height: 220px;
  max-height: 220px;
  overflow: hidden;
}

.chart-frame canvas {
  display: block;
  width: 100% !important;
  height: 220px !important;
  max-height: 220px !important;
}

.stats-tables {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.config-list {
  display: grid;
  gap: 10px;
  max-width: 620px;
}

.config-list label {
  grid-template-columns: 1fr 90px;
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 720px) {
  .topbar,
  .hero,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar,
  .section-title {
    display: flex;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  nav {
    justify-content: flex-start;
  }

  .title-actions {
    justify-content: stretch;
  }

  .title-actions a,
  .section-title > a {
    width: 100%;
  }

  .day-line,
  .detail-list div {
    grid-template-columns: 1fr;
  }

  .inline-form input,
  .inline-form select,
  .inline-form button,
  .inline-form a {
    width: 100%;
  }

  .month-scroll {
    width: calc(100vw - 24px);
    margin-left: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .month-table {
    min-width: 860px;
    font-size: 0.78rem;
  }

  .month-table th,
  .month-table td {
    min-width: 36px;
    height: 38px;
  }

  .month-table th:first-child {
    position: static;
    width: 112px;
    min-width: 112px;
  }
}

@media print {
  .topbar,
  .inline-form,
  .messages {
    display: none;
  }

  body {
    background: white;
  }

  main {
    width: 100%;
    padding: 0;
  }

  .month-scroll {
    overflow: visible;
    border: 0;
  }

  .month-table {
    min-width: 0;
    font-size: 0.68rem;
  }

  .month-table th,
  .month-table td {
    min-width: 24px;
    height: 24px;
    padding: 2px;
  }
}
