*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #faf7f2;
  --bg-card: #ffffff;
  --accent: #2f6f5e;
  --accent-strong: #1f5646;
  --accent-soft: rgba(47, 111, 94, 0.1);
  --danger: #c94f4f;
  --text-main: #24211d;
  --text-muted: #6b6558;
  --border-subtle: rgba(36, 33, 29, 0.14);
  --shadow-soft: 0 8px 24px rgba(36, 33, 29, 0.1);
  --radius-lg: 18px;
  --radius-md: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --bg-card: #262320;
    --accent: #6fbfa4;
    --accent-strong: #8fd4bc;
    --accent-soft: rgba(111, 191, 164, 0.16);
    --text-main: #f3f1ec;
    --text-muted: #b8b2a5;
    --border-subtle: rgba(243, 241, 236, 0.16);
    --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-main);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 17px;
}

button, input, textarea {
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.header {
  text-align: center;
  padding: 0.5rem 0 1.25rem;
}

.header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.tagline {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.capture-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.capture-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.4rem 0.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-weight: 600;
  min-height: 96px;
}

.capture-btn:active {
  background: var(--accent-soft);
}

.capture-icon {
  font-size: 1.8rem;
}

.search-row {
  margin-bottom: 1rem;
}

.search-row input {
  width: 100%;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.9rem;
  background: var(--bg-card);
}

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

.entry {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.8rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.entry-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.entry-main {
  min-width: 0;
  flex: 1;
}

.entry-text {
  margin: 0 0 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.entry-time {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.entry-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

.timeline-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

/* Overlays / bottom sheets */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 1.1rem 1.1rem calc(1.5rem + env(safe-area-inset-bottom));
}

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

.sheet-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  cursor: pointer;
}

textarea, input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.7rem;
  background: var(--bg-card);
  resize: vertical;
  margin-bottom: 0.75rem;
}

.measurement-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.measurement-row input {
  margin-bottom: 0;
}

.measurement-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
}

.flag-banner {
  background: var(--warn-bg, #fff4e5);
  border: 1px solid var(--warn-border, #e8a33d);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.measurement-compare {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.1rem 0 0.5rem;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.1rem;
  min-height: 48px;
  cursor: pointer;
  font-weight: 600;
}

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

.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-lg {
  flex: 1;
  font-size: 1.05rem;
}

.mic-btn {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  font-size: 1.3rem;
  cursor: pointer;
}

.mic-btn.listening {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.hint {
  min-height: 1.2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.photo-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem 1rem;
  margin-bottom: 0.9rem;
  cursor: pointer;
  color: var(--text-muted);
  text-align: center;
}

.photo-preview {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius-md);
  object-fit: contain;
}

#detailBody p {
  margin: 0.4rem 0;
}

#detailBody img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 0.5rem 0;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-strong);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 60;
  box-shadow: var(--shadow-soft);
}
