/* AI support assistant widget (Phase 5; live WS chat + ticket attachments + status
   badge added 2026-07-12/13 enhancement wave). var(--cf-*)/var(--*) tokens only - R7. */

.cf-support-fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: var(--cf-accent);
  color: var(--cf-on-accent);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-floating);
  z-index: 250;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.cf-support-fab:hover { background: var(--cf-accent-hover); transform: translateY(-1px); }
.cf-support-fab:focus-visible { outline: 2px solid var(--cf-ring); outline-offset: 2px; }
.cf-support-fab-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--cf-error);
  border: 2px solid var(--cf-bg);
}

.cf-support-panel {
  position: fixed;
  right: 20px;
  bottom: 86px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--cf-bg);
  border: 1px solid var(--cf-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-floating);
  z-index: 250;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cf-support-panel[hidden] { display: none; }
.cf-support-scrim { display: none; }   /* desktop: never; the mobile @media turns it on as a sheet backdrop */

.cf-support-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--cf-border-subtle);
  flex-shrink: 0;
}
.cf-support-header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 1;
  min-width: 0;
}
.cf-support-title {
  font-weight: 600;
  font-size: var(--text-body);
  color: var(--cf-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Live WS connection dot - unobtrusive, header-left, next to the title. */
.cf-support-ws-status {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--cf-text-disabled);
  flex-shrink: 0;
}
.cf-support-ws-status[hidden] { display: none; }
.cf-support-ws-status.is-connected { background: var(--cf-success); }
.cf-support-ws-status.is-reconnecting { background: var(--cf-warning); animation: cf-support-pulse 1.1s ease-in-out infinite; }
.cf-support-ws-status.is-disconnected { background: var(--cf-error); }

@keyframes cf-support-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* Ticket status badge - observed from message flow only, no dedicated status endpoint
   (see static/js/support-chat.js). "open" once a ticket exists, "replied" once a
   role='operator' message has been seen; "closed" has no client-observable signal today
   and is deliberately not represented here. */
.cf-support-ticket-badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-helper);
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
}
.cf-support-ticket-badge[hidden] { display: none; }
.cf-support-ticket-badge--open { background: var(--cf-warning-bg); color: var(--cf-warning); }
.cf-support-ticket-badge--replied { background: var(--cf-success-bg); color: var(--cf-success); }

/* Proactive suggestion chips (Phase 4-5, 2026-07-13) - widget-only, empty-conversation-
   only (see static/js/support-chat.js). Empty when unpopulated so it takes no layout
   space; :empty avoids a stray gap from cf-support-messages' flex `gap`. */
.cf-support-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: 0 var(--sp-4) var(--sp-3);
  flex-shrink: 0;
}
.cf-support-suggestions:empty { display: none; }
.cf-support-suggestion-chip {
  font-size: var(--text-helper);
  font-weight: 500;
  color: var(--cf-text-secondary);
  background: var(--cf-surface-hover);
  border: 1px solid var(--cf-border);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  cursor: pointer;
  text-align: left;
}
.cf-support-suggestion-chip:hover { background: var(--cf-accent-subtle); color: var(--cf-accent); border-color: var(--cf-accent); }
.cf-support-suggestion-chip:focus-visible { outline: 2px solid var(--cf-ring); outline-offset: 1px; }

.cf-support-header-actions { display: flex; gap: var(--sp-1); flex-shrink: 0; }
.cf-support-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--cf-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.cf-support-icon-btn:hover { background: var(--cf-surface-hover); color: var(--cf-text); }
.cf-support-icon-btn:focus-visible { outline: 2px solid var(--cf-ring); outline-offset: 1px; }

.cf-support-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.cf-support-intro p {
  font-size: var(--text-body-sm);
  color: var(--cf-text-secondary);
  line-height: 1.5;
  margin: 0;
}

.cf-msg { display: flex; flex-direction: column; max-width: 88%; }
.cf-msg--user { align-self: flex-end; align-items: flex-end; }
.cf-msg--assistant { align-self: flex-start; align-items: flex-start; }
.cf-msg-bubble {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-lg);
  font-size: var(--text-body-sm);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.cf-msg--user .cf-msg-bubble { background: var(--cf-accent); color: var(--cf-on-accent); }
.cf-msg--assistant .cf-msg-bubble { background: var(--cf-surface-sunken); color: var(--cf-text); }

/* Live WS roles (2026-07-12 enhancement wave): 'operator' is the human support reply -
   visually distinct from both the AI assistant and the member's own bubble. 'agent' is
   the member's own live-channel message (wire role from api/_support_ws.py's
   serialize_chat_message) - rendered identically to 'user' since both represent the
   member speaking; kept as its own class rather than reusing .cf-msg--user directly so a
   future outbound-over-WS flow does not need a CSS change. */
.cf-msg--operator { align-self: flex-start; align-items: flex-start; }
.cf-msg--operator .cf-msg-bubble { background: var(--cf-info-bg); color: var(--cf-text); }
.cf-msg--agent { align-self: flex-end; align-items: flex-end; }
.cf-msg--agent .cf-msg-bubble { background: var(--cf-accent); color: var(--cf-on-accent); }
.cf-msg-role-label {
  font-size: var(--text-helper);
  font-weight: 600;
  color: var(--cf-info);
  margin-bottom: 2px;
}

.cf-msg-citations { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-1); }
.cf-msg-citation {
  font-size: var(--text-helper);
  color: var(--cf-accent);
  text-decoration: none;
  border: 1px solid var(--cf-border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
}
.cf-msg-citation:hover { background: var(--cf-accent-subtle); }

.cf-msg-feedback { display: flex; gap: var(--sp-1); margin-top: var(--sp-1); }
.cf-msg-feedback-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--cf-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cf-msg-feedback-btn:hover { background: var(--cf-surface-hover); color: var(--cf-text); }
.cf-msg-feedback-btn.is-active { color: var(--cf-accent); }
.cf-msg-feedback-btn:focus-visible { outline: 2px solid var(--cf-ring); outline-offset: 1px; }

.cf-support-state {
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-helper);
  color: var(--cf-text-muted);
  border-top: 1px solid var(--cf-border-subtle);
  flex-shrink: 0;
}
.cf-support-state[hidden] { display: none; }
.cf-support-state.is-error { color: var(--cf-error); }
.cf-support-state.is-success { color: var(--cf-success); }

.cf-support-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-top: 1px solid var(--cf-border-subtle);
  flex-shrink: 0;
}
.cf-support-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--cf-border);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  font: inherit;
  font-size: var(--text-body-sm);
  color: var(--cf-text);
  background: var(--cf-bg);
  max-height: 96px;
}
.cf-support-input:focus-visible { outline: 2px solid var(--cf-ring); outline-offset: 1px; }

/* Ticket attachment control - hidden until a ticket exists for the session (see
   static/js/support-chat.js). Sized to match .cf-support-send-btn for row alignment. */
.cf-support-attach-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--cf-border);
  background: transparent;
  color: var(--cf-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.cf-support-attach-btn[hidden] { display: none; }
.cf-support-attach-btn:hover { background: var(--cf-surface-hover); color: var(--cf-text); }
.cf-support-attach-btn:disabled { opacity: .5; cursor: not-allowed; }
.cf-support-attach-btn:focus-visible { outline: 2px solid var(--cf-ring); outline-offset: 1px; }

.cf-support-send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  border: none;
  background: var(--cf-accent);
  color: var(--cf-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.cf-support-send-btn:hover { background: var(--cf-accent-hover); }
.cf-support-send-btn:disabled { background: var(--cf-gray-300); cursor: not-allowed; }
.cf-support-send-btn:focus-visible { outline: 2px solid var(--cf-ring); outline-offset: 1px; }

.cf-support-footer {
  padding: var(--sp-2) var(--sp-4) var(--sp-3);
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--cf-text-disabled);
  flex-shrink: 0;
}
.cf-support-footer a { color: var(--cf-text-muted); }

@media (max-width: 767px) {
  .cf-support-fab { bottom: calc(16px + 58px + env(safe-area-inset-bottom)); }
  /* Tap-to-close backdrop behind the sheet (shown by JS when the panel opens). */
  .cf-support-scrim {
    display: block;
    position: fixed; inset: 0; z-index: 249;
    background: rgba(17,24,39,.32);
  }
  .cf-support-scrim[hidden] { display: none; }
  /* Mobile = a BOTTOM SHEET. IDLE (no keyboard) this CSS applies: 82dvh with a clear top gap so the
     page + status bar show and the header never sits under the clock. When the keyboard is up, JS
     sets inline top+height to EXACTLY overlay window.visualViewport (an exact overlay that cannot
     overflow the screen no matter how flaky the iOS keyboard resize events are) and inline
     bottom:auto - the inline styles win over these rules. */
  .cf-support-panel {
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 82dvh;
    max-height: calc(100dvh - env(safe-area-inset-top));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    transition: none;   /* don't animate on every keyboard resize */
  }
  .cf-support-messages { flex: 1 1 auto; min-height: 0; }   /* bound the empty gap; enable scroll */
}

@media (prefers-reduced-motion: reduce) {
  .cf-support-fab { transition: none; }
  .cf-support-ws-status.is-reconnecting { animation: none; }
}

/* Mobile: no floating FAB - the assistant opens as its own page from the avatar menu (/app/support),
   which handles the keyboard natively instead of fighting a position:fixed overlay. Desktop keeps it. */
@media (max-width: 767px) { .cf-support-fab { display: none; } }

/* ── Full-page support chat (body.cf-support-page, /app/support) ────────────────────────────────
   Reuses the SAME #cf-support-panel + support-chat.js in "page mode": the panel fills the screen and
   the FAB + app chrome are hidden. Idle = full-screen; when the keyboard opens, support-chat.js sets
   inline top+height to overlay window.visualViewport exactly (can't overflow). */
body.cf-support-page .cf-support-fab { display: none !important; }
body.cf-support-page .topbar,
body.cf-support-page .mtab,
body.cf-support-page .mmore,
body.cf-support-page .mmore-overlay,
body.cf-support-page .sidebar,
body.cf-support-page .sidebar-overlay,
body.cf-support-page .demo-banner { display: none !important; }
body.cf-support-page .main-content { margin: 0 !important; padding: 0 !important; }
body.cf-support-page .page-content { padding: 0 !important; }
body.cf-support-page .cf-support-panel {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
