:root {
  color-scheme: light;
  --cream: var(--canvas);
  --surface: var(--paper);
  --surface-soft: var(--canvas-strong);
  --action: var(--forest);
  --moss-soft: var(--moss-pale);
  --terra: var(--danger);
  --terra-soft: var(--danger-soft);
  --muted: var(--ink-soft);
  --radius: var(--radius-md);
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--cream); line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.wrap { width: min(calc(100% - 40px), 1200px); margin-inline: auto; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.site-header { position: sticky; z-index: 30; top: 0; border-bottom: 1px solid rgba(68, 88, 74, 0.08); background: rgba(248, 245, 239, 0.86); backdrop-filter: blur(18px); }

.records-main { padding-top: 34px; padding-bottom: 52px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 8px; color: var(--action); font-size: 12px; font-weight: 800; letter-spacing: .11em; }
.eyebrow span { color: var(--moss); padding-inline: 4px; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 760px; margin-bottom: 8px; color: var(--forest); font-size: clamp(28px, 4vw, 38px); line-height: 1.25; letter-spacing: -.025em; }
.lede { margin: 0; color: var(--muted); font-size: 16px; }
.privacy-pill { display: inline-flex; flex: none; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; border: 1px solid var(--leaf-line); border-radius: 999px; background: var(--moss-pale); color: var(--forest); font-size: 13px; font-weight: 700; }
.privacy-pill span { font-size: 9px; color: var(--moss-strong); }

.privacy-note { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border: 1px solid var(--leaf-line); border-radius: 16px; background: rgba(229, 236, 229, 0.72); }
.privacy-icon { display: grid; width: 38px; height: 38px; flex: none; place-items: center; border-radius: 12px; background: var(--moss-pale); color: var(--forest); font-size: 22px; }
.privacy-note strong { display: block; margin-bottom: 2px; color: var(--forest); font-size: 14px; }
.privacy-note p { margin: 0; color: var(--ink-soft); font-size: 13px; }
.backup-actions { display: flex; flex: none; gap: 8px; margin-left: auto; }

.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid transparent; border-radius: 12px; font-size: 14px; font-weight: 700; transition: background-color .16s ease, border-color .16s ease, transform .16s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--action); color: #fff; }
.button-primary:hover { background: #34483b; }
.button-primary:disabled { cursor: not-allowed; opacity: .48; transform: none; }
.button-soft { border-color: #d8e1d8; background: var(--moss-soft); color: #34483b; }
.button-soft:hover { background: #d8e4d8; }
.button-outline { border-color: #a7b7a8; background: #fff; color: #34483b; }
.button-outline:hover { background: #f5f8f4; }
.button-quiet { border-color: #decabd; background: rgba(255,255,255,.66); color: #624f43; }
.button-quiet:hover { background: #fff; }
.button-danger { border-color: #963f32; background: #963f32; color: #fff; }
.button-danger:hover { background: #7e3429; }

.status-message { margin: 14px 0 0; padding: 11px 14px; border: 1px solid #bdd0bd; border-radius: 12px; background: #edf4ed; color: #294a32; font-size: 14px; }
.status-message.error { border-color: #e3bcb0; background: #fbefeb; color: #78372d; }
.pet-picker { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 26px 0 16px; }
.pet-picker label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.pet-picker select { width: min(360px, 54vw); min-height: 46px; padding: 8px 42px 8px 13px; border: 1px solid #c9d3c9; border-radius: 12px; background: #fff; font-size: 16px; }
.pet-count { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.picker-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.content-area { min-height: 250px; }
.loading-state, .empty-state, .storage-error { display: grid; justify-items: center; gap: 9px; padding: 54px 24px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.72); text-align: center; }
.loading-state { color: var(--muted); }
.empty-illustration { display: grid; width: 60px; height: 60px; place-items: center; margin-bottom: 2px; border-radius: 20px; background: var(--moss-soft); color: var(--forest); font-size: 28px; }
.empty-state h2, .storage-error h2 { margin: 0; color: var(--forest); font-size: 21px; }
.empty-state p, .storage-error p { max-width: 520px; margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.storage-error { border-color: #e5bfb2; background: #fcf2ed; }
.storage-error h2 { color: var(--terra); }
.storage-error .button { margin-top: 4px; }

.pet-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px; border: 1px solid #dce5dc; border-radius: var(--radius); background: linear-gradient(120deg, #fff 0%, #f0f5ef 100%); }
.pet-identity { min-width: 0; }
.pet-species { display: inline-flex; align-items: center; min-height: 26px; margin-bottom: 5px; padding: 1px 9px; border-radius: 999px; background: #e5ece5; color: #34483b; font-size: 12px; font-weight: 700; }
.pet-summary h2 { margin: 0; color: var(--forest); font-size: 25px; line-height: 1.3; overflow-wrap: anywhere; }
.pet-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.pet-notes { max-width: 360px; margin: 0; color: #56635a; font-size: 14px; }
.pet-delete { margin-left: auto; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.metric { min-height: 114px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.metric-label { display: block; margin-bottom: 9px; color: var(--muted); font-size: 13px; font-weight: 700; }
.metric-value { display: block; color: var(--forest); font-size: 24px; font-weight: 800; line-height: 1.25; }
.metric-caption { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }

.records-columns { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .85fr); align-items: start; gap: 14px; }
.panel { min-width: 0; padding: 19px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.88); }
.panel + .panel { margin-top: 14px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.panel-heading h2 { margin: 0; color: var(--forest); font-size: 18px; line-height: 1.35; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.weight-chart { width: 100%; min-height: 200px; overflow: visible; }
.chart-gridline { stroke: #e8e5dd; stroke-width: 1; }
.chart-line { fill: none; stroke: #50745a; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: #fff; stroke: #50745a; stroke-width: 3; }
.chart-label { fill: #687068; font-size: 11px; }
.chart-empty { display: grid; min-height: 175px; place-items: center; padding: 18px; border-radius: 14px; background: #f8f7f3; color: var(--muted); text-align: center; font-size: 14px; }
.chart-empty strong { display: block; margin-bottom: 4px; color: var(--ink); }
.weight-list { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0 0; padding: 0; list-style: none; }
.weight-list li { padding: 5px 9px; border-radius: 9px; background: #f3f5f0; color: #425547; font-size: 12px; }

.feeding-calendar { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); grid-auto-columns: minmax(10px, 1fr); gap: 5px; justify-content: space-between; overflow-x: auto; padding: 3px 1px 7px; }
.calendar-cell { width: 100%; min-width: 9px; max-width: 16px; height: 13px; border-radius: 4px; background: #ecebe5; }
.calendar-cell[data-level="1"] { background: #d2e0d0; }.calendar-cell[data-level="2"] { background: #abc7a9; }.calendar-cell[data-level="3"] { background: #7fa47f; }.calendar-cell[data-level="4"] { background: #50745a; }
.calendar-legend { display: flex; align-items: center; gap: 5px; margin-top: 12px; color: var(--muted); font-size: 11px; }
.calendar-legend .calendar-cell { width: 13px; min-width: 13px; }
.calendar-caption { margin: 9px 0 0; color: var(--muted); font-size: 12px; }

.timeline-head { align-items: center; }
.timeline-filter { min-height: 40px; max-width: 170px; padding: 6px 32px 6px 10px; border: 1px solid #c9d3c9; border-radius: 10px; background: #fff; font-size: 14px; }
.timeline { display: grid; gap: 10px; }
.record-item { padding: 14px 15px; border: 1px solid #e9e5dc; border-radius: 14px; background: #fff; }
.record-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.record-kind { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 5px; color: var(--forest); font-size: 15px; font-weight: 800; }
.record-kind::before { content: ""; width: 9px; height: 9px; flex: none; border-radius: 50%; background: #83a585; }
.record-item[data-type="weight"] .record-kind::before { background: #527b9b; }
.record-item[data-type="shed"] .record-kind::before { background: #a68761; }
.record-item[data-type="health"] .record-kind::before { background: #d17c65; }
.record-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.record-summary { margin: 0; color: #3f4b42; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.record-notes { margin: 6px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap; }
.record-actions { display: flex; gap: 4px; margin: -7px -7px 0 0; }
.text-button { min-width: 44px; min-height: 44px; padding: 4px 8px; border: 0; border-radius: 9px; background: transparent; color: #56635a; font-size: 13px; font-weight: 700; }
.text-button:hover { background: #f1f4ef; color: var(--forest); }
.text-button.danger { color: var(--terra); }.text-button.danger:hover { background: #fbefeb; }
.timeline-empty { padding: 28px 18px; border: 1px dashed #cfd7ce; border-radius: 14px; color: var(--muted); text-align: center; font-size: 14px; }
.timeline-empty strong { display: block; margin-bottom: 4px; color: var(--ink); }
.records-note { padding: 14px 16px; border-radius: 14px; background: #f1f4ef; color: #536056; font-size: 13px; }
.records-note strong { color: #34483b; }

.site-footer { border-top: 1px solid var(--line); background: #f3f0e8; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 66px; color: var(--muted); font-size: 13px; }
.footer-inner a { color: var(--action); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.dialog { width: min(600px, calc(100% - 28px)); max-height: min(88vh, 860px); padding: 24px; border: 1px solid #d8d2c7; border-radius: 22px; background: var(--cream); color: var(--ink); box-shadow: 0 24px 80px rgba(31,48,37,.22); overflow: auto; }
.dialog::backdrop { background: rgba(22,40,29,.48); backdrop-filter: blur(3px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.dialog-heading .eyebrow { margin-bottom: 2px; font-size: 11px; }
.dialog-heading h2 { margin: 0; color: var(--forest); font-size: 24px; }
.icon-button { display: grid; width: 44px; height: 44px; flex: none; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: #fff; color: var(--muted); font-size: 27px; line-height: 1; }
.field { display: grid; gap: 6px; margin-bottom: 14px; color: #36443a; font-size: 14px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #aeb9ae; border-radius: 11px; background: #fff; font-size: 16px; font-weight: 400; }
.field textarea { min-height: 88px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: #777e76; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.required { margin-left: 5px; color: #77511c; font-size: 11px; font-weight: 700; }
.type-fields { padding-top: 2px; }
.field-hint { margin: -8px 0 12px; color: var(--muted); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.form-error { margin: 0; padding: 9px 11px; border-radius: 10px; background: #fbefeb; color: var(--terra); font-size: 13px; }

.share-dialog { width: min(920px, calc(100% - 28px)); max-height: min(calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 960px); }
.share-source { display: grid; gap: 5px; margin-bottom: 16px; padding: 14px 16px; border: 1px solid #ecd2c2; border-radius: 14px; background: #fbf0e9; }
.share-source .eyebrow { margin: 0; color: #79543d; font-size: 11px; }
.share-source strong { color: #4d493e; font-size: 15px; }
.share-source > span:last-of-type { color: var(--muted); font-size: 13px; }
.share-source p { margin: 0; color: #554b40; font-size: 14px; }
.share-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.share-selection, .share-preview { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.share-selection h3, .share-preview h3 { margin: 0; color: var(--forest); font-size: 16px; }
.share-selection > p { margin: 4px 0 12px; color: var(--muted); font-size: 13px; }
.share-fields { display: grid; gap: 7px; }
.share-field { display: flex; min-height: 52px; align-items: center; gap: 11px; padding: 8px 10px; border: 1px solid #d5dfd4; border-radius: 11px; background: #f7faf6; cursor: pointer; }
.share-field:has(input:checked) { border-color: #7d9a82; background: #edf4ec; }
.share-field input { width: 20px; height: 20px; flex: none; accent-color: var(--forest); }
.share-field span { display: grid; min-width: 0; gap: 2px; }
.share-field strong { color: #34463a; font-size: 14px; }
.share-field small { overflow-wrap: anywhere; color: var(--muted); font-size: 13px; }
.share-preview { background: #f5f7f3; }
.share-preview .panel-heading { margin-bottom: 12px; }
.share-preview .panel-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.share-preview-empty { display: grid; min-height: 160px; place-items: center; padding: 20px; border: 1px dashed #bcc8bb; border-radius: 12px; color: var(--muted); font-size: 14px; text-align: center; }
.public-draft-card { padding: 16px; border: 1px solid #dce5dc; border-radius: 13px; background: #fff; }
.public-draft-card .privacy-pill { min-height: 30px; margin: 0; font-size: 12px; }
.public-draft-card dl { display: grid; gap: 0; margin: 12px 0 0; }
.public-draft-card dl > div { display: grid; grid-template-columns: minmax(78px, .7fr) minmax(0, 1.3fr); gap: 12px; padding: 10px 0; border-top: 1px solid #e9ece6; }
.public-draft-card dt { color: var(--muted); font-size: 13px; }
.public-draft-card dd { margin: 0; color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.share-boundary { display: grid; gap: 5px; margin-top: 14px; padding: 12px 14px; border: 1px solid #d9e2d8; border-radius: 12px; background: #eff4ee; color: #46594a; font-size: 13px; line-height: 1.55; }
.share-boundary strong { color: var(--forest); }
.share-boundary span { color: #72553c; }
.share-dialog .dialog-actions { position: sticky; bottom: -24px; z-index: 2; justify-content: space-between; margin-bottom: -24px; padding: 14px 0 24px; background: linear-gradient(to bottom, rgba(247,245,239,.94), var(--cream) 12px); }
.share-dialog [hidden] { display: none !important; }
.share-dialog .dialog-actions .button { min-height: 44px; }
.share-dialog .button:disabled { cursor: not-allowed; opacity: .55; transform: none; }

@media (max-width: 760px) {
  .wrap { width: min(calc(100% - 28px), 1200px); }
  .nav { min-height: 60px; gap: 8px; }
  .brand { gap: 7px; font-size: 18px; }
  .brand-mark { width: 27px; height: 27px; }
  .nav-links { gap: 2px; }
  .nav-link { padding-inline: 9px; font-size: 12px; }
  .primary-action { min-height: 42px; padding-inline: 12px; font-size: 13px; }
  .records-main { padding-top: 24px; padding-bottom: 36px; }
  .page-heading { display: block; margin-bottom: 17px; }
  h1 { font-size: 28px; }
  .privacy-pill { margin-top: 13px; }
  .privacy-note { align-items: flex-start; flex-wrap: wrap; padding: 14px; }
  .privacy-note > div:nth-child(2) { flex: 1; min-width: 210px; }
  .backup-actions { width: calc(100% - 52px); margin-left: 52px; }
  .backup-actions .button { flex: 1; }
  .pet-picker { align-items: stretch; flex-direction: column; margin-top: 20px; }
  .pet-picker select { width: 100%; }
  .picker-actions { display: grid; grid-template-columns: 1fr 1.1fr; }
  .picker-actions #addPetButton { grid-column: 1; }
  .picker-actions #editPetButton { grid-column: 2; grid-row: 1; }
  .picker-actions #addRecordButton { grid-column: 1 / -1; }
  .pet-summary { align-items: flex-start; flex-direction: column; padding: 17px; }
  .pet-summary h2 { font-size: 23px; }
  .pet-notes { max-width: none; }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .metric { min-height: 100px; padding: 12px 10px; }
  .metric-label { min-height: 35px; margin-bottom: 5px; font-size: 12px; }
  .metric-value { font-size: 19px; }
  .metric-caption { font-size: 11px; }
  .records-columns { grid-template-columns: 1fr; }
  .records-columns > aside { display: block; }
  .panel { padding: 16px; }
  .weight-chart { min-height: 180px; }
  .timeline-head { align-items: flex-start; }
  .timeline-filter { max-width: 140px; }
  .record-item { padding: 13px; }
  .dialog { padding: 20px 17px; border-radius: 18px; }
  .share-columns { grid-template-columns: 1fr; }
  .share-preview-empty { min-height: 120px; }
  .share-dialog { position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: max(16px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)); border: 0; border-radius: 0; }
  .share-dialog[data-step="select"] .share-preview { display: none; }
  .share-dialog[data-step="preview"] .share-selection { display: none; }
  .share-dialog[data-step="preview"] .share-preview { display: block; }
  .share-dialog #previewPublicDraft { display: inline-flex; }
  .share-dialog #copyPublicDraft { display: none; }
  .share-dialog[data-step="preview"] #previewPublicDraft { display: none; }
  .share-dialog[data-step="preview"] #backToShareSelection,
  .share-dialog[data-step="preview"] #copyPublicDraft { display: inline-flex; }
  .share-dialog .dialog-actions { bottom: 0; margin-bottom: 0; padding: 14px 0 max(12px, env(safe-area-inset-bottom)); }
  .share-dialog .dialog-actions .button { width: 100%; }
}

@media (max-width: 360px) {
  .wrap { width: calc(100% - 24px); }
  .nav-link { padding-inline: 6px; font-size: 11px; }
  .primary-action { padding-inline: 9px; }
  .backup-actions { width: 100%; margin-left: 0; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric { min-height: auto; }
  .metric-label { min-height: 0; }
  .field-grid { grid-template-columns: 1fr; gap: 0; }
  .record-topline { gap: 6px; }
  .share-dialog .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .share-dialog { padding-right: 12px; padding-left: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
