/* =============================================================
   BTK Install & Service — ระบบเช็กอินพนักงาน
   style.css : ธีม Modern Mobile Application (Mobile First)
   ============================================================= */

/* ---------- ตัวแปรสี / เงา / มุมมน ---------- */
:root {
  /* โทนสีหลัก: น้ำเงินเข้ม / ฟ้า / ขาว / เทาอ่อน */
  --navy: #0b2447;
  --navy-700: #143a6b;
  --blue: #19a7ce;
  --blue-600: #1287a8;
  --blue-50: #e8f6fb;

  --white: #ffffff;
  --gray-50: #f4f7fa;
  --gray-100: #eaeff5;
  --gray-300: #cbd5e1;
  --gray-500: #6b7c93;
  --gray-700: #3c4a5c;

  --green: #16a34a;
  --green-50: #e9f8ef;
  --red: #dc2626;
  --red-50: #fdecec;
  --orange: #ea8a00;
  --orange-50: #fff4e2;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;

  --shadow-sm: 0 2px 8px rgba(11, 36, 71, .06);
  --shadow-md: 0 6px 20px rgba(11, 36, 71, .10);
  --shadow-lg: 0 16px 40px rgba(11, 36, 71, .22);

  --space: 16px;
  --app-w: 520px;              /* ความกว้างกรอบแอป ใช้จัดตำแหน่งปุ่มลอย */
  --font: "Noto Sans Thai", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-700);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd, dt { margin: 0; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

/* กรอบแอปหลัก */
.app {
  max-width: var(--app-w);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--gray-50);
  padding-bottom: 100px; /* เผื่อพื้นที่ปุ่มลอย */
}

/* =============================================================
   1. Header
   ============================================================= */
.header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-700) 55%, var(--blue-600) 100%);
  color: var(--white);
  padding: calc(env(safe-area-inset-top, 0px) + 20px) var(--space) 26px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header__logo {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, .15);
  border: 1px solid rgba(255, 255, 255, .25);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .5px;
}

.header__title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.header__subtitle {
  font-size: 13px;
  opacity: .8;
}

/* วันที่ / เวลา */
.header__datetime {
  margin-top: 18px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header__date { font-size: 14px; opacity: .92; }

.header__time {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .5px;
}

/* =============================================================
   Layout เนื้อหา + การ์ดมาตรฐาน
   ============================================================= */
.content {
  padding: var(--space);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space);
}

.card--flush { padding: 0; overflow: hidden; }

.card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--navy);
  margin-bottom: 12px;
}

.card__title {
  font-size: 15px;
  font-weight: 600;
}

/* =============================================================
   2. Profile พนักงาน
   ============================================================= */
.profile {
  display: flex;
  align-items: center;
  gap: 14px;
}

.profile__avatar {
  position: relative;
  width: 58px;
  height: 58px;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue) 0%, var(--navy) 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(25, 167, 206, .35);
}

.profile__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--white);
}

/* ตัวอักษรย่อ: ใช้แทนเมื่อโหลดรูปโปรไฟล์ไม่สำเร็จ */
.profile__initial {
  position: absolute;
  color: var(--white);
  font-size: 24px;
  font-weight: 700;
}

.profile__name {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}

.profile__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge--code { background: var(--gray-100); color: var(--gray-700); }
.badge--role { background: var(--blue-50); color: var(--blue-600); font-weight: 600; }

.profile__status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-50);
  margin-left: auto;
  align-self: flex-start;
}

/* =============================================================
   3. GPS Status
   ============================================================= */
.gps__loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--gray-500);
  font-size: 14px;
  padding: 6px 0;
}

/* 13. Loading Spinner */
.spinner {
  width: 20px;
  height: 20px;
  flex: none;
  border: 3px solid var(--gray-100);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.gps__error {
  background: var(--red-50);
  border: 1px solid rgba(220, 38, 38, .2);
  border-radius: var(--radius-sm);
  padding: 14px;
  color: var(--red);
  font-size: 14px;
  text-align: center;
}

.gps__error p { margin-bottom: 12px; }

.gps__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--gray-100);
}

.gps__row:last-of-type { border-bottom: 0; }

.gps__label { font-size: 13px; color: var(--gray-500); }

.gps__value {
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.alert {
  font-size: 13px;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
}

.alert--warn {
  background: var(--orange-50);
  color: var(--orange);
  border: 1px solid rgba(234, 138, 0, .25);
}

/* =============================================================
   4. แผนที่
   ============================================================= */
#map {
  height: 320px;
  width: 100%;
  background: var(--gray-100);
  z-index: 0; /* กัน control ของ Leaflet ทับ modal */
}

/* ปรับหน้าตา control ของ Leaflet ให้เข้ากับธีมแอป */
.leaflet-control-layers,
.leaflet-bar {
  border-radius: 12px !important;
  border: 0 !important;
  box-shadow: var(--shadow-md) !important;
  overflow: hidden;
}

.leaflet-control-layers {
  font-family: var(--font);
  font-size: 13px;
  color: var(--navy);
  padding: 4px 6px;
}

.leaflet-control-layers label { display: flex; align-items: center; gap: 6px; }

.leaflet-container .leaflet-control-attribution {
  font-size: 10px;
  background: rgba(255, 255, 255, .85);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 11px var(--space);
  font-size: 12px;
  color: var(--gray-500);
  border-top: 1px solid var(--gray-100);
}

.legend { display: inline-flex; align-items: center; gap: 6px; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot--blue { background: var(--blue); }
.dot--red { background: var(--red); }
.dot--ring { border: 2px solid #38bdf8; background: rgba(56, 189, 248, .22); }

/* =============================================================
   5. ระยะห่างจากจุดเช็กอิน
   ============================================================= */
.distance {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.distance__site {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.distance__name {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}

.distance__radius { font-size: 12px; color: var(--gray-500); }

.distance__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--gray-100);
}

.distance__label { font-size: 14px; color: var(--gray-500); }

.distance__value {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

/* =============================================================
   6. Status Card (ในพื้นที่ / นอกพื้นที่ / GPS ไม่แม่นยำ)
   ============================================================= */
.status {
  border-left: 5px solid var(--gray-300);
  transition: background-color .25s ease, border-color .25s ease;
}

.status__head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--gray-700);
}

.status__icon {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--gray-100);
  color: var(--gray-500);
  font-size: 16px;
  font-weight: 700;
}

.status__body { margin-top: 10px; }

.status__label { font-size: 13px; color: var(--gray-500); display: block; }

.status__distance {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.status__hint { font-size: 13px; margin-top: 4px; color: var(--gray-500); }

/* อยู่ในพื้นที่ — เขียว */
.status--in { background: var(--green-50); border-left-color: var(--green); }
.status--in .status__head { color: var(--green); }
.status--in .status__icon { background: var(--green); color: var(--white); }
.status--in .status__hint { color: var(--green); }

/* อยู่นอกพื้นที่ — แดง */
.status--out { background: var(--red-50); border-left-color: var(--red); }
.status--out .status__head { color: var(--red); }
.status--out .status__icon { background: var(--red); color: var(--white); }
.status--out .status__hint { color: var(--red); }

/* GPS ยังไม่แม่นยำ — ส้ม */
.status--warn { background: var(--orange-50); border-left-color: var(--orange); }
.status--warn .status__head { color: var(--orange); }
.status--warn .status__icon { background: var(--orange); color: var(--white); }
.status--warn .status__hint { color: var(--orange); }

/* =============================================================
   7. ปุ่ม
   ============================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-weight: 600;
  color: var(--white);
  background: var(--navy);
  transition: transform .12s ease, box-shadow .2s ease, background-color .2s ease;
}

.btn:active { transform: scale(.98); }

.btn--primary {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-600) 100%);
  box-shadow: 0 6px 18px rgba(25, 167, 206, .35);
}

.btn--lg {
  width: 100%;
  min-height: 56px;
  font-size: 17px;
  font-weight: 700;
}

.btn--outline {
  background: transparent;
  color: var(--red);
  border: 1.5px solid currentColor;
  padding: 9px 18px;
  font-size: 14px;
}

/* ปุ่มพร้อมเช็กอิน — เขียว */
.btn--ready {
  background: linear-gradient(135deg, #22c55e 0%, var(--green) 100%);
  box-shadow: 0 6px 18px rgba(22, 163, 74, .35);
}

/* ปุ่มถูก Disable — เทา กดไม่ได้ */
.btn:disabled {
  background: var(--gray-300);
  color: #fbfdff;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

/* ปุ่มหลังเช็กอินแล้ว */
.btn--done:disabled {
  background: var(--green-50);
  color: var(--green);
  border: 1.5px solid var(--green);
}

.checkin-area { margin-top: 2px; }

.checkin-note {
  text-align: center;
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 10px;
  min-height: 20px;
}

/* =============================================================
   14. ปุ่มลอย อัปเดตตำแหน่ง (FAB)
   ============================================================= */
.fab {
  position: fixed;
  /* ชิดขอบขวาของกรอบแอปเสมอ ไม่ลอยห่างเมื่อจอกว้าง */
  right: max(16px, calc(50% - var(--app-w) / 2 + 16px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--navy);
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

.fab:active { transform: scale(.97); }

.fab--busy { opacity: .7; pointer-events: none; }
.fab--busy .icon { animation: spin 1s linear infinite; }

/* =============================================================
   15. Footer
   ============================================================= */
.footer {
  text-align: center;
  padding: 24px var(--space) 32px;
  color: var(--gray-500);
}

.footer__name { font-size: 14px; font-weight: 700; color: var(--navy); }
.footer__desc { font-size: 12px; }
.footer__version { font-size: 12px; opacity: .75; margin-top: 4px; }

/* =============================================================
   8. Modal เช็กอินสำเร็จ
   ============================================================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 36, 71, .55);
  backdrop-filter: blur(3px);
  animation: fade-in .2s ease;
}

.modal__box {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop-in .25s cubic-bezier(.2, .9, .3, 1.2);
}

.modal__icon {
  width: 66px;
  height: 66px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--green-50);
  color: var(--green);
  display: grid;
  place-items: center;
}

.modal__icon svg { width: 34px; height: 34px; }

.modal__title {
  font-size: 20px;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 16px;
}

.modal__list {
  text-align: left;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  margin-bottom: 18px;
}

.modal__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--gray-100);
}

.modal__row:last-child { border-bottom: 0; }

.modal__row dt { font-size: 13px; color: var(--gray-500); }

.modal__row dd {
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.modal .btn { width: 100%; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to { opacity: 1; transform: none; }
}

/* =============================================================
   Responsive : Tablet / Desktop (เน้นมือถือเป็นหลัก)
   ============================================================= */
@media (min-width: 768px) {
  body { font-size: 16px; }

  :root { --app-w: 640px; }

  #map { height: 380px; }

  .header__title { font-size: 20px; }
  .header__time { font-size: 24px; }

  .profile__avatar { width: 66px; height: 66px; }
}

@media (min-width: 1024px) {
  :root { --app-w: 480px; }

  body {
    background: linear-gradient(160deg, #e6ecf4 0%, var(--gray-50) 100%);
  }

  .app {
    max-width: var(--app-w);       /* กรอบแบบ Mobile App กลางจอ */
    margin: 24px auto;
    min-height: calc(100vh - 48px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
  }

}

/* ลดการเคลื่อนไหวสำหรับผู้ใช้ที่ตั้งค่าไว้ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}


.loading-overlay {
  position: fixed;
  inset: 0;

  z-index: 9999;

  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(11, 36, 71, 0.35);
  backdrop-filter: blur(5px);

  animation: loadingFadeIn 0.2s ease;
}

.loading-overlay.hidden {
  display: none;
}

.loading-box {
  width: 190px;
  padding: 26px 22px;

  background: #ffffff;

  border-radius: 20px;

  text-align: center;

  box-shadow:
    0 15px 45px rgba(11, 36, 71, 0.22);

  animation: loadingPop 0.25s ease;
}

.loading-spinner {
  width: 52px;
  height: 52px;

  margin: 0 auto 16px;

  border-radius: 50%;

  border: 5px solid #e8f6fb;
  border-top-color: #19a7ce;
  border-right-color: #0b2447;

  animation: loadingSpin 0.8s linear infinite;
}

.loading-title {
  font-size: 16px;
  font-weight: 700;

  color: #0b2447;
}

.loading-text {
  margin-top: 4px;

  font-size: 13px;

  color: #6b7c93;
}

@keyframes loadingSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes loadingFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes loadingPop {
  from {
    opacity: 0;
    transform: scale(0.92);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}
