/* FBA Cohort Lens — cohort-site widget chrome */

.fba-lens-fab-label--short {
  display: none;
}

.fba-lens-fab {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  z-index: 2147483646;
  background: #c4922e;
  color: #1a1510;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  min-height: 44px;
  font: 600 14px/1.2 "Segoe UI", system-ui, -apple-system, sans-serif;
  box-shadow: 0 6px 24px rgba(26, 21, 16, 0.22);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.fba-lens-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(26, 21, 16, 0.28);
}

.fba-lens-panel {
  position: fixed;
  bottom: max(80px, calc(16px + env(safe-area-inset-bottom, 0px)));
  right: max(16px, env(safe-area-inset-right, 0px));
  width: min(400px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 120px));
  min-width: 280px;
  min-height: 320px;
  max-width: min(92vw, 720px);
  max-height: min(88dvh, 900px);
  z-index: 2147483647;
  display: none;
  flex-direction: column;
  background: #faf7f0;
  color: #1a1510;
  border: 1px solid #d8cfc0;
  border-radius: 16px;
  box-shadow: 0 18px 56px rgba(26, 21, 16, 0.2);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  resize: both;
  box-sizing: border-box;
}

.fba-lens-panel.is-open {
  display: flex;
}

.fba-lens-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #e8dfd0;
  background: linear-gradient(180deg, #f5efe4 0%, #faf7f0 100%);
  flex-shrink: 0;
  cursor: default;
  user-select: none;
}

.fba-lens-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.fba-lens-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.fba-lens-size-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.fba-lens-expand-btn {
  display: none;
}

.fba-lens-icon-btn {
  border: 1px solid #d8cfc0;
  background: #fff;
  color: #4a4035;
  border-radius: 8px;
  min-width: 36px;
  min-height: 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.fba-lens-icon-btn:hover {
  background: #f0ebe1;
  border-color: #c4922e;
}

.fba-lens-icon-btn[aria-pressed="true"] {
  background: #d4a74a;
  border-color: #b8892a;
  color: #1a1510;
}

.fba-lens-log {
  flex: 1;
  overflow: auto;
  overflow-x: hidden;
  padding: 14px;
  background: #f3ede3;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  min-height: 0;
}

.fba-lens-msg {
  position: relative;
  margin-bottom: 12px;
  padding: 10px 12px;
  padding-right: 36px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 92%;
  animation: fba-lens-fade-in 0.2s ease;
}

@keyframes fba-lens-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.fba-lens-msg--user {
  margin-left: auto;
  background: #1a1510;
  color: #f0ebe1;
  border-bottom-right-radius: 4px;
}

.fba-lens-msg--sys {
  background: #e8dfd0;
  color: #4a4035;
  font-size: 13px;
  max-width: 100%;
}

.fba-lens-msg--lens {
  background: #fff;
  border: 1px solid #e0d6c8;
  border-bottom-left-radius: 4px;
}

.fba-lens-msg--loading {
  color: #7a6f62;
  font-style: italic;
}

.fba-lens-msg-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  border: 0;
  background: rgba(255, 255, 255, 0.85);
  color: #4a4035;
  border-radius: 6px;
  min-width: 36px;
  min-height: 36px;
  width: 36px;
  height: 36px;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.12s ease, background 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.fba-lens-msg--user .fba-lens-msg-copy {
  background: rgba(255, 255, 255, 0.15);
  color: #f0ebe1;
}

.fba-lens-msg:hover .fba-lens-msg-copy,
.fba-lens-msg-copy:focus {
  opacity: 1;
}

.fba-lens-msg-copy:hover {
  background: #d4a74a;
  color: #1a1510;
}

.fba-lens-citations {
  margin-top: 8px;
  font-size: 11px;
  color: #7a6f62;
  line-height: 1.4;
}

.fba-lens-find-row {
  padding: 8px 0;
  border-bottom: 1px solid #eee6d8;
}

.fba-lens-find-row:last-child {
  border-bottom: 0;
}

.fba-lens-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e8dfd0;
  background: #faf7f0;
  flex-shrink: 0;
}

.fba-lens-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #d8cfc0;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  font: inherit;
  background: #fff;
  color: #1a1510;
}

.fba-lens-input:focus {
  outline: 2px solid #d4a74a;
  outline-offset: 1px;
  border-color: #c4922e;
}

.fba-lens-send {
  background: #1a1510;
  color: #f0ebe1;
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  min-height: 44px;
  min-width: 64px;
  font: 600 13px/1 inherit;
  cursor: pointer;
  transition: background 0.12s ease;
  flex-shrink: 0;
}

.fba-lens-send:hover {
  background: #3d3428;
}

.fba-lens-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 10px;
  border-top: 1px solid #e8dfd0;
  background: #faf7f0;
  flex-shrink: 0;
}

.fba-lens-chip {
  background: #fff;
  border: 1px solid #d8cfc0;
  color: #1a1510;
  border-radius: 999px;
  padding: 10px 14px;
  min-height: 40px;
  font: 500 12px/1.3 inherit;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.fba-lens-chip:hover {
  background: #f0ebe1;
  border-color: #c4922e;
}

.fba-lens-resize-hint {
  position: absolute;
  bottom: 4px;
  right: 8px;
  font-size: 10px;
  color: #a89888;
  pointer-events: none;
  opacity: 0.7;
}

/* In-panel modal (replaces window.prompt) */
.fba-lens-modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(26, 21, 16, 0.45);
  backdrop-filter: blur(2px);
}

.fba-lens-modal.is-visible {
  display: flex;
}

.fba-lens-modal-card {
  width: 100%;
  max-width: 340px;
  background: #fff;
  border: 1px solid #d8cfc0;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 12px 40px rgba(26, 21, 16, 0.2);
}

.fba-lens-modal-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
}

.fba-lens-modal-desc {
  margin: 0 0 12px;
  font-size: 13px;
  color: #5c5248;
  line-height: 1.45;
}

.fba-lens-modal-field {
  margin-bottom: 10px;
}

.fba-lens-modal-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #4a4035;
  margin-bottom: 4px;
}

.fba-lens-modal-field input,
.fba-lens-modal-field textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d8cfc0;
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  background: #faf7f0;
}

.fba-lens-modal-field textarea {
  min-height: 72px;
  resize: vertical;
}

.fba-lens-modal-field input:focus,
.fba-lens-modal-field textarea:focus {
  outline: 2px solid #d4a74a;
  outline-offset: 0;
}

.fba-lens-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.fba-lens-modal-cancel {
  background: transparent;
  border: 1px solid #d8cfc0;
  color: #4a4035;
  border-radius: 8px;
  padding: 8px 14px;
  font: 500 13px inherit;
  cursor: pointer;
}

.fba-lens-modal-submit {
  background: #c4922e;
  border: 0;
  color: #1a1510;
  border-radius: 8px;
  padding: 8px 16px;
  font: 600 13px inherit;
  cursor: pointer;
}

.fba-lens-modal-submit:hover {
  background: #d4a74a;
}

.fba-lens-modal-cancel,
.fba-lens-modal-submit {
  min-height: 44px;
  padding: 10px 16px;
}

/* Scroll lock while full-screen chat is open (mobile) */
html.fba-lens-open,
body.fba-lens-open {
  overflow: hidden;
  touch-action: none;
}

body.fba-lens-open .fba-lens-panel.is-open {
  touch-action: auto;
}

/* Touch devices: copy always visible */
@media (hover: none), (pointer: coarse) {
  .fba-lens-msg-copy {
    opacity: 0.85;
  }
}

/* Small laptops / short viewports */
@media (max-width: 1100px), (max-height: 720px) {
  .fba-lens-panel.is-compact:not(.is-sheet) {
    resize: none;
    width: min(380px, calc(100vw - 24px)) !important;
    height: min(520px, calc(100dvh - 88px)) !important;
    max-height: calc(100dvh - 72px);
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
  }

  .fba-lens-panel.is-compact.is-expanded:not(.is-sheet) {
    width: min(520px, calc(100vw - 20px)) !important;
    height: min(640px, calc(100dvh - 48px)) !important;
    max-height: calc(100dvh - 40px);
  }

  .fba-lens-size-group {
    display: none;
  }

  .fba-lens-expand-btn {
    display: inline-flex;
  }

  .fba-lens-resize-hint {
    display: none;
  }

  .fba-lens-title {
    font-size: 14px;
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Tablets / large phones landscape */
@media (max-width: 900px) {
  .fba-lens-panel:not(.is-sheet) {
    width: min(360px, calc(100vw - 20px)) !important;
  }

  .fba-lens-actions {
    gap: 8px;
    max-height: 120px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Mobile: full-screen sheet */
@media (max-width: 640px) {
  .fba-lens-fab-label--long {
    display: none;
  }

  .fba-lens-fab-label--short {
    display: inline;
  }

  .fba-lens-fab {
    padding: 12px 16px;
    font-size: 13px;
  }

  .fba-lens-panel.is-sheet {
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    max-height: none;
    min-width: 0;
    min-height: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    resize: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .fba-lens-panel.is-sheet .fba-lens-header {
    padding-top: max(12px, env(safe-area-inset-top, 0px));
  }

  .fba-lens-panel.is-sheet.is-open ~ .fba-lens-fab,
  body.fba-lens-open .fba-lens-fab {
    display: none;
  }

  .fba-lens-title {
    max-width: none;
    font-size: 15px;
  }

  .fba-lens-header {
    padding: 10px 12px;
  }

  .fba-lens-log {
    padding: 12px;
  }

  .fba-lens-msg {
    max-width: 95%;
    padding-right: 40px;
  }

  .fba-lens-form {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px max(12px, env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .fba-lens-send {
    width: 100%;
    min-height: 48px;
    font-size: 15px;
  }

  .fba-lens-input {
    font-size: 16px;
  }

  .fba-lens-actions {
    padding: 8px 12px;
    max-height: 140px;
  }

  .fba-lens-chip {
    flex: 1 1 calc(50% - 4px);
    text-align: center;
    min-width: calc(50% - 8px);
  }

  .fba-lens-modal {
    padding: 12px;
    align-items: flex-end;
  }

  .fba-lens-modal-card {
    max-width: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    max-height: 90dvh;
    overflow-y: auto;
  }

  .fba-lens-modal-actions {
    flex-direction: column-reverse;
  }

  .fba-lens-modal-cancel,
  .fba-lens-modal-submit {
    width: 100%;
    min-height: 48px;
  }

  .fba-lens-resize-hint {
    display: none;
  }
}

/* Very narrow phones */
@media (max-width: 380px) {
  .fba-lens-chip {
    flex: 1 1 100%;
    min-width: 100%;
  }
}
