:root {
  --bg: #14241c;
  --bg2: #1e3528;
  --leaf: #7cb58a;
  --leaf2: #3f7a52;
  --ink: #f4f1ea;
  --muted: #a9b8ac;
  --me: #2c4a39;
  --bot: #eef2ec;
  --bot-ink: #1a2a20;
  --danger: #e08a6b;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse at 20% 0%, #355f45 0%, transparent 50%),
    linear-gradient(180deg, var(--bg), var(--bg2));
}

/* Only one screen visible */
.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  left: 0;
  right: 0;
}
.screen.is-off {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
.screen.is-on {
  display: flex !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* GATE */
.gate {
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b));
}
.gate-box { width: 100%; }
.logo {
  margin: 0;
  font-family: var(--display);
  font-size: 3rem;
  font-weight: 700;
  color: var(--leaf);
  line-height: 1;
}
.gate h1 {
  margin: 10px 0 8px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.45rem;
}
.muted { color: var(--muted); margin: 0; line-height: 1.4; }
.muted.sm { font-size: 0.88rem; margin-top: 2px; }
.weight-edit {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--leaf);
  font: inherit;
  font-weight: 700;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
#subtitle-rest { color: var(--muted); }

.login {
  margin-top: 22px;
  display: grid;
  gap: 10px;
}
.login input, .composer textarea {
  width: 100%;
  border: 1px solid rgba(244,241,234,0.2);
  background: rgba(0,0,0,0.28);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 14px;
  font: inherit;
  font-size: 16px;
  outline: none;
}
.login button, .btn-send {
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--leaf), var(--leaf2));
  color: #0f1a14;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 14px;
}
.err { color: var(--danger); margin-top: 10px; }

/* CHAT */
.chat {
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

.bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
}
.bar-top {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.logo-sm {
  font-family: var(--display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--leaf);
}
.day-label {
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--leaf);
  background: rgba(124, 181, 138, 0.18);
  border: 1px solid rgba(124, 181, 138, 0.35);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
  white-space: nowrap;
  cursor: pointer;
}
.day-label.active {
  background: rgba(124, 181, 138, 0.35);
  color: #e8f5eb;
}
.day-caret {
  opacity: 0.8;
  margin-left: 2px;
}
.day-pick-row {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}
.day-pick-label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.day-pick-label input {
  width: 100%;
  border: 1px solid rgba(244,241,234,0.18);
  background: rgba(0,0,0,0.28);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-size: 16px;
}
.archive-item.is-current {
  border-color: rgba(124, 181, 138, 0.55);
  background: rgba(124, 181, 138, 0.12);
}

.measure-hist-title {
  margin: 18px 0 8px;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
}
.measure-list {
  display: grid;
  gap: 8px;
  padding-bottom: 8px;
}
.measure-item {
  border: 1px solid rgba(244,241,234,0.12);
  background: rgba(0,0,0,0.22);
  border-radius: 14px;
  padding: 12px;
}
.measure-item-main {
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.4;
  margin-bottom: 10px;
}
.measure-item-actions {
  display: flex;
  gap: 8px;
}
.measure-item-actions .chip {
  flex: 1;
  min-height: 40px;
}
.measure-item-actions .chip.danger {
  background: rgba(224, 138, 107, 0.22);
  color: #f0c4b4;
}

.cals-actions {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.chip {
  border: 0;
  background: rgba(244,241,234,0.12);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  min-height: 40px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.chip.active {
  background: rgba(124, 181, 138, 0.35);
  color: #e8f5eb;
}

.feed {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
  font-size: 1.02rem;
}
.msg.md {
  white-space: normal;
}
.msg.md p {
  margin: 0 0 0.55em;
}
.msg.md p:last-child {
  margin-bottom: 0;
}
.msg.md h1,
.msg.md h2,
.msg.md h3 {
  margin: 0 0 0.45em;
  font-family: var(--display);
  font-weight: 700;
  line-height: 1.25;
  color: #163024;
}
.msg.md h1 { font-size: 1.15rem; }
.msg.md h2 { font-size: 1.08rem; }
.msg.md h3 { font-size: 1.02rem; }
.msg.md ul,
.msg.md ol {
  margin: 0.2em 0 0.65em;
  padding-left: 1.15em;
}
.msg.md li {
  margin: 0.2em 0;
}
.msg.md strong {
  font-weight: 700;
  color: #12261c;
}
.msg.md em {
  font-style: italic;
}
.msg.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: rgba(20, 36, 28, 0.08);
  border-radius: 6px;
  padding: 0.1em 0.35em;
}
.msg.system.md h1,
.msg.system.md h2,
.msg.system.md h3,
.msg.system.md strong {
  color: var(--leaf);
}
.msg.me {
  align-self: flex-end;
  background: var(--me);
  border-bottom-right-radius: 6px;
}
.msg.bot {
  align-self: flex-start;
  background: var(--bot);
  color: var(--bot-ink);
  border-bottom-left-radius: 6px;
}
.msg.system {
  align-self: center;
  max-width: 95%;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.composer-wrap {
  flex: 0 0 auto;
  padding: 8px 12px calc(10px + var(--safe-b));
  background: rgba(8, 14, 11, 0.92);
  border-top: 1px solid rgba(244,241,234,0.1);
}
.composer {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 48px;
  gap: 8px;
  align-items: end;
}
.composer textarea {
  min-height: 48px;
  max-height: 110px;
  width: 100%;
  min-width: 0;
  resize: none;
  line-height: 1.35;
  box-sizing: border-box;
}
.btn-ico, .btn-send {
  width: 48px;
  height: 48px;
  min-height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  padding: 0;
  flex-shrink: 0;
}
.btn-ico {
  width: 44px;
  border: 0;
  background: rgba(244,241,234,0.12);
  font-size: 1.15rem;
}
.btn-ico.recording {
  background: rgba(224, 138, 107, 0.35);
  box-shadow: 0 0 0 2px rgba(224, 138, 107, 0.55);
}
.sheet-save:disabled {
  opacity: 0.45;
}
.tip {
  margin: 6px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
}

/* Measurement sheet */
.sheet.is-off {
  display: none !important;
}
.sheet.is-on {
  display: block !important;
  position: fixed;
  inset: 0;
  z-index: 20;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: min(88dvh, 640px);
  overflow-y: auto;
  background: #1a2e23;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(18px + var(--safe-b));
  border-top: 1px solid rgba(244,241,234,0.12);
}
.sheet-panel h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
}
.measure-form {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}
.measure-form label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.measure-form input {
  width: 100%;
  border: 1px solid rgba(244,241,234,0.18);
  background: rgba(0,0,0,0.28);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-size: 16px;
}
.measure-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sheet-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}
.sheet-save {
  flex: 1;
  width: auto;
  height: auto;
  min-height: 48px;
}

.archive-list {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}
.archive-item {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(244,241,234,0.12);
  background: rgba(0,0,0,0.22);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.archive-item strong {
  font-weight: 700;
}
.archive-item span {
  color: var(--muted);
  font-size: 0.86rem;
}
.msg.daysep {
  align-self: center;
  max-width: 95%;
  background: transparent;
  color: var(--leaf);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  padding: 4px 0;
}

.msg.system.collapsible {
  cursor: pointer;
  max-width: 95%;
  text-align: left;
  background: rgba(244,241,234,0.06);
  border: 1px solid rgba(244,241,234,0.1);
  border-radius: 14px;
  padding: 10px 12px;
}
.msg.system .sys-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.92rem;
}
.msg.system .sys-toggle {
  color: var(--leaf);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.msg.system .sys-body {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.9rem;
}
.msg.system.is-collapsed .sys-body {
  display: none;
}
