/* Beava assistant widget
   z-index: FAB=100, panel=150. Toast is 80, auth modal is 1000. */

.bva-assistant {
  --bva-footer-offset: 0px;
  font-family: var(--font-ui);
}

/* Ensure [hidden] wins over display: flex/grid on any descendant. */
.bva-assistant [hidden],
.bva-panel[hidden] { display: none !important; }

.bva-fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--bva-footer-offset));
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: var(--grad-accent);
  color: var(--c-white);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: grid;
  place-items: center;
  transition: transform 0.22s ease, box-shadow 0.22s ease, bottom 0.22s ease;
}
.bva-fab:hover { transform: translateY(-2px); }
.bva-fab:focus-visible { outline: 3px solid var(--stroke-accent); outline-offset: 2px; }
.bva-fab-icon { color: var(--c-white); }

.bva-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--c-error);
  color: var(--c-white);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.bva-panel {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--bva-footer-offset));
  width: 380px;
  height: min(620px, 80vh);
  max-height: calc(100vh - 40px - var(--bva-footer-offset));
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--stroke);
  border-radius: var(--radius2);
  box-shadow: var(--shadow-lg);
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: bvaSlideIn 0.22s ease;
  transition: bottom 0.22s ease;
}

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

body.bva-open .bva-fab { display: none; }

.bva-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--stroke);
  background: var(--glass-75);
}
.bva-panel-title {
  flex: 1;
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.bva-panel-back,
.bva-panel-close {
  border: 1px solid var(--stroke);
  background: var(--glass);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--ink);
}
.bva-panel-back:hover,
.bva-panel-close:hover { background: var(--glass-hover); }

.bva-panel-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--stroke);
  overflow-x: auto;
  scrollbar-width: none;
}
.bva-panel-tabs::-webkit-scrollbar { display: none; }
.bva-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.bva-tab:hover { background: var(--glass-hover); }
.bva-tab.is-active {
  background: var(--c-espresso);
  color: var(--c-white);
  border-color: var(--c-espresso);
}

.bva-panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}

.bva-loading,
.bva-empty,
.bva-error {
  padding: 20px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.bva-error { color: var(--c-error); }

.bva-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Chat list */
.bva-conv-list { gap: 2px; }
.bva-conv {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.bva-conv:hover { background: var(--glass-hover); }
.bva-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--c-cream);
}
.bva-avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--c-espresso);
  font-weight: 700;
  font-size: 14px;
}
.bva-conv-main { flex: 1; min-width: 0; }
.bva-conv-row1, .bva-conv-row2 {
  display: flex;
  align-items: center;
  gap: 6px;
}
.bva-conv-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bva-conv-when {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}
.bva-conv-preview {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bva-unread {
  background: var(--c-error);
  color: var(--c-white);
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Thread host inside panel */
.bva-thread-host,
.bva-thread {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.bva-thread-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 10px 0;
}
.bva-thread-list .chat-message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}
.bva-thread-list .chat-message.me { align-self: flex-end; align-items: flex-end; }
.bva-thread-list .chat-message.them { align-self: flex-start; align-items: flex-start; }
.bva-thread-list .message-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
  word-wrap: break-word;
}
.bva-thread-list .chat-message.me .message-bubble {
  background: var(--c-espresso);
  color: var(--c-white);
  border-bottom-right-radius: 4px;
}
.bva-thread-list .chat-message.them .message-bubble {
  background: var(--c-white);
  color: var(--ink);
  border: 1px solid var(--stroke);
  border-bottom-left-radius: 4px;
}
.bva-thread-list .message-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}
.bva-thread-list .chat-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 30px 12px;
}

.bva-thread-compose {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--stroke);
}
.bva-thread-input {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  resize: none;
  padding: 8px 10px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--glass);
  font-size: 13px;
  color: var(--ink);
  outline: none;
  font-family: inherit;
}
.bva-thread-input:focus {
  border-color: var(--c-caramel);
  box-shadow: 0 0 0 3px var(--stroke-accent);
}
.bva-thread-send {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

/* Schedule */
.bva-sched-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  margin: 6px 0 8px;
  color: var(--ink);
}
.bva-sched-item {
  padding: 10px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--card);
  margin-bottom: 6px;
}
.bva-sched-when {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.bva-sched-who {
  font-size: 12px;
  color: var(--muted);
}
.bva-sched-links {
  margin-top: 12px;
  text-align: center;
}
.bva-link-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--glass);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.bva-link-btn:hover { background: var(--glass-hover); }

/* Task items (jobs/orders/requests) */
.bva-task-item {
  padding: 10px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  margin-bottom: 6px;
  transition: background 0.15s ease;
}
.bva-task-item:hover { background: var(--glass-hover); }
.bva-task-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.bva-task-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.bva-task-status {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  flex-shrink: 0;
}
.bva-task-who {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* Mobile: fullscreen panel */
@media (max-width: 780px) {
  .bva-panel {
    right: 0;
    bottom: 0;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  body.bva-open { overflow: hidden; }
  .bva-fab {
    right: 16px;
    bottom: calc(16px + var(--bva-footer-offset));
  }
}

@media (prefers-reduced-motion: reduce) {
  .bva-panel { animation: none; }
  .bva-fab { transition: none; }
}
