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

:root {
  --brand: #4f46e5;
  --brand-dark: #3730a3;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-2: #6b7280;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.15);
  --tab-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top, 16px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header h1 { font-size: 1.25rem; font-weight: 700; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg); color: var(--brand); }
.icon-btn.active { color: var(--brand); }

/* ── Main ── */
.main {
  padding: 16px 16px calc(var(--tab-h) + 80px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.empty-state {
  text-align: center;
  color: var(--text-2);
  padding: 60px 0;
  font-size: .95rem;
}

/* ── Task list ── */
.task-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.task-item {
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  transition: opacity .2s, transform .2s;
}
.task-item.removing {
  opacity: 0;
  transform: translateX(20px);
}

.task-check {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s;
}
.task-check:hover { border-color: var(--brand); background: #ede9fe; }
.task-check svg { display: none; }
.task-check:hover svg { display: block; color: var(--brand); }

.task-title { flex: 1; font-size: .95rem; }

/* ── Reminder list ── */
.reminder-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.reminder-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
}
.reminder-item.overdue { border-left: 3px solid var(--danger); }
.reminder-item.soon    { border-left: 3px solid #f59e0b; }

.check-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: none;
  cursor: pointer;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s;
}
.check-btn svg { display: none; }
.check-btn:hover { border-color: var(--brand); }
.check-btn:hover svg { display: block; color: var(--brand); }

.reminder-body { flex: 1; min-width: 0; cursor: pointer; }
.reminder-title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reminder-notes { font-size: .82rem; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reminder-meta  { font-size: .78rem; color: var(--text-2); margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.repeat-badge {
  font-size: .7rem;
  background: #ede9fe;
  color: var(--brand);
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 500;
  text-transform: capitalize;
}

.delete-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  padding: 4px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity .15s, color .15s;
}
.task-item:hover .delete-btn,
.task-item:focus-within .delete-btn,
.reminder-item:hover .delete-btn,
.reminder-item:focus-within .delete-btn { opacity: 1; }
.delete-btn:hover { color: var(--danger); }

/* ── Tab bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: .72rem;
  font-weight: 500;
  color: var(--text-2);
  transition: color .15s;
}
.tab.active { color: var(--brand); }
.tab svg { transition: color .15s; }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: calc(var(--tab-h) + 16px + var(--safe-bottom));
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .15s;
  z-index: 19;
}
.fab:hover  { background: var(--brand-dark); }
.fab:active { transform: scale(.95); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding-bottom: var(--safe-bottom);
  animation: fade-in .15s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px;
  width: 100%;
  max-width: 640px;
  animation: slide-up .2s ease;
}
@keyframes slide-up { from { transform: translateY(40px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }

.modal h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }

label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 4px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
label:first-of-type { margin-top: 0; }

input[type="text"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s;
  appearance: none;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
}
textarea { resize: vertical; }

.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.btn {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

/* ── Health ── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.metric-icon { font-size: 1.4rem; flex-shrink: 0; }

.metric-info { min-width: 0; }
.metric-name  { font-size: .72rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 1.25rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.metric-unit  { font-size: .72rem; font-weight: 400; color: var(--text-2); }
.metric-range { font-size: .7rem; color: var(--text-2); margin-top: 2px; }

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 16px;
}
.summary-card.hidden { display: none; }

.summary-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.summary-label  { font-size: .8rem; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.summary-date   { font-size: .75rem; color: var(--text-2); }
.summary-card p { font-size: .9rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; }

.analyze-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.analyze-btn:hover    { background: var(--brand-dark); }
.analyze-btn:disabled { opacity: .6; cursor: not-allowed; }
