/* ============================================================
 * Kru Check — reusable components
 * ============================================================ */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px;
  border: 0; border-radius: 999px; cursor: pointer;
  font-size: var(--fs-md); font-weight: 700; color: #fff;
  background: var(--primary); box-shadow: var(--shadow);
  transition: transform 0.08s ease, background 0.15s ease;
  text-align: center;
}
.btn:active { transform: scale(0.97); background: var(--primary-deep); }
.btn--block { display: flex; width: 100%; }
.btn--secondary { background: var(--primary-soft); color: var(--primary-deep); box-shadow: none; }
.btn--secondary:active { background: #d3e9fa; }
.btn--ghost { background: transparent; color: var(--primary-deep); box-shadow: none; }
.btn--danger { background: var(--danger); }
.btn--success { background: var(--success); }
.btn--sm { min-height: 38px; padding: 0 14px; font-size: var(--fs-sm); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: var(--gap); }
.btn-row .btn { flex: 1; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card--tap { cursor: pointer; transition: transform 0.08s ease; }
.card--tap:active { transform: scale(0.98); }
.card-title { font-weight: 700; font-size: var(--fs-md); margin-bottom: 2px; }
.card-sub { color: var(--muted); font-size: var(--fs-sm); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }
.stat {
  background: var(--card); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 12px 8px; text-align: center;
}
.stat b { display: block; font-size: var(--fs-xl); color: var(--primary-deep); }
.stat span { font-size: var(--fs-xs); color: var(--muted); }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; font-size: var(--fs-sm); margin-bottom: 6px; }
.input, .select, textarea.input {
  width: 100%; min-height: var(--tap);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 16px; font-family: var(--font);
  background: #fff; color: var(--ink);
}
.input:focus, .select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.select { appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%236b87a0' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}

/* ---------- app header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  padding-top: var(--sat);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.app-header__inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px var(--page-pad); min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: var(--fs-lg); }
.brand__logo {
  width: 34px; height: 34px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff; display: grid; place-items: center; font-size: 18px; font-weight: 800;
}

/* ---------- sync pill ---------- */
.sync-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 700;
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}
.sync-pill--synced { background: var(--success-soft); color: var(--success); }
.sync-pill--pending { background: var(--warning-soft); color: var(--warning); }
.sync-pill--offline { background: var(--danger-soft); color: var(--danger); }
.header-statuses { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.offline-ready {
  display: inline-flex; align-items: center; min-height: 30px; padding: 5px 10px;
  border-radius: 999px; background: var(--success-soft); color: var(--success);
  font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
}

/* ---------- offline banner ---------- */
.offline-banner {
  background: #fff7e8; border-bottom: 1px solid #f3dfae;
  color: #8a5f0b; font-size: var(--fs-sm); text-align: center;
  padding: 8px 12px;
}

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--sab);
}
.bottom-nav__inner {
  max-width: var(--maxw); margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 60px; justify-content: center;
  color: var(--faint); font-size: 11px; font-weight: 600;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item--active { color: var(--primary-deep); }
.side-nav { display: none; }

/* ---------- choice buttons (ก ข ค ง) ---------- */
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.choice {
  min-height: 56px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1.5px solid var(--line); background: #fff;
  font-size: var(--fs-lg); font-weight: 800; color: var(--ink);
}
.choice--picked { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-deep); }
.choice--wide { grid-column: span 3; font-size: var(--fs-md); font-weight: 600; min-height: var(--tap); }

/* ---------- camera viewport ---------- */
.camera {
  position: relative; width: 100%; aspect-ratio: 3 / 4;
  background: #0f2233; border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-lg);
}
.camera video, .camera img.preview {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.camera__idle {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: #cfe6f7; text-align: center; padding: 20px;
}
.camera__frame {
  position: absolute; inset: 6%; pointer-events: none;
  border: 2px dashed rgba(255, 255, 255, 0.65); border-radius: 12px;
}
.camera__frame::before, .camera__frame::after {
  content: ""; position: absolute; width: 26px; height: 26px;
  border: 4px solid #fff; border-radius: 4px;
}
.camera__frame::before { top: -4px; left: -4px; border-right: 0; border-bottom: 0; }
.camera__frame::after { bottom: -4px; right: -4px; border-left: 0; border-top: 0; }
.camera__hint {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.55));
  color: #fff; font-size: var(--fs-sm); text-align: center;
}

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 999px; padding: 8px 16px;
  box-shadow: var(--shadow); font-weight: 700; font-size: var(--fs-sm);
}
.status-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); }
.status-pill--search .dot { background: var(--warning); animation: pulse 1.2s infinite; }
.status-pill--found .dot { background: var(--success); }
.status-pill--busy .dot { background: var(--primary); animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- sticky sheet preview (review) ---------- */
.sheet-stage { position: relative; }
.sheet-stage__sticky {
  position: sticky; top: 64px; z-index: 20;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 10px;
}
.sheet-stage__viewport {
  position: relative; overflow: hidden; border-radius: var(--radius-sm);
  background: var(--bg-soft); touch-action: pan-x pan-y;
}
.sheet-stage__zoom { transform-origin: 0 0; position: relative; }
.sheet-stage__zoom img.sheet {
  display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none;
}
/* overlay วาดบน layer เดียวกับภาพ — ขยับ/ซูมพร้อมกันเสมอ */
.sheet-overlay { position: absolute; inset: 0; pointer-events: none; }
.sheet-overlay .mark {
  position: absolute; border: 3px solid; border-radius: 8px; opacity: 0.9;
}
.mark--green { border-color: #2fa968; background: rgba(47, 169, 104, 0.15); }
.mark--red { border-color: #d64545; background: rgba(214, 69, 69, 0.15); }
.mark--yellow { border-color: #d9931c; background: rgba(217, 147, 28, 0.18); }
.mark--purple { border-color: #8b5cf6; background: rgba(139, 92, 246, 0.15); }
.mark--orange { border-color: #f97316; background: rgba(249, 115, 22, 0.22); box-shadow: 0 0 0 3px rgba(249,115,22,0.25); }
.sheet-toolbar { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.sheet-toolbar .btn { flex: 1; }
.sheet-caption { font-size: var(--fs-sm); font-weight: 700; text-align: center; margin-bottom: 6px; }

/* ---------- list rows ---------- */
.row-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 10px;
  min-height: 60px;
}
.row-item__main { flex: 1; min-width: 0; }
.row-item__title { font-weight: 700; }
.row-item__sub { font-size: var(--fs-sm); color: var(--muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--primary-soft); color: var(--primary-deep);
  display: grid; place-items: center; font-weight: 800;
}
.avatar svg { width: 24px; height: 24px; }

/* ---------- misc ---------- */
.badge {
  display: inline-block; font-size: var(--fs-xs); font-weight: 700;
  padding: 3px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-deep);
}
.badge--warn { background: var(--warning-soft); color: var(--warning); }
.badge--ok { background: var(--success-soft); color: var(--success); }
.badge--bad { background: var(--danger-soft); color: var(--danger); }

.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.kv:last-child { border-bottom: 0; }
.kv b { font-weight: 700; }

.progress { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1; min-height: var(--tap); border-radius: 999px; border: 1.5px solid var(--line);
  background: #fff; font-weight: 700; font-size: var(--fs-sm); color: var(--muted); cursor: pointer;
}
.tab--active { background: var(--primary); border-color: var(--primary); color: #fff; }

.checkbox-row { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.checkbox-row input { width: 22px; height: 22px; accent-color: var(--primary); }

.fab-actions { position: sticky; bottom: calc(84px + var(--sab)); display: flex; justify-content: flex-end; }

.processing-state, .offline-save-note {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--primary-soft); color: var(--primary-deep);
  display: flex; align-items: center; gap: 10px;
}
.spinner { width: 18px; height: 18px; border: 3px solid rgba(43,143,219,.25); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.single-result { margin-top: 14px; }
.score-big { text-align: center; color: var(--primary-deep); font-size: var(--fs-2xl); font-weight: 800; padding: 16px 0; }
.score-big small { font-size: var(--fs-sm); }
.answer-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.answer-chip { background: var(--bg-soft); border-radius: 8px; padding: 6px; font-size: var(--fs-xs); text-align: center; }
.answer-chip--review { background: var(--warning-soft); color: var(--warning); }
@media (max-width: 480px) {
  .app-header__inner { align-items: flex-start; }
  .header-statuses { max-width: 62%; }
  .offline-ready { white-space: normal; text-align: center; }
  .answer-grid { grid-template-columns: repeat(3, 1fr); }
}
