:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --brand: #1d4ed8;
  --brand-hover: #1e40af;
  --brand-soft: #eff6ff;
  --wi: #059669;
  --wi-hover: #047857;
  --wi-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.07), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.22);
  --font: 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.sidebar {
  background: var(--sidebar-bg);
  color: #cbd5e1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid #1e293b;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.brand-title {
  font-size: 19px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: #94a3b8;
}

.nav-list {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.nav-btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #cbd5e1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.nav-btn.active {
  background: var(--brand);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(29, 78, 216, 0.35);
}

.nav-btn:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: #94a3b8;
  padding-top: 8px;
  border-top: 1px solid #1e293b;
}

.sample-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  font-weight: 600;
  font-size: 11px;
}

.link-btn {
  font: inherit;
  font-size: 12px;
  color: #93c5fd;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.link-btn:hover { color: #dbeafe; }

.reset-confirm-box {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-top: 6px;
  width: 100%;
}

.main-area {
  flex: 1;
  min-width: 0;
  padding: 20px 16px 40px;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
  }
  .sidebar {
    width: 248px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 20px 16px;
    border-bottom: none;
    border-right: 1px solid #1e293b;
  }
  .nav-list {
    flex-direction: column;
    overflow-x: visible;
    margin-top: 12px;
  }
  .nav-btn {
    width: 100%;
    justify-content: flex-start;
  }
  .sidebar-footer {
    margin-top: auto;
    flex-direction: column;
    align-items: flex-start;
    padding-top: 14px;
  }
  .main-area {
    padding: 28px 32px 48px;
  }
}

/* Typography & Headers */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.page-desc {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

/* Cards & Controls */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 680px) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .col-span-2 {
    grid-column: span 2;
  }
}

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

.label-hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 12.5px;
}

.inp {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.inp:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea.inp {
  resize: vertical;
  min-height: 68px;
}

/* Buttons */
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn-sm {
  padding: 6px 11px;
  font-size: 13px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-primary {
  background: var(--brand);
  color: #ffffff;
}
.btn-primary:hover { background: var(--brand-hover); }

.btn-wi {
  background: var(--wi);
  color: #ffffff;
}
.btn-wi:hover { background: var(--wi-hover); }

.btn-secondary {
  background: #ffffff;
  color: var(--ink-secondary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-alt); }

.btn-soft {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: #bfdbfe;
}
.btn-soft:hover { background: #dbeafe; }

.btn-danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger-soft:hover { background: #fee2e2; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.cat-elec { background: #fef9c3; color: #854d0e; }
.cat-mech { background: #dbeafe; color: #1e40af; }
.cat-pneu { background: #cffafe; color: #155e75; }
.cat-hydr { background: #f3e8ff; color: #6b21a8; }
.cat-plc  { background: #fce7f3; color: #9d174d; }
.cat-misc { background: #f1f5f9; color: #475569; }

.st-done { background: #dcfce7; color: #166534; }
.st-wait { background: #ffedd5; color: #9a3412; }
.st-foll { background: #e0f2fe; color: #075985; }

.tag-before { background: #fee2e2; color: #991b1b; }
.tag-during { background: #fef3c7; color: #92400e; }
.tag-after  { background: #dcfce7; color: #166534; }
.tag-point  { background: #dbeafe; color: #1e40af; }

/* Step Builder */
.step-list-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.step-edit-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.step-num-pill {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 5px;
}

.step-row-actions {
  display: flex;
  gap: 3px;
  margin-top: 4px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  padding: 0;
}
.icon-btn:hover { background: #f1f5f9; }
.icon-btn.danger:hover { background: #fee2e2; color: var(--danger); border-color: #fecaca; }

/* Photo Dropzone & Cards */
.photo-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.photo-dropzone:hover,
.photo-dropzone.dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.photo-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.photo-edit-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.photo-edit-thumb-wrap {
  position: relative;
  height: 132px;
  background: #0f172a;
  overflow: hidden;
}

.photo-edit-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}

.photo-remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photo-remove-btn:hover { background: var(--danger); }

.photo-edit-meta {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.photo-edit-meta select,
.photo-edit-meta input {
  font-size: 12.5px;
  padding: 5px 8px;
}

/* Filter Toolbar & History Table */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.filter-bar .search-wrap {
  flex: 1 1 260px;
}

.filter-bar .select-wrap {
  flex: 0 1 180px;
  min-width: 150px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 820px;
}

.data-table thead th {
  background: var(--surface-alt);
  color: var(--ink-secondary);
  font-weight: 700;
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 13px;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: #f0f6ff; }

.data-table td {
  padding: 12px 14px;
  vertical-align: middle;
}

.num-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mono-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand);
}

/* Thumbnails in History Row */
.row-thumbs {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.row-thumb-item {
  position: relative;
  width: 46px;
  height: 36px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #0f172a;
  flex-shrink: 0;
  cursor: zoom-in;
  transition: transform 0.12s, border-color 0.12s;
}

.row-thumb-item:hover {
  transform: scale(1.07);
  border-color: var(--brand);
  z-index: 2;
}

.row-thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.row-thumb-more {
  height: 36px;
  min-width: 32px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.no-photo-chip {
  font-size: 12px;
  color: #94a3b8;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Multi-Repair Selection & Similarity Merge UI */
.row-check {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--wi);
}

.data-table tbody tr.row-selected {
  background: #ecfdf5;
}
.data-table tbody tr.row-selected:hover {
  background: #d1fae5;
}

.merge-bar {
  background: linear-gradient(180deg, #f0fdf4 0%, #ecfdf5 100%);
  border: 1px solid #86efac;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.merge-bar-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.selected-repair-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid #6ee7b7;
  color: #065f46;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}

.selected-repair-chip button {
  border: none;
  background: none;
  color: #047857;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.selected-repair-chip button:hover { color: var(--danger); }

.sim-suggest-box {
  background: rgba(255, 255, 255, 0.85);
  border: 1px dashed #6ee7b7;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.sim-suggest-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.sim-suggest-item {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
}

.sim-score-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #dbeafe;
  color: #1e40af;
  white-space: nowrap;
}

.sim-score-pill.high {
  background: #dcfce7;
  color: #166534;
}

.merge-candidate-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 430px;
  overflow-y: auto;
  padding-right: 4px;
}

.merge-candidate-card {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #ffffff;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.merge-candidate-card:hover {
  border-color: var(--wi);
  background: #f8fafc;
}

.merge-candidate-card.checked {
  border-color: var(--wi);
  background: #ecfdf5;
  box-shadow: 0 0 0 1px var(--wi);
}

.source-ref-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: #e0f2fe;
  color: #0369a1;
}

/* WI Grid Cards */
.wi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

.wi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--wi);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
}

.wi-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.wi-card-cover {
  height: 148px;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wi-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.wi-card-cover-placeholder {
  color: #64748b;
  text-align: center;
  font-size: 13px;
}

.wi-card-photo-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.8);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}

.wi-card-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.wi-card-title {
  font-size: 16px;
  font-weight: 700;
  margin: 8px 0 6px;
  color: var(--ink);
  line-height: 1.35;
}

.wi-card-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.wi-card-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  z-index: 50;
  overflow-y: auto;
  padding: 20px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.modal-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 880px;
  margin: 16px auto 32px;
  padding: 24px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: #f1f5f9; color: var(--ink); }

/* Gallery inside Detail & WI Document */
.detail-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.detail-photo-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-alt);
  cursor: zoom-in;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.detail-photo-card:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}

.detail-photo-card img {
  width: 100%;
  height: 136px;
  object-fit: cover;
  display: block;
  background: #0f172a;
}

.detail-photo-caption {
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--ink-secondary);
}

/* Callouts */
.callout {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  border-left: 4px solid transparent;
}
.callout-red { background: #fef2f2; border-left-color: #ef4444; color: #7f1d1d; }
.callout-amber { background: #fffbeb; border-left-color: #f59e0b; color: #78350f; }
.callout-blue { background: #eff6ff; border-left-color: #3b82f6; color: #1e3a8a; }

/* WI Standard Document Sheet */
.wi-doc {
  border: 2px solid #1e293b;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  font-size: 14px;
}

.wi-doc-header {
  display: grid;
  grid-template-columns: 1fr;
  border-bottom: 2px solid #1e293b;
}

@media (min-width: 640px) {
  .wi-doc-header {
    grid-template-columns: 170px 1fr 185px;
  }
  .wi-doc-brand { border-right: 2px solid #1e293b; }
  .wi-doc-center { border-right: 2px solid #1e293b; }
}

.wi-doc-brand {
  padding: 12px 14px;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #f8fafc;
}

.wi-doc-center {
  padding: 12px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.wi-doc-meta {
  padding: 10px 14px;
  font-size: 12.5px;
  background: #f8fafc;
  line-height: 1.55;
}

.wi-doc-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.wi-sop-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
  font-size: 13.5px;
}

.wi-sop-table th,
.wi-sop-table td {
  border: 1px solid #cbd5e1;
  padding: 10px 12px;
  vertical-align: top;
}

.wi-sop-table thead th {
  background: #f1f5f9;
  font-weight: 700;
  color: var(--ink);
}

.wi-step-img {
  width: 150px;
  max-width: 100%;
  height: 104px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  cursor: zoom-in;
  display: block;
  background: #0f172a;
}

/* WI Step Builder inside Modal */
.wi-builder-step {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wi-step-photo-picker {
  background: #ffffff;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.pool-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-top: 6px;
}

.pool-choice {
  width: 74px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  background: #0f172a;
}
.pool-choice:hover { border-color: var(--brand); }
.pool-choice.selected { border-color: var(--wi); box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.25); }
.pool-choice img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.9);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-img-wrap {
  max-width: 92vw;
  max-height: 76vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.lightbox-img-wrap img {
  max-width: 100%;
  max-height: 76vh;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  background: #0f172a;
}

.lightbox-caption-bar {
  margin-top: 14px;
  color: #f8fafc;
  text-align: center;
  max-width: 680px;
}

.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.lightbox-nav:hover { background: rgba(37, 99, 235, 0.85); }
.lightbox-prev { left: 18px; }
.lightbox-next { right: 18px; }
.lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
}

/* Toast & Inline Alert */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  border-left: 4px solid #22c55e;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 600;
  z-index: 90;
}

.inline-msg {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  margin-top: 8px;
}
.inline-msg.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}

.hidden { display: none !important; }


/* ---------- Cloudflare version additions ---------- */
.status-banner { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:10px; margin-bottom:14px; }
.status-banner.info { background:#eff6ff; border:1px solid #bfdbfe; color:#1e3a8a; border-radius:var(--radius-sm); padding:10px 12px; }
.status-banner.error { background:#fef2f2; border:1px solid #fecaca; color:#b91c1c; border-radius:var(--radius-sm); padding:10px 12px; }
.sidebar-actions { display:flex; flex-wrap:wrap; gap:10px; margin-top:8px; }
.history-more { display:flex; justify-content:center; padding:12px; }
.btn:disabled { opacity:.55; cursor:not-allowed; }
.deleted-ref { color:var(--muted); text-decoration:line-through; }
.wi-print-only { display:none; }

/* Tablet / touch: เป้ากดใหญ่ขึ้น */
@media (pointer: coarse) {
  .icon-btn { min-width:40px; min-height:40px; }
  .row-check { width:22px; height:22px; }
  .btn-xs { min-height:34px; }
  .inp { font-size:16px; }
}

/* ---------- Print: A4 ---------- */
@page { size: A4 portrait; margin: 12mm 10mm; }

@media print {
  html, body { background:#fff !important; font-size:11pt; }
  * { -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  .sidebar, .toast, .lightbox, .status-banner, .filter-bar, .merge-bar, .modal-close, .no-print { display:none !important; }

  /* พิมพ์เฉพาะเอกสาร WI เมื่อเปิดดูอยู่ */
  body.printing-wi .app-shell { display:none !important; }
  body.printing-wi .modal-backdrop { position:static !important; display:block !important; background:none !important; padding:0 !important; overflow:visible !important; backdrop-filter:none !important; }
  body.printing-wi .modal-panel { max-width:none !important; width:100% !important; max-height:none !important; overflow:visible !important; box-shadow:none !important; border:0 !important; border-radius:0 !important; padding:0 !important; margin:0 !important; animation:none !important; }

  .wi-doc { overflow:visible; border-radius:0; font-size:10.5pt; }
  .wi-doc-header { grid-template-columns:38mm 1fr 45mm !important; break-inside:avoid; }
  .wi-doc-brand, .wi-doc-center { border-right:2px solid #1e293b; }
  .wi-doc-body { display:block; padding:4mm; }
  .wi-doc-body > * { margin-bottom:4mm; }
  .wi-doc .detail-photo-grid { grid-template-columns:repeat(3,1fr) !important; gap:3mm; }
  .wi-doc .detail-photo-card { break-inside:avoid; box-shadow:none; }
  .wi-doc .detail-photo-card img { height:34mm; object-fit:contain; }
  .wi-table-wrap { overflow:visible !important; }
  .wi-steps-head { break-after:avoid; break-inside:avoid; }
  .wi-sop-table { font-size:10pt; break-before:avoid; }
  .wi-sop-table th, .wi-sop-table td { padding:2mm 2.5mm; }
  .wi-sop-table thead { display:table-header-group; }
  .wi-sop-table tr { break-inside:avoid; }
  .wi-step-img { width:42mm; height:30mm; object-fit:contain; background:#fff; }
  .wi-signoff, .callout { break-inside:avoid; }
  .wi-print-only { display:block; }
  .wi-doc .link-btn { color:#0f172a !important; text-decoration:none; }
  .stepchk { width:5mm; height:5mm; }
}
