/**
 * CMOC Floating Chat Widget — Frontend Styles
 *
 * Responsive styles for the floating chat widget injected in wp_footer on
 * all non-chat pages. The widget consists of three layers:
 *
 *  1. Toggle button  — circular, fixed bottom-right (#cmoc-floating-widget).
 *  2. Chat-list panel — vertical list of accessible chats (.cmoc-floating__panel).
 *  3. Compact chat window — messaging interface (.cmoc-floating__chat-window).
 *
 * Breakpoints (mirrors cmoc-chat.css conventions):
 *   Desktop : >= 1024px  — panel 320px wide, window 380 × 500 px
 *   Tablet  : 768–1023px — panel 300px wide, window 360 × 460 px
 *   Mobile  : < 768px    — panel and window fill the full viewport
 *
 * @package ContentMediaOrderChat
 * @since   1.0.0
 * Validates: Requirements 11.7
 */

/* =========================================================================
   CSS Custom Properties — reuse the same tokens as cmoc-chat.css
   ========================================================================= */
#cmoc-floating-widget {
  /* Brand / primary */
  --cmoc-primary:          #0071a1;
  --cmoc-primary-dark:     #005a80;
  --cmoc-primary-light:    #e8f4f8;

  /* Own-message bubble */
  --cmoc-bubble-own-bg:    #0071a1;
  --cmoc-bubble-own-text:  #ffffff;

  /* Other-message bubble */
  --cmoc-bubble-other-bg:  #f0f0f0;
  --cmoc-bubble-other-text:#1a1a1a;

  /* System message */
  --cmoc-system-text:      #888888;

  /* Read-only notice */
  --cmoc-readonly-bg:      #fff8e1;
  --cmoc-readonly-border:  #f9a825;
  --cmoc-readonly-text:    #5d4037;

  /* Status colours */
  --cmoc-error-bg:         #fdecea;
  --cmoc-error-text:        #c62828;
  --cmoc-warning-bg:       #fff8e1;
  --cmoc-warning-text:     #e65100;
  --cmoc-success-bg:       #e8f5e9;
  --cmoc-success-text:     #2e7d32;

  /* Layout */
  --cmoc-border:           #e0e0e0;
  --cmoc-radius:           8px;
  --cmoc-shadow:           0 2px 8px rgba(0, 0, 0, 0.08);
  --cmoc-shadow-lg:        0 8px 24px rgba(0, 0, 0, 0.16);
  --cmoc-font:             -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;

  /* Widget geometry */
  --cmoc-toggle-size:      56px;
  --cmoc-toggle-icon-size: 24px;
  --cmoc-badge-size:       20px;
  --cmoc-panel-width:      320px;
  --cmoc-window-width:     380px;
  --cmoc-window-height:    500px;
  --cmoc-z-index:          9990;
}

/* =========================================================================
   Box-sizing reset scoped to the widget
   ========================================================================= */
#cmoc-floating-widget,
#cmoc-floating-widget *,
#cmoc-floating-widget *::before,
#cmoc-floating-widget *::after {
  box-sizing: border-box;
  font-family: var(--cmoc-font);
}

/* =========================================================================
   Root wrapper — fixed anchor for all child elements
   ========================================================================= */
#cmoc-floating-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--cmoc-z-index);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* =========================================================================
   Toggle button (Req. 8.2)
   ========================================================================= */
.cmoc-floating__toggle {
  width: var(--cmoc-toggle-size);
  height: var(--cmoc-toggle-size);
  border-radius: 50%;
  background: var(--cmoc-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 113, 161, 0.4);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  position: relative;  /* anchor for the badge */
  flex-shrink: 0;
  padding: 0;
}

.cmoc-floating__toggle:hover {
  background: var(--cmoc-primary-dark);
  transform: scale(1.07);
  box-shadow: 0 6px 16px rgba(0, 113, 161, 0.5);
}

.cmoc-floating__toggle:focus-visible {
  outline: 3px solid var(--cmoc-primary-light);
  outline-offset: 3px;
}

.cmoc-floating__toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cmoc-toggle-icon-size);
  height: var(--cmoc-toggle-icon-size);
}

.cmoc-floating__toggle-icon svg {
  width: var(--cmoc-toggle-icon-size);
  height: var(--cmoc-toggle-icon-size);
  fill: currentColor;
}

/* =========================================================================
   Unread-message badge (Req. 8.8)
   ========================================================================= */
.cmoc-floating__unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: var(--cmoc-badge-size);
  height: var(--cmoc-badge-size);
  padding: 0 5px;
  border-radius: calc(var(--cmoc-badge-size) / 2);
  background: #e53935;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  line-height: var(--cmoc-badge-size);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  border: 2px solid #ffffff;
}

/* =========================================================================
   Chat-list panel (Req. 8.3)
   ========================================================================= */
.cmoc-floating__panel {
  position: absolute;
  bottom: calc(var(--cmoc-toggle-size) + 10px);
  right: 0;
  width: var(--cmoc-panel-width);
  max-height: 480px;
  background: #ffffff;
  border: 1px solid var(--cmoc-border);
  border-radius: var(--cmoc-radius);
  box-shadow: var(--cmoc-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: calc(var(--cmoc-z-index) + 1);
}

/* Panel header */
.cmoc-floating__panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--cmoc-border);
  background: #fafafa;
  flex-shrink: 0;
}

.cmoc-floating__panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #1a1a1a;
}

.cmoc-floating__panel-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  color: #888;
  padding: 2px 6px;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.cmoc-floating__panel-close:hover {
  background: #f0f0f0;
  color: #333;
}

.cmoc-floating__panel-close:focus-visible {
  outline: 2px solid var(--cmoc-primary);
  outline-offset: 2px;
}

/* Panel body (scrollable list) */
.cmoc-floating__panel-body {
  overflow-y: auto;
  flex: 1 1 auto;
}

/* Empty state */
.cmoc-floating__panel-empty {
  padding: 20px 16px;
  margin: 0;
  font-size: 13px;
  color: var(--cmoc-system-text);
  text-align: center;
}

/* =========================================================================
   Chat list (Req. 8.3, 8.4, 8.5)
   ========================================================================= */
.cmoc-floating__chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cmoc-floating__chat-item {
  border-bottom: 1px solid var(--cmoc-border);
}

.cmoc-floating__chat-item:last-child {
  border-bottom: none;
}

.cmoc-floating__chat-item-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  position: relative;
}

.cmoc-floating__chat-item-btn:hover {
  background: var(--cmoc-primary-light);
}

.cmoc-floating__chat-item-btn:focus-visible {
  outline: 2px solid var(--cmoc-primary);
  outline-offset: -2px;
}

/* Interlocutor name — prominent */
.cmoc-floating__chat-interlocutor {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Order label — muted gray (Req. 8.5) */
.cmoc-floating__chat-order-label {
  font-size: 12px;
  color: var(--cmoc-system-text);
  display: block;
}

/* Per-chat unread badge (inline, right side) */
.cmoc-floating__chat-unread {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #e53935;
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* =========================================================================
   Compact chat window (Req. 8.6, 8.7)
   ========================================================================= */
.cmoc-floating__chat-window {
  position: absolute;
  bottom: calc(var(--cmoc-toggle-size) + 10px);
  right: 0;
  width: var(--cmoc-window-width);
  height: var(--cmoc-window-height);
  background: #ffffff;
  border: 1px solid var(--cmoc-border);
  border-radius: var(--cmoc-radius);
  box-shadow: var(--cmoc-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: calc(var(--cmoc-z-index) + 2);
}

/* Window header */
.cmoc-floating__window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--cmoc-border);
  background: var(--cmoc-primary);
  color: #ffffff;
  flex-shrink: 0;
}

.cmoc-floating__window-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  flex: 1 1 auto;
  min-width: 0;
}

.cmoc-floating__window-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmoc-floating__window-order-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header action buttons (back + close) */
.cmoc-floating__window-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
}

.cmoc-floating__window-back,
.cmoc-floating__window-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.9);
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.cmoc-floating__window-back:hover,
.cmoc-floating__window-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.cmoc-floating__window-back:focus-visible,
.cmoc-floating__window-close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}

/* =========================================================================
   Read-only notice (Req. 10.3)
   ========================================================================= */
.cmoc-floating__window-readonly-notice {
  padding: 8px 12px;
  background: var(--cmoc-readonly-bg);
  border-bottom: 2px solid var(--cmoc-readonly-border);
  color: var(--cmoc-readonly-text);
  font-size: 12px;
  flex-shrink: 0;
}

.cmoc-floating__window-readonly-notice p {
  margin: 0;
}

/* =========================================================================
   Message list area (Req. 8.7)
   ========================================================================= */
.cmoc-floating__window-messages-wrap {
  flex: 1 1 auto;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.cmoc-floating__message-list {
  list-style: none;
  margin: 0;
  padding: 12px;
  overflow-y: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Loading indicator */
.cmoc-floating__window-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  color: var(--cmoc-system-text);
}

/* =========================================================================
   Message bubbles
   ========================================================================= */
.cmoc-floating__message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

/* Own messages — right-aligned */
.cmoc-floating__message--own {
  align-self: flex-end;
  align-items: flex-end;
}

/* Other messages — left-aligned */
.cmoc-floating__message--other {
  align-self: flex-start;
  align-items: flex-start;
}

/* System messages — centered */
.cmoc-floating__message--system {
  align-self: center;
  align-items: center;
  max-width: 95%;
}

/* Message meta */
.cmoc-floating__message-meta {
  display: flex;
  gap: 4px;
  align-items: baseline;
  margin-bottom: 2px;
  font-size: 10px;
  color: #999;
}

.cmoc-floating__message-author {
  font-weight: 600;
  color: #666;
}

/* Message bubble body */
.cmoc-floating__message-body {
  padding: 7px 10px;
  border-radius: var(--cmoc-radius);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.cmoc-floating__message--own .cmoc-floating__message-body {
  background: var(--cmoc-bubble-own-bg);
  color: var(--cmoc-bubble-own-text);
  border-bottom-right-radius: 2px;
}

.cmoc-floating__message--other .cmoc-floating__message-body {
  background: var(--cmoc-bubble-other-bg);
  color: var(--cmoc-bubble-other-text);
  border-bottom-left-radius: 2px;
}

.cmoc-floating__message--system .cmoc-floating__message-body {
  background: transparent;
  color: var(--cmoc-system-text);
  font-style: italic;
  font-size: 11px;
  padding: 3px 6px;
}

/* Attachment link */
.cmoc-floating__message-attachment {
  margin-top: 3px;
  font-size: 11px;
}

.cmoc-floating__message-attachment a {
  color: inherit;
  text-decoration: underline;
  opacity: 0.85;
}

.cmoc-floating__message-attachment a:hover {
  opacity: 1;
}

/* Empty list state */
.cmoc-floating__message-empty {
  align-self: center;
  color: var(--cmoc-system-text);
  font-style: italic;
  font-size: 12px;
  text-align: center;
  padding: 16px 0;
}

/* =========================================================================
   Compose area (Req. 8.7, 9.1, 9.2)
   ========================================================================= */
.cmoc-floating__window-compose {
  border-top: 1px solid var(--cmoc-border);
  padding: 8px 10px;
  background: #ffffff;
  flex-shrink: 0;
}

/* Attachment preview */
.cmoc-floating__attachment-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--cmoc-primary-light);
  border-radius: var(--cmoc-radius);
  margin-bottom: 6px;
  font-size: 11px;
}

.cmoc-floating__attachment-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--cmoc-primary-dark);
}

.cmoc-floating__attachment-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: #888;
  padding: 0 2px;
  transition: color 0.15s;
}

.cmoc-floating__attachment-remove:hover {
  color: #e53935;
}

/* Compose row: textarea + action buttons */
.cmoc-floating__compose-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.cmoc-floating__message-input {
  flex: 1;
  resize: none;
  padding: 7px 10px;
  border: 1px solid var(--cmoc-border);
  border-radius: var(--cmoc-radius);
  font-family: var(--cmoc-font);
  font-size: 13px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
  min-height: 48px;
  max-height: 120px;
  overflow-y: auto;
}

.cmoc-floating__message-input:focus {
  border-color: var(--cmoc-primary);
}

.cmoc-floating__compose-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

/* Attach button */
.cmoc-floating__attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f5f5f5;
  border: 1px solid var(--cmoc-border);
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s, border-color 0.15s;
}

.cmoc-floating__attach-btn:hover {
  background: var(--cmoc-primary-light);
  border-color: var(--cmoc-primary);
}

/* Hidden file input */
.cmoc-floating__file-input {
  display: none;
}

/* Send button */
.cmoc-floating__send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: var(--cmoc-primary);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.cmoc-floating__send-btn:hover {
  background: var(--cmoc-primary-dark);
  transform: scale(1.05);
}

.cmoc-floating__send-btn:disabled {
  background: #b0bec5;
  cursor: not-allowed;
  transform: none;
}

.cmoc-floating__send-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Character counter */
.cmoc-floating__char-count {
  margin-top: 3px;
  font-size: 10px;
  color: #999;
  text-align: right;
}

.cmoc-floating__char-remaining--low {
  color: #e53935;
  font-weight: 600;
}

/* Compose status messages */
.cmoc-floating__compose-status {
  margin-top: 4px;
  padding: 5px 8px;
  border-radius: var(--cmoc-radius);
  font-size: 11px;
}

.cmoc-floating__compose-status--error {
  background: var(--cmoc-error-bg);
  color: var(--cmoc-error-text);
}

.cmoc-floating__compose-status--warning {
  background: var(--cmoc-warning-bg);
  color: var(--cmoc-warning-text);
}

.cmoc-floating__compose-status--success {
  background: var(--cmoc-success-bg);
  color: var(--cmoc-success-text);
}

/* =========================================================================
   Utility: visually hidden (screen-reader only)
   ========================================================================= */
#cmoc-floating-widget .screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =========================================================================
   RESPONSIVE — Tablet (768px – 1023px)
   Req. 11.7: adapt to tablet screens
   ========================================================================= */
@media (min-width: 768px) and (max-width: 1023px) {
  #cmoc-floating-widget {
    --cmoc-panel-width:  300px;
    --cmoc-window-width: 360px;
    --cmoc-window-height: 460px;

    bottom: 20px;
    right: 20px;
  }
}

/* =========================================================================
   RESPONSIVE — Mobile (< 768px)
   Req. 11.7: adapt to mobile screens — panel and window go full-viewport
   ========================================================================= */
@media (max-width: 767px) {
  #cmoc-floating-widget {
    --cmoc-toggle-size: 50px;

    bottom: 16px;
    right: 16px;
  }

  /* Panel: full-width, attached to bottom of viewport */
  .cmoc-floating__panel {
    position: fixed;
    bottom: 80px; /* above the toggle button */
    right: 0;
    left: 0;
    width: 100%;
    max-height: 60vh;
    border-radius: var(--cmoc-radius) var(--cmoc-radius) 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  /* Chat window: full-screen overlay */
  .cmoc-floating__chat-window {
    position: fixed;
    inset: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    z-index: calc(var(--cmoc-z-index) + 5);
  }

  /* Wider bubbles on small screens */
  .cmoc-floating__message {
    max-width: 88%;
  }

  /* Larger textarea on touch devices */
  .cmoc-floating__message-input {
    font-size: 16px; /* prevents iOS zoom on focus */
    min-height: 44px;
  }

  /* Larger touch targets */
  .cmoc-floating__attach-btn,
  .cmoc-floating__send-btn {
    width: 38px;
    height: 38px;
  }

  .cmoc-floating__chat-item-btn {
    padding: 14px 14px;
  }
}

/* =========================================================================
   RESPONSIVE — Desktop (>= 1024px) — explicit confirmation of defaults
   Req. 11.7: desktop layout
   ========================================================================= */
@media (min-width: 1024px) {
  #cmoc-floating-widget {
    --cmoc-panel-width:   320px;
    --cmoc-window-width:  380px;
    --cmoc-window-height: 500px;

    bottom: 24px;
    right: 24px;
  }
}
