:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1c2536;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-dark: #15803d;
  --red: #dc2626;
  --amber: #d97706;
  --border: #e5e7eb;
  --soft: #f8fafc;         /* พื้นอ่อน (หัวตาราง, ช่อง readonly) */
  --soft-blue: #eff6ff;    /* พื้นเน้นฟ้าอ่อน */
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* 🌙 โหมดกลางคืน */
:root[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --green: #22c55e;
  --green-dark: #16a34a;
  --red: #f87171;
  --amber: #fbbf24;
  --border: #334155;
  --soft: #0f172a;
  --soft-blue: #1e3a8a;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  /* ฟอนต์อังสนานิว (บนวินโดว์) → สำรองด้วยสารบรรณ/ระบบ สำหรับมือถือ */
  font-family: "Angsana New", "AngsanaUPC", "Sarabun", "Leelawadee UI",
    -apple-system, "Segoe UI", Tahoma, sans-serif;
  font-size: 17px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
}

.center-screen {
  display: flex;
  align-items: center;
  min-height: 100vh;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  width: 100%;
}

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 0.9rem; }

label { display: block; font-size: 0.9rem; font-weight: 600; margin: 14px 0 6px; }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="month"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[readonly] { background: var(--soft); }
/* ปุ่มสลับโหมดกลางวัน/กลางคืน */
.theme-toggle {
  position: fixed; right: 16px; bottom: 16px; z-index: 200;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--card); color: var(--text);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  font-size: 1.3rem; display: flex; align-items: center; justify-content: center;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.05s, background 0.15s;
}
button:active { transform: scale(0.98); }

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
  padding: 13px;
  margin-top: 20px;
}
.btn-primary:hover { background: var(--primary-dark); }

/* ปุ่มเช็คอิน/เอาท์ ใหญ่ ๆ */
.btn-action {
  width: 100%;
  padding: 22px;
  font-size: 1.3rem;
  color: #fff;
  margin-top: 8px;
}
.btn-checkin { background: var(--green); }
.btn-checkin:hover { background: var(--green-dark); }
.btn-checkout { background: var(--amber); }
.btn-checkout:hover { background: #b45309; }
.btn-action:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 8px;
  font-size: 0.9rem;
}

/* ตัวเลือกกะ */
.shift-toggle { display: flex; gap: 10px; margin: 6px 0 16px; }
.shift-toggle button {
  flex: 1;
  padding: 14px 8px;
  background: var(--card);
  border: 2px solid var(--border);
  color: var(--text);
}
.shift-toggle button.active {
  border-color: var(--primary);
  background: var(--soft-blue);
  color: var(--primary);
}

.status-box {
  text-align: center;
  padding: 18px;
  border-radius: 12px;
  margin: 14px 0;
}
.status-in { background: #dcfce7; color: #15803d; }
.status-out { background: var(--soft); color: var(--muted); }
.status-box .big { font-size: 1.6rem; font-weight: 700; }

.clock { text-align: center; font-size: 2.2rem; font-weight: 700; margin: 4px 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}

.list { margin-top: 18px; }
.list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem;
}
.badge {
  font-size: 0.75rem; padding: 2px 8px; border-radius: 20px; font-weight: 600;
}
.badge-in { background: #dcfce7; color: var(--green-dark); }
.badge-out { background: #fee2e2; color: var(--red); }
.badge-day { background: #fef9c3; color: #a16207; }
.badge-night { background: #e0e7ff; color: #4338ca; }

.alert { padding: 12px 14px; border-radius: 10px; margin: 12px 0; font-size: 0.92rem; }
.alert-error { background: #fee2e2; color: var(--red); }
.alert-ok { background: #dcfce7; color: var(--green-dark); }
.hidden { display: none !important; }
.gps-note { font-size: 0.82rem; margin-top: 10px; text-align: center; }

/* กล้องถ่ายรูป */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.88);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-inner { width: 100%; max-width: 460px; }
#camVideo {
  width: 100%; border-radius: 14px; background: #000;
  aspect-ratio: 3 / 4; object-fit: cover;
  transform: scaleX(-1); /* กล้องหน้าแบบกระจกเงา (เหมือนแอปเซลฟี่) */
}
.cam-buttons { display: flex; gap: 10px; margin-top: 14px; }
.cam-buttons button { flex: 1; margin-top: 0; padding: 14px; }
.cam-title { color: #fff; text-align: center; margin-bottom: 10px; font-weight: 600; }

/* รูปย่อในรายการ */
.thumb {
  width: 36px; height: 36px; border-radius: 7px; object-fit: cover;
  border: 1px solid var(--border); margin-right: 8px; vertical-align: middle;
  cursor: pointer;
}
.badge-warn { background: #fee2e2; color: var(--red); }

/* ลิงก์แอดมิน */
.admin-link { font-size: 0.85rem; color: var(--primary); text-decoration: none; }
