/*
 * Pill Tracker - mobile-first stylesheet
 */

:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --primary: #007aff;
  --primary-dark: #0056cc;
  --danger: #ff3b30;
  --text: #1c1c1e;
  --muted: #6c6c70;
  --border: #e0e0e5;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────── */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  max-width: 600px;
  margin: 0 auto;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}

.nav-links {
  display: flex;
  gap: 16px;
  align-items: center;
}

.nav-links a,
.nav-links button {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.95rem;
}

.btn-link {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--primary);
  padding: 0;
}

/* ── Main ────────────────────────────────────── */
main {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Flash messages ──────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.95rem;
}

.flash-notice {
  background: #d4edda;
  color: #155724;
}

.flash-alert {
  background: #f8d7da;
  color: #721c24;
}

/* ── Log page ────────────────────────────────── */
.log-section h1,
.history-section h2 {
  margin-bottom: 16px;
  font-size: 1.4rem;
}

.history-section {
  margin-top: 32px;
}

.med-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.med-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.med-btn {
  width: 100%;
  padding: 18px 20px;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-tap-highlight-color: rgba(0,0,0,0.05);
  transition: background 0.1s;
}

.med-btn:active {
  background: #f0f0f5;
}

.med-name {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary);
}

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

.time-details {
  border-top: 1px solid var(--border);
}

.time-details summary {
  padding: 10px 20px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.time-details summary::-webkit-details-marker { display: none; }
.time-details summary::before { content: "⏱ "; }

.time-row {
  padding: 12px 20px;
  background: #fafafa;
}

.time-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--text);
  background: white;
}

/* ── Timeline ────────────────────────────────── */
.timeline-section {
  margin-bottom: 8px;
}

.timeline-section h2 {
  margin-bottom: 12px;
  font-size: 1.1rem;
}

.timeline-wrap {
  /* Extra horizontal padding so edge dots aren't clipped */
  padding: 0 12px;
}

.timeline-track {
  position: relative;
  height: 52px; /* dot (24px) centered on line at 20px, tick labels below */
}

/* The horizontal line */
.timeline-track::before {
  content: '';
  position: absolute;
  top: 20px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
}

/* Dose dot */
.timeline-dot {
  position: absolute;
  top: 8px; /* center = 8 + 12 = 20px, aligns with line */
  width: 24px;
  height: 24px;
  border-radius: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: default;
}

/* Hour tick marks */
.timeline-tick {
  position: absolute;
  top: 20px;
  transform: translateX(-50%);
}

.timeline-tick::before {
  content: '';
  display: block;
  width: 1px;
  height: 8px;
  background: #c0c0c8;
  margin: 0 auto;
}

.tick-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  margin-top: 3px;
  white-space: nowrap;
}

/* "Now" marker — a blue vertical line */
.timeline-now {
  position: absolute;
  top: 10px;
  width: 2px;
  height: 20px;
  background: var(--primary);
  border-radius: 1px;
  transform: translateX(-50%);
}

/* Legend */
.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 4px;
  padding: 0 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.event-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.event-med {
  font-weight: 600;
  font-size: 0.95rem;
}

.event-time {
  color: var(--muted);
  font-size: 0.85rem;
  flex: 1;
  text-align: right;
  margin-right: 12px;
}

.btn-edit {
  color: var(--muted);
  text-decoration: none;
  font-size: 1rem;
  padding: 4px 6px;
  line-height: 1;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 6px;
  line-height: 1;
}

.edit-event-med {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 20px;
}

/* ── Medications page ────────────────────────── */
.medications-section h1 {
  margin-bottom: 16px;
  font-size: 1.4rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h1 {
  margin-bottom: 0;
}

.med-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.med-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.med-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.med-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Form ────────────────────────────────────── */
.form-section h1 {
  margin-bottom: 20px;
  font-size: 1.4rem;
}

.med-form-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"] {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--card);
  width: 100%;
  -webkit-appearance: none;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}

.form-errors {
  background: #f8d7da;
  color: #721c24;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}

/* ── Buttons ─────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  -webkit-appearance: none;
}

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

.btn-full { width: 100%; text-align: center; }

.btn-secondary {
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-danger {
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
}

/* ── Auth page ───────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--border);
}

.auth-card h1 {
  font-size: 2rem;
  text-align: center;
  margin-bottom: 8px;
}

.auth-card h2 {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  margin-bottom: 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Misc ────────────────────────────────────── */
.empty-state {
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 32px 0;
}

.empty-state a {
  color: var(--primary);
}
