/* ═══════════════════════════════════════════════════════
   SAFO — Category Picker CSS
   Bottom Sheet (mobile) / Modal (desktop)
   RTL-first, namespaced .safo-cp-*
   ═══════════════════════════════════════════════════════ */

/* ── Overlay ──────────────────────────────────────────── */
.safo-cp-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.safo-cp-overlay.safo-cp-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Backdrop ─────────────────────────────────────────── */
.safo-cp-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ── Sheet ────────────────────────────────────────────── */
.safo-cp-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  background: #fff;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
}
.safo-cp-open .safo-cp-sheet {
  transform: translateY(0);
}

/* Desktop: center modal instead of bottom sheet */
@media (min-width: 769px) {
  .safo-cp-overlay {
    align-items: center;
  }
  .safo-cp-sheet {
    max-height: 70vh;
    border-radius: 20px;
    transform: translateY(30px) scale(0.95);
    opacity: 0;
  }
  .safo-cp-open .safo-cp-sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* ── Handle (mobile drag indicator) ───────────────────── */
.safo-cp-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
}
.safo-cp-handle-bar {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: #D1D5DB;
}

/* ── Header ───────────────────────────────────────────── */
.safo-cp-header {
  padding: 0 20px 16px;
  border-bottom: 1px solid #F3F4F6;
  flex-shrink: 0;
}
.safo-cp-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.safo-cp-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
  color: #111827;
  margin: 0;
}
.safo-cp-back-btn,
.safo-cp-close-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: #F3F4F6;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6B7280;
  transition: all 0.2s;
}
.safo-cp-back-btn:hover,
.safo-cp-close-btn:hover {
  background: #E5E7EB;
  color: #111827;
}

/* ── Breadcrumb ───────────────────────────────────────── */
.safo-cp-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
}
.safo-cp-bc-item {
  color: #6B7280;
  cursor: pointer;
  transition: color 0.2s;
}
.safo-cp-bc-item:hover {
  color: #49B47B;
}
.safo-cp-bc-item.active {
  color: #111827;
  font-weight: 600;
  cursor: default;
}
.safo-cp-bc-sep {
  color: #D1D5DB;
}

/* ── Search ───────────────────────────────────────────── */
.safo-cp-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #F9FAFB;
  border: 1px solid #E5E7EB;
  border-radius: 12px;
  padding: 0 12px;
  transition: all 0.2s;
}
.safo-cp-search-wrap:focus-within {
  border-color: #49B47B;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(73, 180, 123, 0.1);
}
.safo-cp-search-wrap svg {
  flex-shrink: 0;
  color: #9CA3AF;
}
.safo-cp-search {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 0;
  font-size: 14px;
  outline: none;
  color: #111827;
}
.safo-cp-search::placeholder {
  color: #9CA3AF;
}
.safo-cp-search-clear {
  width: 24px;
  height: 24px;
  border: none;
  background: #E5E7EB;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6B7280;
  transition: all 0.2s;
}
.safo-cp-search-clear:hover {
  background: #D1D5DB;
}

/* ── Content ──────────────────────────────────────────── */
.safo-cp-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}

/* ── Grid (main categories) — DEPRECATED, kept for fallback ── */
.safo-cp-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 480px) {
  .safo-cp-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ── Category Cards (main + sub — unified design) ──── */
.safo-cp-cats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.safo-cp-cat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #F9FAFB;
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}
.safo-cp-cat-card:hover {
  background: #F0FDF4;
  border-color: #BBF7D0;
  transform: translateX(-2px);
}
.safo-cp-cat-card:active {
  transform: scale(0.98);
}
.safo-cp-cat-card.selected {
  background: #F0FDF4;
  border-color: #49B47B;
  box-shadow: 0 0 0 3px rgba(73, 180, 123, 0.12);
}
.safo-cp-cat-emoji {
  font-size: 1.8rem;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.safo-cp-cat-card.selected .safo-cp-cat-emoji {
  background: #E8F5EE;
}
.safo-cp-cat-info {
  flex: 1;
  min-width: 0;
}
.safo-cp-cat-name {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  line-height: 1.3;
}
.safo-cp-cat-count {
  font-size: 12px;
  color: #9CA3AF;
  margin-top: 2px;
}
.safo-cp-cat-arrow {
  flex-shrink: 0;
  color: #D1D5DB;
  display: flex;
  align-items: center;
  transition: color 0.2s, transform 0.2s;
}
.safo-cp-cat-card:hover .safo-cp-cat-arrow {
  color: #49B47B;
  transform: translateX(-3px);
}
.safo-cp-cat-check {
  width: 24px;
  height: 24px;
  background: #49B47B;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  animation: safo-cp-checkPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Dark mode cards */
.dark-mode .safo-cp-cat-card {
  background: #374151;
}
.dark-mode .safo-cp-cat-card:hover {
  background: #064E3B;
  border-color: #059669;
}
.dark-mode .safo-cp-cat-card.selected {
  background: #064E3B;
  border-color: #49B47B;
}
.dark-mode .safo-cp-cat-emoji {
  background: #1F2937;
}
.dark-mode .safo-cp-cat-card.selected .safo-cp-cat-emoji {
  background: #064E3B;
}
.dark-mode .safo-cp-cat-name {
  color: #F9FAFB;
}

/* ── Card ─────────────────────────────────────────────── */
.safo-cp-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px 12px;
  background: #F9FAFB;
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
}
.safo-cp-card:hover {
  background: #F0FDF4;
  border-color: #BBF7D0;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(73, 180, 123, 0.1);
}
.safo-cp-card.selected {
  background: #F0FDF4;
  border-color: #49B47B;
  box-shadow: 0 0 0 3px rgba(73, 180, 123, 0.15);
}
.safo-cp-card.selected .safo-cp-card-emoji {
  transform: scale(1.1);
}

.safo-cp-card-emoji {
  font-size: 2rem;
  line-height: 1;
  transition: transform 0.2s;
}
.safo-cp-card-name {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.safo-cp-card-count {
  font-size: 11px;
  color: #9CA3AF;
}
.safo-cp-card-arrow {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #D1D5DB;
  transition: color 0.2s;
}
.safo-cp-card:hover .safo-cp-card-arrow {
  color: #49B47B;
}
.safo-cp-card-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  background: #49B47B;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  animation: safo-cp-checkPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── List (subcategories) ─────────────────────────────── */
.safo-cp-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.safo-cp-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #F9FAFB;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.safo-cp-list-item:hover {
  background: #F0FDF4;
  border-color: #BBF7D0;
}
.safo-cp-list-item.selected {
  background: #F0FDF4;
  border-color: #49B47B;
  box-shadow: 0 0 0 3px rgba(73, 180, 123, 0.12);
}
.safo-cp-list-emoji {
  font-size: 1.5rem;
  flex-shrink: 0;
}
.safo-cp-list-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}
.safo-cp-list-check {
  width: 24px;
  height: 24px;
  background: #49B47B;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  animation: safo-cp-checkPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Empty State ──────────────────────────────────────── */
.safo-cp-empty {
  text-align: center;
  padding: 40px 20px;
  color: #6B7280;
}
.safo-cp-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}
.safo-cp-empty p {
  margin: 0 0 16px;
  font-size: 14px;
}

/* ── No Subcategories State ───────────────────────────── */
.safo-cp-no-subs {
  text-align: center;
  padding: 32px 20px;
}
.safo-cp-no-subs-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}
.safo-cp-no-subs h4 {
  font-size: 18px;
  font-weight: 700;
  color: #111827;
  margin: 0 0 6px;
}
.safo-cp-no-subs p {
  font-size: 14px;
  color: #6B7280;
  margin: 0 0 4px;
}
.safo-cp-no-subs-hint {
  font-size: 13px;
  color: #9CA3AF;
  margin-bottom: 16px !important;
}

/* ── Footer ───────────────────────────────────────────── */

/* ── Footer ───────────────────────────────────────────── */
.safo-cp-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid #F3F4F6;
  background: #fff;
  flex-shrink: 0;
}
.safo-cp-selected-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #111827;
}
.safo-cp-check-icon {
  width: 22px;
  height: 22px;
  background: #49B47B;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ── Animations ───────────────────────────────────────── */
@keyframes safo-cp-checkPop {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

/* ── RTL Adjustments ──────────────────────────────────── */
[dir="rtl"] .safo-cp-card-arrow {
  left: auto;
  right: 10px;
  transform: translateY(-50%) scaleX(-1);
}
[dir="rtl"] .safo-cp-card-check {
  right: auto;
  left: 6px;
}

/* ── Dark Mode Support ────────────────────────────────── */
.dark-mode .safo-cp-sheet {
  background: #1F2937;
}
.dark-mode .safo-cp-header {
  border-color: #374151;
}
.dark-mode .safo-cp-title {
  color: #F9FAFB;
}
.dark-mode .safo-cp-card {
  background: #374151;
}
.dark-mode .safo-cp-card:hover {
  background: #064E3B;
  border-color: #059669;
}
.dark-mode .safo-cp-card.selected {
  background: #064E3B;
  border-color: #49B47B;
}
.dark-mode .safo-cp-card-name {
  color: #F9FAFB;
}
.dark-mode .safo-cp-list-item {
  background: #374151;
}
.dark-mode .safo-cp-list-item:hover {
  background: #064E3B;
}
.dark-mode .safo-cp-list-item.selected {
  background: #064E3B;
  border-color: #49B47B;
}
.dark-mode .safo-cp-list-name {
  color: #F9FAFB;
}
.dark-mode .safo-cp-search-wrap {
  background: #374151;
  border-color: #4B5563;
}
.dark-mode .safo-cp-search-wrap:focus-within {
  background: #1F2937;
  border-color: #49B47B;
}
.dark-mode .safo-cp-search {
  color: #F9FAFB;
}
.dark-mode .safo-cp-footer {
  background: #1F2937;
  border-color: #374151;
}
.dark-mode .safo-cp-selected-summary {
  color: #F9FAFB;
}
.dark-mode .safo-cp-empty {
  color: #9CA3AF;
}
