/* ---------- ฟอนต์ไทยสมัยใหม่ เก็บไว้ในโปรเจกต์เอง ใช้ได้ตอนออฟไลน์ ---------- */
@font-face {
  font-family: 'Anuphan';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(assets/fonts/anuphan-thai.woff2) format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Anuphan';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(assets/fonts/anuphan-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}

/* ---------- โทนสี: ส้ม-น้ำเงิน พาสเทล ---------- */
:root {
  --bg: #f4f7fc;
  --surface: #ffffff;
  --surface-2: #eaf1fa;
  --line: #dde6f2;
  --ink: #22364f;
  --muted: #7d8fa6;

  --orange: #ffb083;
  --orange-hot: #ff9256;
  --orange-soft: #fff0e6;
  --on-orange: #7d3a10;      /* ตัวอักษรบนพื้นส้มพาสเทล — ต้องเข้มทั้งสองธีม */
  --warn-text: #a05320;      /* ข้อความเตือน — สลับตามธีมได้ */

  --blue: #9cc4f0;
  --blue-hot: #5b95d8;
  --blue-soft: #e7f0fb;
  --blue-ink: #1f4d80;

  --danger: #d9553f;

  --dark-bg: #141b26;
  --dark-surface: #1f2836;
  --dark-line: #2f3a4b;
  --dark-ink: #eaf0f7;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141b26;
    --surface: #1f2836;
    --surface-2: #263142;
    --line: #313d4f;
    --ink: #e9eff7;
    --muted: #93a3b8;
    --orange-soft: #3a2618;
    --warn-text: #ffc59b;
    --blue-soft: #1e2c3e;
    --blue-ink: #b8d6f7;
  }
}

/* ---------- ให้รู้สึกเป็นแอปจริง ไม่ใช่หน้าเว็บ ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  color: var(--ink);
  font-family: 'Anuphan', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  touch-action: manipulation;          /* ปิดดับเบิลแท็ปซูม */
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea { -webkit-user-select: text; user-select: text; }

/* ---------- โครงหน้าจอ ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.screen.is-active { display: flex; }
.screen--dark { background: var(--dark-bg); color: var(--dark-ink); }

.sheet {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px 28px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* .sheet เลื่อนได้อยู่แล้ว ห้ามให้ลูกบีบตัวจนเนื้อหาล้นกรอบ */
.sheet > * { flex: none; }

.head { margin-bottom: 22px; }
h1 { margin: 4px 0 6px; font-size: 25px; font-weight: 700; letter-spacing: -.2px; }
.lead { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- ช่องกรอกเลขงาน ---------- */
.code-field { display: block; }
.code-field__label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 7px;
  padding-left: 2px;
}
.code-field input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 24px;              /* >=16px กัน iOS ซูมตอนโฟกัส */
  font-weight: 600;
  letter-spacing: 1px;
  text-align: center;
  text-transform: uppercase;
  padding: 16px 12px;
  transition: border-color .15s;
}
.code-field input::placeholder { color: var(--muted); opacity: .5; font-weight: 400; }
.code-field input:focus { outline: none; border-color: var(--orange-hot); }
.code-field input.is-warn { border-color: var(--orange-hot); }
.code-field input.is-error { border-color: var(--danger); }

.note {
  margin: 9px 2px 0;
  font-size: 13px;
  min-height: 20px;
  color: var(--muted);
}
.note.is-warn { color: var(--warn-text); }
.note.is-error { color: var(--danger); }
.note.is-ok { color: var(--blue-hot); }

/* ---------- ตัวอย่างป้าย ---------- */
.plate-preview {
  margin: 18px 0 24px;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 18px;
  background: var(--surface-2);
}
.plate-preview img { width: 100%; max-width: min(380px, 100%); height: auto; display: block; }

/* ---------- ปุ่ม ---------- */
.actions { display: flex; flex-direction: column; gap: 11px; margin-top: auto; }
.actions--row { flex-direction: row; padding: 0 16px 12px; margin-top: 0; }
.actions--row .btn { flex: 1; }
.actions--tight { padding-bottom: 8px; }
.actions--bottom { padding-bottom: calc(14px + var(--safe-bottom)); }
.actions--row .btn[hidden] { display: none; }

.btn {
  display: block;
  width: 100%;
  padding: 15px 18px;
  border-radius: 16px;
  border: 1.5px solid transparent;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.985); }
.btn small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  opacity: .72;
}
.btn--primary { background: var(--orange); color: var(--on-orange); }
.btn--soft { background: var(--blue-soft); color: var(--blue-ink); border-color: var(--blue-soft); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn:disabled { opacity: .4; }

.screen--dark .btn--ghost { border-color: var(--dark-line); color: #a9b7c8; }

/* ---------- แถบบน ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  min-height: 48px;
  flex: none;
}
.bar__code {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .8px;
  background: none;
  border: none;
  color: var(--dark-ink);
  padding: 6px 4px;
  text-decoration: underline dotted rgba(255, 176, 131, .7);
  text-underline-offset: 5px;
}
.bar__code--plain { text-decoration: none; }
.bar__spacer { width: 44px; flex: none; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--dark-line);
  background: var(--dark-surface);
  color: var(--dark-ink);
  font-size: 22px;
  line-height: 1;
  font-family: inherit;
}

/* ---------- เวทีรูป ---------- */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 4px;
}

.frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  border-radius: 14px;
  background: #000;
  touch-action: none;
}
.frame--fit { height: 100%; width: auto; margin: 0 auto; }

.frame video,
.frame canvas { display: block; width: 100%; height: 100%; object-fit: cover; }
.frame--fit canvas { object-fit: fill; }

.frame__guide {
  position: absolute;
  inset: 11%;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 8px;
  pointer-events: none;
}

.plate-layer {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: top left;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.plate-layer img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  pointer-events: none;
}
.plate-layer::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 1.5px dashed rgba(255, 176, 131, .85);
  border-radius: 8px;
  pointer-events: none;
}

/* ---------- แถบเลื่อน ---------- */
.controls { padding: 10px 18px 2px; display: flex; flex-direction: column; gap: 8px; flex: none; }
.slider { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #9fb0c4; }
.slider > span { width: 76px; flex: none; }
.slider input { flex: 1; accent-color: var(--orange-hot); height: 26px; min-width: 0; }

/* ---------- ประเภทรูป ---------- */
.typebar { padding: 8px 16px 2px; flex: none; }
.typebar__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: #9fb0c4;
  margin-bottom: 7px;
}
.typebar__name {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--orange);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--dark-line);
  background: var(--dark-surface);
  color: #b9c6d6;
  font-family: inherit;
  font-size: 13.5px;
  white-space: nowrap;
}
.chip.is-on {
  background: var(--blue);
  border-color: var(--blue);
  color: #10344f;
  font-weight: 600;
}
.chip[hidden] { display: none; }

/* ---------- ชัตเตอร์ ---------- */
.shutter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px calc(14px + var(--safe-bottom));
  gap: 12px;
  flex: none;
}
.shutter-row .chip { flex: 1; max-width: 130px; text-align: center; }
.shutter {
  width: 70px;
  height: 70px;
  flex: none;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .85);
  background: var(--orange-hot);
}
.shutter:active { transform: scale(.94); }

/* ---------- อื่น ๆ ---------- */
.error {
  margin: 0;
  padding: 0 20px;
  color: #ff9f92;
  font-size: 13px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(20, 27, 38, .96);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 50;
  max-width: 86vw;
  text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- แถบแจ้งเมื่อแอปพัง ---------- */
.fatal {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 100;
  background: var(--surface);
  border: 1.5px solid var(--danger);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28);
}
.fatal[hidden] { display: none; }
.fatal__title { margin: 0 0 4px; font-weight: 700; color: var(--danger); }
.fatal__msg {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  word-break: break-word;
  max-height: 5.5em;
  overflow: auto;
}
