/* ==========================================================================
   Baker Bridge Rescue — Admin
   Warm, wholesome dog-rescue styling. Nunito + earth tones + paw accents.
   ========================================================================== */

:root {
  --cream: #FAF6F0;
  --cream-dark: #F1EAE0;
  --surface: #FFFDFA;
  --green: #2F5D46;
  --green-deep: #244A37;
  --terracotta: #C97B4A;
  --terracotta-soft: #F5E3D5;
  --brown: #3E332B;
  --brown-soft: #6B5D51;
  --brown-faint: #8A7E72;
  --sage: #A8BFA5;
  --sage-soft: #E4EBE2;
  --brick: #A94438;
  --brick-deep: #8E3529;
  --brick-soft: #F9E9E6;
  --amber-soft: #F7E8C9;
  --amber-text: #8A5A00;
  --line: #EDE4D7;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-pill: 999px;
  --shadow-soft: 0 1px 2px rgba(62, 51, 43, 0.05), 0 4px 14px rgba(62, 51, 43, 0.07);
  --shadow-lift: 0 2px 4px rgba(62, 51, 43, 0.07), 0 10px 24px rgba(62, 51, 43, 0.12);
  --shadow-pop: 0 8px 40px rgba(62, 51, 43, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  font-weight: 500;
  background: var(--cream);
  color: var(--brown);
  line-height: 1.5;
}

/* Faint oversized pawprint watermark in the corner */
body::after {
  content: "";
  position: fixed;
  right: -130px;
  bottom: -110px;
  width: 460px;
  height: 460px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%233E332B'%3E%3Cellipse cx='12' cy='16.2' rx='4.4' ry='3.9'/%3E%3Cellipse cx='4.9' cy='10.6' rx='1.9' ry='2.5' transform='rotate(-22 4.9 10.6)'/%3E%3Cellipse cx='9.3' cy='6.9' rx='2' ry='2.7' transform='rotate(-8 9.3 6.9)'/%3E%3Cellipse cx='14.7' cy='6.9' rx='2' ry='2.7' transform='rotate(8 14.7 6.9)'/%3E%3Cellipse cx='19.1' cy='10.6' rx='1.9' ry='2.5' transform='rotate(22 19.1 10.6)'/%3E%3C/svg%3E")
    center / contain no-repeat;
  opacity: 0.045;
  transform: rotate(-16deg);
  pointer-events: none;
  z-index: 0;
}

button {
  font-family: inherit;
}

::selection {
  background: var(--sage);
  color: var(--brown);
}

:focus-visible {
  outline: 3px solid rgba(201, 123, 74, 0.55);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Header / nav bar
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 10px rgba(62, 51, 43, 0.05);
}

.site-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.8rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.brand-mark {
  display: flex;
  color: var(--terracotta);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 27px;
  height: 27px;
}

.brand-name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--brown);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-sub {
  color: var(--green);
}

.env-badge {
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.22rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--cream-dark);
  color: var(--brown-faint);
  flex-shrink: 0;
}

.env-badge.env-development {
  background: var(--amber-soft);
  color: var(--amber-text);
}

.env-badge.env-production {
  background: var(--brick-soft);
  color: var(--brick);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.welcome-message {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brown-soft);
  margin-right: 0.5rem;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.admin-wrap {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 5rem;
}

/* Auth screens sit narrow and centered */
#login-section,
#mfa-enroll-section,
#mfa-challenge-section {
  max-width: 440px;
  margin: 3rem auto 0;
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 1.75rem;
  margin-bottom: 1.75rem;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--brown);
  letter-spacing: -0.01em;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

/* Collapsible cards: the content brings its own top margin when expanded,
   so the header keeps no bottom margin — collapsed cards stay symmetric. */
.card-header-row:has(+ .collapsible-content) {
  margin-bottom: 0;
}

.card-header-row h2 {
  margin: 0;
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-icon {
  width: 20px;
  height: 20px;
  color: var(--green);
  vertical-align: -4px;
  margin-right: 0.35rem;
}

.muted {
  color: var(--brown-faint);
  font-size: 0.9rem;
}

p {
  margin: 0 0 0.9rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  border: 1.5px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--green);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(47, 93, 70, 0.22);
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease,
    transform 0.16s ease, box-shadow 0.16s ease;
}

.btn:hover:not(:disabled) {
  background: var(--green-deep);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(47, 93, 70, 0.3);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(47, 93, 70, 0.25);
}

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

form .btn {
  margin-top: 1rem;
  align-self: flex-start;
}

/* Small utility buttons inside forms (e.g. "+ Add image") stay tight */
form .btn-small {
  margin-top: 0.25rem;
}

/* Secondary — soft outline */
.btn-secondary {
  background: var(--surface);
  color: var(--green);
  border-color: rgba(47, 93, 70, 0.35);
  box-shadow: none;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--sage-soft);
  border-color: var(--green);
  color: var(--green-deep);
  box-shadow: none;
}

/* Ghost — header nav buttons */
.btn-ghost {
  background: transparent;
  color: var(--brown-soft);
  box-shadow: none;
  padding: 0.45rem 0.9rem;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--cream-dark);
  color: var(--brown);
  box-shadow: none;
  transform: none;
}

/* Danger — quiet text style that fills on hover */
.btn-danger {
  background: transparent;
  color: var(--brick);
  box-shadow: none;
}

.btn-danger:hover:not(:disabled) {
  background: var(--brick);
  color: #fff;
  box-shadow: 0 3px 10px rgba(169, 68, 56, 0.3);
}

/* In dialogs the destructive confirm is solid so intent is unmistakable */
.dialog-actions .btn-danger {
  background: var(--brick);
  color: #fff;
  box-shadow: 0 2px 8px rgba(169, 68, 56, 0.25);
}

.dialog-actions .btn-danger:hover:not(:disabled) {
  background: var(--brick-deep);
}

.btn-small {
  font-size: 0.83rem;
  padding: 0.4rem 0.9rem;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--brown-faint);
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-pill);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.btn-icon:hover {
  background: var(--cream-dark);
  color: var(--brown);
}

/* ==========================================================================
   Forms
   ========================================================================== */

form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--brown-soft);
  margin-top: 0.6rem;
}

.required {
  color: var(--terracotta);
}

input,
textarea {
  font: inherit;
  font-weight: 500;
  color: var(--brown);
  padding: 0.62rem 0.85rem;
  border: 1.5px solid #E2D8CA;
  border-radius: var(--radius-md);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder,
textarea::placeholder {
  color: #B7AB9D;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 93, 70, 0.14);
}

textarea {
  resize: vertical;
  min-height: 70px;
}

input[type="checkbox"] {
  accent-color: var(--green);
  width: 16px;
  height: 16px;
}

.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--brown-soft);
  margin-top: 0.85rem;
  cursor: pointer;
}

.input-with-upload {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.input-with-upload input {
  flex: 1;
  min-width: 0;
}

.image-actions-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.additional-images-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.image-url-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.image-url-row input {
  flex: 1;
  min-width: 0;
}

/* ==========================================================================
   Error banner
   ========================================================================== */

.error {
  background: var(--brick-soft);
  color: var(--brick);
  font-weight: 600;
  border: 1px solid #EBC7C0;
  border-radius: var(--radius-md);
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
}

/* ==========================================================================
   MFA
   ========================================================================== */

.mfa-qr {
  margin: 1rem 0;
  max-width: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

.mfa-qr svg {
  width: 100%;
  height: auto;
  display: block;
}

.mfa-secret {
  font-size: 0.88rem;
  color: var(--brown-soft);
}

.mfa-secret code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  background: var(--cream-dark);
  color: var(--brown);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  word-break: break-all;
}

.mfa-factors-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.mfa-factor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.95rem;
  background: var(--cream);
  border-radius: var(--radius-md);
}

.mfa-factor-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--brown);
}

.mfa-factor-date {
  font-size: 0.8rem;
  color: var(--brown-faint);
}

/* Collapsible section toggle */
.collapsible-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.collapsible-header h2 {
  margin: 0;
  display: flex;
  align-items: center;
}

.collapse-toggle-btn {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--sage-soft);
  color: var(--green);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.collapse-toggle-btn:hover {
  background: var(--sage);
  color: var(--green-deep);
  transform: scale(1.08);
}

.collapsible-content {
  margin-top: 1.1rem;
}

/* ==========================================================================
   Tabs
   ========================================================================== */

.tabs {
  display: inline-flex;
  gap: 0.25rem;
  background: var(--cream-dark);
  padding: 0.28rem;
  border-radius: var(--radius-pill);
  margin-bottom: 1.4rem;
}

.tab-btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--brown-soft);
  padding: 0.42rem 1.1rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.tab-btn:hover {
  color: var(--green);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 1px 4px rgba(62, 51, 43, 0.12);
}

/* ==========================================================================
   Product grid & cards
   ========================================================================== */

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 1.25rem;
}

.products-grid > .muted,
.products-grid > .empty-state {
  grid-column: 1 / -1;
}

.product-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}

.product-card.sortable-chosen {
  box-shadow: var(--shadow-pop);
  transform: rotate(1.2deg);
}

.product-card.sortable-ghost {
  opacity: 0.35;
}

/* Image area — fixed ratio, cover, paw fallback behind */
.product-card-image-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--cream-dark)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23A8BFA5'%3E%3Cellipse cx='12' cy='16.2' rx='4.4' ry='3.9'/%3E%3Cellipse cx='4.9' cy='10.6' rx='1.9' ry='2.5' transform='rotate(-22 4.9 10.6)'/%3E%3Cellipse cx='9.3' cy='6.9' rx='2' ry='2.7' transform='rotate(-8 9.3 6.9)'/%3E%3Cellipse cx='14.7' cy='6.9' rx='2' ry='2.7' transform='rotate(8 14.7 6.9)'/%3E%3Cellipse cx='19.1' cy='10.6' rx='1.9' ry='2.5' transform='rotate(22 19.1 10.6)'/%3E%3C/svg%3E")
    center / 60px no-repeat;
}

.product-card-image-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-card-image-wrap img.img-broken {
  opacity: 0;
}

.drag-handle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(255, 253, 250, 0.92);
  border-radius: 8px;
  padding: 0.12rem 0.5rem;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--brown-soft);
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 5px rgba(62, 51, 43, 0.18);
}

.drag-handle:active {
  cursor: grabbing;
}

/* Carousel */
.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  width: 27px;
  height: 27px;
  border: none;
  border-radius: 50%;
  background: rgba(62, 51, 43, 0.45);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.carousel-arrow:hover {
  background: rgba(62, 51, 43, 0.7);
  opacity: 1;
}

.carousel-prev {
  left: 8px;
}

.carousel-next {
  right: 8px;
}

.carousel-dots {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  display: flex;
  gap: 4px;
}

.carousel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 3px rgba(62, 51, 43, 0.35);
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.carousel-dot.active {
  background: #fff;
  transform: scale(1.25);
}

/* Card body */
.product-info {
  padding: 0.8rem 0.95rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.product-info .name {
  font-weight: 800;
  font-size: 1rem;
  color: var(--brown);
  line-height: 1.3;
}

.product-info .price {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--terracotta);
}

.product-info a {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green);
  text-decoration-color: rgba(47, 93, 70, 0.4);
  text-underline-offset: 3px;
}

.product-info a:hover {
  color: var(--green-deep);
  text-decoration-color: currentColor;
}

/* Status badges — pill with tiny dot */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.62rem;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  align-self: flex-start;
}

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

.status-badge.active {
  background: var(--sage-soft);
  color: var(--green);
}

.status-badge.inactive {
  background: var(--cream-dark);
  color: var(--brown-faint);
}

.product-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.85rem 0.95rem;
  margin-top: auto;
  border-top: 1px solid #F4EDE3;
}

/* Empty state (JS-rendered) */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 2.75rem 1rem;
  color: var(--brown-faint);
  text-align: center;
}

.empty-state svg {
  width: 46px;
  height: 46px;
  color: var(--sage);
}

.empty-state p {
  margin: 0;
  font-weight: 600;
  font-size: 0.92rem;
}

/* ==========================================================================
   Drawers
   ========================================================================== */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(62, 51, 43, 0.42);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  box-shadow: -8px 0 32px rgba(62, 51, 43, 0.22);
  padding: 1.75rem;
  overflow-y: auto;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.drawer:not(.hidden) .drawer-overlay {
  animation: fadeIn 0.22s ease both;
}

.drawer:not(.hidden) .drawer-panel {
  animation: slideIn 0.26s cubic-bezier(0.32, 0.72, 0.35, 1) both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}

.drawer-panel-header h2 {
  margin: 0;
}

.drawer-panel p {
  font-size: 0.92rem;
  color: var(--brown-soft);
}

/* ==========================================================================
   Confirm dialog
   ========================================================================== */

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(62, 51, 43, 0.42);
  padding: 1rem;
}

.dialog-overlay:not(.hidden) {
  animation: fadeIn 0.18s ease both;
}

.dialog-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.6rem 1.75rem;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-pop);
  animation: popIn 0.2s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

@keyframes popIn {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.dialog-box h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--brown);
}

.dialog-box p {
  margin: 0 0 1.3rem;
  color: var(--brown-soft);
  font-size: 0.92rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: calc(100vw - 2.5rem);
}

.toast {
  background: var(--brown);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lift);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: var(--green);
}

.toast-error {
  background: var(--brick);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 720px) {
  .site-header-inner {
    padding: 0.7rem 1rem;
  }

  .welcome-message {
    display: none;
  }

  .admin-wrap {
    padding: 1.5rem 1rem 4rem;
  }

  .card {
    padding: 1.25rem;
  }

  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.9rem;
  }

  .drawer-panel {
    max-width: 100%;
    border-radius: 0;
  }
}

@media (max-width: 460px) {
  .brand-name {
    font-size: 1rem;
  }

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