:root {
  --bg: #F2F2F5;
  --card: #FFFFFF;
  --ink: #1C1C1E;
  --ink-soft: #8A8A8E;
  --line: #E4E4E8;
  --accent: #FF9F0A;
  --accent-deep: #D9840A;
  --blue: #0A84FF;
  --good: #34C759;
  --good-bg: #E7F8EB;
  --warn: #FF9500;
  --warn-bg: #FFF1DE;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 14px rgba(0,0,0,0.06);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}

h1, h2 { margin: 0; color: var(--ink); font-weight: 700; }

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

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.paw-spin { font-size: 2rem; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.15); opacity: 1; }
}

.screen { min-height: 100vh; display: flex; flex-direction: column; }

/* Topbar — large-title style */
.topbar {
  padding: 14px 20px 18px;
  background: var(--bg);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.topbar h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
  margin-top: 6px;
}
.status-pill {
  margin: 2px 0 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
  font-weight: 500;
}
.status-pill.recent { color: var(--good); font-weight: 600; }

.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  border: none;
  background: rgba(120, 120, 128, 0.12);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.icon-btn:active { opacity: 0.6; }
.icon-btn-accent {
  background: var(--accent);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 400;
}

/* Calendar — month grid */
.cal-card {
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 2px 16px 14px;
}
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.cal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}
.cal-nav {
  border: none;
  background: none;
  color: var(--blue);
  font-size: 1.3rem;
  font-weight: 600;
  width: 32px;
  height: 32px;
  cursor: pointer;
  line-height: 1;
}
.cal-nav:active { opacity: 0.5; }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 2px;
}
.cal-weekdays span {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  row-gap: 2px;
}
.cal-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 5px 0;
  border: none;
  background: none;
  font-family: inherit;
  cursor: pointer;
}
.cal-day-num {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
}
.cal-day.other-month .cal-day-num { color: var(--ink-soft); opacity: 0.45; }
.cal-day.today .cal-day-num { color: var(--warn); font-weight: 700; }
.cal-day.selected .cal-day-num { background: var(--blue); color: #fff; font-weight: 700; }
.cal-day-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  visibility: hidden;
}
.cal-day.has-visits .cal-day-dot { visibility: visible; }
.cal-day.selected .cal-day-dot { background: var(--blue); }

.cal-card-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px 18px 24px;
}
.cal-card-main .cal-grid-main { flex: 1; }
.cal-grid-main .cal-day { padding: 10px 0; }
.cal-grid-main .cal-day-num { width: 38px; height: 38px; font-size: 1.05rem; }

/* Day view — timeline */
.day-view-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 10px 10px 4px;
}
.day-view-topbar .day-view-title {
  flex: 1;
  font-size: 1.3rem;
  text-align: center;
}
.day-view-title .day-sub {
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin-left: 6px;
}
.day-view-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin: 0 0 8px;
  padding: 0 20px;
}
.timeline-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 40px;
}
.timeline {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  border-left: 1px solid var(--line);
}
.hour-row {
  position: relative;
  height: 60px;
  border-top: 1px solid var(--line);
}
.hour-row:first-child { border-top: none; }
.hour-label {
  position: absolute;
  left: -46px;
  top: -8px;
  width: 40px;
  text-align: right;
  font-size: 0.7rem;
  color: var(--ink-soft);
}
.timeline-card {
  position: absolute;
  left: 12px;
  right: 8px;
  min-height: 44px;
  background: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  touch-action: none;
  cursor: grab;
  user-select: none;
  z-index: 1;
}
.timeline-card.dragging {
  cursor: grabbing;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  z-index: 20;
  opacity: 0.96;
}
.timeline-card .tl-cat {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--accent-deep);
}
.timeline-card .tl-time {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
}
.timeline-card .tl-tags {
  font-size: 0.72rem;
  color: var(--ink-soft);
}

/* Ledger — grouped by day */
.ledger {
  flex: 1;
  padding: 4px 16px 60px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 60px 20px;
  font-size: 0.95rem;
}

.day-section { margin-bottom: 22px; }
.day-heading {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 8px 4px;
}
.day-heading .day-sub {
  font-weight: 500;
  color: var(--ink-soft);
  margin-left: 6px;
}

.visit-list { display: flex; flex-direction: column; gap: 10px; }

.visit-card {
  background: var(--card);
  border: none;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  position: relative;
}
.visit-card.editable { cursor: pointer; }
.visit-card.editable:active { opacity: 0.85; }

.visit-cat {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--accent-deep);
  margin: 0 0 4px;
}
.visit-card .visit-date {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
}
.visit-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.visit-tag {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--good-bg);
  color: #1E8A3C;
  font-weight: 600;
}
.visit-tag.meds { background: var(--warn-bg); color: var(--accent-deep); }
.visit-notes {
  font-size: 0.92rem;
  color: var(--ink);
  margin: 6px 0 0;
  line-height: 1.4;
}
.visit-meta {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 8px;
}
.visit-delete {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 6px;
}
.visit-delete:hover { color: var(--warn); }

/* Setup screen */
.setup-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.setup-card {
  max-width: 420px;
  width: 100%;
  background: var(--card);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.eyebrow-free-mark {
  font-size: 0.85rem;
  color: var(--accent-deep);
  font-weight: 600;
  margin: 0 0 6px;
}
.setup-card h1 { font-size: 1.6rem; margin-bottom: 10px; }
.lede { color: var(--ink-soft); font-size: 0.92rem; line-height: 1.5; margin: 0 0 20px; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; font-weight: 600; }
.field small { font-weight: 400; color: var(--ink-soft); }
.field input, .field textarea {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 400;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.field input:focus, .field textarea:focus, #pinForm input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}
.form-error {
  color: var(--warn);
  font-size: 0.85rem;
  margin: -6px 0 0;
  min-height: 1em;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.check-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}
.check-tile input { width: 18px; height: 18px; accent-color: var(--good); }

.day-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.day-tile {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 8px;
  background: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.day-tile input { width: 16px; height: 16px; accent-color: var(--good); }

.date-picker-btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.date-picker-btn:active { opacity: 0.7; }
.date-picker-modal { max-width: 380px; padding: 22px 18px 24px; }
.date-picker-modal .cal-grid { margin-bottom: 10px; }

.time-list { display: flex; flex-direction: column; gap: 8px; }
.time-row { display: flex; align-items: center; gap: 8px; }
.time-row input[type="time"] {
  flex: 1;
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.time-remove {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 1rem;
  cursor: pointer;
  padding: 6px;
}
.time-remove:hover { color: var(--warn); }
.btn-small { padding: 9px 14px; font-size: 0.85rem; align-self: flex-start; }
.form-hint {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin: -6px 0 0;
}

.danger-zone {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  text-align: center;
}
.danger-zone p { color: var(--ink-soft); font-size: 0.85rem; margin: 0 0 10px; }

/* Buttons */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 13px 18px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active { opacity: 0.85; }
.btn-ghost { background: rgba(120,120,128,0.12); color: var(--ink); border: none; }
.btn-danger { background: #fff; color: var(--warn); border: 1px solid var(--warn); }

/* Modal (bottom sheet form) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.modal {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 26px 22px 28px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
}
.modal h2 { font-size: 1.35rem; margin-bottom: 6px; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}
.modal-actions .btn { flex: 1; }

/* iOS-style action sheet */
.action-sheet {
  width: 100%;
  max-width: 480px;
  padding: 0 10px 10px;
}
.action-sheet-group {
  background: rgba(250,250,252,0.96);
  backdrop-filter: blur(20px);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 8px;
}
.action-sheet-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid rgba(60,60,67,0.15);
  padding: 16px;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--blue);
  font-family: inherit;
  cursor: pointer;
}
.action-sheet-item:last-child { border-bottom: none; }
.action-sheet-item:active { background: rgba(0,0,0,0.05); }
.action-sheet-cancel {
  background: rgba(250,250,252,0.96);
  backdrop-filter: blur(20px);
  border-radius: 14px;
  font-weight: 700;
}

@media (min-width: 640px) {
  .modal-backdrop:not(.sheet-backdrop) { align-items: center; }
  .modal-backdrop:not(.sheet-backdrop) .modal { border-radius: 20px; }
}
