/* @adr [[ADR-CSS]]  */
/* @guide [[chrome-modern-css]]  */

/* css/floating.css */

/* --- 1. GLOBAL POPOVER TOAST (#toast-v4) --- */
#toast-v4 {
  position: fixed;
  top: 24px;
  right: 24px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-sidebar-glass);
  backdrop-filter: var(--glass-blur);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  pointer-events: auto;
  touch-action: pan-x; /* For horizontal swipe-to-dismiss */
  
  /* Flex Layout for Message and Close Button */
  display: flex;
  align-items: center;
  gap: 12px;
  
  /* Initial state (Hidden and slid up) */
  opacity: 0;
  transform: translateY(-20px) translateX(var(--swipe-x, 0px));
  
  /* Modern discrete transition handling exit and entrance */
  transition: 
    opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
    display 0.25s cubic-bezier(0.16, 1, 0.3, 1) allow-discrete,
    overlay 0.25s cubic-bezier(0.16, 1, 0.3, 1) allow-discrete;
}

#toast-v4:popover-open {
  display: flex;
  opacity: calc(1 - (var(--swipe-x-abs, 0) / 150));
  transform: translateY(0) translateX(var(--swipe-x, 0px));
}

@starting-style {
  #toast-v4:popover-open {
    opacity: 0;
    transform: translateY(-20px) translateX(var(--swipe-x, 0px));
  }
}

@starting-style {
  #toast-v4:popover-open {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Stacking Counter Badge */
.toast-badge:empty, .toast-action-btn:empty {
  display: none !important;
}

.toast-badge {
  background: var(--text-primary);
  color: var(--bg-sidebar-glass);
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Action Button */
.toast-action-btn {
  background: var(--border-color);
  color: var(--text-primary);
  border: none;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.toast-action-btn:hover {
  background: var(--text-primary);
  color: var(--bg-sidebar);
}

/* Shake Animation for Updates */
@keyframes shakeToast {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px) translateY(0); }
  50% { transform: translateX(4px) translateY(0); }
  75% { transform: translateX(-4px) translateY(0); }
  100% { transform: translateX(0); }
}

#toast-v4[data-shake="true"] {
  animation: shakeToast 0.3s ease-in-out;
}

#toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

#toast-close:hover {
  color: var(--c-danger);
  background: oklch(50% 0.2 20 / 10%); /* Slight red tint on hover */
}

/* Toast Semantic Border Accents */
#toast-v4.type-success {
  border-left: 4px solid var(--c-success);
}
#toast-v4.type-error {
  border-left: 4px solid var(--c-danger);
}
#toast-v4.type-info {
  border-left: 4px solid var(--c-primary);
}
#toast-v4.type-warning {
  border-left: 4px solid var(--c-warning);
}

/* --- 2. WHATSAPP-STYLE SELECTION TOOLBAR (#format-toolbar) --- */
#selection-anchor {
  anchor-name: --selection-anchor;
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
}

#format-toolbar {
  position: absolute;
  position-anchor: --selection-anchor;
  position-area: top center;
  position-try-options: flip-block;
  margin-bottom: 8px;
  background: var(--bg-sidebar-glass);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  z-index: 8888;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  
  /* Initial transition state */
  opacity: 0;
  transform: scale(0.9) translateY(5px);
  
  /* Modern discrete transition handling exit and entrance */
  transition: 
    opacity 0.15s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.15s cubic-bezier(0.16, 1, 0.3, 1),
    display 0.15s cubic-bezier(0.16, 1, 0.3, 1) allow-discrete,
    overlay 0.15s cubic-bezier(0.16, 1, 0.3, 1) allow-discrete;
}

#format-toolbar:popover-open {
  display: flex;
  opacity: 1;
  transform: scale(1) translateY(0);
}

@starting-style {
  #format-toolbar:popover-open {
    opacity: 0;
    transform: scale(0.9) translateY(5px);
  }
}

/* Buttons inside the toolbar */
#format-toolbar button {
  background: transparent;
  border: none;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease, color 0.1s ease;
}

#format-toolbar button:hover {
  background: var(--border-color);
  color: var(--accent-color);
}

#format-toolbar button[aria-pressed="true"] {
  background: var(--accent-color);
  color: contrast-color(var(--accent-color));
  font-weight: 600;
}

#format-toolbar button b {
  font-weight: 800;
}

#format-toolbar button u {
  text-underline-offset: 2px;
}

/* --- 3. INPUT FLOATING ERROR FEEDBACK --- */
.input-feedback-msg {
  position: absolute;
  top: 102%;
  left: 0;
  background: var(--c-danger);
  color: oklch(100% 0 0); /* OKLCH White */
  padding: 4px 8px;

  border-radius: 6px;
  font-size: 0.725rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

.input-feedback-msg.show {
  opacity: 1;
  transform: translateY(0);
}

.input-feedback-msg.warning {
  background: var(--c-warning);
  color: oklch(15% 0.01 240);
}

.input-feedback-msg.success {
  background: var(--c-success);
}

/* --- 4. ADDRESS SUGGESTIONS POPOVER --- */
#address-suggestions {
  position: absolute;
  position-anchor: --anchor-address-search;
  position-area: bottom span-right;
  position-try-options: flip-block;
  
  margin-top: 4px;
  width: anchor-size(width); /* Same width as input */
  max-height: 250px;
  overflow-y: auto;
  
  background: var(--bg-sidebar-glass);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 9000;
  
  padding: 4px;
  list-style: none;
  
  /* Initial transition state */
  opacity: 0;
  transform: translateY(-5px);
  
  transition: 
    opacity 0.15s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.15s cubic-bezier(0.16, 1, 0.3, 1),
    display 0.15s allow-discrete,
    overlay 0.15s allow-discrete;
}

#address-suggestions:popover-open {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

@starting-style {
  #address-suggestions:popover-open {
    opacity: 0;
    transform: translateY(-5px);
  }
}

/* Styling the individual list items inside the popover */
#address-suggestions li {
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text-primary);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s ease;
  line-height: 1.3;
}

#address-suggestions li:hover {
  background: var(--segment-bg);
}

/* Fuzzy Search Match Highlighting */
#address-suggestions li b {
  color: var(--accent-color);
  font-weight: 700;
}

