/* ===========================================================
   สมุดสุขภาพ — styles หลัก
   หลักการ (CONTEXT § 5.8): ตัวหนังสือใหญ่ ปุ่มชัด ขั้นตอนน้อย
   เน้น UX ผู้สูงอายุ — contrast สูง แตะง่าย อ่านสบาย
   =========================================================== */

:root {
  /* ขนาดฐานใหญ่กว่าปกติ เพื่อให้อ่านง่าย */
  --font-base: 20px;
  --color-bg: #fff5f7;
  --color-surface: #ffffff;
  --color-text: #1f2933;
  --color-muted: #52606d;
  --color-primary: #e05a7d;      /* ชมพู — โยงกับ "สมุดสีชมพู" */
  --color-primary-dark: #c23e63;
  --color-border: #f0c4d1;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(194, 62, 99, 0.12);
  --touch: 56px;                 /* ปุ่มสูงอย่างน้อย 56px แตะง่าย */
}

* { box-sizing: border-box; }

html { font-size: var(--font-base); }

body {
  margin: 0;
  font-family: "Sarabun", "Noto Sans Thai", -apple-system, "Segoe UI", sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  overflow-x: hidden;          /* กันเลื่อนแนวนอนจากเนื้อหาหลุดกรอบ */
}

/* กันข้อความยาว/คำยาวหลุดกรอบทั่วทั้งเว็บ */
h1, h2, h3, p, span, div, a, li, label { overflow-wrap: anywhere; word-break: break-word; }
img, svg { max-width: 100%; }

/* ---------- Header ---------- */
.app-header {
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  padding: 1rem 1.25rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { font-size: 1.8rem; }
.brand-name { font-size: 1.4rem; font-weight: 700; color: var(--color-primary-dark); }

/* ---------- Layout ---------- */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* ---------- Hero ---------- */
.hero { text-align: center; margin-bottom: 2.5rem; }
.hero h1 {
  font-size: 2.2rem;
  line-height: 1.3;
  margin: 0 0 1rem;
  color: var(--color-text);
}
.lead {
  font-size: 1.15rem;
  color: var(--color-muted);
  max-width: 32em;
  margin: 0 auto 2rem;
}

/* ---------- Buttons ---------- */
.cta-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 420px;
  margin: 0 auto;
}
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0.75rem 1.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary-dark);
  border-color: var(--color-primary);
}
.btn-secondary:hover { background: #fff0f4; }

/* ---------- Features ---------- */
.features {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  margin-bottom: 2.5rem;
}
.feature-card {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.feature-icon { font-size: 2.4rem; display: block; margin-bottom: 0.5rem; }
.feature-card h2 { font-size: 1.3rem; margin: 0 0 0.5rem; }
.feature-card p { font-size: 1.05rem; color: var(--color-muted); margin: 0; }

/* ---------- Disclaimer ---------- */
.disclaimer {
  background: #fff8e6;
  border: 2px solid #f5d97a;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 1rem;
  color: #6b5900;
  text-align: center;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--color-muted);
  font-size: 0.95rem;
}

/* ---------- ฟอร์ม (สมัคร/เข้าสู่ระบบ) ---------- */
.container-narrow { max-width: 460px; }
.form-title { font-size: 2rem; margin: 0 0 0.5rem; }
.card-form {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field-label { font-size: 1.1rem; font-weight: 600; }
.field-input {
  min-height: var(--touch);
  padding: 0.6rem 0.9rem;
  font-size: 1.15rem;
  border: 2px solid var(--color-border);
  border-radius: 12px;
  background: #fff;
  width: 100%;
  min-width: 0;        /* กัน input หลุดกรอบใน flex */
  max-width: 100%;
}
.field-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(224, 90, 125, 0.2);
}
.form-msg { margin: 0; min-height: 1.4em; font-size: 1.05rem; }
.form-msg-error { color: #b3261e; font-weight: 600; }
.form-alt { text-align: center; font-size: 1.05rem; }
.form-alt a, .field a { color: var(--color-primary-dark); font-weight: 600; }

/* ---------- Nav ในหน้าหลังล็อกอิน ---------- */
.app-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }
.app-nav { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.link-btn {
  background: none; border: none; cursor: pointer;
  color: var(--color-primary-dark); font-weight: 600; font-size: 1rem;
  padding: 0.5rem; font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }

/* ปุ่มย้อนกลับหน้าหลัก (เด่น แตะง่าย) */
.back-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: #fff0f4; border: 2px solid var(--color-primary);
  color: var(--color-primary-dark); font-weight: 700; font-size: 1rem;
  padding: 0.5rem 0.9rem; border-radius: 999px; text-decoration: none; min-height: 44px;
}
.back-link:active { transform: scale(0.98); }

/* ปุ่มปรับขนาดตัวอักษร (ก− / ก+) */
.fontctl { display: inline-flex; gap: 0.3rem; align-items: center; }
.fontctl-btn {
  min-width: 44px; min-height: 44px; padding: 0 0.6rem;
  border: 2px solid var(--color-border); background: #fff; border-radius: 10px;
  font-weight: 700; font-size: 1rem; cursor: pointer; color: var(--color-primary-dark); font-family: inherit;
  line-height: 1;
}
.fontctl-btn:active { transform: scale(0.96); }
.fontctl-label { font-size: 0.85rem; color: var(--color-muted); }

/* ---------- Hub (app.html) ---------- */
.greeting { font-size: 1.6rem; margin: 0 0 0.25rem; }
.greeting-sub { color: var(--color-muted); margin: 0 0 1.5rem; }
.hub-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.hub-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: var(--radius); padding: 1.25rem; text-decoration: none;
  color: var(--color-text); box-shadow: var(--shadow);
}
.hub-card:active { transform: scale(0.99); }
.hub-card .hub-icon { font-size: 2rem; }
.hub-card h2 { font-size: 1.25rem; margin: 0 0 0.15rem; }
.hub-card p { margin: 0; color: var(--color-muted); font-size: 1rem; }

/* ---------- รายการ record ---------- */
.record-list { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-direction: column; gap: 0.75rem; }
.record-item {
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: 12px; padding: 1rem;
}
.record-item .r-title { font-weight: 700; font-size: 1.1rem; }
.record-item .r-meta { color: var(--color-muted); font-size: 0.98rem; margin-top: 0.25rem; }
.section-block { margin-bottom: 2.5rem; }
.section-block h2 { font-size: 1.4rem; border-bottom: 2px solid var(--color-border); padding-bottom: 0.4rem; }
.empty-note { color: var(--color-muted); font-style: italic; }
.field-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 45%; min-width: 0; }
.hidden { display: none !important; }

/* ---------- Popup (สิ่งที่ต้องทำ) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100;
}
.modal {
  background: var(--color-surface); border-radius: var(--radius);
  max-width: 460px; width: 100%; padding: 1.5rem; box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  max-height: 85vh; overflow-y: auto;
}
.modal h2 { margin-top: 0; }
.todo-list { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.todo-item { display: flex; gap: 0.6rem; padding: 0.75rem; border-radius: 10px; background: #fff5f7; border: 1px solid var(--color-border); }
.todo-badge { font-size: 1.3rem; }

/* ---------- สรุปสุขภาพ (dashboard) ---------- */
.summary-top { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-bottom: 1.5rem; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.stat {
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: 12px; padding: 0.9rem 1rem; text-align: center;
}
.stat-label { font-size: 0.95rem; color: var(--color-muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--color-primary-dark); }
.stat-date { font-size: 0.85rem; color: var(--color-muted); }
.trend {
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: 12px; padding: 1rem; margin-top: 1rem;
}
.trend-title { font-weight: 600; margin-bottom: 0.5rem; }
.trend-link { display: block; text-decoration: none; color: var(--color-text); cursor: pointer; }
.trend-link:hover { border-color: var(--color-primary); background: #fff5f7; }
.trend-go { color: var(--color-primary-dark); font-weight: 800; float: right; }
#dashboard h2 { font-size: 1.3rem; border-bottom: 2px solid var(--color-border); padding-bottom: 0.4rem; margin-top: 1.5rem; }

/* ---------- ลูกเล่นสุขภาพวันนี้ ---------- */
.wellness-card {
  background: linear-gradient(135deg, #eafaf0, #f0fbf5);
  border: 2px solid #b6e3c8; border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.5rem;
}
.wellness-head { font-weight: 700; font-size: 1.15rem; color: #1f7a4d; margin-bottom: 0.5rem; }
.wellness-tag { font-size: 0.85rem; font-weight: 600; color: #2a8c5a; background: #fff; border: 1px solid #b6e3c8; border-radius: 999px; padding: 0.1rem 0.6rem; }
.wellness-row { display: flex; gap: 0.75rem; margin-top: 0.6rem; align-items: flex-start; }
.wellness-label { min-width: 8.5em; font-weight: 600; color: #2a6c4a; }
.wellness-body { flex: 1; min-width: 0; }
.wellness-desc { color: var(--color-muted); font-size: 0.98rem; }

/* ---------- AI วิเคราะห์สุขภาพ ---------- */
.ai-section h2 { font-size: 1.3rem; }
.ai-beta { font-size: 0.9rem; color: var(--color-muted); font-weight: 400; }
.ai-result { margin-top: 1rem; }
.ai-loading { color: var(--color-muted); }
.ai-text {
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: var(--radius); padding: 1.25rem; line-height: 1.7; box-shadow: var(--shadow);
}
.ai-disclaimer {
  margin-top: 0.75rem; font-size: 0.95rem; color: #6b5900;
  background: #fff8e6; border: 1.5px solid #f5d97a; border-radius: 12px; padding: 0.75rem 1rem;
}

/* ---------- การ์ดเตือนโรคประจำตัว/แพ้ยา (dashboard) ---------- */
.health-alert {
  background: #fff8e6; border: 2px solid #f5d97a; border-radius: var(--radius);
  padding: 1rem 1.25rem; margin-bottom: 1.5rem;
}
.ha-title { font-weight: 700; font-size: 1.15rem; margin-bottom: 0.5rem; color: #7a5c00; }
.ha-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.4rem; }
.ha-label { font-weight: 600; color: var(--color-muted); min-width: 5.5em; }
.ha-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ha-tag {
  background: #fff; border: 1.5px solid #e0b64d; color: #7a5c00;
  border-radius: 999px; padding: 0.2rem 0.7rem; font-weight: 600; font-size: 0.98rem;
}
.ha-tag.ha-danger { border-color: #e08080; color: #b3261e; background: #fff5f5; }

/* ---------- ลิงก์ค้นหาเบอร์ใน Google ---------- */
.find-phone { display: inline-block; margin-top: 0.4rem; font-size: 0.98rem; color: var(--color-primary-dark); font-weight: 600; text-decoration: none; }
.find-phone:hover { text-decoration: underline; }

/* ---------- เบอร์ฉุกเฉิน ---------- */
.myhosp {
  background: #fff0f4; border: 2px solid var(--color-primary); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.5rem; text-align: center;
}
.myhosp-label { font-size: 1rem; color: var(--color-muted); }
.myhosp-name { font-size: 1.4rem; font-weight: 700; margin: 0.25rem 0 0.75rem; }
.myhosp-call { width: 100%; }
.myhosp-note { font-size: 0.9rem; color: var(--color-muted); margin-top: 0.5rem; }
.emg-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
.emg-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: 12px; padding: 1rem 1.25rem; text-decoration: none; color: var(--color-text);
}
.emg-card:active { transform: scale(0.99); }
.emg-num { font-size: 1.6rem; font-weight: 800; color: var(--color-primary-dark); min-width: 3.5em; }
.emg-name { font-size: 1.05rem; }
.emg-urgent { border-color: #e0808f; background: #fff5f6; }
.emg-urgent .emg-num { color: #c0143c; }

/* ---------- จอใหญ่: การ์ด 3 คอลัมน์ ---------- */
@media (min-width: 720px) {
  .features { grid-template-columns: repeat(3, 1fr); }
  .hero h1 { font-size: 2.6rem; }
  .hub-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-top { grid-template-columns: repeat(4, 1fr); }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .emg-grid { grid-template-columns: repeat(2, 1fr); }
}
