/* ============================================================
   MESO HOUSEHOLDS — Admin styling
   Login / add / edit dialogs, inline in-page admin controls
   ============================================================ */

/* ---------- Shared dialog chrome (login, category, product, manage) ---------- */
.admin-dialog { border: 0; border-radius: 20px; padding: 0; width: min(440px, 92vw); box-shadow: 0 24px 80px rgba(0,0,0,.28); background: var(--white); color: var(--ink); }
.admin-dialog::backdrop { background: rgba(17,17,17,.6); backdrop-filter: blur(3px); }
.admin-dialog-lg { width: min(640px, 94vw); }
.admin-dialog-xl { width: min(720px, 94vw); }
.admin-form { position: relative; padding: 34px; display: grid; gap: 16px; }
.admin-form h2 { margin-bottom: -6px; font-family: var(--font-head); color: var(--ink); }
.admin-help { color: var(--muted); font-size: .86rem; }
.admin-form label { display: grid; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--accent-2); }

.admin-form input,
.admin-form select,
.admin-form textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  font-size: .9rem;
  background: var(--cream);
  color: var(--ink);
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.admin-form input::placeholder,
.admin-form textarea::placeholder { color: #9a9a9a; font-style: italic; }
.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
  background: var(--white);
}
.admin-form textarea { resize: vertical; min-height: 72px; }

/* Custom select arrow, brand-coloured instead of the OS-default control */
.admin-form select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23d90429' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 36px;
}

.dialog-close { position: absolute; top: 15px; right: 17px; font-size: 1.6rem; line-height: 1; color: var(--muted); border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; transition: background .18s, color .18s; }
.dialog-close:hover { background: var(--primary-light); color: var(--primary-dark); }
.admin-error { color: var(--primary-dark); min-height: 1.3em; font-size: .82rem; font-weight: 500; }
.admin-dialog-actions { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: 4px; }
.admin-delete-link { color: var(--primary-dark); margin-top: 0; }

/* ---------- Field row: select + inline "+" / "edit" icon buttons ---------- */
.field-row { display: flex; align-items: stretch; gap: 8px; }
.field-row select { flex: 1; }
.icon-btn {
  flex-shrink: 0;
  width: 42px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--cream);
  color: var(--primary-dark);
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .18s, border-color .18s, transform .15s;
}
.icon-btn:hover { background: var(--primary-light); border-color: var(--primary); transform: translateY(-1px); }

/* ---------- Photo upload (product + category dialogs) ---------- */
.image-upload { border: 1.5px dashed var(--border); border-radius: 12px; padding: 14px; display: grid; gap: 10px; background: var(--cream); }
.image-upload-preview { width: 100%; max-width: 220px; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: var(--white); }
.image-upload-empty { font-size: .82rem; color: var(--muted); }
.image-upload-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* Styled "Choose photo" control replacing the raw OS file-input button */
.file-btn { position: relative; display: inline-flex; align-items: center; gap: 8px; }
.file-btn input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.file-btn-label {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--white); border: 1.5px solid var(--primary); color: var(--primary-dark);
  font-weight: 600; font-size: .82rem; padding: 9px 16px; border-radius: 100px;
  transition: background .18s, color .18s;
}
.file-btn:hover .file-btn-label { background: var(--primary); color: var(--white); }

/* Multi-photo gallery for products */
.photo-gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.photo-thumb { position: relative; width: 78px; height: 78px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--white); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb.is-cover { border: 2px solid var(--primary); }
.photo-thumb-cover-tag { position: absolute; bottom: 0; left: 0; right: 0; background: var(--primary); color: var(--white); font-size: .58rem; font-weight: 700; text-align: center; text-transform: uppercase; letter-spacing: .04em; padding: 2px 0; }
.photo-thumb-remove { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: rgba(17,17,17,.75); color: #fff; font-size: .7rem; display: flex; align-items: center; justify-content: center; }
.photo-thumb-remove:hover { background: var(--primary); }
.photo-thumb-add { display: flex; align-items: center; justify-content: center; color: var(--primary-dark); font-size: 1.6rem; font-weight: 700; background: var(--cream); border: 1.5px dashed var(--primary-light); cursor: pointer; }
.photo-thumb-add:hover { background: var(--primary-light); }
.photo-gallery-hint { font-size: .76rem; color: var(--muted); }

/* Merge dialog: photos shown LARGE (with the product each came from) so they are easy to identify */
.photo-gallery-lg { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; max-height: 52vh; overflow-y: auto; padding: 2px; }
.photo-card-lg { margin: 0; cursor: pointer; }
.photo-card-lg .photo-thumb { width: 100%; height: auto; aspect-ratio: 1 / 1; border-radius: 14px; }
.photo-card-lg.is-cover .photo-thumb { border: 2px solid var(--primary); }
.photo-card-lg .photo-thumb img { transition: transform .2s ease; }
.photo-card-lg:hover .photo-thumb img { transform: scale(1.05); }
.photo-card-lg .photo-thumb-cover-tag { font-size: .64rem; padding: 4px 0; }
.photo-card-lg .photo-thumb-remove { top: 6px; right: 6px; width: 26px; height: 26px; font-size: .95rem; }
.photo-card-lg-name { margin-top: 6px; font-size: .78rem; font-weight: 600; color: var(--ink); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Admin toolbar (sits inside the live Products section) ----------
   Hidden by DEFAULT so visitors never see it. It is only shown when BOTH are
   true: <body> has the .is-admin class (set by JS only after verifying the
   signed-in user is in admin_users) AND the [hidden] attribute is absent
   (JS re-adds it instantly on sign-out). Author CSS would otherwise override
   the UA's [hidden] { display: none } and leak the panel to logged-out
   visitors — hence display:none here and the :not([hidden]) guard below. */
.admin-toolbar { display: none; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px; background: linear-gradient(135deg, var(--primary-light), #fff); border: 1.5px dashed var(--primary); border-radius: 100px; padding: 10px 22px; margin: 0 auto 30px; width: fit-content; max-width: 100%; }
body.is-admin .admin-toolbar:not([hidden]) { display: flex; }
.admin-toolbar-label { font-weight: 700; font-size: .85rem; color: var(--primary-dark); white-space: nowrap; }
.admin-toolbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-toolbar-actions .btn-text { margin-top: 0; }

/* ---------- Category filter chips: edit pencil + add chip ---------- */
.filter-chip-wrap { position: relative; display: inline-flex; }
.filter-chip-img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; margin-right: 4px; vertical-align: -3px; }
.filter-chip-edit { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: var(--white); font-size: .68rem; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm); transition: background .2s; }
.filter-chip-edit:hover { background: var(--primary-dark); }
.filter-btn-add { border-style: dashed; color: var(--muted); }
.filter-btn-add:hover { color: var(--primary-dark); }

/* ---------- Inline admin controls on product cards ---------- */
.product-card.is-admin .product-media { position: relative; }
.admin-overlay { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 2; }
.admin-overlay-btn { width: 30px; height: 30px; border-radius: 50%; background: rgba(217,4,41,.85); color: #fff; display: flex; align-items: center; justify-content: center; font-size: .85rem; transition: background .2s, transform .2s; }
.admin-overlay-btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.admin-quick-move { display: grid; gap: 4px; font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px; }
.admin-quick-move select { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: .82rem; font-weight: 500; text-transform: none; letter-spacing: normal; background: var(--white); color: var(--ink); }

/* ---------- "Add product" ghost card at the end of the grid ---------- */
.add-product-card {
  border: 2px dashed var(--primary-light);
  background: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: .92rem;
  min-height: 260px;
  transition: border-color .25s, color .25s, background .25s;
}
.add-product-card:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-light); }
.add-product-plus { font-size: 2.2rem; line-height: 1; font-family: var(--font-head); color: var(--primary); }

/* ---------- Bulk upload dialog ---------- */
.bulk-drop { cursor: pointer; transition: border-color .18s, background .18s; }
.bulk-drop.dragover { border-color: var(--primary); background: var(--primary-light); }
.bulk-preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
.bulk-thumb { position: relative; margin: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--white); }
.bulk-thumb img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.bulk-thumb figcaption { font-size: .68rem; color: var(--muted); padding: 6px 8px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bulk-thumb-remove { position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; border-radius: 50%; background: rgba(17,17,17,.75); color: #fff; font-size: .8rem; display: flex; align-items: center; justify-content: center; }
.bulk-thumb-remove:hover { background: var(--primary); }
.bulk-combine-option { display: flex !important; flex-direction: row; align-items: flex-start; gap: 10px; font-size: .82rem; font-weight: 500; color: var(--muted); line-height: 1.45; cursor: pointer; background: var(--primary-light); border: 1px dashed var(--primary); border-radius: 12px; padding: 10px 14px; }
.bulk-combine-option input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); margin-top: 3px; }
.bulk-combine-option strong { color: var(--primary-dark); }

/* ---------- "Manage all" catalogue overview modal ---------- */
.manage-toolbar { display: flex; gap: 10px; margin: 4px 0 6px; flex-wrap: wrap; }
.manage-bulk-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; border: 1.5px dashed var(--border); border-radius: 12px; padding: 10px 14px; background: var(--cream); }
.manage-select-all { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; cursor: pointer; color: var(--accent-2); user-select: none; }
.manage-bulk-count { font-size: .8rem; color: var(--muted); font-weight: 600; }
#manageDeleteSelectedBtn { margin-left: auto; }
input[type="checkbox"].manage-product-check,
.manage-select-all input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.btn-danger { background: var(--primary); color: var(--white); }
.btn-danger:hover { background: var(--primary-dark); box-shadow: 0 10px 24px rgba(217,4,41,.4); }
.btn-danger:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.manage-list { max-height: 55vh; overflow-y: auto; display: grid; gap: 10px; padding-right: 4px; margin-top: 4px; }
.manage-cat-group { border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 12px; padding: 0 16px; background: var(--white); box-shadow: var(--shadow-sm); }
.manage-cat-group summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 0; cursor: pointer; font-size: .92rem; }
.manage-cat-group summary::-webkit-details-marker { display: none; }
.manage-cat-group summary small { color: var(--muted); font-weight: 500; margin-left: 8px; }
.manage-cat-thumb { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; margin-right: 6px; vertical-align: -6px; }
.manage-cat-actions { display: flex; gap: 12px; flex-shrink: 0; }
.manage-cat-actions .btn-text { margin-top: 0; }
.manage-products { display: grid; gap: 12px; padding: 4px 0 16px; }
.manage-product-row { display: grid; grid-template-columns: 18px 44px 1fr auto auto auto; align-items: center; gap: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.manage-product-row img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; background: var(--cream); }
.manage-product-info { display: grid; gap: 2px; font-size: .85rem; }
.manage-product-info small { color: var(--muted); }
.manage-category-select { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: .78rem; background: var(--white); }
.manage-product-row .btn-text { margin-top: 0; }

/* ---------- Buttons: consistent brand look inside admin dialogs ---------- */
.admin-form .btn-primary:disabled { opacity: .7; cursor: progress; }

@media (max-width: 700px) {
  .admin-toolbar { border-radius: var(--radius); }
}
@media (max-width: 640px) {
  .manage-product-row { grid-template-columns: 18px 36px 1fr; row-gap: 8px; }
  .manage-category-select, .manage-product-row .manage-edit-product, .manage-product-row .manage-delete-product { grid-column: 1 / -1; }
  #manageDeleteSelectedBtn, #manageMergeSelectedBtn { margin-left: 0; width: 100%; }
}
