/* style.css - ระบบดีไซน์กลางของทั้งโปรเจ็ค (mobile-first, มินิมอล)
   - สี/ระยะ/มุมโค้ดทั้งหมดอยู่ใน :root เปลี่ยนที่เดียวมีผลทุกหน้า
   - คอมโพเนนต์กลาง: .container, .app-header, .card (= .form-container), ปุ่ม, ช่องกรอก, .field
   - หน้าไหนมีของเฉพาะตัวใส่ <style> ในหน้านั้น แต่ใช้ตัวแปรจากที่นี่ */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  /* แบรนด์ PaiNam: เขียวสด #2BD47D ใช้กับโลโก้/จุดเด่น (ตัวอักษรขาวบนสีนี้อ่านยาก — ห้ามใช้เป็นพื้นปุ่ม)
     เขียวเข้ม #0E7A45 ใช้กับปุ่ม/ลิงก์ (ตัวอักษรขาว 5.4:1) — สีมาจากดีไซน์โลโก้ */
  --brand: #2BD47D;
  --brand-ink: #0B1F14;
  --primary: #0E7A45;
  --primary-hover: #095C33;
  --primary-soft: #E8F7EF;
  --focus-ring: rgba(14, 122, 69, 0.35);
  --focus-glow: rgba(14, 122, 69, 0.15);
  --success: #16a34a;
  --success-hover: #15803d;
  --success-soft: #f0fdf4;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --warning: #b45309;
  --warning-soft: #fffbeb;

  /* สีประจำบทบาท (ผู้ขับ = เขียว, ผู้โดยสาร = น้ำเงิน) - body[data-role] สลับ --accent ให้ */
  --accent: var(--primary);
  --accent-soft: var(--primary-soft);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.16);

  --tap: 48px; /* พื้นที่แตะขั้นต่ำของปุ่ม/ช่องกรอกหลัก */
  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

body[data-role="driver"]    { --accent: #16a34a; --accent-soft: #f0fdf4; }
body[data-role="passenger"] { --accent: #2563eb; --accent-soft: #eff6ff; }

/* ---------- พื้นฐาน ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
}

/* แอตทริบิวต์ hidden ต้องซ่อนจริงเสมอ (button/flex ที่ตั้ง display ไว้จะชนะค่าเริ่มต้นของเบราว์เซอร์) */
[hidden] { display: none !important; }

.muted { color: var(--muted); }

/* หัวหน้า: ชื่อหน้า + ลิงก์ย้อนกลับ/ปุ่มเสริมด้านขวา */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.app-header h1 { font-size: 1.4rem; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  margin-left: -12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.93rem;
  font-weight: 500;
}
.back-link:hover { background: var(--surface-2); text-decoration: none; }

/* แบรนด์ (หน้าล็อกอิน/ตั้งรหัสผ่านใหม่) */
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  margin: 24px 0 24px;
}
.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.brand-mark svg { width: 30px; height: 30px; }
.brand h1 { font-size: 1.6rem; }
/* โลโก้ PaiNam (img/logo-mark.svg + wordmark Outfit 900 สีเขียวแบรนด์) */
.brand-logo { width: 64px; height: 64px; display: block; }

/* แถบแบรนด์บนหัวทุกหน้า (โลโก้ + ชื่อ) — กดกลับแดชบอร์ด */
.brand-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 4px;
  color: var(--primary);
  text-decoration: none;
}
.brand-bar:hover { text-decoration: none; opacity: 0.85; }
.brand-bar img { width: 28px; height: 28px; display: block; }
.brand-bar span,
.wordmark {
  font-family: 'Outfit', var(--font);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
}
.brand-bar span { font-size: 1.35rem; }
.brand h1.brand-wordmark {
  font-family: 'Outfit', var(--font, sans-serif);
  font-weight: 900;
  font-size: 2.6rem;
  letter-spacing: -0.045em;
  line-height: 1;
  color: #2BD47D;
}
.brand p { color: var(--muted); font-size: 0.95rem; }

/* ---------- การ์ด ---------- */
.card,
.form-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 16px;
}
.card > h2,
.form-container > h2 { margin-bottom: 14px; }
.card-sub { color: var(--muted); font-size: 0.9rem; margin: -8px 0 14px; }

/* ---------- ฟอร์ม ---------- */
form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ช่องกรอกทั่วไป (ยกเว้น checkbox/radio/file) - font-size 16px ห้ามลด: ต่ำกว่านี้ iOS Safari
   จะซูมเข้าเองตอนแตะช่อง */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-glow);
}
input::placeholder, textarea::placeholder { color: #9ca3af; }
input[type="checkbox"], input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

/* ช่องกรอกพร้อมป้ายกำกับ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label,
.field-label { font-size: 0.88rem; font-weight: 500; color: var(--text-2); }
.field-hint { font-size: 0.8rem; color: var(--muted); }

/* ---------- ปุ่ม ----------
   button เปล่า = ปุ่มหลัก (สี primary); เปลี่ยนแบบด้วยคลาส .btn-secondary / .btn-ghost / .btn-danger
   ปุ่มของปลั๊กอินแผนที่ (Leaflet / Routing Machine) มีสไตล์ตัวเองที่เฉพาะเจาะจงกว่าอยู่แล้ว */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  background-color: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}
button:hover { background-color: var(--primary-hover); }
button:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-block { width: 100%; }
.btn-secondary,
button.btn-secondary {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover,
button.btn-secondary:hover { background-color: var(--surface-2); }
button.btn-ghost {
  background: transparent;
  color: var(--text-2);
}
button.btn-ghost:hover { background: var(--surface-2); }
button.btn-danger,
.btn-danger { background-color: var(--danger); color: #fff; }
button.btn-danger:hover,
.btn-danger:hover { background-color: var(--danger-hover); }
button.btn-danger-outline {
  background: var(--surface);
  color: var(--danger);
  border-color: #fecaca;
}
button.btn-danger-outline:hover { background: var(--danger-soft); }

/* ป้าย/ชิป */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}

/* ---------- ข้อความแจ้งเตือน ---------- */
.alert {
  padding: 12px 14px;
  margin: 4px 0;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
}
.alert-success { background-color: var(--success-soft); color: #166534; }
.alert-error { background-color: var(--danger-soft); color: #991b1b; }

.form-msg { min-height: 1.2em; color: var(--danger); font-size: 0.9rem; }

.text-links {
  text-align: center;
  font-size: 0.92rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
}

/* ช่องติ๊กยอมรับข้อตกลงตอนลงทะเบียน */
.consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text-2);
  cursor: pointer;
}
.consent input { margin-top: 3px; }

/* ---------- ปุ่มเข้าสู่ระบบด้วย Google (js/googleSignIn.js) ---------- */
.gsi-slot { display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 44px; }
.or-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 14px;
}
.or-sep::before, .or-sep::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.gsi-notice { font-size: 0.88rem; color: var(--text-2); text-align: center; margin: 0; }
.gsi-external { font-weight: 600; }
.gsi-terms {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.9rem;
}
.gsi-terms button { width: 100%; }

.legal-links {
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 8px;
}
.legal-links a { color: var(--muted); }

/* ---------- หน้าข้อตกลงการใช้งาน / ประกาศความเป็นส่วนตัว ---------- */
.legal-doc { line-height: 1.75; }
.legal-doc h1 { font-size: 1.4rem; margin-bottom: 4px; }
.legal-doc h2 {
  margin-top: 1.4em;
  margin-bottom: 0.4em;
  font-size: 1.05rem;
}
.legal-doc p, .legal-doc li { color: var(--text-2); }
.legal-doc ul,
.legal-doc ol {
  padding-left: 1.4em;
}
.legal-doc .meta {
  color: var(--muted);
  font-size: 0.88rem;
}
.legal-doc .todo {
  background: var(--warning-soft);
  color: var(--warning);
  padding: 0 4px;
  border-radius: 4px;
}
.accept-box {
  border-top: 1px solid var(--border);
  margin-top: 1.5em;
  padding-top: 1em;
}
.accept-box form { margin: 12px 0; }
.accept-box button { width: 100%; }
.legal-doc #backLink { margin-top: 1.5em; }

/* ---------- แผนที่ (map.html) ---------- */
.map-container {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  position: relative;
}

#map {
  height: 100%;
  width: 100%;
}

.controls {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--surface);
  padding: 12px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1001;
}

/* ส่วนแสดงเส้นทางที่ตรงกัน (มุมซ้ายล่าง - มือถือถูกจัดใหม่ใน map.html) */
.matches-container {
  position: absolute;
  left: 16px !important;
  bottom: 16px;
  background: var(--surface);
  padding: 14px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(340px, calc(100vw - 32px)); /* กันล้นขอบจอแคบมาก ๆ */
  max-height: min(480px, calc(100vh - 32px));
  overflow-y: auto;
  z-index: 1000;
}

/* บรรทัด "ค้นจาก: ..." ใต้หัวกล่องผลลัพธ์ */
.matches-ref {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 10px;
  overflow-wrap: anywhere;
}

/* routing panel ของ Leaflet Routing Machine (map.js ย้ายเข้า .controls - กฎใน map.html ทับอีกชั้น) */
.leaflet-routing-container {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  top: auto !important;
  left: auto !important;
  width: 300px !important;
  max-height: 400px !important;
  overflow-y: auto !important;
  background: white !important;
  padding: 10px !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  z-index: 999 !important;
}

.leaflet-routing-alt {
  max-height: 250px !important;
  overflow-y: auto !important;
  margin-top: 10px !important;
  border-top: 1px solid var(--border) !important;
  padding-top: 10px !important;
  font-size: 13px;
  color: var(--text-2);
}
.leaflet-routing-alt h2 { font-size: 14px; color: var(--text); }
.leaflet-routing-alt h3 { font-size: 13px; font-weight: 500; color: var(--muted); }

/* ซ่อนปุ่มที่ไม่จำเป็น */
.leaflet-routing-collapse-btn {
  display: none !important;
}

.leaflet-routing-geocoders {
  margin-bottom: 4px !important;
  border-bottom: none !important;
  padding: 0 !important;
}

.leaflet-routing-geocoders input {
  width: 100% !important;
  min-height: 44px !important;
  margin: 3px 0 !important;
  padding: 8px 12px !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--radius-sm) !important;
  background: var(--surface-2) !important;
}
.leaflet-routing-geocoders input:focus {
  background: var(--surface) !important;
}

/* Leaflet ใช้ฟอนต์ของตัวเอง - ให้ตรงกับทั้งเว็บ */
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper { border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- จอกว้าง ---------- */
@media (min-width: 601px) {
  .container { padding-top: 40px; }
  .card, .form-container { padding: 24px; }
  button { min-height: 44px; }
}

/* ป้ายยานพาหนะของคนขับ (รถยนต์/มอเตอร์ไซค์) - สี+ไอคอนต่างกัน ผู้โดยสารแยกออกได้ทันทีที่เห็น */
.vehicle-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.vehicle-badge.car        { background: var(--primary-soft); color: var(--primary-hover); }
.vehicle-badge.motorcycle { background: var(--warning-soft); color: var(--warning); }
.vehicle-badge.unknown    { background: var(--surface-2); color: var(--muted); }

/* ---------- สลับภาษา (js/i18n.js) ---------- */
.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
button.lang-toggle {
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border-strong);
  font-size: 14px;
  font-weight: 600;
}
button.lang-toggle:hover { background: var(--primary-soft); }
.lang-toggle--corner {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  z-index: 10;
}
/* หน้าแผนที่: ถัดจากปุ่มกลับมุมซ้ายบน (left ตั้งใน i18n.js ตามความกว้างปุ่มกลับ) — มุมล่างซ้ายเป็นที่ของผลค้นหา */
.lang-toggle--map {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: 160px;
  z-index: 1001;
  box-shadow: var(--shadow);
}
/* เนื้อหายาวสองภาษา (terms/privacy): แสดงบล็อกตามภาษาที่เลือก */
[data-lang-block="en"] { display: none; }
html[data-lang="en"] [data-lang-block="th"] { display: none; }
html[data-lang="en"] [data-lang-block="en"] { display: block; }
.legal-note { color: var(--muted); font-size: 0.85rem; font-style: italic; margin-bottom: 12px; }

/* ---------- หน้าว่าง (ยังไม่มีข้อมูล): บอกว่าส่วนนี้คืออะไร + ขั้นถัดไป ---------- */
.empty-state { text-align: center; padding: 16px 0; }
.empty-state .empty-title { color: var(--text-2); font-weight: 500; }
.empty-hint { color: var(--muted); font-size: 0.86rem; margin-top: 4px; line-height: 1.6; }
.empty-state .btn-accent { margin-top: 12px; }
/* ลิงก์หน้าตาเป็นปุ่ม สีตามบทบาท */
a.btn-accent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}
a.btn-accent:hover { text-decoration: none; opacity: 0.92; }
