/* ═══════════════════════════════════════════════════════════════════
   Avatar Panel + Settings Styles
   ═══════════════════════════════════════════════════════════════════ */

/* ── Hub Layout: Two-panel when Avatar panel is present ── */
.hub-main--with-avatar {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .hub-main--with-avatar {
    grid-template-columns: 1fr;
  }
}

.hub-companies-column {
  min-width: 0;
}

/* ── Avatar Panel ── */
.avatar-panel {
  background: rgba(15, 15, 25, 0.85);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  height: 600px;
  overflow: hidden;
  backdrop-filter: blur(20px);
  position: sticky;
  top: 24px;
}

/* Drag handle — only visible in mobile drawer mode */
.avatar-panel-handle {
  display: none;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.25);
  margin: 8px auto 4px;
  flex-shrink: 0;
  cursor: grab;
}

/* Backdrop for mobile drawer */
.avatar-panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-drawer-backdrop);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.avatar-panel-backdrop--open { opacity: 1; }

.avatar-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(139, 92, 246, 0.15);
}

.avatar-panel-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-panel-icon {
  font-size: 20px;
  color: #a78bfa;
  text-shadow: 0 0 8px rgba(139, 92, 246, 0.5);
}

.avatar-panel-name-block {
  display: flex;
  flex-direction: column;
}

.avatar-panel-name {
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
}

.avatar-panel-status {
  font-size: 11px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 5px;
}

.avatar-panel-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a78bfa;
  box-shadow: 0 0 6px rgba(139, 92, 246, 0.6);
  animation: avatar-pulse 2s ease-in-out infinite;
}

@keyframes avatar-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.avatar-panel-settings-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.avatar-panel-settings-btn:hover {
  background: rgba(139, 92, 246, 0.1);
  color: #a78bfa;
}

/* ── Messages Area ── */
.avatar-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Make scrollbar visible (not always-on auto-hide) so users know the
     panel scrolls. Kept thin to not look heavy. */
  scrollbar-width: thin;
  scrollbar-color: rgba(167, 139, 250, 0.3) transparent;
  scroll-behavior: smooth;
  /* Subtle bottom fade to hint there's more content below the fold */
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 24px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 24px), transparent 100%);
}
.avatar-panel-messages::-webkit-scrollbar { width: 5px; }
.avatar-panel-messages::-webkit-scrollbar-thumb {
  background: rgba(167, 139, 250, 0.35);
  border-radius: 4px;
}

.avatar-msg {
  max-width: 90%;
  animation: avatar-msg-in 0.3s ease-out;
}

@keyframes avatar-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar-msg--assistant {
  align-self: flex-start;
}

.avatar-msg--user {
  align-self: flex-end;
}

.avatar-msg-content {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.avatar-msg--assistant .avatar-msg-content {
  background: rgba(30, 30, 50, 0.8);
  color: #e2e8f0;
  border: 1px solid rgba(139, 92, 246, 0.1);
}

.avatar-msg--user .avatar-msg-content {
  background: rgba(139, 92, 246, 0.15);
  color: #e2e8f0;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

/* ── Briefing Card ── */
.avatar-briefing-greeting {
  font-weight: 600;
  margin-bottom: 8px;
  color: #f1f5f9;
}

.avatar-briefing-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
}

.avatar-briefing-item {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(15, 15, 25, 0.6);
  border-left: 3px solid #64748b;
}

.avatar-item--high { border-left-color: #f97316; }
.avatar-item--medium { border-left-color: #eab308; }
.avatar-item--low { border-left-color: #64748b; }

.avatar-item-headline {
  font-weight: 500;
  font-size: 12px;
  color: #f1f5f9;
}

.avatar-item-detail {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

.avatar-item-company {
  display: inline-block;
  font-size: 10px;
  color: #a78bfa;
  margin-top: 4px;
}

.avatar-briefing-actions {
  margin: 8px 0;
  padding: 8px 12px;
  background: rgba(139, 92, 246, 0.05);
  border-radius: 8px;
}

.avatar-actions-label {
  font-size: 11px;
  font-weight: 600;
  color: #a78bfa;
  margin-bottom: 4px;
}

.avatar-action-item {
  font-size: 11px;
  color: #94a3b8;
}

.avatar-briefing-closing {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 8px;
  font-style: italic;
}

/* ── Quick Chips ── */
.avatar-quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}

.avatar-chip {
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 11px;
  color: #c4b5fd;
  cursor: pointer;
  transition: all 0.2s;
}

.avatar-chip:hover {
  background: rgba(139, 92, 246, 0.2);
  border-color: rgba(139, 92, 246, 0.4);
  color: #e9e2ff;
}

/* ── Typing Indicator ── */
.avatar-typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.avatar-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a78bfa;
  animation: avatar-typing-bounce 1.4s ease-in-out infinite;
}

.avatar-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.avatar-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes avatar-typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.avatar-typing-status {
  font-size: 11px;
  color: #a78bfa;
  margin-top: 2px;
  opacity: 0.8;
}

/* ── Data Freshness Indicator ── */
.avatar-data-freshness {
  font-size: 11px;
  color: rgba(52, 211, 153, 0.6);
  padding: 2px 16px 8px;
}

.avatar-data-freshness--warn {
  color: rgba(251, 191, 36, 0.6);
}

/* ── Input Area ── */
.avatar-panel-input-area {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid rgba(139, 92, 246, 0.15);
}

.avatar-panel-input {
  flex: 1;
  background: rgba(15, 15, 25, 0.6);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-radius: 10px;
  padding: 8px 12px;
  color: #e2e8f0;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.avatar-panel-input:focus {
  border-color: rgba(139, 92, 246, 0.4);
}

.avatar-panel-input::placeholder {
  color: #64748b;
}

.avatar-panel-send-btn,
.avatar-panel-mic-btn {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 10px;
  color: #a78bfa;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  transition: all 0.2s;
}

.avatar-panel-send-btn:hover,
.avatar-panel-mic-btn:hover {
  background: rgba(139, 92, 246, 0.25);
}

/* ── Smart Company Card Metrics ── */
.hub-card-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.hub-card-metric-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 10px;
  background: rgba(30, 30, 50, 0.6);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.15);
}

.hub-card-metric-chip--attention {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.2);
  background: rgba(245, 158, 11, 0.05);
}

.hub-card-metric-chip--good {
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.2);
}

.hub-card-metric-chip--warn {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.2);
}

.hub-card-metric-chip--bad {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.2);
}

.hub-card-avatar-line {
  font-size: 10px;
  color: #a78bfa;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.8;
}

/* ── Avatar Settings Page ── */
.avatar-settings-page {
  background: rgba(10, 10, 20, 0.95);
  min-height: 100vh;
  color: #e2e8f0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.avatar-settings-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(139, 92, 246, 0.15);
  background: rgba(15, 15, 25, 0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.avatar-settings-back {
  background: none;
  border: 1px solid rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.avatar-settings-back:hover {
  background: rgba(139, 92, 246, 0.1);
}

.avatar-settings-title-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-settings-icon {
  font-size: 28px;
  color: #a78bfa;
  text-shadow: 0 0 12px rgba(139, 92, 246, 0.5);
}

.avatar-settings-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.avatar-settings-subtitle {
  font-size: 12px;
  color: #94a3b8;
  margin: 0;
}

.avatar-settings-body {
  max-width: 700px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.avatar-settings-section {
  background: rgba(15, 15, 25, 0.6);
  border: 1px solid rgba(139, 92, 246, 0.1);
  border-radius: 16px;
  padding: 20px;
}

.avatar-settings-section-title {
  font-size: 16px;
  font-weight: 600;
  color: #c4b5fd;
  margin: 0 0 16px 0;
}

.avatar-settings-field {
  margin-bottom: 14px;
}

.avatar-settings-field label {
  display: block;
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 6px;
}

.avatar-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.avatar-settings-row label {
  font-size: 13px;
  color: #e2e8f0;
}

.avatar-settings-input {
  background: rgba(10, 10, 20, 0.5);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-radius: 8px;
  padding: 8px 12px;
  color: #e2e8f0;
  font-size: 13px;
  width: 100%;
  outline: none;
}

.avatar-settings-input:focus {
  border-color: rgba(139, 92, 246, 0.4);
}

.avatar-settings-input--small {
  width: 100px;
}

.avatar-channel-status {
  font-size: 11px;
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.5);
}

.avatar-settings-select {
  background: rgba(10, 10, 20, 0.5);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-radius: 8px;
  padding: 6px 10px;
  color: #e2e8f0;
  font-size: 13px;
  outline: none;
}

.avatar-settings-range {
  width: 100%;
  accent-color: #a78bfa;
}

.avatar-settings-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #64748b;
  margin-top: 2px;
}

.avatar-settings-time-range {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #94a3b8;
  font-size: 12px;
}

.avatar-settings-hint {
  font-size: 11px;
  color: #64748b;
  margin: 4px 0 12px 0;
  font-style: italic;
}

.avatar-settings-warning {
  font-size: 11px;
  color: #f59e0b;
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(245, 158, 11, 0.05);
  border: 1px solid rgba(245, 158, 11, 0.15);
  border-radius: 8px;
}

/* ── Toggle Switch ── */
.avatar-settings-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
}

.avatar-settings-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.avatar-toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(100, 116, 139, 0.3);
  border-radius: 20px;
  transition: all 0.2s;
}

.avatar-toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #94a3b8;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}

.avatar-settings-toggle input:checked + .avatar-toggle-slider {
  background: rgba(139, 92, 246, 0.4);
}

.avatar-settings-toggle input:checked + .avatar-toggle-slider::before {
  transform: translateX(16px);
  background: #a78bfa;
}

/* ── Autonomy Grid ── */
.avatar-settings-autonomy-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 600px) {
  .avatar-settings-autonomy-grid {
    grid-template-columns: 1fr;
  }
}

.avatar-autonomy-col h3 {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  margin: 0 0 10px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.avatar-autonomy-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #e2e8f0;
}

.avatar-settings-input-prefix {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #94a3b8;
  font-size: 13px;
}

/* ── Status Grid ── */
.avatar-settings-status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.avatar-status-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  background: rgba(10, 10, 20, 0.4);
  border-radius: 8px;
}

.avatar-status-label {
  font-size: 10px;
  color: #64748b;
  text-transform: uppercase;
}

.avatar-status-value {
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
}

.avatar-settings-actions {
  display: flex;
  gap: 12px;
}

.avatar-test-btn,
.avatar-reset-btn {
  padding: 8px 16px;
  font-size: 12px;
}

.avatar-reset-btn {
  color: #ef4444 !important;
  border-color: rgba(239, 68, 68, 0.2) !important;
}

/* ── Save Footer ── */
.avatar-settings-footer {
  position: sticky;
  bottom: 0;
  padding: 16px 24px;
  background: rgba(15, 15, 25, 0.95);
  border-top: 1px solid rgba(139, 92, 246, 0.15);
  display: flex;
  justify-content: flex-end;
}

.avatar-save-btn {
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  border: none;
  color: white;
  padding: 10px 28px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.avatar-save-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}

/* ── Mobile Avatar Access ── */
.hub-avatar-fab {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
  z-index: 50;
  transition: all 0.2s;
}

.hub-avatar-fab:hover {
  transform: scale(1.05);
}

@media (max-width: 900px) {
  .hub-avatar-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Inset from safe-area on devices with home indicator */
    bottom: calc(20px + var(--safe-bottom, 0px));
    right: calc(20px + var(--safe-right, 0px));
  }

  .avatar-panel-handle { display: block; }
  .avatar-panel-backdrop { display: block; }

  .avatar-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 78vh;
    height: 78dvh;
    max-height: 78dvh;
    border-radius: 20px 20px 0 0;
    z-index: var(--z-drawer);
    transform: translateY(100%);
    transition: transform var(--dur-base) var(--ease-out);
    padding-bottom: var(--safe-bottom, 0px);
    /* Reset desktop sticky positioning */
    position: fixed;
    top: auto;
  }

  .avatar-panel--open {
    transform: translateY(0);
  }

  /* Hide FAB while drawer is open — drag handle is the dismissal */
  .avatar-panel--open ~ .hub-avatar-fab,
  body:has(.avatar-panel--open) .hub-avatar-fab {
    opacity: 0;
    pointer-events: none;
  }
}

/* ── Hub Header Avatar Indicator ── */
.hub-avatar-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.2);
  color: #a78bfa;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.hub-avatar-indicator:hover {
  background: rgba(139, 92, 246, 0.2);
}

.hub-avatar-indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a78bfa;
  box-shadow: 0 0 4px rgba(139, 92, 246, 0.5);
}
