/* ================================================================
   style.css — ระบบเบิกอุปกรณ์
   ================================================================ */

/* ── CSS Variables ─────────────────────────────────────────────── */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --border2: #3d4468;
  --accent: #f5a623;
  --accent-dark: #c4841a;
  --accent-glow: rgba(245, 166, 35, .18);
  --green: #2ecc71;
  --green-bg: rgba(46, 204, 113, .12);
  --red: #e74c3c;
  --red-bg: rgba(231, 76, 60, .12);
  --blue: #4a9eff;
  --text: #edf0ff;
  --text-muted: #7c85b0;
  --text-soft: #adb5d6;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .45);
  --font: 'Angsana New', serif;
  --mono: 'Angsana New', monospace;
  --nav-h: 60px;
  --max-w: 580px;
  /* Fluid type scale */
  --text-xs:  clamp(12px, 1.4vw, 14px);
  --text-sm:  clamp(14px, 1.7vw, 16px);
  --text-base: clamp(16px, 2vw, 18px);
  --text-md:  clamp(18px, 2.2vw, 20px);
  --text-lg:  clamp(20px, 2.5vw, 24px);
  --text-xl:  clamp(24px, 3vw, 30px);
  --text-2xl: clamp(28px, 4vw, 36px);
}

/* ── Reset & Base ───────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
  /* Fluid base: 16px mobile → 20px desktop */
  font-size: clamp(16px, 2.2vw, 20px);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Navbar ─────────────────────────────────────────────────────── */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: rgba(15, 17, 23, .92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
  padding: 0 clamp(12px, 3vw, 24px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: clamp(0.85rem, 2vw, 1rem);
  flex-shrink: 0;
}

.nav-icon {
  font-size: 1.3rem;
}

.nav-links {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.nav-link {
  text-decoration: none;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: clamp(0.78rem, 1.5vw, 0.9rem);
  font-weight: 500;
  transition: all .2s;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface2);
}

.nav-link.active {
  color: var(--accent);
  background: var(--accent-glow);
}

@media (max-width: 420px) {
  .nav-link {
    padding: 5px 7px;
    font-size: 0.75rem;
  }
}

/* ── Main Layout ────────────────────────────────────────────────── */
.main-content {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: calc(var(--nav-h) + 20px) clamp(12px, 3vw, 20px) 48px;
}

/* history page uses wider layout */
body.history-page .main-content {
  max-width: 1100px;
}

/* settings page also wider */
body.settings-page .main-content {
  max-width: 960px;
}

@media (max-width: 480px) {
  .main-content {
    padding-top: calc(var(--nav-h) + 14px);
  }
}

@media (min-width: 768px) {
  :root { --max-w: 640px; }
}

@media (min-width: 1024px) {
  :root { --max-w: 680px; }
}

/* ── Page Header ────────────────────────────────────────────────── */
.page-header {
  margin-bottom: clamp(14px, 2.5vw, 24px);
}

.page-title {
  font-size: clamp(1.25rem, 3.5vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -.3px;
  line-height: 1.25;
}

.page-title::after {
  content: '';
  display: block;
  width: 36px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin-top: 6px;
}

.page-sub {
  color: var(--text-muted);
  font-size: clamp(0.82rem, 1.5vw, 0.95rem);
  margin-top: 5px;
}

/* ── Card ───────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
 /* border: 1px solid var(--border);*/
  border-radius: var(--radius);
  padding: clamp(14px, 3vw, 24px);
  box-shadow: var(--shadow);
}

/* ── Form Fields ────────────────────────────────────────────────── */
.field {
  margin-bottom: 18px;
}

.label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.label-icon {
  font-size: 1rem;
}

.optional {
  text-transform: none;
  font-weight: 400;
  color: var(--text-muted);
}

/* Select */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  width: 100%;
  appearance: none;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 14px 44px 14px 14px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  cursor: pointer;
}

.select-wrapper select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: .85rem;
}

/* Text input */
.text-input {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 10px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.text-input::placeholder {
  color: var(--text-muted);
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Admin Add Card (UX/UI improvements) ─────────────────────────── */
.admin-add-card {
  display: block; /* card container uses default card styles */
}

.admin-add-card .admin-add-form {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 12px;
  align-items: start;
  padding: 14px 18px 18px;
}

.admin-add-card .admin-field { width: 100%; }
.admin-add-card .admin-field-sm { width: 100%; }

.admin-add-card .admin-field .label,
.admin-add-card .admin-field-sm .label {
  font-size: .85rem;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.admin-add-card input[type="file"] {
  padding: 8px 10px;
}

.admin-add-card .admin-add-btn {
  align-self: end;
  justify-self: baseline;
  background: var(--accent);
  color: #111;
  border: none;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .12s ease;
}

.admin-add-card .admin-add-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}

.admin-add-card .field-error { margin-top: 8px; }

/* Mobile / small screens: stack fields */
@media (max-width: 720px) {
  .admin-add-card .admin-add-form { grid-template-columns: 1fr; }
  .admin-add-card .admin-add-btn { width: 100%; justify-self: stretch; }
}

/* Slightly tighter spacing for compact view */
@media (max-width: 420px) {
  .admin-add-card .admin-add-form { gap: 10px; padding: 12px; }
  .admin-add-card .admin-field .label { font-size: .82rem; }
}

/* Delete-photo icon overlay on image preview */
.delete-photo-icon {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: background .12s, transform .08s;
  z-index: 20;
}
.delete-photo-icon:hover { background: rgba(0,0,0,0.65); transform: translateY(-1px); }


/* Quantity row */
.qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-user-select: none;
  user-select: none;
}

.qty-btn:active {
  transform: scale(.93);
  background: var(--accent-glow);
}

.qty-input {
  width: 80px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 600;
  padding: 10px;
  border-radius: var(--radius-sm);
  outline: none;
  text-align: center;
  transition: border-color .2s;
}

.qty-input::-webkit-inner-spin-button,
.qty-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.qty-input:focus {
  border-color: var(--accent);
}

.unit-label {
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
}

/* Field error */
.field-error {
  color: var(--red);
  font-size: .82rem;
  margin-top: 5px;
  min-height: 18px;
}

/* ── Photo Area ─────────────────────────────────────────────────── */
.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.photo-buttons {
  display: flex;
  gap: 10px;
}

.photo-btn {
  flex: 1;
  padding: 13px 8px;
  touch-action: manipulation;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all .2s;
}

.photo-btn.primary {
  border-color: var(--accent);
  color: var(--accent);
}

.photo-btn.primary:active {
  background: var(--accent-glow);
}

.photo-btn.secondary:active {
  background: var(--surface2);
}

/* Photo preview */
.photo-preview {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--border2);
  position: relative;
}

.photo-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
}

.preview-actions {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: rgba(0, 0, 0, .55);
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

.preview-btn {
  flex: 1;
  padding: 9px;
  border-radius: 6px;
  border: none;
  font-family: var(--font);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}

.preview-btn:active {
  opacity: .75;
}

.preview-btn.view {
  background: var(--accent);
  color: #111;
}

.preview-btn.remove {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red);
}

/* ── Submit Button ──────────────────────────────────────────────── */
.submit-btn {
  width: 100%;
  margin-top: 8px;
  padding: 16px;
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .2s, transform .15s;
}

.submit-btn:active {
  transform: scale(.98);
  background: var(--accent-dark);
}

.submit-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* ── Spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(0, 0, 0, .25);
  border-top-color: #111;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  min-width: 240px;
  max-width: calc(100vw - 32px);
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  z-index: 200;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.success {
  background: var(--green);
  color: #0a1a10;
}

.toast.error {
  background: var(--red);
  color: #fff;
}

.toast.info {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ── Modal ──────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .8);
}

.modal-box {
  position: relative;
  max-width: min(500px, 100%);
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border2);
  transform: scale(.94);
  transition: transform .25s;
}

.modal.open .modal-box {
  transform: scale(1);
}

.modal-box img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* ── History — Search ───────────────────────────────────────────── */
.search-bar {
  position: relative;
  margin-bottom: 16px;
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  padding: 13px 13px 13px 40px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .2s;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* ── Stats Row ──────────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.stat-num {
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
}

/* ── History Cards (mobile-first) ───────────────────────────────── */
.req-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.req-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 6px 12px;
  transition: border-color .2s;
}

.req-card:hover {
  border-color: var(--border2);
}

.req-equip {
  font-weight: 700;
  font-size: 1rem;
  grid-column: 1;
}

.req-meta {
  font-size: .83rem;
  color: var(--text-muted);
  grid-column: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.req-meta span {
  display: flex;
  align-items: center;
  gap: 3px;
}

.req-qty {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  background: var(--accent-glow);
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 700;
  font-size: .95rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  text-align: center;
}

.req-photo-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--blue);
  font-family: var(--font);
  font-size: .8rem;
  padding: 5px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: all .15s;
  margin-top: 4px;
}

.req-photo-btn:hover {
  background: rgba(74, 158, 255, .1);
  border-color: var(--blue);
}

/* ── Table (tablet+) ────────────────────────────────────────────── */
@media (min-width: 640px) {
  .req-list {
    display: none;
  }

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

  .req-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;

  }

  .req-table th {
    background: var(--surface2);
    color: var(--text-muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 11px 14px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
  }

  .req-table td {
    padding: 12px 5px;
    border-top: 1px solid var(--border);
    vertical-align: middle;
  }

  .req-table tr:hover td {
    background: var(--surface2);
  }

  .td-qty {
    font-family: var(--mono);
    font-weight: 700;
    color: var(--accent);
  }

  .td-photo button {
    background: none;
    border: 1px solid var(--border);
    color: var(--blue);
    font-family: var(--font);
    font-size: .78rem;
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: all .15s;
  }

  .td-photo button:hover {
    background: rgba(74, 158, 255, .1);
    border-color: var(--blue);
  }
}

@media (max-width: 639px) {
  .req-table-wrap {
    display: none;
  }
}

/* ── Pagination ─────────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-btn:hover {
  border-color: var(--border2);
  color: var(--text);
}

.page-btn.active {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

.page-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

/* ── Skeleton ───────────────────────────────────────────────────── */
.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-row {
  height: 80px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ── Empty state ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: .95rem;
}

/* ── Utility ────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ================================================================
   Item Row (multi-item requisition)
   ================================================================ */
.item-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}

/* อุปกรณ์ select button */
.equip-select-btn {
  display: flex;
  touch-action: manipulation;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: border-color .2s;
  grid-column: 1 / -1;
}

.equip-select-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.equip-select-thumb,
.search-item-thumb {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.equip-select-thumb img,
.search-item-thumb img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  position: absolute;
  inset: 0;
  z-index: 2;
}

.thumb-image--hidden {
  display: none !important;
}

.equip-select-thumb .equip-select-thumb--placeholder,
.search-item-thumb .search-item-thumb--placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.equip-select-thumb--placeholder,
.search-item-thumb--placeholder {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1;
}

.thumb-clickable {
  cursor: pointer;
}

.equip-select-btn:focus,
.equip-select-btn:active {
  border-color: var(--accent);
}

.equip-select-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.equip-select-arrow {
  color: var(--text-muted);
  margin-left: 8px;
  flex-shrink: 0;
}

/* qty row inside item */
.item-row .qty-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ลบ row */
.remove-row-btn {
  touch-action: manipulation;
  background: none;
  border: 1px solid var(--border);
  color: var(--red);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}

.remove-row-btn:active {
  background: var(--red-bg);
}

/* เพิ่มรายการ */
.add-item-btn {
  touch-action: manipulation;
  width: 100%;
  margin-top: 4px;
  padding: 11px;
  background: none;
  border: 1.5px dashed var(--border2);
  color: var(--accent);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.add-item-btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
}

.add-item-btn:active {
  background: var(--accent-glow);
}

/* ================================================================
   Search Popup
   ================================================================ */
.search-popup {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: flex-end;
  /* slide up from bottom on mobile */
  justify-content: center;
  padding: 0;
}

.search-popup.hidden {
  display: none;
}

.search-popup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .7);
}

.search-popup-box {
  position: relative;
  width: 100%;
  max-width: var(--max-w);
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border2);
  border-bottom: none;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .22s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(40px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.search-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-popup-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--text-muted);
  font-size: .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-popup-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-popup-input {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  outline: none;
}

.search-popup-input:focus {
  border-color: var(--accent);
}

.search-popup-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}

.search-popup-item {
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  cursor: pointer;
  transition: background .15s;
  gap: 12px;
}

.search-popup-item:active {
  background: var(--surface2);
}

.search-item-name {
  font-weight: 600;
  font-size: .95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-item-meta {
  font-size: .8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.search-popup-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ── Out-of-stock item in search popup ── */
.search-popup-item--oos {
  opacity: 1;
  cursor: not-allowed;
  pointer-events: none;
  /* กดไม่ได้ */
}

.search-popup-item--oos .search-item-name {
  color: var(--text-muted);
}

.search-item-meta--oos {
  color: var(--red);
  font-weight: 600;
}

/* Image viewer modal */
.image-viewer-shell {
  position: relative;
  width: min(92vw, 360px);
  height: min(72vw, 280px);
  max-height: min(82vh, 320px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: auto;
  background: rgba(0, 0, 0, 0.12);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.image-viewer-shell img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
}

@media (max-width: 600px) {
  .image-viewer-shell {
    width: min(96vw, 320px);
    height: min(78vw, 240px);
    max-height: calc(100vh - 64px);
    border-radius: 12px;
  }

  .image-viewer-shell img {
    border-radius: 12px;
  }
}

/* desktop: center popup instead of bottom sheet */
@media (min-width: 600px) {
  .search-popup {
    align-items: center;
    padding: 16px;
  }

  .search-popup-box {
    border-radius: var(--radius);
    border: 1px solid var(--border2);
    max-height: 60vh;
  }
}

/* ── Responsive Table — ALL screen sizes ────────────────────────── */
.req-table-wrap {
  display: block !important;
}

.req-list {
  display: none !important;
}

@media (max-width: 600px) {
  .equip-select-thumb,
  .search-item-thumb {
    width: 24px;
    height: 24px;
    border-radius: 5px;
  }

  .req-table {
    font-size: clamp(12px, 3vw, 15px);
  }

  .req-table th {
    font-size: clamp(10px, 2.5vw, 13px);
    padding: 8px 6px;
    letter-spacing: 0;
  }

  .req-table td {
    padding: 10px 6px;
  }

  .td-date {
    font-size: clamp(11px, 2.5vw, 13px);
    white-space: nowrap;
  }

  .td-items {
    min-width: 120px;
  }

  .photo-view-btn,
  .td-photo button {
    font-size: 11px;
    padding: 3px 7px;
  }
}

/* ── Table Styles ────────────────────────────────────────────────── */
.req-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
 /* border: 1px solid var(--border); */
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.req-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(13px, 1.8vw, 16px);
  min-width: 480px; /* prevent too-narrow tables */
}

.req-table th {
  background: var(--surface2);
  color: var(--text-muted);
  font-size: clamp(11px, 1.4vw, 14px);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: clamp(8px, 1.5vw, 12px) clamp(8px, 2vw, 16px);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 2px solid var(--border);
}

.req-table td {
  padding: clamp(10px, 1.8vw, 14px) clamp(8px, 2vw, 16px);
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

/* Prevent table text from compressing too much; show ellipsis instead */
.req-table th, .req-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Ensure photo column keeps a stable size */
.req-table td img, .req-table td div[style*="width:40px"] {
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  flex-shrink: 0;
}

/* Card wrapping the table should expand to table width and allow visible scroll */
.admin-table-card {
  padding: 0;
  overflow: visible;
}

.req-table tr:hover td {
  background: var(--surface2);
}

/* Equipment name column - word wrap */
.req-table td:first-child {
  max-width: clamp(140px, 30vw, 300px);
  word-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}

/* Actions column */
.req-table td:last-child {
  min-width: 150px;
}

.req-table th:last-child {
  min-width: 160px;
}

.td-qty {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.td-center {
  text-align: center;
}

.photo-view-btn,
.td-photo button {
  background: none;
  border: 1px solid var(--border);
  color: var(--blue);
  font-family: var(--font);
  font-size: .78rem;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.photo-view-btn:hover,
.td-photo button:hover {
  background: rgba(74, 158, 255, .1);
  border-color: var(--blue);
}

/* ── History Toolbar ─────────────────────────────────────────────── */
.history-toolbar {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.history-toolbar .search-bar {
  flex: 1;
  min-width: 160px;
  margin-bottom: 0;
}

.export-btn {
  flex-shrink: 0;
  padding: 0 clamp(10px, 2vw, 18px);
  background: var(--surface);
  border: 1.5px solid var(--border2);
  color: var(--green);
  font-family: var(--font);
  font-size: clamp(0.8rem, 1.6vw, 0.9rem);
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all .2s;
  min-height: 42px;
}

.export-btn:hover {
  background: var(--green-bg);
  border-color: var(--green);
}

.export-btn:active {
  transform: scale(.97);
}

/* ── Date Filter Bar ─────────────────────────────────────────────── */
.date-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: clamp(8px, 1.5vw, 12px) clamp(10px, 2vw, 16px);
  margin-bottom: 14px;
}

.date-filter-label {
  font-size: clamp(0.78rem, 1.4vw, 0.85rem);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.date-input {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: clamp(0.8rem, 1.5vw, 0.9rem);
  padding: clamp(6px, 1.2vw, 9px) clamp(8px, 1.5vw, 12px);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  transition: border-color .2s;
  color-scheme: dark;
  min-width: 0;
  flex: 1;
  max-width: 160px;
}

.date-input:focus {
  border-color: var(--accent);
}

.date-sep {
  color: var(--text-muted);
  font-weight: 600;
  flex-shrink: 0;
}

.date-clear-btn {
  padding: clamp(6px, 1.2vw, 8px) clamp(8px, 1.5vw, 14px);
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: clamp(0.78rem, 1.4vw, 0.85rem);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
  white-space: nowrap;
}

.date-clear-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

@media (max-width: 480px) {
  .date-filter-bar {
    gap: 6px;
  }
  .date-input {
    max-width: 130px;
  }
}

/* ── Settings Tabs ───────────────────────────────────────────────── */
.settings-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-tab {
  flex: 1;
  text-align: center;
  padding: clamp(8px, 1.5vw, 11px) clamp(10px, 2vw, 18px);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: clamp(0.82rem, 1.6vw, 0.92rem);
  font-weight: 600;
  transition: all .2s;
  white-space: nowrap;
}

.settings-tab:hover {
  color: var(--text);
  background: var(--surface2);
}

.settings-tab.active {
  color: var(--accent);
  background: var(--accent-glow);
}

/* ── Admin Nav link ──────────────────────────────────────────────── */
.nav-link-admin {
  font-size: .85rem;
}

/* ── Login Page ──────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  padding: 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo {
  font-size: 3rem;
  margin-bottom: 12px;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.login-sub {
  color: var(--text-muted);
  font-size: .9rem;
  margin-top: 4px;
  margin-bottom: 24px;
}

.login-error {
  background: var(--red-bg);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .88rem;
  margin-bottom: 16px;
}

.login-form {
  text-align: left;
}

.login-field {
  margin-bottom: 14px;
}

.login-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.login-back {
  display: block;
  margin-top: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .88rem;
  text-decoration: none;
  transition: color .2s;
}

.login-back:hover {
  color: var(--accent);
}

/* ── Admin Panel ─────────────────────────────────────────────────── */
.logout-btn {
  padding: 8px 16px;
  background: var(--red-bg);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
  white-space: nowrap;
}

.logout-btn:hover {
  background: rgba(231, 76, 60, .2);
}

.admin-add-card {
  margin-bottom: 0;
}

.admin-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-soft);
  margin-bottom: 14px;
}

.admin-add-form {
  display: grid;
  grid-template-columns: 1fr clamp(90px, 15vw, 130px) clamp(90px, 15vw, 130px) auto;
  gap: clamp(6px, 1.5vw, 12px);
  align-items: end;
}

@media (max-width: 680px) {
  .admin-add-form {
    grid-template-columns: 1fr 1fr;
  }

  .admin-add-form .admin-field:first-child {
    grid-column: 1 / -1;
  }

  .admin-add-btn {
    grid-column: 1 / -1;
  }
}

@media (max-width: 400px) {
  .admin-add-form {
    grid-template-columns: 1fr;
  }

  .admin-add-form .admin-field,
  .admin-add-btn {
    grid-column: 1 / -1;
  }
}

.admin-field label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.admin-add-btn {
  padding: 14px 20px;
  background: var(--accent);
  color: #2ec633;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s;
}

.admin-add-btn:hover {
  background: var(--accent-dark);
}

.admin-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.admin-count-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: .82rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

/* Admin table extras */
.admin-table .row-inactive td {
  opacity: .45;
}

/* ── Admin table Out-of-stock row ── */
.row-oos {
  background: var(--red-bg);
  box-shadow: inset 3px 0 0 var(--red);
}

.row-oos td {
  background: transparent;
}

/* ← td โปร่งใส รับสีจาก tr */


.status-badge {
  font-size: clamp(0.72rem, 1.3vw, 0.82rem);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.status-on {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(46, 204, 113, .3);
}

.status-off {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(231, 76, 60, .3);
}

.action-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: clamp(0.72rem, 1.3vw, 0.82rem);
  padding: clamp(4px, 1vw, 6px) clamp(7px, 1.5vw, 11px);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin: 0 2px;
  transition: all .15s;
  white-space: nowrap;
}

.edit-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.delete-btn:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-bg);
}

/* ── Pagination ───────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  flex-wrap: wrap;
}

.pagination-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: .85rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  min-width: 40px;
}

.pagination-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.pagination-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

.pagination-ellipsis {
  color: var(--text-muted);
  padding: 8px 4px;
  font-size: .85rem;
}

/* ── Edit Modal ──────────────────────────────────────────────────── */
.edit-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vw, 16px);
}

.edit-modal.hidden {
  display: none;
}

.edit-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .75);
}

.edit-modal-box {
  position: relative;
  width: 100%;
  max-width: min(440px, 96vw);
  background: var(--surface);
 /* border: 1px solid var(--border2);*/
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 26px);
  box-shadow: var(--shadow);
  animation: fadeUp .2s ease;
  max-height: 92vh;
  overflow-y: auto;
}

@keyframes fadeUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.edit-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-weight: 700;
  font-size: 1rem;
}

/* required badge */
.required-badge {
  font-size: .75rem;
  font-weight: 600;
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid rgba(231, 76, 60, .3);
  border-radius: 20px;
  padding: 2px 8px;
  text-transform: none;
  letter-spacing: 0;
}

/* hint text below photo */
.field-hint {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 6px;
  transition: color .3s;
}

/* compress badge overlay on preview */
.compress-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(46, 204, 113, .9);
  color: #0a1a10;
  font-size: .75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  z-index: 2;
  backdrop-filter: blur(4px);
}

/* photo-preview: needs relative positioning for badge */
.photo-preview {
  position: relative;
}

/* shake animation for missing photo */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-6px);
  }

  40% {
    transform: translateX(6px);
  }

  60% {
    transform: translateX(-4px);
  }

  80% {
    transform: translateX(4px);
  }
}

.shake {
  animation: shake .45s ease;
}

/* photo area: highlight border when error */
.photo-area.shake .photo-buttons {
  border-color: var(--red) !important;
}

@media (max-width: 640px) {
  .td-actions {
    display: flex;
    flex-direction: row;
    gap: 4px;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

/* ── Responsive Stats Row ──────────────────────────────────────────── */
@media (max-width: 480px) {
  .stats-row {
    flex-wrap: wrap;
  }
  .stat-chip {
    flex: 1;
    min-width: 80px;
  }
}

/* ── Responsive page-header with logout btn ─────────────────────── */
@media (max-width: 500px) {
  .page-header[style*='flex'] {
    flex-direction: column !important;
    align-items: flex-start !important;
  }
}

/* ── Responsive Qty Row ─────────────────────────────────────────── */
@media (max-width: 380px) {
  .qty-btn {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
  }
  .qty-input {
    width: 60px;
  }
}

.items-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}


.item-name {
  font-weight: 500;
}

.item-qty {
  color: var(--primary);
  font-weight: bold;
  margin-left: 15px;
}

tr.is-grouped {
  background-color: var(--bg);
  border-left: 4px solid var(--primary);
}

.td-items {
  min-width: 200px;
}


footer {
  display: flex;
  justify-content: center;
  padding-bottom: 10px;
}

.cardfoot {
  position: relative;
  width: 220px;
  height: 50px;
  border-radius: 14px;
  z-index: 1;
  overflow: hidden;
}

.bgfoot {
  position: absolute;
  inset: 2px;
  z-index: 2;
  background: var(--bg);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.blob {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 120px;
  height: 120px;
  border-radius: 100%;
  background-color: transparent;
  box-shadow: 0 0 40px 20px var(--accent);
  will-change: transform;
  animation: blob-bounce 20s infinite ease;
}

@keyframes blob-bounce {
  0% {
    transform: translate(-100%, -100%) translate3d(0, 0, 0);
  }

  25% {
    transform: translate(-100%, -100%) translate3d(100%, 0, 0);
  }

  50% {
    transform: translate(-100%, -100%) translate3d(100%, 100%, 0);
  }

  75% {
    transform: translate(-100%, -100%) translate3d(0, 100%, 0);
  }

  100% {
    transform: translate(-100%, -100%) translate3d(0, 0, 0);
  }
}

.foot-text {
  color: var(--text);
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
  position: relative;
  z-index: 3;
}

/* ── Pagination ─────────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.pagination-btn {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text-soft);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s ease;
  min-width: 42px;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.pagination-btn:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--accent-glow);
}

.pagination-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.pagination-ellipsis {
  color: var(--text-muted);
  padding: 0 4px;
  font-weight: 500;
}