/* chat-dock.css — P7-02: Web chat dock styles.
 *
 * Loaded by the conductor when it adds <link rel="stylesheet" href="/css/chat-dock.css">
 * to frontend/index.html. Namespaced under .cd-* to avoid collisions.
 *
 * Variables reuse the existing :root palette from styles.css.
 * Floating dock sits in the bottom-right corner above other UI (z-index 1000).
 */

/* -------------------------------------------------------------------------
 * Dock root — collapsed: shows only the floating button
 * Expanded: shows floating button + panel
 * ------------------------------------------------------------------------- */

.cd-dock {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: var(--z-dock, 900);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 0.875rem;
}

/* -------------------------------------------------------------------------
 * Floating toggle button
 * ------------------------------------------------------------------------- */

.cd-toggle-btn {
  position: relative;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: none;
  background: var(--primary, #3b82f6);
  color: var(--text-primary, #f8fafc);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: var(--shadow, 0 4px 6px -1px rgba(0, 0, 0, 0.3));
  transition: background 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.cd-toggle-btn:hover {
  background: var(--primary-dark, #2563eb);
  transform: scale(1.05);
}

.cd-toggle-btn:active {
  transform: scale(0.97);
}

/* -------------------------------------------------------------------------
 * Unread badge
 * ------------------------------------------------------------------------- */

.cd-badge {
  position: absolute;
  top: -0.25rem;
  right: -0.25rem;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.25rem;
  border-radius: 0.6rem;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
}

.cd-badge-hidden {
  display: none;
}

/* -------------------------------------------------------------------------
 * Expanded panel
 * ------------------------------------------------------------------------- */

.cd-panel {
  width: 22rem;
  max-width: calc(100vw - 3rem);
  height: 28rem;
  max-height: calc(100vh - 5rem);
  background: var(--bg-card, #334155);
  border: 1px solid var(--border-color, #475569);
  border-radius: 10px;
  box-shadow: var(--shadow, 0 4px 6px -1px rgba(0, 0, 0, 0.3));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Panel is hidden by default; shown when dock is expanded */
.cd-collapsed .cd-panel {
  display: none;
}

.cd-expanded .cd-panel {
  display: flex;
}

/* -------------------------------------------------------------------------
 * Panel header
 * ------------------------------------------------------------------------- */

.cd-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-color, #475569);
  background: var(--bg-dark, #1e293b);
  flex-shrink: 0;
}

.cd-panel-title {
  font-weight: 600;
  color: var(--text-primary, #f8fafc);
  font-size: 0.9rem;
}

.cd-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary, #94a3b8);
  padding: 0.2rem 0.3rem;
  border-radius: 4px;
  transition: color 0.15s;
  line-height: 1;
}

.cd-panel-close:hover {
  color: var(--text-primary, #f8fafc);
}

/* -------------------------------------------------------------------------
 * Channel switcher tabs
 * ------------------------------------------------------------------------- */

.cd-channel-switcher {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color, #475569);
  flex-shrink: 0;
}

.cd-channel-tab {
  flex: 1;
  padding: 0.4rem 0.5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary, #94a3b8);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.cd-channel-tab:hover {
  color: var(--text-primary, #f8fafc);
}

.cd-channel-tab-active {
  color: var(--primary, #3b82f6);
  border-bottom-color: var(--primary, #3b82f6);
  font-weight: 600;
}

/* -------------------------------------------------------------------------
 * Message list
 * ------------------------------------------------------------------------- */

.cd-message-list-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.75rem;
  gap: 0.4rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color, #475569) transparent;
}

.cd-load-older {
  align-self: center;
  margin-bottom: 0.5rem;
  padding: 0.25rem 0.75rem;
  background: var(--bg-light, #475569);
  border: 1px solid var(--border-color, #475569);
  border-radius: 4px;
  color: var(--text-secondary, #94a3b8);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.cd-load-older:hover {
  background: var(--bg-dark, #1e293b);
  color: var(--text-primary, #f8fafc);
}

.cd-load-older-hidden {
  display: none;
}

.cd-message-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
}

/* -------------------------------------------------------------------------
 * Individual message items
 * ------------------------------------------------------------------------- */

.cd-message {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  max-width: 95%;
}

.cd-message-hugo {
  align-self: flex-start;
  background: var(--bg-dark, #1e293b);
  border: 1px solid var(--border-color, #475569);
}

.cd-message-user {
  align-self: flex-end;
  background: var(--primary, #3b82f6);
  border: 1px solid var(--primary-dark, #2563eb);
}

.cd-message-muted {
  opacity: 0.6;
}

.cd-msg-author {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cd-message-user .cd-msg-author {
  color: rgba(248, 250, 252, 0.75);
}

.cd-msg-body {
  color: var(--text-primary, #f8fafc);
  line-height: 1.45;
}

.cd-msg-body p {
  margin: 0;
}

.cd-msg-body p + p {
  margin-top: 0.3em;
}

.cd-msg-body strong {
  font-weight: 700;
}

.cd-msg-body em {
  font-style: italic;
}

.cd-msg-body code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.8em;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

/* -------------------------------------------------------------------------
 * State chips (acted / expired)
 * ------------------------------------------------------------------------- */

.cd-state-chip {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  align-self: flex-start;
}

.cd-state-acted {
  background: var(--success, #22c55e);
  color: #fff;
}

.cd-state-expired {
  background: var(--secondary, #64748b);
  color: #fff;
}

/* -------------------------------------------------------------------------
 * Action buttons
 * ------------------------------------------------------------------------- */

.cd-msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.cd-action-btn {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border-color, #475569);
  background: var(--bg-light, #475569);
  color: var(--text-primary, #f8fafc);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.cd-action-btn:hover:not(:disabled) {
  background: var(--primary, #3b82f6);
  border-color: var(--primary-dark, #2563eb);
}

.cd-action-btn:disabled,
.cd-action-muted {
  opacity: 0.5;
  cursor: default;
}

/* -------------------------------------------------------------------------
 * Error chip (inline action error)
 * ------------------------------------------------------------------------- */

.cd-error-chip {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  background: var(--danger, #ef4444);
  color: #fff;
  display: inline-block;
  margin-top: 0.2rem;
}

/* -------------------------------------------------------------------------
 * Empty / loading / error states
 * ------------------------------------------------------------------------- */

.cd-msg-empty,
.cd-loading {
  color: var(--text-secondary, #94a3b8);
  font-size: 0.8rem;
  text-align: center;
  padding: 1rem 0;
  list-style: none;
}

.cd-error {
  color: var(--danger, #ef4444);
  font-size: 0.8rem;
  text-align: center;
  padding: 0.5rem 0;
  list-style: none;
}

/* -------------------------------------------------------------------------
 * Composer
 * ------------------------------------------------------------------------- */

.cd-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border-color, #475569);
  flex-shrink: 0;
  background: var(--bg-dark, #1e293b);
}

.cd-composer-input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border-color, #475569);
  border-radius: 6px;
  background: var(--bg-card, #334155);
  color: var(--text-primary, #f8fafc);
  font-size: 0.85rem;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
  transition: border-color 0.15s;
  min-height: 2.5rem;
  max-height: 6rem;
}

.cd-composer-input::placeholder {
  color: var(--text-secondary, #94a3b8);
}

.cd-composer-input:focus {
  outline: none;
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.cd-composer-send {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: none;
  background: var(--primary, #3b82f6);
  color: var(--text-primary, #f8fafc);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: background 0.15s;
  flex-shrink: 0;
}

.cd-composer-send:hover {
  background: var(--primary-dark, #2563eb);
}

.cd-composer-send:active {
  transform: scale(0.95);
}

/* -------------------------------------------------------------------------
 * Tablet (768–1023 px): minor panel size reduction only
 * ------------------------------------------------------------------------- */

@media (min-width: 768px) and (max-width: 1023px) {
  .cd-panel {
    width: 20rem;
    height: 26rem;
  }
}

/* -------------------------------------------------------------------------
 * Phone (<768 px)
 *
 * Collapsed state: the floating button moves to sit ABOVE the bottom-nav
 * (not overlapping it).  Its bottom offset = --bottom-nav-height + safe-area
 * + a small gap so it never hides behind the nav bar.
 *
 * Expanded state: the panel becomes a full-screen bottom sheet that covers
 * everything above the bottom-nav.  The toggle button stays visible above
 * it (positioned inside the dock root which is fixed).
 * ------------------------------------------------------------------------- */

@media (max-width: 767px) {
  /* Dock root: anchored to the bottom-right; lifted above the bottom-nav */
  .cd-dock {
    bottom: calc(var(--bottom-nav-height, 56px) + env(safe-area-inset-bottom) + 0.75rem);
    right: 1rem;
    /* Use z-dock so it sits below modals but above the bottom-nav */
    z-index: var(--z-dock, 900);
  }

  /* Collapsed toggle button: touch target ≥ 44px */
  .cd-toggle-btn {
    width: 3rem;    /* 48px */
    height: 3rem;
  }

  /* Expanded panel: full-width sheet from bottom-nav up to top of screen */
  .cd-expanded .cd-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--bottom-nav-height, 56px) + env(safe-area-inset-bottom));
    /* Top clears the collapsed header */
    top: var(--header-height, 56px);
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: none;
    border-radius: var(--radius-lg, 0.5rem) var(--radius-lg, 0.5rem) 0 0;
    z-index: var(--z-dock, 900);
  }

  /* When expanded, push toggle button above the sheet (it stays in normal
     dock flow which is already above the bottom-nav) */
  .cd-expanded .cd-toggle-btn {
    /* Stays at the bottom-right above the sheet header */
    position: relative;
    z-index: calc(var(--z-dock, 900) + 1);
  }

  /* Composer padding: adds bottom safe-area clearance */
  .cd-composer {
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  }

  /* Message list takes all remaining height */
  .cd-message-list-wrap {
    flex: 1 1 0;
    min-height: 0;
  }
}
