/**
 * assets/css/erp-dock.css
 * JungFoodKorea ERP Bottom-Right Persistent 3-Item Dock Stylesheet
 *
 * Implements tg-9521 & tg-9523
 * - 📥 입력 창 바구니 (Input Tray)
 * - 🔍 조회 창 바구니 (View Tray)
 * - ✨ AI 입력 버튼 (Agentic Vibe Input Launcher)
 * - Widget conflict mitigations (toasts, fb button, duplicate AI button)
 */

/* ── 1. Dock Container ── */
.erp-dock {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
  position: relative;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
}

/* ── 2. Dock Buttons ── */
.erp-dock-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border, #2a3648);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text, #e7ebf2);
  transition: all 0.15s ease-in-out;
  box-sizing: border-box;
  white-space: nowrap;
}

.erp-dock-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.erp-dock-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.erp-dock-btn[aria-expanded="true"] {
  background: rgba(37, 99, 235, 0.2);
  border-color: #2563eb;
  color: #93c5fd;
}

.erp-dock-icon {
  font-size: 13px;
  line-height: 1;
  display: inline-block;
}

.erp-dock-label {
  font-size: 12px;
  line-height: 1;
}

/* ── 3. Dock Badges & Unsaved Indicator ── */
.erp-dock-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  font-size: 10.5px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-muted, #94a3b8);
  box-sizing: border-box;
  line-height: 1;
}

.erp-dock-badge.has-count {
  background: #2563eb;
  color: #ffffff;
}

.erp-dock-unsaved-dot {
  color: #f97316;
  font-size: 11px;
  line-height: 1;
  margin-left: 1px;
  text-shadow: 0 0 6px rgba(249, 115, 22, 0.7);
  display: none;
}

/* ── 4. AI Input Launcher Button ── */
.erp-dock-btn-ai {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.18), rgba(168, 85, 247, 0.18));
  border-color: rgba(168, 85, 247, 0.45);
  color: #c084fc;
}

.erp-dock-btn-ai:hover {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.32), rgba(168, 85, 247, 0.32));
  border-color: #a855f7;
  color: #f3e8ff;
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.3);
}

/* ── 5. Popover Trays ── */
.erp-dock-tray {
  position: absolute;
  bottom: 42px;
  right: 0;
  width: 320px;
  max-height: 380px;
  background: var(--surface, #16202e);
  border: 1px solid var(--border, #2a3648);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  z-index: 920;
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.erp-dock-tray.is-open {
  display: flex;
  animation: erpDockTrayFadeIn 0.15s ease-out forwards;
}

@keyframes erpDockTrayFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.erp-dock-tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border, #2a3648);
  background: rgba(0, 0, 0, 0.15);
}

.erp-dock-tray-header-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text, #e7ebf2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.erp-dock-tray-header-count {
  font-size: 11.5px;
  color: var(--text-muted, #94a3b8);
  font-weight: 500;
}

.erp-dock-tray-close-btn {
  background: none;
  border: none;
  color: var(--text-muted, #94a3b8);
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.erp-dock-tray-close-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.erp-dock-tray-list {
  padding: 6px;
  overflow-y: auto;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.erp-dock-tray-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted, #94a3b8);
}

.erp-dock-tray-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.erp-dock-tray-row:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

.erp-dock-tray-row:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: -1px;
}

.erp-dock-tray-row.is-active {
  background: rgba(37, 99, 235, 0.15);
  border-color: rgba(37, 99, 235, 0.4);
}

.erp-dock-tray-row.is-minimized {
  opacity: 0.72;
}

.erp-dock-tray-left {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex: 1;
}

.erp-dock-tray-title {
  font-size: 12px;
  color: var(--text, #e7ebf2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.erp-dock-tray-dirty-dot {
  color: #f97316;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.erp-dock-tray-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 6px;
}

.erp-dock-tray-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
}

.erp-dock-tray-badge.badge-active {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}

.erp-dock-tray-badge.badge-minimized {
  background: rgba(148, 163, 184, 0.2);
  color: #94a3b8;
}

.erp-dock-tray-badge.badge-visible {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.erp-dock-tray-item-close {
  background: none;
  border: none;
  color: var(--text-muted, #94a3b8);
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.erp-dock-tray-item-close:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

/* ── 6. Light Theme Support ── */
[data-theme="light"] .erp-dock-btn {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #1e293b;
}

[data-theme="light"] .erp-dock-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

[data-theme="light"] .erp-dock-btn[aria-expanded="true"] {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #1d4ed8;
}

[data-theme="light"] .erp-dock-badge {
  background: #e2e8f0;
  color: #64748b;
}

[data-theme="light"] .erp-dock-badge.has-count {
  background: #2563eb;
  color: #ffffff;
}

[data-theme="light"] .erp-dock-btn-ai {
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.7), rgba(243, 232, 255, 0.7));
  border-color: #c084fc;
  color: #7e22ce;
}

[data-theme="light"] .erp-dock-btn-ai:hover {
  background: linear-gradient(135deg, rgba(191, 219, 254, 0.9), rgba(233, 213, 255, 0.9));
  border-color: #a855f7;
  color: #581c87;
}

[data-theme="light"] .erp-dock-tray {
  background: #ffffff;
  border-color: #cbd5e1;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .erp-dock-tray-header {
  background: #f8fafc;
  border-bottom-color: #e2e8f0;
}

[data-theme="light"] .erp-dock-tray-header-title {
  color: #0f172a;
}

[data-theme="light"] .erp-dock-tray-row {
  background: #f8fafc;
}

[data-theme="light"] .erp-dock-tray-row:hover {
  background: #f1f5f9;
}

[data-theme="light"] .erp-dock-tray-row.is-active {
  background: #eff6ff;
  border-color: #bfdbfe;
}

[data-theme="light"] .erp-dock-tray-title {
  color: #1e293b;
}

/* ── 7. Widget Overlap & Collision Mitigations (PLAN.md §2.2) ── */

/* 7.1 Hide duplicate legacy floating AI chat button (unified into ✨ AI 입력 button) */
#erp-ai-btn {
  display: none !important;
}

/* 7.2 Toast notifications: offset bottom to 54px to clear taskbar & dock, z-index 950 */
.toast {
  bottom: 54px !important;
  z-index: 950 !important;
}

/* 7.3 Feedback floating button: offset above dock */
#fb-float-btn {
  bottom: 54px !important;
}

/* 7.4 Login screen protection: hide entire taskbar and dock */
#login-screen:not(.hidden) ~ .erp-window-taskbar,
body:has(#login-screen:not(.hidden)) .erp-window-taskbar,
#login-screen:not(.hidden) ~ #erp-window-taskbar,
body:has(#login-screen:not(.hidden)) #erp-window-taskbar {
  display: none !important;
}

/* ── 8. Mobile & Narrow Viewport Responsive (max-width: 768px, specifically 390px) ── */
@media (max-width: 768px) {
  .erp-dock {
    gap: 4px;
  }

  .erp-dock-btn {
    height: 28px;
    padding: 0 6px;
    font-size: 11px;
    gap: 4px;
  }

  .erp-dock-label {
    font-size: 11px;
  }

  .erp-dock-tray {
    width: calc(100vw - 16px);
    max-width: 340px;
    right: 0;
    bottom: 46px;
  }

  .erp-dock-tray-title {
    max-width: 140px;
  }

  #fb-float-btn {
    bottom: 54px !important;
  }
}
