:root {
  --green: #169447;
  --green-dark: #0f7436;
  --bg: #f5f7f6;
  --card: #ffffff;
  --text: #142018;
  --muted: #6c766f;
  --border: #e2e8e4;
  --danger: #c0392b;
  --shadow: 0 10px 30px rgba(10, 60, 30, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #FFF9C4; color: var(--text); }
button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
.hidden { display: none !important; }
.screen { min-height: 100dvh; padding: 18px; padding-bottom: 96px; max-width: 620px; margin: 0 auto; }

.login-logo-wrap { display: flex; justify-content: center; margin: 4vh 0 18px; }
.login-logo { width: min(245px, 72vw); height: auto; display: block; filter: drop-shadow(0 14px 24px rgba(10, 60, 30, .16)); }
.login-card { margin-top: 0; background: rgba(255,255,255,.96); border-radius: 28px; padding: 28px 22px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.login-header { text-align: center; }
h1, h2 { margin: 0; }
h1 { color: var(--green-dark); text-align: center; }
.muted { color: var(--muted); margin: 8px 0 24px; }
label { display: block; font-weight: 700; margin: 18px 0 8px; }
select, input { width: 100%; border: 1px solid var(--border); border-radius: 14px; padding: 15px 14px; background: #fff; outline: none; }
select:focus, input:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(22,148,71,.12); }
.primary { background: linear-gradient(135deg, var(--green), var(--green-dark)); color: white; border-radius: 16px; padding: 15px 18px; font-weight: 800; box-shadow: 0 8px 18px rgba(22,148,71,.25); }
.primary:disabled { opacity: .55; cursor: not-allowed; }
.full { width: 100%; margin-top: 22px; }
.ghost { background: #edf7f1; color: var(--green-dark); border-radius: 999px; padding: 10px 14px; font-weight: 800; }
.error { color: var(--danger); font-weight: 700; }

.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { width: 44px; height: 44px; object-fit: contain; flex: 0 0 auto; }
.topbar { position: sticky; top: 0; z-index: 4; margin: -18px -18px 6px; padding: calc(16px + env(safe-area-inset-top)) 18px 16px; background: rgba(245,247,246,.92); backdrop-filter: blur(12px); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(226,232,228,.8); }
.tiny { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.day-card { display: flex; justify-content: space-between; align-items: center; background: #eaf8ef; border: 1px solid #d5efdf; padding: 14px 16px; border-radius: 18px; margin-bottom: 6px; }

.sticky-header { position:sticky; top:0; z-index:1000; background:#FFF9C4; border-bottom-left-radius: 16px; border-bottom-right-radius: 16px;}
.tabs { display:flex; gap:8px; overflow-x:auto; padding:8px 10px 14px; margin-bottom:14px; background:#E53935; border-radius:16px; box-shadow:0 2px 8px rgba(198,40,40,0.18); }
#storeTitle { white-space:normal; overflow:visible; text-overflow:unset; }

@media (max-width:768px){.tabs{scrollbar-width:none;-ms-overflow-style:none}.tabs::-webkit-scrollbar{display:none}}
.tab { border:0; border-radius:999px; padding:10px 14px; white-space:nowrap; background:#fff; color:#C62828; font-weight:700; }
.tab.active { background:#FFF3E0; color:#8B0000; }
.products { display: grid; gap: 10px; }
.product { background: white; border: 1px solid var(--border); border-radius: 18px; padding: 14px; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; box-shadow: 0 4px 12px rgba(20,32,24,.04); }
.product-name { font-weight: 850; margin-bottom: 3px; }
.product-meta { color: var(--muted); font-size: 13px; }
.qty { display: flex; align-items: center; gap: 7px; }
.qty button { width: 36px; height: 36px; border-radius: 12px; background: #eaf8ef; color: var(--green-dark); font-size: 22px; font-weight: 900; }
.qty input { width: 62px; text-align: center; padding: 10px 4px; border-radius: 12px; font-weight: 900; }
.product.has-qty { border-color: #9ad8ae; background: #fbfffc; }

.bottom-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 620px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; align-items: center; box-shadow: 0 -8px 24px rgba(20,32,24,.08); }
.bottom-bar .primary { min-width: 180px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: 86px; max-width: 580px; margin: 0 auto; background: #142018; color: white; padding: 14px 16px; border-radius: 16px; text-align: center; font-weight: 800; z-index: 10; }
.loader { position: fixed; inset: 0; background: rgba(255,255,255,.72); backdrop-filter: blur(4px); display: grid; place-content: center; gap: 12px; z-index: 20; color: var(--green-dark); font-weight: 900; }
.loader div { width: 42px; height: 42px; border: 5px solid #cdebd7; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 700px) {
  body { background: #FFF9C4; }
  .screen { padding-top: 24px; }
}

#changeStoreButton { display: none !important; }

/* =======================
   PANEL ADMIN
======================= */

.topbar-actions {
    display: flex;
    gap: 8px;
}

.admin-day-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #eaf8ef;
    border: 1px solid #d5efdf;
    padding: 14px 16px;
    border-radius: 18px;
    margin-bottom: 12px;
}

.day-nav {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: #E53935;
    color: white;
    font-size: 26px;
    font-weight: bold;
}

.admin-filters {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.admin-filters details {
    background: white;
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 12px;
}

.admin-filters summary {
    cursor: pointer;
    font-weight: 800;
    margin-bottom: 8px;
}

.checkbox-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.checkbox-list label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-weight: 600;
}

.checkbox-list input {
    width: auto;
}

.admin-results {
    display: grid;
    gap: 12px;
}

.admin-product {
    background: white;
    border-radius: 18px;
    padding: 14px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(20,32,24,.05);
}

.admin-product h3 {
    margin: 0 0 8px;
    color: var(--green-dark);
}

.admin-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dashed #ececec;
}

.admin-row:last-child {
    border-bottom: none;
}

/* =======================
   DEVOLUCIÓN
======================= */
.danger-ghost { background:#fdecea; color:#8B0000; }

.modal { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,32,24,.55); backdrop-filter: blur(3px); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 92dvh;
  background: #fff;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -20px 40px rgba(20,32,24,.25);
  display: flex;
  flex-direction: column;
  animation: slideUp .25s ease-out;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 24px; }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { color: var(--green-dark); font-size: 20px; }
.icon-btn { background: transparent; font-size: 28px; line-height: 1; width: 36px; height: 36px; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: #f0f3f1; }

.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-body label { margin-top: 14px; }
.modal-body label:first-child { margin-top: 0; }
.modal-body textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; background: #fff; outline: none; resize: vertical; font-family: inherit;
}
.modal-body textarea:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(22,148,71,.12); }
.modal-body input[type=file] { padding: 12px; background: #f7faf8; }

.preview { margin-top: 10px; min-height: 0; }
.preview img { max-width: 100%; max-height: 200px; border-radius: 12px; border: 1px solid var(--border); display: block; }

.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

/* Fotos de devolución una al lado de la otra */
.modal-body .return-photos-container {
  display: grid;
  grid-template-columns: 1fr;
  width: 100%;
  margin-bottom: 18px;
}

.modal-body .return-photo-group {
  min-width: 0;
}

.modal-body .return-photo-group label {
  margin: 0 0 8px;
  font-size: 14px;
}

.modal-body .return-photo-group input[type="file"] {
  width: 100%;
  min-width: 0;
  padding: 10px;
  font-size: 12px;
  background: #f7faf8;
}

.modal-body .return-photo-group .preview {
  margin-top: 8px;
  width: 100%;
}

.modal-body .return-photo-group .preview img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}

@media (max-width: 400px) {
  .modal-body .return-photos-container {
    gap: 8px;
  }

  .modal-body .return-photo-group label {
    font-size: 12px;
  }

  .modal-body .return-photo-group input[type="file"] {
    padding: 8px 5px;
    font-size: 10px;
  }

  .modal-body .return-photo-group .preview img {
    height: 120px;
  }
}

.photo-grid {
    display: flex;
    gap: 16px;
    width: 100%;
}

.photo-field {
    flex: 1;
    min-width: 0;
}

.photo-field label {
    display: block;
    margin: 0 0 8px;
}

.photo-field input[type="file"] {
    display: block;
    width: 100%;
}

.photo-field .preview img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    border-radius: 12px;
}

@media (max-width: 600px) {
    .photo-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
}