/* YP Factory — base styles */
:root {
  /* คลีน เน้นขาว + ทองอ่อนเป็น accent (ชั่วคราว — เปลี่ยนทีหลังที่นี่ที่เดียว) */
  --brand-primary: #B8924A;       /* ทองอ่อน */
  --brand-primary-soft: #F6EFDF;  /* ทองจางมาก (พื้น active/hover) */
  --brand-secondary: #9C8B66;
  --brand-danger: #C0392B;
  --brand-warn: #C99A2E;
  --brand-info: #6B7A8F;
  --text: #2B2B2B;
  --text-muted: #8C887C;
  --bg: #F7F6F2;                  /* ขาวอุ่น */
  --card-bg: #FFFFFF;
  --border: #ECE8DE;             /* hairline อุ่น */
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand-info); text-decoration: none; }

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

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.header .meta {
  font-size: 12px;
  color: var(--text-muted);
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FFF;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
}
/* material picker rows (ฟอร์มเปิดงานผลิต) — ให้สไตล์เท่าช่อง .field */
.mat-row { align-items: center; gap: 8px; margin-bottom: 8px; }
.mat-row select, .mat-row input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FFF;
}
.mat-row select { flex: 1; min-width: 0; }
.mat-row select:focus, .mat-row input:focus {
  outline: none;
  border-color: var(--brand-primary);
}

.btn {
  display: inline-block;
  padding: 12px 20px;
  font: inherit;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  background: var(--brand-primary);
  color: #FFF;
  cursor: pointer;
  transition: opacity .2s;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { display: block; width: 100%; }
.btn-secondary { background: #BDC3C7; color: var(--text); }
.btn-danger { background: var(--brand-danger); }
.btn-warn { background: var(--brand-warn); }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .main {
  font-weight: 500;
}
.list-item .meta {
  font-size: 12px;
  color: var(--text-muted);
}
.list-item .qty {
  font-weight: 600;
  color: var(--brand-primary);
}
.list-item .qty.low { color: var(--brand-danger); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 999px;
  background: #ECEFF1;
  color: var(--text-muted);
}
.badge-approved { background: #D5F5E3; color: #186A3B; }
.badge-quarantine { background: #FCF3CF; color: #7D6608; }
.badge-rejected { background: #FADBD8; color: #78281F; }
.badge-released { background: #D6EAF8; color: #1B4F72; }
.badge-expired { background: #E5E7E9; color: #424949; }

/* Camera */
.camera-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}
.camera-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.shot-thumb {
  width: 90px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.shot-grid {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

/* Loading */
#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.85);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.loading-box {
  background: #FFF;
  padding: 24px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(40px);
  background: var(--text);
  color: #FFF;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  z-index: 10000;
  transition: opacity .3s, transform .3s;
  max-width: 90vw;
}
.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast-error { background: var(--brand-danger); }
.toast-success { background: var(--brand-primary); }

.muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex-row { display: flex; gap: 8px; align-items: center; }
.flex-1 { flex: 1; }

hr.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ===== Phase 2 — Production ===== */
/* Used by production.html (kanban board) and job.html (job detail + traveler).
   Reuses base tokens: --brand-primary (single teal accent), status brand
   colors, --border (hairline), --radius, --card-bg, --text/-muted, --shadow.
   Flat: hairline borders, no gradients, no glow. */

/* --- Kanban board (horizontal scroll of status columns) --- */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
  margin: 0 -16px;        /* bleed to screen edges inside .app padding */
  padding-left: 16px;
  padding-right: 16px;
  scroll-snap-type: x proximity;
}
.kanban-col {
  flex: 0 0 78%;
  max-width: 280px;
  scroll-snap-align: start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.kanban-col-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.kanban-col-head .count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  min-width: 22px;
  text-align: center;
}

/* --- Job summary card (clickable) --- */
.job-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: opacity .2s;
}
.job-card:active { opacity: .85; }
.job-card .job-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}
.job-card .job-id {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.job-card .job-qty {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.job-card .job-qty strong {
  color: var(--brand-primary);
  font-weight: 600;
}
.job-card .progress-bar { margin-top: 10px; }

/* --- Stage progress bar --- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--brand-primary);
  border-radius: 999px;
  transition: width .3s ease;
}

/* --- Lifecycle strip (draft -> reserved -> in_progress -> produced -> closed) --- */
.lifecycle-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}
.lifecycle-strip .chip {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: #ECEFF1;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.lifecycle-strip .chip.current {
  color: #FFF;
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  font-weight: 600;
}
.lifecycle-strip .sep {
  color: var(--text-muted);
  font-size: 11px;
}

/* --- Stage list (traveler: ordered production stages) --- */
.stage-list {
  display: flex;
  flex-direction: column;
}
.stage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--card-bg);
}
.stage-row:last-child { margin-bottom: 0; }
.stage-row .stage-icon {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
}
.stage-row .stage-name {
  flex: 1;
  font-weight: 500;
  font-size: 14px;
}
.stage-row .stage-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* state: locked — not yet reachable, muted/disabled look */
.stage-locked {
  opacity: .55;
  background: var(--bg);
}
.stage-locked .stage-name { color: var(--text-muted); }

/* state: current — accent border + active */
.stage-current {
  border-color: var(--brand-primary);
  box-shadow: inset 3px 0 0 var(--brand-primary);
}
.stage-current .stage-icon {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}
.stage-current .stage-name { color: var(--text); }

/* state: done — check + muted/strikethrough */
.stage-done .stage-icon {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #FFF;
}
.stage-done .stage-name {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* --- Status badges (one per lifecycle status, reuse token colors) --- */
.badge-draft        { background: #E5E7E9; color: #424949; }
.badge-reserved     { background: #FCF3CF; color: #7D6608; }  /* warn tone */
.badge-in_progress  { background: #D6EAF8; color: #1B4F72; }  /* info tone */
.badge-produced     { background: #D5F5E3; color: #186A3B; }  /* primary tone */
.badge-closed       { background: #D1F0EB; color: #0E5C4E; }  /* deep teal */
.badge-cancelled    { background: #FADBD8; color: #78281F; }  /* danger tone */

/* ===== Web app shell (topbar + sidebar/drawer) ===== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 30;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: #FFF; border-bottom: 1px solid var(--border);
}
.topbar-burger { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text); padding: 4px 8px; }
.topbar-brand { font-weight: 600; font-size: 16px; }
.topbar-user { margin-left: auto; font-size: 12px; color: var(--text-muted); }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 240px; z-index: 40;
  background: #FFF; border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .22s ease;
  display: flex; flex-direction: column; overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-head { height: 52px; display: flex; align-items: center; padding: 0 18px; font-weight: 700; border-bottom: 1px solid var(--border); color: var(--brand-primary); }
.drawer-nav { padding: 8px 0; flex: 1; }
.nav-group { font-size: 11px; letter-spacing: .04em; color: var(--text-muted); padding: 12px 18px 4px; }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 18px; font: inherit; color: var(--text); text-align: left; background: none; border: none; cursor: pointer; text-decoration: none; }
.nav-item:hover { background: var(--brand-primary-soft); }
.nav-item.active { background: var(--brand-primary-soft); color: var(--brand-primary); font-weight: 600; box-shadow: inset 3px 0 0 var(--brand-primary); }
.nav-soon { margin-left: auto; font-size: 10px; color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.nav-logout { color: var(--brand-danger); border-top: 1px solid var(--border); margin-top: 4px; }

/* หน้าที่มี shell → เว้นที่ใต้ topbar */
body.has-shell .app { padding-top: 64px; }

/* จอกว้าง: sidebar ค้างถาวร ไม่มี burger/scrim */
@media (min-width: 900px) {
  .topbar-burger, .scrim { display: none; }
  .drawer { transform: translateX(0); }
  body.has-shell .topbar { left: 240px; }
  body.has-shell .app { margin-left: 240px; }
}

/* ===== Launcher (หน้าภาพรวม) ===== */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.module-card { display: block; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, transform .05s; }
.module-card:hover { border-color: var(--brand-primary); }
.module-card:active { transform: scale(.99); }
.module-card .m-title { font-weight: 600; font-size: 15px; }
.module-card .m-desc { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.module-card.soon { opacity: .6; }
.module-card .m-soon { display: inline-block; margin-top: 8px; font-size: 10px; color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }

/* skeleton placeholder (หน้ายังไม่ทำ) */
.skeleton-note { text-align: center; padding: 32px 16px; color: var(--text-muted); }
.skeleton-note .big { font-size: 40px; opacity: .4; }
