/* ============================================
   ADMIN PANEL — STYLES (Mobile-first)
   ============================================ */

.admin-body {
  background: #f3f6f3;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ---- Touch reset ---- */
a, button, [role="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ============================================
   LOGIN SCREEN
   ============================================ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.login-logo { text-align: center; margin-bottom: 1.75rem; }
.login-logo span { font-size: 2.75rem; display: block; margin-bottom: .5rem; }
.login-logo h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--green-dark);
  margin-bottom: .25rem;
}
.login-logo p { color: var(--gray-400); font-size: .88rem; }

.login-form { display: flex; flex-direction: column; gap: 1.1rem; }

/* ---- FORM FIELDS (shared) ---- */
.form-field { display: flex; flex-direction: column; gap: .4rem; }
.form-field label {
  font-weight: 700;
  font-size: .85rem;
  color: var(--gray-700);
}
.form-field input,
.form-field select,
.form-field textarea {
  padding: .8rem 1rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: 'Nunito', sans-serif;
  /* 16px mínimo para evitar zoom en iOS */
  font-size: 1rem;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  background: white;
  width: 100%;
  /* Scroll suave en iOS al enfocar */
  -webkit-overflow-scrolling: touch;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,.15);
}
.form-field input.error,
.form-field select.error { border-color: #e63946; }
.form-field small { font-size: .76rem; color: var(--gray-400); }
.form-field textarea { resize: vertical; }

.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 3rem; }
.pass-toggle {
  position: absolute;
  right: .75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: .4rem;
  opacity: .55;
  /* Target táctil */
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pass-toggle:active { opacity: 1; }

.field-error { font-size: .76rem; color: #e63946; min-height: 1rem; display: block; }

.btn-full { width: 100%; justify-content: center; }

.back-link {
  display: block;
  text-align: center;
  margin-top: 1.1rem;
  font-size: .85rem;
  color: var(--gray-400);
  padding: .5rem;
}
.back-link:active { color: var(--green-mid); }

/* ============================================
   ADMIN HEADER
   ============================================ */
.admin-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  top: env(safe-area-inset-top, 0px);
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.admin-header-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 1rem;
  padding-left: calc(1rem + env(safe-area-inset-left, 0px));
  padding-right: calc(1rem + env(safe-area-inset-right, 0px));
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.admin-header-right { display: flex; align-items: center; gap: .6rem; }

.admin-badge {
  display: none; /* se muestra en tablet+ */
  background: var(--green-pale);
  color: var(--green-dark);
  font-size: .72rem;
  font-weight: 800;
  padding: .22rem .65rem;
  border-radius: 50px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.btn-logout {
  background: none;
  border: 2px solid var(--gray-200);
  border-radius: 50px;
  padding: .4rem .85rem;
  font-size: .82rem;
  font-weight: 700;
  color: var(--gray-700);
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  min-height: 40px;
}
.btn-logout:active { border-color: var(--green-mid); background: var(--green-pale); color: var(--green-dark); }

/* ============================================
   ADMIN MAIN
   ============================================ */
.admin-main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  padding-bottom: calc(3rem + env(safe-area-inset-bottom, 0px));
}

.admin-topbar {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  margin-bottom: 1.25rem;
}
.admin-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--green-dark);
  margin-bottom: .2rem;
}
.admin-subtitle { color: var(--gray-400); font-size: .85rem; }
.admin-topbar .btn { width: 100%; }

/* ---- FILTERS ---- */
.admin-filters {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin-bottom: 1rem;
  /* Scroll horizontal en móvil */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: .25rem;
}
.admin-filters::-webkit-scrollbar { display: none; }

.filter-btn {
  padding: .5rem 1rem;
  border-radius: 50px;
  border: 2px solid var(--gray-200);
  background: white;
  font-family: 'Nunito', sans-serif;
  font-size: .82rem;
  font-weight: 700;
  color: var(--gray-700);
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
  flex-shrink: 0;
}
.filter-btn:active, .filter-btn.active {
  border-color: var(--green-mid);
  background: var(--green-mid);
  color: white;
}
.filter-search { margin-left: auto; flex-shrink: 0; }
.filter-search input {
  padding: .5rem .9rem;
  border: 2px solid var(--gray-200);
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem; /* 16px para evitar zoom en iOS */
  outline: none;
  width: 160px;
  min-height: 40px;
}
.filter-search input:focus { border-color: var(--green-light); }

/* ============================================
   TABLA → TARJETAS en móvil
   ============================================ */
.admin-table-wrap {
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* En móvil: tabla se convierte en lista de tarjetas */
.admin-table { width: 100%; border-collapse: collapse; }

.admin-table thead { display: none; }

.admin-table tbody tr {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem;
  padding: 1rem;
  border-bottom: 1px solid var(--gray-200);
  position: relative;
}
.admin-table tbody tr:last-child { border-bottom: none; }
.admin-table tbody tr:active { background: #f9fbf9; }

.admin-table td {
  border: none;
  padding: 0;
  vertical-align: middle;
}

/* Imagen: siempre a la izquierda */
.admin-table td:nth-child(1) { flex-shrink: 0; }

/* Nombre + desc: ocupa el espacio restante */
.admin-table td:nth-child(2) { flex: 1; min-width: 0; }

/* Categoría */
.admin-table td:nth-child(3) { width: auto; }

/* Precio */
.admin-table td:nth-child(4) { width: auto; }

/* Unidad — ocultar en móvil para ahorrar espacio */
.admin-table td:nth-child(5) { display: none; }

/* Tags — ocultar en móvil */
.admin-table td:nth-child(6) { display: none; }

/* Oferta — pequeño dot */
.admin-table td:nth-child(7) { width: auto; }

/* Acciones: fila completa abajo */
.admin-table td:nth-child(8) {
  width: 100%;
  padding-top: .6rem;
  border-top: 1px solid var(--gray-200);
  margin-top: .25rem;
}

.table-thumb {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}
.table-emoji {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: var(--green-pale);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
}

.table-name { font-weight: 800; color: var(--green-dark); font-size: .9rem; }
.table-desc { color: var(--gray-400); font-size: .78rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

.cat-badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 50px;
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}
.cat-badge.frutas   { background: #fff0d6; color: #a85e00; }
.cat-badge.verduras { background: var(--green-pale); color: var(--green-dark); }
.cat-badge.ofertas  { background: #fde2e4; color: #a00010; }

.price-cell { font-weight: 900; color: var(--green-mid); font-size: .95rem; white-space: nowrap; }
.price-old-cell { font-size: .72rem; color: var(--gray-400); text-decoration: line-through; display: block; }

.tag-list { display: flex; flex-wrap: wrap; gap: .25rem; }
.tag-item {
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: .7rem;
  font-weight: 700;
  padding: .12rem .45rem;
  border-radius: 50px;
}

.offer-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gray-200);
}
.offer-dot.on { background: var(--red-offer); }

.table-actions {
  display: flex;
  gap: .5rem;
  width: 100%;
}
.btn-edit, .btn-del {
  flex: 1;
  padding: .65rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: 'Nunito', sans-serif;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  min-height: 44px;
}
.btn-edit { background: var(--green-pale); color: var(--green-dark); }
.btn-edit:active { background: var(--green-light); color: white; }
.btn-del { background: #fde2e4; color: #a00010; }
.btn-del:active { background: var(--red-offer); color: white; }

.empty-admin-msg {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--gray-400);
  font-size: .95rem;
}

/* ============================================
   BOTONES GLOBALES
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .8rem 1.5rem;
  border-radius: 50px;
  font-weight: 700;
  font-size: .9rem;
  font-family: 'Nunito', sans-serif;
  border: none;
  cursor: pointer;
  min-height: 48px;
  transition: transform var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--orange); color: white; box-shadow: 0 4px 16px rgba(247,127,0,.35); }
.btn-primary:active { background: #e06e00; }
.btn-cancel { background: var(--gray-100); color: var(--gray-700); border: 2px solid var(--gray-200); }
.btn-cancel:active { background: var(--gray-200); }
.btn-danger { background: var(--red-offer); color: white; }
.btn-danger:active { background: #c0323e; }

/* ============================================
   EDIT MODAL — full screen en móvil
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.edit-modal {
  background: white;
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 95svh;
  max-height: 95vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.modal-overlay.open .edit-modal { transform: translateY(0); }

.edit-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  background: white;
  z-index: 5;
}
/* Handle drag */
.edit-modal-header::before {
  display: none; /* no en admin */
}
.edit-modal-header h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  color: var(--green-dark);
}

.modal-close {
  background: var(--gray-100);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-700);
  flex-shrink: 0;
}
.modal-close:active { background: var(--gray-200); }

.edit-form { padding: 1.25rem 1.25rem 1.5rem; }

/* Una columna en móvil */
.edit-form-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.edit-form-left, .edit-form-right { display: flex; flex-direction: column; gap: .9rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }

/* ---- ZONA DE SUBIDA DE IMAGEN ---- */
.img-upload-zone {
  position: relative;
  width: 100%;
  height: 150px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--gray-200);
  background: var(--gray-100);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.img-upload-zone:hover,
.img-upload-zone.drag-over {
  border-color: var(--green-light);
  background: var(--green-pale);
}
.img-upload-zone.drag-over { border-style: solid; }
.img-upload-zone.has-image { border-style: solid; border-color: var(--green-light); }

.img-upload-preview {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.img-upload-emoji { font-size: 3.5rem; pointer-events: none; }

.img-upload-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
  background: rgba(0,0,0,.45);
}
.img-upload-zone.has-image:hover .img-upload-overlay { opacity: 1; }
.img-upload-zone:not(.has-image) .img-upload-overlay {
  opacity: 1;
  background: transparent;
}
.img-upload-icon  { font-size: 1.6rem; }
.img-upload-label {
  font-size: .78rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.img-upload-zone:not(.has-image) .img-upload-label {
  color: var(--gray-700);
  text-shadow: none;
}
.img-upload-zone:not(.has-image) .img-upload-icon { font-size: 1.8rem; }

.img-upload-actions {
  display: flex;
  gap: .5rem;
  margin-top: .5rem;
  flex-wrap: wrap;
}
.btn-img-upload, .btn-img-remove {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .45rem .9rem;
  border-radius: 50px;
  border: none;
  font-family: 'Nunito', sans-serif;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 38px;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-img-upload { background: var(--green-pale); color: var(--green-dark); }
.btn-img-upload:hover, .btn-img-upload:active { background: var(--green-light); color: white; }
.btn-img-remove { background: #fde2e4; color: #a00010; }
.btn-img-remove:hover, .btn-img-remove:active { background: var(--red-offer); color: white; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
  font-weight: 700;
  color: var(--gray-700);
  min-height: 44px;
}
.checkbox-label input[type=checkbox] {
  width: 20px;
  height: 20px;
  accent-color: var(--green-mid);
  cursor: pointer;
  flex-shrink: 0;
}

.edit-form-actions {
  display: flex;
  gap: .65rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
}
.edit-form-actions .btn { flex: 1; }

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--green-dark);
  color: white;
  padding: .85rem 1.5rem;
  border-radius: 50px;
  font-weight: 700;
  font-size: .88rem;
  box-shadow: var(--shadow-md);
  z-index: 999;
  transition: transform .35s cubic-bezier(.4,0,.2,1), opacity .35s;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 2rem);
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: var(--red-offer); }

/* ============================================
   CONFIRM DIALOG
   ============================================ */
.confirm-dialog {
  background: white;
  border-radius: var(--radius);
  max-width: 340px;
  width: calc(100% - 2rem);
  padding: 1.75rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: scale(.9) translateY(10px);
  transition: transform var(--transition);
}
.modal-overlay.open .confirm-dialog { transform: scale(1) translateY(0); }
.confirm-icon { font-size: 2.25rem; margin-bottom: .85rem; }
.confirm-dialog h3 { font-size: 1.1rem; color: var(--green-dark); margin-bottom: .45rem; }
.confirm-dialog p  { color: var(--gray-400); font-size: .88rem; margin-bottom: 1.25rem; line-height: 1.5; }
.confirm-actions { display: flex; gap: .65rem; justify-content: center; }
.confirm-actions .btn { flex: 1; }

/* El overlay de confirm centra en lugar de bottom */
#confirmOverlay { align-items: center; padding: 1rem; }

/* ============================================
   TABLET — 600px+
   ============================================ */
@media (min-width: 600px) {
  .admin-main { padding: 1.75rem 1.5rem; }
  .admin-topbar { flex-direction: row; align-items: flex-start; justify-content: space-between; }
  .admin-topbar .btn { width: auto; }
  .filter-search input { width: 200px; }

  .edit-modal {
    border-radius: var(--radius);
    max-width: 560px;
    max-height: 92vh;
    transform: scale(.94) translateY(12px);
  }
  .modal-overlay.open .edit-modal { transform: scale(1) translateY(0); }
  .modal-overlay { align-items: center; padding: 1.5rem; }
  .edit-form-actions .btn { flex: none; }
  .edit-form-actions { justify-content: flex-end; }
}

/* ============================================
   TABLET GRANDE — 768px+
   ============================================ */
@media (min-width: 768px) {
  .admin-header-inner { height: 64px; padding: 0 1.5rem; }
  .admin-badge { display: inline-block; }

  /* Tabla vuelve a ser tabla real */
  .admin-table thead { display: table-header-group; }
  .admin-table thead { background: var(--gray-100); border-bottom: 2px solid var(--gray-200); }
  .admin-table th {
    padding: .9rem 1rem;
    text-align: left;
    font-weight: 800;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--gray-700);
    display: table-cell;
  }

  .admin-table tbody tr {
    display: table-row;
    border: none;
    padding: 0;
  }
  .admin-table tbody tr:last-child td { border-bottom: none; }
  .admin-table tbody tr:hover { background: #f9fbf9; }

  .admin-table td {
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: table-cell;
    vertical-align: middle;
  }

  /* Mostrar todas las columnas */
  .admin-table td:nth-child(5),
  .admin-table td:nth-child(6) { display: table-cell; }

  /* Acciones vuelven a ser inline */
  .admin-table td:nth-child(8) {
    width: auto;
    padding-top: .85rem;
    border-top: none;
    margin-top: 0;
  }

  .table-actions { flex-direction: row; width: auto; gap: .5rem; }
  .btn-edit, .btn-del { flex: none; padding: .4rem .8rem; min-height: auto; font-size: .8rem; }

  .table-thumb { width: 48px; height: 48px; }
  .table-emoji { width: 48px; height: 48px; }
  .table-desc { max-width: none; }

  /* Edit modal en dos columnas */
  .edit-modal { max-width: 780px; }
  .edit-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem 2rem;
  }
}

/* ============================================
   DESKTOP — 1024px+
   ============================================ */
@media (min-width: 1024px) {
  .btn-edit:hover { background: var(--green-light); color: white; }
  .btn-del:hover  { background: var(--red-offer); color: white; }
  .btn-logout:hover { border-color: var(--green-mid); background: var(--green-pale); color: var(--green-dark); }
  .btn-primary:hover { background: #e06e00; }
  .filter-btn:hover { border-color: var(--green-mid); background: var(--green-mid); color: white; }
}

/* Reducir animaciones */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
