:root {
  --bg: #0a0a0a;
  --card: #1c1c1e;
  --text: #f5f5f7;
  --muted: #8e8e93;
  --line: #2c2c2e;
  --accent: #0a84ff;
  --chip: #2c2c2e;
  --grid: #2c2c2e;
  --danger: #ff453a;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f2f7;
    --card: #ffffff;
    --text: #111111;
    --muted: #8e8e93;
    --line: #e5e5ea;
    --accent: #0a84ff;
    --chip: #f2f2f7;
    --grid: #e5e5ea;
    --danger: #ff453a;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

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

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

.topbar {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: 28px;
  font-weight: 700;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-add {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  line-height: 36px;
}

.topbar-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 12px;
  border: none;
  background: var(--chip);
  color: var(--text);
  font-size: 13px;
  line-height: 32px;
}

.topbar-btn.danger {
  color: var(--danger);
}

.back {
  width: 34px;
  height: 34px;
  border-radius: 17px;
  border: none;
  background: var(--chip);
  color: var(--text);
  font-size: 20px;
  line-height: 34px;
}

.hidden {
  display: none !important;
}

.view {
  display: none;
  padding: 0 16px 24px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.view.active {
  display: block;
}

#viewList.view.active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#viewEdit.view.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#viewList .card {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 14px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--muted);
}

.measurements-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  position: relative;
  cursor: pointer;
}

.list-item:last-child {
  border-bottom: none;
}

.list-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}

body.search-focus .list-footer {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 5.2%;
  transform: translateY(-60%);
  z-index: 6;
}

.filter-panel {
  position: absolute;
  right: 16px;
  bottom: 74px;
  width: 200px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  z-index: 5;
}

.filter-group-title {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 10px 0 6px;
}

.filter-options {
  display: grid;
  gap: 6px;
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.filter-option input {
  accent-color: var(--accent);
}

.search-input {
  flex: 1;
  height: 40px;
  padding: 0 12px;
  line-height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--chip);
  color: var(--text);
}

.search-input::placeholder {
  color: var(--muted);
}

.filter-btn {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  border: none;
  background: var(--chip);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filter-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.item-main {
  display: grid;
  gap: 4px;
}

.item-title {
  font-weight: 600;
  font-size: 16px;
}


.days {
  color: var(--muted);
  font-size: 12px;
  margin-left: 6px;
}

.item-meta {
  color: var(--muted);
  font-size: 13px;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 2;
}

.icon-btn {
  background: var(--chip);
  border: none;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 16px;
}

.icon-btn.delete {
  color: var(--danger);
}

.item-actions .icon-btn:first-child {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  background: transparent;
  border: none;
  color: transparent;
  z-index: 1;
}

.item-actions .icon-btn:nth-child(n+2) {
  position: relative;
  z-index: 3;
}

.empty {
  color: var(--muted);
  padding: 8px 0;
}

.form label {
  display: block;
  margin-top: 12px;
  margin-bottom: 6px;
  color: var(--muted);
}

.form input, select {
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  border: none;
  background: var(--chip);
  color: var(--text);
}

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

.toggle input {
  accent-color: var(--accent);
}

.actions {
  display: flex;
  gap: 12px;
}

.primary, .secondary, .ghost {
  border: none;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  width: 100%;
}

.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.secondary {
  background: var(--chip);
  color: var(--text);
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--line);
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.detail-title {
  font-size: 22px;
}

.stats {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}

.stats-row {
  display: grid;
  gap: 12px;
}

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

.stats-row-mid,
.stats-row-bottom {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
  background: var(--chip);
  padding: 10px;
  border-radius: 12px;
}

.stat-wide {
  grid-column: 1 / -1;
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.stat-value {
  font-size: 16px;
  margin-top: 4px;
}

.field-row-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.field-row-line label {
  color: var(--muted);
  font-size: 13px;
}

.chart-wrap {
  width: 100%;
  min-height: 280px;
  overflow: hidden;
}

#plot {
  width: 100%;
  min-height: 280px;
  max-width: 100%;
}

#plot .svg-container,
#plot .main-svg,
.js-plotly-plot,
.plot-container {
  width: 100% !important;
  max-width: 100% !important;
}

.measurements {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  align-content: start;
}

.measurement-row {
  display: grid;
  grid-template-columns: 80px 40px 40px 20px;
  gap: 8px;
  align-items: center;
  min-width: 220px;
}

.measurement-row input {
  padding: 8px;
  border-radius: 10px;
  border: none;
  background: var(--chip);
  color: var(--text);
  width: 100%;
  min-width: 0;
  font-size: 13px;
  height: 32px;
}

/* iOS date inputs are taller by default; normalize to match other fields */
.measurement-row input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  height: 32px;
  line-height: 32px;
}

.measurement-row input[type="date"]::-webkit-date-and-time-value {
  line-height: 32px;
}

.measurement-row button {
  width: 26px;
  height: 32px;
  border-radius: 10px;
  border: none;
  background: var(--chip);
  color: var(--danger);
  font-size: 16px;
}

@media (max-width: 520px) {
  .measurement-row {
    grid-template-columns: 0.6fr 0.6fr 0.6fr auto;
  }

  .measurement-row button {
    width: 20px;
  }

  .field-row-line {
    flex-direction: column;
    align-items: flex-start;
  }
}
