/* ClippyMail — Zoho Cliq panel.
 *
 * Docked right-hand surface, in the shape of Gmail's Chat panel: chat is a
 * companion to the message being read, not a separate full-screen app (which is
 * what the CRM surface is). Docking also keeps this clear of the layout-toggle
 * and compact-header machinery.
 *
 * Follows crm.css conventions: cm-* class names, custom properties at the top,
 * html.dark-mode overrides at the bottom, !important where the skin's own
 * cascade would otherwise win.
 */

:root {
  /* Palette lifted from the skin's own mobile-shell tokens, so the panel reads
     as part of ClippyMail instead of inventing a second design language. */
  --cm-cliq-width: 360px;
  --cm-cliq-blue: #1a73e8;
  --cm-cliq-surface: #f3f6fb;   /* --clippymail-mobile-surface */
  --cm-cliq-panel: #ffffff;     /* --clippymail-mobile-panel   */
  --cm-cliq-text: #202124;
  --cm-cliq-muted: #5f6368;
  --cm-cliq-border: #d8e0eb;    /* --clippymail-mobile-border  */
  --cm-cliq-hover: rgba(15, 23, 42, 0.05);
  --cm-cliq-bubble: #eef2f8;
  --cm-cliq-mine: #dbeaff;      /* the skin's swipe-unread blue */
  --cm-cliq-shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
}

/* ---- rail button ------------------------------------------------------- */

#clippymail-cliq-toggle.clippymail-cliq-nav {
  position: relative !important;
}

#clippymail-cliq-toggle.clippymail-cliq-nav::before {
  content: "\1F4AC";           /* speech balloon */
  font-family: Arial, sans-serif !important;
  font-size: 18px !important;
  width: 24px !important;
  height: 24px !important;
  line-height: 24px !important;
  text-align: center !important;
  display: block !important;
}

#clippymail-cliq-toggle.clippymail-cliq-nav.is-active,
body.cm-cliq-open #clippymail-cliq-toggle.clippymail-cliq-nav {
  background: #e8f0fe !important;
  color: var(--cm-cliq-blue) !important;
}

.cm-cliq-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #d93025;
  color: #fff;
  font: 500 10px/16px Roboto, Arial, sans-serif;
  text-align: center;
}

.cm-cliq-badge[hidden] {
  display: none !important;
}

/* ---- panel shell ------------------------------------------------------- */

.cm-cliq-panel[hidden] {
  display: none !important;
}

.cm-cliq-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  /* This skin's stacking ladder is much higher than a default Roundcube's:
     #fast-search-box is 100000, the View menu 100010, the keyboard-help
     overlay 100050, the task-due popover 200000. At the obvious-looking 1090
     the search row painted straight over the panel header (verified live,
     2026-07-28). Sit just above the mail chrome and deliberately BELOW the
     menus and overlays, so those still open on top of the panel. */
  z-index: 100005;
  display: flex;
  flex-direction: column;
  width: var(--cm-cliq-width);
  background: var(--cm-cliq-panel);
  border-left: 1px solid var(--cm-cliq-border);
  box-shadow: var(--cm-cliq-shadow);
  color: var(--cm-cliq-text);
  font: 400 13px/1.45 Roboto, Arial, sans-serif;
}

.cm-cliq-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 8px 0 12px;
  border-bottom: 1px solid var(--cm-cliq-border);
}

.cm-cliq-title {
  flex: 1;
  overflow: hidden;
  font-size: 15px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cm-cliq-head button {
  border: 0;
  background: transparent;
  color: var(--cm-cliq-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 50%;
}

.cm-cliq-head button:hover {
  background: rgba(60, 64, 67, 0.08);
}

.cm-cliq-head button[hidden] {
  display: none !important;
}

/* One-line status banner: not connected / paused / unreachable. */
.cm-cliq-note {
  padding: 8px 12px;
  background: #fef7e0;
  border-bottom: 1px solid #feefc3;
  color: #7c5800;
  font-size: 12px;
}

.cm-cliq-note[hidden] {
  display: none !important;
}

.cm-cliq-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.cm-cliq-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 16px;
  color: var(--cm-cliq-muted);
  text-align: center;
}

.cm-cliq-connect {
  padding: 8px 16px;
  border: 0;
  border-radius: 18px;
  background: var(--cm-cliq-blue);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

/* ---- chat list --------------------------------------------------------- */

.cm-cliq-chats {
  list-style: none;
  margin: 0;
  padding: 6px 8px;
}

.cm-cliq-chat-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 120ms ease;
}

.cm-cliq-chat-button:hover {
  background: var(--cm-cliq-hover);
}

.cm-cliq-chat-main {
  flex: 1;
  min-width: 0;
}

.cm-cliq-chat-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cm-cliq-chat-title {
  flex: 1;
  overflow: hidden;
  font-size: 13.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cm-cliq-chat.is-unread .cm-cliq-chat-title {
  font-weight: 700;
}

.cm-cliq-chat-unread {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--cm-cliq-blue);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
}

.cm-cliq-chat-preview {
  display: block;
  overflow: hidden;
  margin-top: 1px;
  color: var(--cm-cliq-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Coloured initials, the same device the mail list uses for senders — it is
   what makes the panel read as part of this app rather than a bolted-on box. */
.cm-cliq-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 30px;
  text-align: center;
  user-select: none;
}

/* ---- messages ---------------------------------------------------------- */

.cm-cliq-messages {
  list-style: none;
  margin: 0;
  padding: 10px 12px 14px;
}

/* Day separator: a hairline with a centred label. */
.cm-cliq-day {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 2px 10px;
  color: var(--cm-cliq-muted);
  font-size: 11px;
}

.cm-cliq-day::before,
.cm-cliq-day::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--cm-cliq-border);
}

.cm-cliq-message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

/* Grouped messages hide the avatar but keep its width, so bubbles stay aligned. */
.cm-cliq-message.is-grouped {
  margin-bottom: 3px;
  padding-left: 38px;
}

.cm-cliq-bubble {
  max-width: 84%;
  padding: 7px 11px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  background: var(--cm-cliq-bubble);
}

.cm-cliq-message.is-mine .cm-cliq-bubble {
  background: var(--cm-cliq-mine);
}

.cm-cliq-message.is-pending .cm-cliq-bubble {
  opacity: 0.6;
}

.cm-cliq-message.is-failed .cm-cliq-bubble {
  background: #fce8e6;
  box-shadow: inset 0 0 0 1px #d93025;
}

.cm-cliq-meta {
  display: flex;
  gap: 6px;
  align-items: baseline;
  margin-bottom: 2px;
  color: var(--cm-cliq-muted);
  font-size: 11px;
}

.cm-cliq-sender {
  font-weight: 600;
  color: var(--cm-cliq-text);
}

.cm-cliq-status {
  font-size: 11px;
  color: var(--cm-cliq-muted);
}

.cm-cliq-message.is-failed .cm-cliq-status {
  color: #d93025;
  font-weight: 600;
}

.cm-cliq-text {
  /* Chat text is user content: wrap it, never let a long token blow out the
     panel width, and preserve the newlines people actually typed. */
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 13.5px;
}

/* ---- inline media ------------------------------------------------------ */

.cm-cliq-media {
  position: relative;
  margin: 2px 0;
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
}

.cm-cliq-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 320px;
  border-radius: 10px;
  background: var(--cm-cliq-hover);
  object-fit: cover;
}

/* GIFs are labelled, the way Slack and Gmail chat do, so an animation is not
   mistaken for a broken still. */
.cm-cliq-gif-tag {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 16px;
}

/* Non-image attachment. */
.cm-cliq-file {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
  padding: 8px 10px;
  border: 1px solid var(--cm-cliq-border);
  border-radius: 10px;
  background: var(--cm-cliq-surface);
  color: inherit;
  text-decoration: none;
}

.cm-cliq-file:hover {
  background: var(--cm-cliq-hover);
}

.cm-cliq-file-icon {
  font-size: 15px;
}

.cm-cliq-file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cm-cliq-file-name {
  overflow: hidden;
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cm-cliq-file-size {
  color: var(--cm-cliq-muted);
  font-size: 11px;
}

/* Message types this panel cannot render. Visibly different from real text so
   the owner knows to open the real client rather than assuming they have seen
   everything. */
.cm-cliq-placeholder {
  padding: 3px 0;
  color: var(--cm-cliq-muted);
  font-size: 12.5px;
  font-style: italic;
}

/* ---- composer ---------------------------------------------------------- */

.cm-cliq-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--cm-cliq-border);
  background: var(--cm-cliq-surface);
}

.cm-cliq-composer[hidden] {
  display: none !important;
}

/* Pill input with the tools tucked inside it — 999px is this skin's dominant
   radius, used by its search box and buttons. */
.cm-cliq-inputwrap {
  display: flex;
  flex: 1;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
  padding: 4px 6px 4px 12px;
  border: 1px solid var(--cm-cliq-border);
  border-radius: 20px;
  background: var(--cm-cliq-panel);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.cm-cliq-inputwrap:focus-within {
  border-color: var(--cm-cliq-blue);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.12);
}

.cm-cliq-input {
  flex: 1;
  max-height: 120px;
  min-height: 26px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13.5px;
  resize: none;
  outline: none;
}

.cm-cliq-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}

.cm-cliq-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cm-cliq-muted);
  cursor: pointer;
}

.cm-cliq-tool:hover {
  background: var(--cm-cliq-hover);
  color: var(--cm-cliq-blue);
}

.cm-cliq-send {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: var(--cm-cliq-blue);
  color: #fff;
  cursor: pointer;
}

.cm-cliq-send:hover {
  background: #1667d3;
}

.cm-cliq-send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Drag-and-drop target. */
.cm-cliq-drop {
  position: absolute;
  inset: 48px 10px 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--cm-cliq-blue);
  border-radius: 14px;
  background: rgba(232, 240, 254, 0.92);
  color: #15406f;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
}

.cm-cliq-drop[hidden] {
  display: none !important;
}


/* Shrink the mail UI instead of hiding part of it. A docked panel that simply
   overlaps leaves the message list clipped mid-column, which reads as broken;
   Gmail reflows for its chat panel and so do we.

   #layout is a full-width grid and plain margin-right lost the cascade here
   (verified live: it computed to 0px), so shrink the declared width and match
   the skin's own !important idiom. */
@media (min-width: 769px) {
  body.cm-cliq-open #layout {
    width: calc(100% - var(--cm-cliq-width)) !important;
    transition: width 120ms ease-out;
  }
}

/* ---- mobile ------------------------------------------------------------ */

/* On a phone the panel is the whole screen and the reading pane is hidden —
   they compete for the same space and a 340px dock would be unusable at 412px. */
@media (max-width: 768px) {
  .cm-cliq-panel {
    width: 100%;
    border-left: 0;
    /* Stop above the phone shell's bottom nav (fixed, z-index 1285) so the
       user can still switch apps with the panel open. Reuses the shell's own
       height variable rather than hard-coding 52px. */
    bottom: calc(var(--clippymail-mobile-bottomnav, 52px) + env(safe-area-inset-bottom, 0px));
  }

  body.cm-cliq-open #layout-content,
  body.cm-cliq-open #layout-list {
    display: none !important;
  }
}

/* ---- dark mode --------------------------------------------------------- */

html.dark-mode .cm-cliq-panel {
  --cm-cliq-surface: #1a1c20;
  --cm-cliq-panel: #1f232b;
  --cm-cliq-text: #e8eaed;
  --cm-cliq-muted: #9aa0a6;
  --cm-cliq-border: #3c4043;
  --cm-cliq-hover: rgba(232, 234, 237, 0.08);
  --cm-cliq-bubble: #2a2f38;
  --cm-cliq-mine: #394457;
  background: var(--cm-cliq-panel);
  color: var(--cm-cliq-text);
}

html.dark-mode .cm-cliq-drop {
  background: rgba(57, 68, 87, 0.94);
  color: #d2e3fc;
}

html.dark-mode .cm-cliq-note {
  background: #3a3323;
  border-bottom-color: #4d4327;
  color: #fdd663;
}

html.dark-mode .cm-cliq-input {
  background: #2a2f38;
  color: var(--cm-cliq-text);
}

html.dark-mode #clippymail-cliq-toggle.clippymail-cliq-nav.is-active,
html.dark-mode body.cm-cliq-open #clippymail-cliq-toggle.clippymail-cliq-nav {
  background: #394457 !important;
  color: #8ab4f8 !important;
}

/* Read-only mode. Zoho refuses message-posting for every user-level scope on
   this tenant (verified 2026-07-28), so rather than leave a composer that fails
   on submit, the panel offers the real client for the reply. */
.cm-cliq-readonly {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--cm-cliq-border);
  background: #fef7e0;
  color: #7c5800;
  font-size: 12px;
}

.cm-cliq-readonly[hidden] {
  display: none !important;
}

.cm-cliq-readonly-text {
  flex: 1;
}

.cm-cliq-openin {
  flex: none;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--cm-cliq-blue);
  color: #fff;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

html.dark-mode .cm-cliq-readonly {
  background: #3a3323;
  color: #fdd663;
}

/* Optimistic send states. The echo appears the instant Send is pressed and is
   replaced by the real message when the send round-trip returns. */
.cm-cliq-message.is-pending {
  opacity: 0.65;
}

.cm-cliq-message.is-failed {
  border: 1px solid #d93025;
}

.cm-cliq-status {
  font-size: 11px;
  color: var(--cm-cliq-muted);
}

.cm-cliq-message.is-failed .cm-cliq-status {
  color: #d93025;
  font-weight: 500;
}
