/* ============================================================
   หน้าผู้ดูแลร้าน (Admin) — เกี๊ยวบางทราย GYO BANGSAI
   ใช้ตัวแปรสี/ฟอนต์ร่วมกับ styles.css
   ============================================================ */

.admin-body {
  background: var(--bg);
  padding-bottom: 48px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Top bar ---------- */
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(14px, 4vw, 28px);
  background: rgba(255, 249, 242, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.admin-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.admin-brand img {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  object-fit: cover;
  flex: none;
  box-shadow: var(--shadow-sm);
}

.admin-brand span {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.admin-brand strong {
  font-family: var(--font-head);
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-brand small {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.admin-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-head);
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--brand-50);
  color: var(--brand);
  border: 1px solid var(--brand-100);
  white-space: nowrap;
}

.mode-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.mode-badge.local {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--line-strong);
}

/* ---------- Buttons ---------- */
.admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  text-align: center;
}

.admin-btn:active {
  transform: translateY(1px);
}

.admin-btn.primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 8px 18px -10px rgba(20, 83, 45, 0.7);
}

.admin-btn.primary:hover {
  background: var(--brand-600);
}

.admin-btn.ghost {
  background: var(--surface);
  color: var(--ink-soft);
  border-color: var(--line-strong);
}

.admin-btn.ghost:hover {
  background: var(--surface-2);
}

.admin-btn.danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

.admin-btn.danger:hover {
  background: #fee2e2;
}

.admin-btn.sm {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.admin-btn.block {
  width: 100%;
}

.admin-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- PIN gate ---------- */
.gate {
  min-height: calc(100dvh - 60px);
  display: grid;
  place-items: center;
  padding: 28px 18px 60px;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 30px 26px 24px;
  text-align: center;
}

.gate-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--brand-50);
  color: var(--brand);
  border: 1px solid var(--brand-100);
}

.gate-icon svg {
  width: 26px;
  height: 26px;
}

.gate-card h1 {
  font-size: 22px;
  margin-bottom: 6px;
}

.gate-desc {
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 20px;
}

.gate-input {
  width: 100%;
  text-align: center;
  font-family: var(--font-head);
  font-size: 26px;
  letter-spacing: 0.35em;
  padding: 13px 12px;
  border-radius: 13px;
  border: 1.5px solid var(--line-strong);
  background: var(--surface-2);
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.gate-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 83, 45, 0.14);
  background: #fff;
}

.gate-error {
  font-size: 13px;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.gate-hint {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
}

.gate-hint code {
  font-family: var(--font-head);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--accent-strong);
}

.gate.shake {
  animation: gate-shake 0.36s ease;
}

@keyframes gate-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* ---------- Layout ---------- */
.admin-main {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 30px) clamp(14px, 4vw, 28px) 40px;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 5px;
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}

.admin-tabs::-webkit-scrollbar {
  display: none;
}

.admin-tab {
  flex: 1 0 auto;
  padding: 10px 14px;
  border-radius: 10px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.admin-tab.is-active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}

/* ---------- Cards ---------- */
.admin-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: clamp(16px, 3vw, 24px);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px dashed var(--line-strong);
}

.card-head.compact {
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 18px;
  margin-bottom: 3px;
}

.card-head p {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Fields ---------- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field.wide {
  grid-column: 1 / -1;
}

.field > span {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  font-family: var(--font-head);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line-strong);
  background: var(--surface-2);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.field textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 83, 45, 0.12);
  background: #fff;
}

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

/* image field */
.image-field {
  grid-column: 1 / -1;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.image-preview {
  width: 74px;
  height: 74px;
  border-radius: 12px;
  object-fit: cover;
  background: #fff;
  border: 1px solid var(--line-strong);
  flex: none;
}

.image-controls {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-controls input[type="text"] {
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1.5px solid var(--line-strong);
  background: #fff;
  font-size: 13px;
  outline: none;
}

.image-controls input[type="text"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 83, 45, 0.12);
}

.image-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Sub cards ---------- */
.sub-card {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.sub-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sub-head h3 {
  font-size: 15px;
}

.option-groups {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.option-group {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px auto;
  gap: 10px;
  align-items: start;
}

.option-group .opt-choices {
  grid-column: 1 / -1;
}

.option-group label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  font-family: var(--font-head);
}

.option-group input,
.option-group textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1.5px solid var(--line-strong);
  background: var(--surface-2);
  font-size: 13px;
  outline: none;
  resize: vertical;
}

.option-group input:focus,
.option-group textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 83, 45, 0.12);
  background: #fff;
}

.option-group .opt-remove {
  align-self: end;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  font-size: 18px;
  line-height: 1;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-head);
  color: var(--ink-soft);
  cursor: pointer;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
  flex: none;
}

.bulk-fields {
  margin-top: 14px;
}

/* ---------- Save bar ---------- */
.save-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px dashed var(--line-strong);
}

.dirty {
  margin-right: auto;
  font-size: 12.5px;
  color: var(--accent-strong);
  font-weight: 600;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.55;
}

.hint code {
  font-family: var(--font-head);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--accent-strong);
}

/* ---------- Menu tab ---------- */
.menu-layout {
  display: grid;
  grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.menu-list-card {
  position: sticky;
  top: 78px;
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 2px;
}

.product-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.product-list-item:hover {
  border-color: var(--brand-100);
  background: var(--brand-50);
}

.product-list-item.is-active {
  border-color: var(--brand);
  background: var(--brand-50);
}

.product-list-item img {
  width: 44px;
  height: 44px;
  border-radius: 9px;
  object-fit: cover;
  flex: none;
  background: #fff;
  border: 1px solid var(--line);
}

.product-list-item .pli-main {
  min-width: 0;
  flex: 1;
}

.product-list-item .pli-name {
  font-family: var(--font-head);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-list-item .pli-meta {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-list-item .pli-price {
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
  flex: none;
}

.product-form {
  min-width: 0;
}

/* ---------- Settings ---------- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.pin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.storage-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.storage-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  overflow: hidden;
}

.storage-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 0.3s ease;
}

.storage-row p {
  font-size: 12.5px;
  color: var(--muted);
}

.danger-card {
  border-color: #fecaca;
  background: #fffafa;
}

.admin-note {
  margin-top: 18px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 12px 14px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  max-width: min(92vw, 460px);
  padding: 11px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  text-align: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.ok {
  background: var(--brand);
}

.toast.err {
  background: var(--danger);
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .menu-layout {
    grid-template-columns: 1fr;
  }

  .menu-list-card {
    position: static;
  }

  .product-list {
    max-height: none;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .admin-brand small {
    display: none;
  }

  .admin-top-actions .admin-btn.ghost:first-child {
    display: none;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .option-group {
    grid-template-columns: 1fr 80px auto;
  }

  .save-bar {
    justify-content: stretch;
  }

  .save-bar .admin-btn {
    flex: 1;
  }

  .dirty {
    width: 100%;
    margin-right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gate.shake {
    animation: none;
  }
}
