:root {
  --brand: #0f766e;
  --brand-dark: #0b5c56;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --body-fill: #e2e8f0;
  --body-stroke: #94a3b8;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Topbar / bottom nav ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0) 1rem 0.75rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  background: var(--brand);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
}

.view {
  flex: 1;
  padding: 1rem;
  padding-bottom: 5.5rem;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 10;
}

.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.55rem 0;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.7rem;
}

.bottomnav a.active {
  color: var(--brand);
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
}

/* ---------- Forms ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form.inline {
  flex-direction: row;
  gap: 0.5rem;
  align-items: center;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
textarea {
  font-size: 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

.form.inline input {
  flex: 1;
}

textarea {
  resize: vertical;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
}

legend {
  font-weight: 700;
  padding: 0 0.35rem;
  font-size: 0.95rem;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.checkbox-tile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.6rem;
  font-weight: 500;
  font-size: 0.88rem;
  color: var(--text);
}

.checkbox-tile span::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dot-color, var(--brand));
  margin-right: 0.4rem;
}

.checkbox-tile input {
  width: 18px;
  height: 18px;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
}

button.primary,
button.secondary {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

button.primary {
  background: var(--brand);
  color: white;
}

button.primary:active { background: var(--brand-dark); }

button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

button.link-btn {
  background: none;
  border: none;
  color: var(--brand);
  text-decoration: underline;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  align-self: flex-start;
}

.error {
  color: var(--danger);
  font-size: 0.88rem;
  min-height: 1em;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------- Login ---------- */

.login-screen {
  max-width: 380px;
  margin: 10vh auto 0;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-screen h1 {
  text-align: center;
  color: var(--brand);
}

/* ---------- Entry list ---------- */

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.entry-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.entry-actions {
  display: flex;
  gap: 0.25rem;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.badge {
  background: #ecfdf5;
  color: var(--brand-dark);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge.muted-badge {
  background: #f1f5f9;
  color: var(--muted);
}

/* ---------- Body map ---------- */

.bodymap {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bodymap-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.legend-dot {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  background: var(--surface);
  font-size: 0.78rem;
  cursor: pointer;
}

.legend-dot::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot-color);
}

.legend-dot.active {
  border-color: var(--dot-color);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--dot-color) 30%, transparent);
}

.bodymap-view-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.reset-chip {
  margin-left: auto;
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------- Overview: tabs / filter / sort ---------- */

.overview-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.list-controls {
  margin-bottom: 0.6rem;
}

.sort-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.sort-label select {
  font-size: 0.95rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.filter-chip::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-color, transparent);
  margin-right: 0.35rem;
}

/* ---------- Calendar ---------- */

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.calendar-nav strong {
  text-transform: capitalize;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 1rem;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font-size: 0.8rem;
  color: var(--text);
  padding: 0.15rem;
}

.cal-cell.cal-weekday {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
}

.cal-cell.has-entry {
  background: var(--surface);
  border-color: var(--border);
  cursor: pointer;
  font-weight: 600;
}

.cal-cell.today .cal-daynum {
  color: var(--brand);
  text-decoration: underline;
}

.cal-cell.selected {
  border-color: var(--brand);
  background: #ecfdf5;
}

.cal-dots {
  display: flex;
  gap: 2px;
}

.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.cal-selected-heading {
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.bodymap-svg-holder {
  display: flex;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
}

.bodymap-svg {
  width: 100%;
  max-width: 220px;
  touch-action: manipulation;
  cursor: crosshair;
}

/* ---------- Export / Observers ---------- */

.export-panel,
.observers-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.date-range {
  display: flex;
  gap: 0.75rem;
}

.date-range label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.share-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.share-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
