:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Sarabun", "Leelawadee UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}
.wrap.wide { max-width: 1100px; }

header.app {
  background: var(--brand);
  color: #fff;
  padding: 18px 16px;
  text-align: center;
}
header.app h1 { margin: 0; font-size: 20px; }
header.app p { margin: 4px 0 0; font-size: 13px; opacity: 0.9; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

label.field { display: block; margin-bottom: 14px; }
label.field > span.lbl {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}
.req { color: var(--danger); }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }

input[type="text"],
input[type="tel"],
input[type="date"],
input[type="number"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }

/* แก้ช่องวันที่บน iOS/Safari ที่กรอบล้น/ตัวอักษรใหญ่ผิดปกติ
   -webkit-appearance: none บังคับให้ช่องวันที่หดตามความกว้าง 100% เหมือนช่องอื่น
   (แตะที่ช่องยังเปิดปฏิทินได้ปกติทั้ง iOS และ Android) */
input[type="date"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  line-height: 1.4;
}
input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
  font-size: 16px;
  margin: 0;
}
input[type="date"]::-webkit-datetime-edit {
  font-size: 16px;
  line-height: 1.4;
  padding: 0;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  transition: background 0.15s;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: #eef2f7; color: var(--text); }
.btn.ghost:hover { background: #e2e8f0; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { padding: 7px 12px; font-size: 14px; }

/* รายการสินค้า */
.item-row {
  display: grid;
  grid-template-columns: 1fr 90px 40px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: start;
}
.item-row input { padding: 9px 10px; }
.item-del {
  background: #fee2e2;
  color: var(--danger);
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  height: 40px;
}
.item-head {
  display: grid;
  grid-template-columns: 1fr 90px 40px;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  padding: 0 2px;
}

.radios label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
}
.radios input { width: auto; }
.radios label.active { border-color: var(--brand); background: #eff6ff; }

/* รูปภาพ */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.success-box { text-align: center; padding: 30px 16px; }
.success-box .check {
  width: 64px; height: 64px;
  background: var(--ok); color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; margin: 0 auto 14px;
}
.success-box .no {
  font-size: 22px; font-weight: 700; color: var(--brand);
  margin: 8px 0; letter-spacing: 0.5px;
}

/* badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.in_progress { background: #dbeafe; color: #1e40af; }
.badge.resolved { background: #dcfce7; color: #166534; }

/* admin */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.toolbar input, .toolbar select { width: auto; flex: 1 1 130px; }

.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.stat {
  flex: 1 1 100px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat .num { font-size: 24px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); }

.report-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.report-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
/* สีกรอบตามสถานะ: ยังไม่เรียบร้อย = แดง, ปิดงาน = เขียว */
.report-card.pending {
  border: 2px solid var(--danger);
  background: #fef2f2;
}
.report-card.resolved {
  border: 2px solid var(--ok);
  background: #f0fdf4;
}
.report-card .top {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 6px;
}
.report-card .no { font-weight: 700; color: var(--brand); font-size: 14px; }
.report-card .meta { font-size: 13px; color: var(--muted); }
.report-card .line { font-size: 14px; margin-top: 2px; }

/* modal */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  padding: 20px;
  margin: auto;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.kv { display: flex; gap: 8px; padding: 7px 0; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.kv .k { color: var(--muted); min-width: 110px; flex-shrink: 0; }
.kv .v { font-weight: 500; }
.modal table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
.modal table th, .modal table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #f1f5f9; }
.modal table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.modal-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: 8px; margin-top: 8px; }
.modal-photos img { width: 100%; border-radius: 8px; cursor: pointer; border: 1px solid var(--line); }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 14px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid #cbd5e1; border-top-color: var(--brand);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer-link { text-align: center; margin: 18px 0; font-size: 13px; }
.footer-link a { color: var(--muted); }
