/* Admin floating toolbar + toasts + sheets — Wareed (mobile-first) */

.admin-toolbar,
.wat-toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  z-index: var(--z-admin-toolbar, 2500);
  width: 100%;
  max-width: 100%;
  border-radius: 20px 20px 0 0;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid rgba(40, 167, 69, 0.22);
  border-bottom: none;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.14);
  font-family: "Cairo", sans-serif;
  color: var(--wareed-dark, #68000C);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  transform: none;
}
.wat-toolbar[hidden] { display: none !important; }

.wat-desktop-only { display: none !important; }
.wat-mobile-only { display: flex !important; }

.wat-mobile-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.wat-mobile-badge-row {
  margin-top: 8px;
  width: 100%;
}
.wat-mobile-badge-row:has(.wat-badge[hidden]) {
  display: none !important;
  margin: 0;
}

.wat-btn {
  border: 1px solid #ddd;
  background: #fff;
  color: var(--wareed-dark, #68000C);
  border-radius: 12px;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.wat-btn:hover { border-color: var(--wareed-red, #d00018); }
.wat-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.wat-save {
  background: #28a745 !important;
  color: #fff !important;
  border-color: #28a745 !important;
  font-size: 16px !important;
  border-radius: 14px !important;
  box-shadow: 0 6px 16px rgba(40, 167, 69, 0.35);
  font-weight: 800;
}
.wat-save:hover {
  background: #218838 !important;
  border-color: #1e7e34 !important;
}
.wat-save.is-dirty {
  animation: watPulse 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #dc3545, 0 6px 16px rgba(40, 167, 69, 0.35);
}
.wat-save.is-saving { opacity: 0.85; }
.wat-save.is-success {
  background: #fff !important;
  color: #28a745 !important;
  border-color: #28a745 !important;
}
.wat-force {
  background: #6f42c1 !important;
  color: #fff !important;
  border-color: #6f42c1 !important;
  font-weight: 800;
}
.wat-force:hover { filter: brightness(1.08); }
.wat-force.is-saving { opacity: 0.85; }
.wat-force.is-success {
  background: #fff !important;
  color: #28a745 !important;
  border-color: #28a745 !important;
}

.wat-save-mobile {
  flex: 0 0 60%;
  width: 60%;
  min-height: 52px;
}
.wat-undo-mobile {
  flex: 0 0 calc(20% - 6px);
  width: calc(20% - 6px);
  min-height: 52px;
  font-size: 22px;
  padding: 0;
}
.wat-more-btn {
  flex: 0 0 calc(20% - 6px);
  width: calc(20% - 6px);
  min-height: 52px;
  font-size: 22px;
  padding: 0;
  background: #f7f7f7;
}

@keyframes watPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.wat-logout {
  background: #fff5f5;
  border-color: #f5c2c2;
  color: var(--wareed-red, #d00018);
}

.wat-badge {
  display: block;
  width: 100%;
  text-align: center;
  color: #fff;
  background: #dc3545;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  box-sizing: border-box;
}
.wat-badge[hidden] { display: none !important; }

.wat-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  min-width: 140px;
}
.wat-saved { color: #666; font-size: 13px; }

.wat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
}
.wat-toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--wareed-red, #d00018);
}

.wat-actions,
.wat-right {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.wat-status-text {
  font-size: 13px;
  font-weight: 700;
  color: #555;
  white-space: nowrap;
}

/* Body offset for fixed bars */
body.wat-toolbar-visible {
  padding-top: 0;
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}
body.wat-toolbar-visible.wat-has-dirty {
  padding-bottom: calc(132px + env(safe-area-inset-bottom, 0px));
}

/* —— Bottom sheet —— */
.wat-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3300;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}
.wat-sheet-backdrop[hidden] { display: none !important; }

.wat-more-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3310;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.2);
  font-family: "Cairo", sans-serif;
  max-height: min(70vh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.wat-more-sheet[hidden] { display: none !important; }
.wat-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: #ddd;
  margin: 4px auto 14px;
}
.wat-sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: none;
  border-radius: 14px;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  color: var(--wareed-dark, #68000C);
  cursor: pointer;
  text-align: start;
  -webkit-tap-highlight-color: transparent;
}
.wat-sheet-item:active,
.wat-sheet-item:hover { background: #f5f5f5; }
.wat-sheet-item.is-danger { color: #dc3545; }
.wat-sheet-item .wat-sheet-ico { font-size: 22px; width: 28px; text-align: center; }

/* —— Toasts (mobile: top-center) —— */
.wat-toast-host {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  z-index: var(--z-toast, 3000);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}
.wat-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
  font-family: "Cairo", sans-serif;
  font-weight: 700;
  color: #fff;
  animation: watToastIn 0.35s ease;
  box-sizing: border-box;
}
.wat-toast.is-ok { background: #28a745; }
.wat-toast.is-error { background: #dc3545; }
.wat-toast-icon { font-size: 20px; flex-shrink: 0; line-height: 1.2; }
.wat-toast-msg {
  flex: 1;
  font-size: 16px;
  line-height: 1.45;
  color: #fff;
  word-break: break-word;
}
.wat-toast-copy {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wat-toast-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.85;
}
@keyframes watToastIn {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes watToastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}
.wat-toast.is-leaving { animation: watToastOut 0.3s ease forwards; }

/* —— Save overlay —— */
.wat-save-overlay {
  position: fixed;
  inset: 0;
  z-index: 4500;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  font-family: "Cairo", sans-serif;
  color: var(--wareed-dark, #68000C);
}
.wat-save-overlay[hidden] { display: none !important; }
.wat-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e5e5e5;
  border-top-color: #28a745;
  border-radius: 50%;
  animation: watSpin 0.8s linear infinite;
}
@keyframes watSpin { to { transform: rotate(360deg); } }
.wat-save-overlay-text {
  font-size: 18px;
  font-weight: 800;
}
.wat-save-check {
  font-size: 64px;
  line-height: 1;
  animation: watCheckPop 0.4s ease;
}
@keyframes watCheckPop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* —— Error modal —— */
.wat-error-modal {
  position: fixed;
  inset: 0;
  z-index: 4600;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0;
  font-family: "Cairo", sans-serif;
}
.wat-error-modal[hidden] { display: none !important; }
.wat-error-card {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  background: #fff;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.wat-error-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: #dc3545;
}
.wat-error-msg {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--wareed-dark, #68000C);
  line-height: 1.5;
  word-break: break-word;
}
.wat-error-details {
  border: 1px solid #eee;
  border-radius: 12px;
  overflow: hidden;
}
.wat-error-details summary {
  padding: 14px 16px;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  background: #fafafa;
  min-height: 44px;
}
.wat-error-details pre {
  margin: 0;
  padding: 12px;
  max-height: 180px;
  overflow: auto;
  font-size: 12px;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  background: #111;
  color: #eee;
}
.wat-error-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
}
.wat-error-actions .wat-btn {
  width: 100%;
  min-height: 52px;
  font-size: 16px;
}
.wat-error-copy { border-color: #dc3545; color: #dc3545; background: #fff; }
.wat-error-retry { background: #28a745 !important; color: #fff !important; border-color: #28a745 !important; }

.admin-toolbar-toggle {
  position: absolute;
  top: -22px;
  right: 12px;
  background: #C62828;
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 2;
}

/* Desktop toolbar stays at the bottom and can collapse */
@media (min-width: 769px) {
  .admin-toolbar,
  .wat-toolbar {
    top: auto;
    bottom: 0;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(900px, calc(100% - 16px));
    max-width: 900px;
    border-radius: 16px 16px 0 0;
    border: 1px solid rgba(40, 167, 69, 0.28);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    padding: 12px 16px;
    background: rgba(30, 30, 30, 0.95);
    color: #fff;
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
  .wat-status-text,
  .wat-saved { color: #fff; }

  .wat-desktop-only { display: flex !important; }
  .wat-mobile-only { display: none !important; }

  .wat-desktop-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    width: 100%;
  }

  .wat-save {
    min-width: 180px;
    min-height: 48px;
    padding: 12px 18px !important;
  }

  .admin-toolbar.collapsed,
  .wat-toolbar.collapsed {
    transform: translateX(-50%) translateY(calc(100% - 44px));
  }

  body.wat-toolbar-visible {
    padding-bottom: 120px;
    padding-top: 0;
  }
  body.wat-toolbar-visible.wat-toolbar-collapsed {
    padding-bottom: 56px;
  }
  body.wat-toolbar-visible.wat-has-dirty {
    padding-bottom: 120px;
  }
  body.wat-toolbar-visible.wat-toolbar-collapsed.wat-has-dirty {
    padding-bottom: 56px;
  }

  .wat-toast-host {
    top: 100px;
    left: auto;
    right: 16px;
    transform: none;
    width: auto;
    max-width: 400px;
    align-items: stretch;
  }

  .wat-error-modal {
    align-items: center;
    padding: 24px;
  }
  .wat-error-card {
    max-width: 480px;
    min-height: auto;
    border-radius: 20px;
    max-height: 90vh;
  }
}

@media (max-width: 768px) {
  .admin-toolbar.collapsed,
  .wat-toolbar.collapsed {
    transform: translateY(calc(100% - 44px));
  }
  body.wat-toolbar-visible.wat-toolbar-collapsed {
    padding-bottom: 56px;
  }
}

/* Small phones */
@media (max-width: 360px) {
  .wat-save-mobile { font-size: 15px !important; }
  .wat-badge { font-size: 13px; padding: 8px 10px; }
}
