:root {
  color-scheme: light;
  --ink: #15303d;
  --muted: #6b7e87;
  --navy: #123b55;
  --teal: #16868d;
  --teal-dark: #0f6870;
  --coral: #e35d4f;
  --bg: #eef4f5;
  --card: #ffffff;
  --line: #dce5e9;
  --shadow: 0 14px 38px rgba(18, 59, 85, .09);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 85% -5%, rgba(22,134,141,.12), transparent 32rem), var(--bg); font-size: 16px; line-height: 1.5; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.topbar { background: rgba(18,59,85,.97); color: white; position: sticky; top: 0; z-index: 10; box-shadow: 0 3px 18px rgba(11,40,55,.18); }
.topbar-inner { max-width: 1120px; margin: auto; min-height: 64px; padding: 8px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { color: white; text-decoration: none; font-weight: 750; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 52px; height: 52px; border-radius: 18px; background: var(--coral); color: white; display: grid; place-items: center; font-size: 28px; box-shadow: 0 9px 20px rgba(227,93,79,.28); }
.brand-mark.small { width: 34px; height: 34px; border-radius: 11px; font-size: 19px; box-shadow: none; }
.header-actions, .button-row { display: flex; align-items: center; gap: 10px; }
.header-actions form { margin: 0; }
.text-button, .icon-button { border: 0; background: transparent; color: rgba(255,255,255,.86); cursor: pointer; padding: 9px; }
.icon-button { border: 1px solid rgba(255,255,255,.35); border-radius: 10px; font-weight: 650; }
.page-shell { width: min(1120px, calc(100% - 32px)); margin: 30px auto 50px; }
.entry-card, .content-card, .summary-card { background: var(--card); border: 1px solid rgba(18,59,85,.07); box-shadow: var(--shadow); border-radius: 22px; }
.entry-card { padding: 28px 30px 24px; border-top: 5px solid var(--teal); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.section-heading h1, .section-heading h2 { margin: 0; line-height: 1.2; letter-spacing: -.025em; }
.section-heading h1 { font-size: clamp(1.55rem, 4vw, 2.15rem); }
.section-heading h2 { font-size: 1.35rem; }
.eyebrow { margin: 0 0 4px; color: var(--teal-dark); font-size: .78rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.reading-form { display: grid; grid-template-columns: 1fr auto 1fr 1.2fr 1.6fr; align-items: end; gap: 16px; }
label { display: grid; gap: 7px; font-weight: 700; color: #294552; }
label em { font-style: normal; font-weight: 500; color: var(--muted); font-size: .82rem; }
input { width: 100%; min-height: 48px; border: 1px solid #bdccd2; border-radius: 12px; padding: 10px 12px; color: var(--ink); background: #fbfdfd; outline: none; }
input:focus { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(22,134,141,.13); }
.measure-field > span:first-child { color: var(--muted); }
.measure-input, .input-with-unit { position: relative; display: block; }
.measure-input input { min-height: 72px; padding: 7px 62px 7px 14px; font-size: 2rem; font-weight: 800; border-width: 2px; }
.measure-input small, .input-with-unit small { position: absolute; right: 12px; bottom: 11px; color: var(--muted); font-size: .72rem; font-weight: 600; pointer-events: none; }
.measure-slash { font-size: 2.2rem; font-weight: 300; color: #91a2aa; padding-bottom: 11px; }
.input-with-unit input { padding-right: 82px; }
.full-width { grid-column: 1 / -2; }
.button { min-height: 48px; border: 0; border-radius: 12px; padding: 11px 18px; display: inline-flex; justify-content: center; align-items: center; gap: 8px; text-decoration: none; font-weight: 750; cursor: pointer; }
.button.primary { color: white; background: var(--teal); box-shadow: 0 8px 18px rgba(22,134,141,.22); }
.button.primary:hover { background: var(--teal-dark); }
.button.secondary { color: var(--navy); border: 1px solid #c8d5da; background: #f8fbfb; }
.button.compact { min-height: 40px; padding: 8px 12px; font-size: .88rem; }
.button.full { width: 100%; }
.save-button { min-height: 48px; }
.safety-note { margin: 18px 0 0; padding-top: 15px; border-top: 1px solid var(--line); color: #7c4a44; font-size: .84rem; }
.summary-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 16px; margin: 18px 0; }
.summary-card { padding: 20px 22px; box-shadow: none; }
.summary-card p { margin: 0 0 6px; color: var(--muted); font-weight: 650; font-size: .88rem; }
.summary-card strong { font-size: 1.9rem; line-height: 1.15; letter-spacing: -.04em; }
.summary-card strong span { color: #90a1a9; font-weight: 400; padding: 0 4px; }
.summary-card small { display: block; color: var(--muted); margin-top: 6px; }
.latest-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.unit-label { color: var(--muted); font-size: .8rem; font-weight: 700; }
.content-card { padding: 24px; margin-top: 18px; box-shadow: 0 8px 28px rgba(18,59,85,.06); }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: .82rem; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.sys-dot { background: var(--coral); }.dia-dot { background: var(--teal); }
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap canvas { display: block; max-width: none; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th { color: var(--muted); font-size: .78rem; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 14px 12px; border-bottom: 1px solid #e8eef0; vertical-align: middle; }
td small { display: block; color: var(--muted); }
.reading-value { font-size: 1.12rem; margin-right: 8px; }
.note-cell { max-width: 280px; color: #526a75; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions a, .row-actions button, .text-link { border: 0; background: none; color: var(--teal-dark); font-weight: 700; cursor: pointer; padding: 6px; text-decoration: none; }
.row-actions form { display: inline; }.row-actions button { color: #a94438; }
.notice { border-radius: 13px; padding: 12px 15px; margin-bottom: 16px; font-weight: 600; }
.notice.success { color: #176747; background: #def4e8; border: 1px solid #b9e4cd; }.notice.error { color: #8b2e26; background: #ffe7e3; border: 1px solid #ffc9c1; }
.empty-state { display: grid; place-items: center; min-height: 150px; color: var(--muted); border: 1px dashed #bdccd2; border-radius: 14px; text-align: center; padding: 20px; }
footer { color: var(--muted); text-align: center; padding: 0 20px 35px; font-size: .82rem; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 0, rgba(22,134,141,.18), transparent 32rem), var(--bg); }
.auth-card { width: min(100%, 410px); background: white; border-radius: 24px; padding: 32px; box-shadow: var(--shadow); border-top: 5px solid var(--teal); }
.auth-card .brand-mark { margin-bottom: 22px; }.auth-card h1 { margin: 0 0 5px; font-size: 2rem; }.auth-card .muted { margin: 0 0 24px; }.stack { display: grid; gap: 16px; }.muted { color: var(--muted); }
code { overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .reading-form { grid-template-columns: 1fr auto 1fr; }
  .regular-field { grid-column: span 1; }.full-width { grid-column: 1 / -1; }.save-button { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: 1fr 1fr; }.summary-card.latest { grid-column: 1 / -1; }
}
@media (max-width: 620px) {
  .topbar-inner { padding: 8px 16px; }.brand > span:last-child { font-size: .93rem; }.text-button { font-size: .85rem; }
  .page-shell { width: min(100% - 20px, 1120px); margin-top: 16px; }
  .entry-card, .content-card { border-radius: 18px; padding: 20px 16px; }
  .reading-form { gap: 12px 8px; }
  .measure-input input { min-height: 68px; font-size: 1.75rem; padding-right: 52px; }
  .measure-input small { right: 8px; }.measure-slash { padding: 0 0 10px; }
  .regular-field { grid-column: 1 / -1; }.full-width { grid-column: 1 / -1; }
  .summary-grid { gap: 10px; }.summary-card { padding: 16px; border-radius: 17px; }.summary-card strong { font-size: 1.6rem; }
  .history-heading { display: block; }.button-row { margin-top: 14px; }.button-row .button { flex: 1; }
  .legend { padding-top: 4px; }.section-heading { margin-bottom: 18px; }
}
@media print {
  body { background: white; }.topbar, .entry-card, .chart-card, .button-row, .row-actions, footer, .notice { display: none !important; }
  .page-shell { width: 100%; margin: 0; }.summary-grid { margin: 0 0 14px; }.summary-card, .content-card { box-shadow: none; border: 1px solid #bbb; }
  .history-card { margin: 0; padding: 12px; }.history-card .section-heading { margin-bottom: 8px; }
  table { min-width: 0; font-size: 12px; } th, td { padding: 7px; }
}

/* --- v2: nav + health features --- */
.tab-nav { background: white; border-bottom: 1px solid var(--line); position: sticky; top: 64px; z-index: 9; }
.tab-nav-inner { max-width: 1120px; margin: auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-link { display: flex; align-items: center; gap: 7px; padding: 13px 15px; text-decoration: none; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; white-space: nowrap; font-size: .95rem; }
.tab-link.active { color: var(--teal-dark); border-bottom-color: var(--teal); }
.tab-link:hover { color: var(--navy); }
.tab-icon { font-size: 1.05rem; }
.stack-form { display: grid; gap: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
select { width: 100%; min-height: 48px; border: 1px solid #bdccd2; border-radius: 12px; padding: 10px 12px; color: var(--ink); background: #fbfdfd; font: inherit; }
select:focus { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(22,134,141,.13); outline: none; }
.items-editor { border: 1px dashed #bdccd2; border-radius: 14px; padding: 14px; }
.items-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; color: #294552; margin-bottom: 10px; }
.item-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }
.remove-item { border: 1px solid #e6c5c0; background: #fff5f3; color: #a94438; border-radius: 10px; min-width: 44px; cursor: pointer; font-weight: 700; }
.checkup-list { display: grid; gap: 14px; }
.checkup-card { border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; }
.checkup-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.checkup-head strong { font-size: 1.05rem; }
.checkup-head small { display: block; color: var(--muted); }
.items-table { min-width: 0 !important; }
.checkup-note { margin: 10px 0 0; color: #526a75; font-size: .92rem; }
.appt-list { display: grid; gap: 12px; }
.appt-card { border: 1px solid var(--line); border-radius: 16px; padding: 15px 18px; display: grid; gap: 8px; }
.appt-when { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.appt-when strong { color: var(--teal-dark); }
.appt-body strong { display: block; font-size: 1.06rem; }
.appt-body small { display: block; color: var(--muted); }
.appt-note { color: #7c4a44 !important; }
.appt-actions { text-align: left; }
.appt-actions .action-done { color: #176747; }
.appt-list.past .appt-card { opacity: .82; }
.badge { border-radius: 999px; padding: 3px 11px; font-size: .76rem; font-weight: 750; white-space: nowrap; }
.badge-scheduled { background: #e2f2f3; color: var(--teal-dark); }
.badge-done { background: #def4e8; color: #176747; }
.badge-cancelled { background: #f3e5e3; color: #a94438; }
.setup-steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; color: #294552; font-weight: 550; }
.muted-note { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.inline-form { margin-top: 4px; }
@media (max-width: 620px) {
  .tab-nav { top: 0; position: static; }
  .field-row { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1.6fr 1fr; }
  .item-row input[name="item_unit[]"] { grid-column: 1; }
  .remove-item { grid-column: 2; }
  .checkup-head { flex-wrap: wrap; }
}
@media print { .tab-nav { display: none !important; } }

/* --- v3: reminders, link code, attachments --- */
.reminder-list { display: grid; gap: 8px; margin-bottom: 16px; }
.reminder-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.reminder-row.off { opacity: .6; }
.reminder-time { font-size: 1.2rem; font-weight: 800; color: var(--teal-dark); font-variant-numeric: tabular-nums; }
.reminder-label strong { display: block; }
.reminder-label small { color: var(--muted); }
.reminder-add { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: end; padding-top: 16px; border-top: 1px solid var(--line); }
.link-code { font-size: 1.8rem; font-weight: 800; letter-spacing: .28em; color: var(--navy); background: #eef6f6; border: 1px dashed var(--teal); border-radius: 12px; padding: 14px; text-align: center; margin: 10px 0 14px; }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attach-chip { display: inline-flex; align-items: center; gap: 8px; background: #f3f8f8; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .88rem; }
.attach-chip a { color: var(--teal-dark); font-weight: 650; text-decoration: none; overflow-wrap: anywhere; }
.attach-chip small { color: var(--muted); }
.attach-chip form { display: inline; margin: 0; }
.attach-chip button { border: 0; background: none; color: #a94438; cursor: pointer; font-weight: 700; padding: 2px 4px; }
input[type=file] { width: 100%; min-height: 48px; border: 1px solid #bdccd2; border-radius: 12px; padding: 10px 12px; background: #fbfdfd; }
@media (max-width: 620px) {
  .reminder-add { grid-template-columns: 1fr; }
  .reminder-row { grid-template-columns: auto 1fr; }
  .reminder-row .row-actions { grid-column: 1 / -1; text-align: right; }
}
