/* ============================================================
   ระบบแจ้งซ่อม IT — หน้า Ticket (ฟอร์มแจ้งซ่อมภายนอก)
   ออกแบบ: Formal / Flat — เส้น 1px มุมเล็ก สีเขียวเข้มชุดเดียว ไม่มีการตกแต่ง
   token ประกาศที่ :root เพื่อให้หน้าประวัติ (my-tickets.css) ใช้ร่วมได้จริง
   visual scope: body.ticket-page:not(.admin-login-page) — ไม่กระทบหน้า admin
   ============================================================ */

:root {
  --tk-green: #0b7a45;
  --tk-green-deep: #075c34;
  --tk-green-soft: #eef6f1;
  --tk-ink: #1b2420;
  --tk-muted: #5c6a63;
  --tk-line: #d9e0dc;
  --tk-line-soft: #e7ece9;
  --tk-bg: #f1f4f2;
  --tk-card: #ffffff;
  --tk-shadow: 0 1px 2px rgba(16, 32, 24, 0.06);
  --tk-shadow-sm: 0 1px 2px rgba(16, 32, 24, 0.05);
  --tk-shadow-pop: 0 10px 30px rgba(16, 32, 24, 0.16);
  --tk-radius: 8px;
  --tk-amber: #9a6208;
  --tk-amber-soft: #fdf3e0;
  --tk-blue: #1d4ed8;
  --tk-blue-soft: #e6edfd;
}

body.ticket-page:not(.admin-login-page) { background: var(--tk-bg); }

/* ---------- ตัวช่วย animation (สมูท + เท่านั้น transform/opacity) ---------- */
@keyframes ticketFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes ticketRise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes ticketPop {
  0% { opacity: 0; transform: scale(0.92); }
  60% { opacity: 1; transform: scale(1.02); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes ticketSlideDown {
  from { opacity: 0; transform: translateY(-18px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes ticketSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes ticketDraw {
  from { stroke-dashoffset: 48; }
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  body.ticket-page *,
  body.ticket-page *::before,
  body.ticket-page *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- NAVBAR : ทางการ เงียบ ๆ ---------- */
body.ticket-page .navbar { background: rgba(255, 255, 255, 0.9); border-bottom: 1px solid var(--tk-line); }
body.ticket-page .navbar-inner { max-width: 680px; }
body.ticket-page .navbar-brand { color: var(--tk-ink); }
body.ticket-page .navbar-logo-img {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(12, 163, 92, 0.20);
}
body.ticket-page .navbar-title {
  font-weight: 700;
  letter-spacing: 0.2px;
  /* ชื่อยาว "ระบบแจ้งปัญหา/แจ้งซ่อมอุปกรณ์ไอที" ต้องไม่ถูกตัดเป็น ... */
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.25;
}
@media (max-width: 420px) {
  body.ticket-page .navbar-title { font-size: 13px; }
}
body.ticket-page .nav-trigger { color: var(--tk-ink); border-radius: 6px; transition: background 0.15s ease; }
body.ticket-page .nav-trigger:hover { background: var(--tk-green-soft); }

/* ---------- BANNER ฉบับร่าง ---------- */
body.ticket-page .draft-banner {
  max-width: 680px;
  margin: 14px auto 0;
  border-radius: var(--tk-radius);
  background: #fdf7e8;
  border: 1px solid #e8d9ae;
}
body.ticket-page .draft-btn {
  border-radius: 5px;
  border: 1px solid #e5cd7f;
  background: #fff;
  color: #7a5b08;
  font-weight: 600;
  transition: background 0.15s ease;
}
body.ticket-page .draft-btn:hover { background: #fff4d6; }
body.ticket-page .draft-btn.restore { background: var(--tk-green); border-color: var(--tk-green); color: #fff; }
body.ticket-page .draft-close { color: #8a7a3a; transition: color 0.15s ease; }
body.ticket-page .draft-close:hover { color: #5c4a12; }

/* ---------- FORM ---------- */
body.ticket-page .form-wrap {
  max-width: 680px;
  margin: 22px auto 0;
  padding: 0 16px 8px;
}

body.ticket-page .step.is-active {
  background: var(--tk-card);
  border: 1px solid var(--tk-line);
  border-radius: var(--tk-radius);
  padding: 24px 22px 22px;
  box-shadow: var(--tk-shadow);
  will-change: transform, opacity;
}

body.ticket-page .step.is-active.slide-next { animation: slideNext 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }
body.ticket-page .step.is-active.slide-prev { animation: slidePrev 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }

/* ---------- FIELD ---------- */
body.ticket-page .field {
  margin-bottom: 22px;
}
body.ticket-page .field + .field { margin-top: 22px; }
body.ticket-page .field-label { font-size: 14px; font-weight: 600; color: var(--tk-ink); margin-bottom: 6px; }
body.ticket-page .field-hint { font-size: 12.5px; color: var(--tk-muted); margin-bottom: 10px; line-height: 1.5; }
body.ticket-page .req { color: var(--tk-green); }
body.ticket-page .opt-hint {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 500;
  color: var(--tk-muted);
  background: #f4f6f5;
  border: 1px solid var(--tk-line-soft);
  border-radius: 4px;
  padding: 1px 6px;
  vertical-align: middle;
}

body.ticket-page .text-input {
  display: block;
  width: 100%;
  border: 1px solid var(--tk-line);
  border-radius: 6px;
  padding: 11px 13px;
  font-size: 15px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
body.ticket-page .text-input:focus {
  outline: none;
  border-color: var(--tk-green);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(11, 122, 69, 0.14);
}
body.ticket-page .text-input.invalid { border-color: #c0392b !important; box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12); }

/* ---------- โหมดพิมพ์ / พิมพ์ด้วยเสียง (segmented control) ---------- */
body.ticket-page .mode-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: #f1f4f2;
  border: 1px solid var(--tk-line);
  border-radius: 6px;
}
body.ticket-page .mode-btn {
  padding: 10px 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--tk-muted);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.15s ease, color 0.15s ease;
}
body.ticket-page .mode-btn:hover { color: var(--tk-green-deep); }
body.ticket-page .mode-btn.is-active {
  background: #fff;
  color: var(--tk-green-deep);
  box-shadow: 0 1px 2px rgba(16, 32, 24, 0.10);
}

/* ---------- Voice panel ---------- */
body.ticket-page .voice-panel {
  margin-top: 4px;
  border: 1px solid var(--tk-line);
  border-radius: 8px;
  padding: 14px;
  background: #fafcfb;
}
body.ticket-page .voice-help {
  font-size: 13px;
  line-height: 1.55;
  color: var(--tk-muted);
  border-left: 3px solid var(--tk-green);
  padding: 2px 0 2px 12px;
  margin: 0 0 12px;
}
body.ticket-page .mic-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 18px;
  border-radius: 6px;
  border: 1px solid var(--tk-green);
  background: var(--tk-green);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  transition: background 0.15s ease;
}
body.ticket-page .mic-btn:hover { background: var(--tk-green-deep); }
body.ticket-page .mic-btn.listening { background: var(--tk-green-deep); }
body.ticket-page .voice-unsupported {
  margin-top: 10px;
  padding: 10px 13px;
  border: 1px solid #e8d9ae;
  border-radius: 6px;
  background: #fdf7e8;
  color: #7a5b08;
  font-size: 13px;
}

/* ---------- Photo ---------- */
body.ticket-page .photo-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
body.ticket-page .photo-head .field-label { margin-bottom: 6px; }
body.ticket-page .photo-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--tk-muted);
  background: #f4f6f5;
  border: 1px solid var(--tk-line-soft);
  border-radius: 4px;
  padding: 1px 7px;
}
body.ticket-page .photo-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 14px;
  border-radius: 6px;
  border: 1px dashed var(--tk-line);
  background: #fafcfb;
  color: var(--tk-green-deep);
  transition: background 0.15s ease, border-color 0.15s ease;
}
body.ticket-page .photo-btn:hover { background: var(--tk-green-soft); border-color: var(--tk-green); }
body.ticket-page .photo-btn-text { font-size: 14.5px; font-weight: 600; }
body.ticket-page .cam-icon { width: 20px; height: 20px; flex: 0 0 auto; }

body.ticket-page .photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}
body.ticket-page .photo-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: #eef1ef;
  border: 1px solid var(--tk-line);
}
body.ticket-page .photo-item img { width: 100%; height: 100%; object-fit: cover; }
body.ticket-page .photo-index {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  min-width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(11, 122, 67, 0.88);
  border-radius: 999px;
}
body.ticket-page .photo-del {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: rgba(15, 20, 17, 0.66);
  color: #fff;
  transition: transform 0.15s ease, background 0.15s ease;
}
body.ticket-page .photo-del:hover { background: #d64541; transform: scale(1.08); }
body.ticket-page .photo-add {
  aspect-ratio: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px dashed var(--tk-line);
  background: #fafcfb;
  color: var(--tk-muted);
  transition: border-color 0.15s ease, color 0.15s ease;
}
body.ticket-page .photo-add:hover { border-color: var(--tk-green); color: var(--tk-green); }

/* ---------- สาขา (radio list) ---------- */
body.ticket-page .loc-group { display: flex; flex-direction: column; gap: 8px; }
body.ticket-page .loc-group input { position: absolute; opacity: 0; pointer-events: none; }
body.ticket-page .loc-option {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--tk-line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
body.ticket-page .loc-option::before {
  content: "";
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.5px solid #b6c2bb;
  background: #fff;
  transition: border-color 0.15s ease, background 0.15s ease;
}
body.ticket-page .loc-option:hover { border-color: #b9c9c0; }
body.ticket-page .loc-group input:checked + .loc-option {
  border-color: var(--tk-green);
  background: var(--tk-green-soft);
}
body.ticket-page .loc-group input:checked + .loc-option::before {
  background: var(--tk-green);
  border-color: var(--tk-green);
  box-shadow: inset 0 0 0 3.5px #fff;
}
body.ticket-page .loc-group input:checked + .loc-option .loc-title { color: var(--tk-green-deep); }
body.ticket-page .loc-group input:checked + .loc-option .loc-desc { color: var(--tk-muted); }
body.ticket-page .loc-title { font-size: 14px; font-weight: 600; color: var(--tk-ink); }
body.ticket-page .loc-desc { font-size: 12.5px; color: var(--tk-muted); margin-top: 1px; }

/* ---------- ACTION BAR ---------- */
body.ticket-page .action-bar {
  max-width: 680px;
  /* เว้นที่ท้ายหน้าให้แถบเมนูล่าง (ดู padding-bottom ของ body.has-bottom-nav) */
  margin: 0 auto 20px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--tk-line);
  border-radius: var(--tk-radius);
  box-shadow: var(--tk-shadow);
}
body.ticket-page .action-btn { border-radius: 6px; }
body.ticket-page .action-btn.primary {
  background: var(--tk-green);
  color: #fff;
  font-weight: 600;
  transition: background 0.15s ease, opacity 0.2s ease;
}
body.ticket-page .action-btn.primary:hover { background: var(--tk-green-deep); }
body.ticket-page .action-btn.primary:disabled { opacity: 0.6; pointer-events: none; }

/* ---------- Loading overlay ---------- */
body.ticket-page .overlay {
  background: rgba(241, 244, 242, 0.96);
}
body.ticket-page .overlay .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(11, 122, 69, 0.18);
  border-top-color: var(--tk-green);
  animation: spin 0.8s linear infinite;
}
body.ticket-page .overlay-msg { color: var(--tk-muted); font-weight: 600; }

/* ---------- Success ---------- */
body.ticket-page .success-box {
  max-width: 320px;
  border-radius: 10px;
  padding: 22px 20px 20px;
  text-align: center;
  border: 1px solid var(--tk-line);
  box-shadow: var(--tk-shadow-pop);
}
body.ticket-page .success-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--tk-green);
}
body.ticket-page .success-icon::after { display: none; }
body.ticket-page .success-icon svg { width: 22px; height: 22px; }
body.ticket-page .done-title { font-size: 17px; font-weight: 700; color: var(--tk-ink); }
body.ticket-page .done-desc { font-size: 12.5px; color: var(--tk-muted); margin: 4px 0 14px; line-height: 1.5; }
body.ticket-page .success-card {
  background: #fafcfb;
  border: 1px solid var(--tk-line);
  border-radius: 6px;
  padding: 2px 12px;
  margin: 0 0 14px;
  text-align: left;
}
body.ticket-page .success-row { padding: 8px 0; }
body.ticket-page .success-row + .success-row { border-top: 1px solid var(--tk-line-soft); }
body.ticket-page .srow-label { font-size: 12px; color: var(--tk-muted); }
body.ticket-page .srow-value { font-size: 13px; font-weight: 600; color: var(--tk-ink); }
body.ticket-page .srow-detail {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
body.ticket-page .success-card .ticket-no {
  font-family: Consolas, monospace;
  font-size: 17px;
  font-weight: 700;
  color: var(--tk-green-deep);
  letter-spacing: 1px;
}
body.ticket-page .copy-btn {
  width: 100%;
  display: block;
  padding: 10px;
  margin: 0 0 8px;
  border-radius: 6px;
  border: 1px solid var(--tk-line);
  background: #fff;
  color: var(--tk-ink);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease;
}
body.ticket-page .copy-btn:hover { background: #f4f6f5; }
body.ticket-page .back-btn {
  width: 100%;
  display: block;
  padding: 11px;
  border: none;
  border-radius: 6px;
  background: var(--tk-green);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease;
}
body.ticket-page .back-btn:hover { background: var(--tk-green-deep); }
body.ticket-page .history-btn {
  width: 100%;
  display: block;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--tk-line);
  border-radius: 6px;
  background: #fff;
  color: var(--tk-green-deep);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.18s ease;
}
body.ticket-page .history-btn:hover { background: #f4f6f5; }
body.ticket-page .modal-close {
  border-radius: 6px;
  color: var(--tk-muted);
  transition: color 0.15s ease, background 0.15s ease;
}
body.ticket-page .modal-close:hover { color: var(--tk-ink); background: #eef1ef; }

/* ---------- Toast ---------- */
body.ticket-page .toast {
  position: fixed;
  top: auto;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 65;
  max-width: calc(100% - 48px);
  border-radius: 6px;
  background: rgba(23, 36, 28, 0.95);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  padding: 12px 18px;
  text-align: center;
  will-change: transform, opacity;
  animation: toastPopIn 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes toastPopIn {
  from { opacity: 0; transform: translate(-50%, 14px) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* ---------- Shake (field error) ---------- */
body.ticket-page .shake { animation: shakeX 0.4s ease; }

/* ---------- จอเล็กจัด (มือถือ) ---------- */
@media (max-width: 380px) {
  body.ticket-page .step.is-active { padding: 20px 14px 18px; }
  body.ticket-page .mic-btn { width: 100%; justify-content: center; }
  body.ticket-page .photo-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- VOICE: actions / bars ---------- */
body.ticket-page .voice-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
body.ticket-page .mic-label { white-space: nowrap; }
body.ticket-page .voice-hint { font-size: 13px; color: var(--tk-green-deep); }
body.ticket-page .voice-help strong { color: var(--tk-ink); font-weight: 700; }

body.ticket-page .vbar-wrap { display: inline-flex; align-items: flex-end; gap: 3px; height: 18px; }
body.ticket-page .vbar {
  width: 4px;
  border-radius: 3px;
  background: #fff;
  height: 6px;
  animation: vbar-bounce 1s ease-in-out infinite;
}
body.ticket-page .vbar:nth-child(2) { animation-delay: 0.12s; }
body.ticket-page .vbar:nth-child(3) { animation-delay: 0.28s; }
body.ticket-page .vbar:nth-child(4) { animation-delay: 0.4s; }

/* ---------- NAV utils ---------- */
body.ticket-page .mode-btn svg { flex: 0 0 auto; }

/* ---------- KEYFRAMES ---------- */
@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
@keyframes vbar-bounce {
  0%, 100% { height: 5px; }
  50% { height: 17px; }
}