/* Clapcake site widget.
   Follows the Paces dashboard system (paces/resources/css): Nunito, 4px radius, 37px controls,
   soft-tinted badges, dashed card-header rule. Light and dark values are Paces' own
   (_root.css :root and [data-theme="dark"]). The widget sets data-theme on .cw itself:
   it follows the host page's <html data-theme>, else the OS setting (see clapcake-widget.js). */

.cw {
  /* Accent: Paces --color-primary by default; override per site with the `accent` option. */
  --cw-accent: #236dc9;
  --cw-on-accent: #ffffff;

  --cw-bg: #ffffff;            /* Paces --color-card */
  --cw-bg-subtle: #f6f7fb;     /* Paces --color-body-bg */
  --cw-bg-soft: #eef2f7;       /* Paces --color-light */
  --cw-border: #e7e9eb;        /* Paces default-300 */
  --cw-border-strong: #a1a9b1; /* Paces default-500, input hover/focus */
  --cw-text: #313a46;          /* Paces default-900, headings */
  --cw-text-2: #4c4c5c;        /* Paces --color-body-color */
  --cw-muted: #6c757d;         /* Paces default-700; use on --cw-bg only */
  --cw-success: #02bc9c;
  --cw-warning: #f9bf59;
  --cw-danger: #f7577e;
  --cw-shadow: 0 0.25rem 1rem rgba(76, 76, 92, 0.2); /* Paces --shadow-lg */

  /* Soft badges: Paces tints the colour at 15%. Text is darkened here so it reads at 4.5:1. */
  --cw-soft-mix: #000000;
  --cw-soft-text-amount: 55%;
  --cw-accent-text: color-mix(in srgb, var(--cw-accent) 80%, #000000);

  --cw-radius: 4px;            /* Paces --radius */
  --cw-font: var(--font-body, "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif);

  color-scheme: light;
  font-family: var(--cw-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--cw-text-2);
}

.cw[data-theme="dark"] {
  color-scheme: dark;
  --cw-bg: #1e1f27;            /* Paces dark --color-card */
  --cw-bg-subtle: #17181e;     /* Paces dark --color-body-bg */
  --cw-bg-soft: #252630;       /* Paces dark --color-light */
  --cw-border: #293036;        /* Paces dark default-300 */
  --cw-border-strong: #8391a2; /* Paces dark default-400 */
  --cw-text: #dce0fb;          /* Paces dark .text-dark */
  --cw-text-2: #aab8c5;        /* Paces dark --color-body-color */
  --cw-muted: #8391a2;
  --cw-shadow: 0 0 30px rgba(0, 0, 0, 0.3); /* Paces dark --shadow */
  --cw-soft-mix: #ffffff;
  --cw-soft-text-amount: 80%;
  --cw-accent-text: color-mix(in srgb, var(--cw-accent) 55%, #ffffff);
}

.cw *, .cw *::before, .cw *::after { box-sizing: border-box; }
.cw :where(svg) { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
/* Resets use :where() so every component rule below wins over them. They also shield the widget
   from host-page rules (a site's own section, p or form styles). */
.cw :where(section, header, form, div, p, dl, dt, dd, span, a) { margin: 0; padding: 0; }
.cw :where(section, header, form) { display: block; border: 0; background: none; box-shadow: none; }
.cw :where(button, input) { font: inherit; color: inherit; margin: 0; letter-spacing: normal; text-transform: none; }
.cw :where(button) { cursor: pointer; }
.cw :focus-visible { outline: 2px solid var(--cw-accent); outline-offset: 2px; }

/* ---------- Placement ---------- */
.cw-floating { position: fixed; right: 20px; bottom: 20px; z-index: 2147483000; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.cw-embedded { position: absolute; inset: 16px 16px 16px auto; width: min(360px, calc(100% - 32px)); display: flex; }
@media (max-width: 480px) { .cw-floating { right: 12px; bottom: 12px; } .cw-embedded { left: 12px; right: 12px; width: auto; } }

/* ---------- Launcher (one button; widens into the nudge) ---------- */
.cw-launcher {
  display: inline-flex; align-items: center; gap: 10px;
  min-width: 56px; height: 56px; padding: 0 16px; border: 0; border-radius: 999px;
  background: var(--cw-accent); color: var(--cw-on-accent);
  box-shadow: var(--cw-shadow); font-weight: 600; justify-content: center;
}
.cw-launcher svg { width: 22px; height: 22px; }

/* ---------- Panel ---------- */
.cw-panel {
  width: min(380px, calc(100vw - 24px)); height: min(640px, calc(100vh - 104px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--cw-bg); border: 1px solid var(--cw-border); border-radius: var(--cw-radius);
  box-shadow: var(--cw-shadow); color: var(--cw-text-2);
}
.cw-embedded .cw-panel { width: 100%; height: 100%; }
.cw-panel[hidden] { display: none; }

.cw-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px;
  border-bottom: 1px dashed var(--cw-border); /* Paces .card-header */
}
.cw-head-mark {
  width: 32px; height: 32px; border-radius: var(--cw-radius); display: grid; place-items: center;
  background: color-mix(in srgb, var(--cw-accent) 15%, transparent); color: var(--cw-accent-text);
}
.cw-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.cw-head-title { color: var(--cw-text); font-size: 15px; font-weight: 600; }
.cw-head-sub { color: var(--cw-muted); font-size: 12px; }

.cw-icon-btn {
  width: 37px; height: 37px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: var(--cw-radius); background: none; color: var(--cw-text-2);
}
.cw-icon-btn:hover { background: var(--cw-bg-soft); color: var(--cw-text); }

.cw-body {
  flex: 1; min-height: 0; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px; background: var(--cw-bg-subtle);
}
.cw-label { margin: 4px 0 -4px; color: var(--cw-text-2); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.cw-foot-note { margin: 0; color: var(--cw-text-2); font-size: 12px; }

/* List card (tools, questions) */
.cw-list { display: flex; flex-direction: column; background: var(--cw-bg); border: 1px solid var(--cw-border); border-radius: var(--cw-radius); }
.cw-row {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 12px;
  border: 0; border-top: 1px solid var(--cw-border); background: none; text-align: left; color: var(--cw-text);
}
.cw-row:first-child { border-top: 0; }
.cw-row:hover { background: var(--cw-bg-soft); }
.cw-row-icon {
  width: 32px; height: 32px; border-radius: var(--cw-radius); display: grid; place-items: center;
  background: color-mix(in srgb, var(--cw-accent) 15%, transparent); color: var(--cw-accent-text);
}
.cw-row-name { flex: 1; min-width: 0; font-weight: 600; }
.cw-row-cmd { color: var(--cw-muted); font-size: 13px; }
.cw-row-q { flex: 1; font-weight: 500; }
.cw-row-arrow { color: var(--cw-muted); }

/* Badges (Paces .badge, soft variant) */
.cw-badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--cw-tone, var(--cw-accent)) 15%, transparent);
  color: color-mix(in srgb, var(--cw-tone, var(--cw-accent)) var(--cw-soft-text-amount), var(--cw-soft-mix));
}
.cw-badge.is-success { --cw-tone: var(--cw-success); }
.cw-badge.is-warning { --cw-tone: var(--cw-warning); }
.cw-badge.is-solid { background: var(--cw-accent); color: var(--cw-on-accent); }

/* Buttons (Paces .btn: 37px, 4px radius, 500) */
.cw-btn {
  min-height: 37px; padding: 0 16px; border-radius: var(--cw-radius);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; font-weight: 500; border: 1px solid transparent;
  background: var(--cw-accent); color: var(--cw-on-accent);
}
.cw-btn:hover { background: color-mix(in srgb, var(--cw-accent) 85%, #000000); }
.cw-btn.is-outline { background: var(--cw-bg); color: var(--cw-text); border-color: var(--cw-border); }
.cw-btn.is-outline:hover { border-color: var(--cw-border-strong); background: var(--cw-bg); }
.cw-btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* New tool card */
.cw-new {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: var(--cw-radius);
  background: color-mix(in srgb, var(--cw-accent) 10%, var(--cw-bg));
  border: 1px solid color-mix(in srgb, var(--cw-accent) 35%, var(--cw-bg));
}
.cw-new-title { display: flex; align-items: center; gap: 8px; color: var(--cw-text); font-weight: 600; }
.cw-new p { margin: 0; color: var(--cw-text-2); }
.cw-new .cw-btn { align-self: flex-start; }

/* Conversation */
.cw-msg { max-width: 88%; padding: 8px 12px; border-radius: var(--cw-radius); }
.cw-msg.is-user { align-self: flex-end; background: var(--cw-accent); color: var(--cw-on-accent); font-weight: 500; }
.cw-msg.is-bot { align-self: flex-start; background: var(--cw-bg); border: 1px solid var(--cw-border); color: var(--cw-text); display: flex; flex-direction: column; gap: 8px; }
.cw-msg p { margin: 0; }
.cw-choices { display: flex; flex-wrap: wrap; gap: 6px; }
.cw-meta { margin: -4px 0 0; color: var(--cw-text-2); font-size: 12px; }

/* Tool result card */
.cw-result { align-self: stretch; max-width: none; padding: 12px 14px; gap: 10px; }
.cw-result-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cw-result-head a { color: var(--cw-accent-text); font-size: 15px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.cw-result-head a:hover { text-decoration: underline; }
.cw-result-head a svg { width: 14px; height: 14px; }
.cw-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; margin: 0; }
.cw-grid div { display: flex; justify-content: space-between; gap: 6px; }
.cw-grid dt { color: var(--cw-muted); }
.cw-grid dd { margin: 0; color: var(--cw-text); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.cw-flag svg { width: 15px; height: 15px; color: color-mix(in srgb, var(--cw-danger) 85%, var(--cw-soft-mix)); }
.cw-note { margin: 0; color: var(--cw-muted); font-size: 13px; }

/* Composer + "/" list */
.cw-compose { position: relative; display: flex; align-items: center; gap: 8px; padding: 12px; border-top: 1px solid var(--cw-border); background: var(--cw-bg); }
.cw-input {
  flex: 1; min-width: 0; height: 37px; padding: 0 12px;
  border: 1px solid var(--cw-border); border-radius: var(--cw-radius); background: var(--cw-bg); color: var(--cw-text);
  font-size: 14px; outline: 0;
}
.cw-input::placeholder { color: var(--cw-muted); }
.cw-input:hover, .cw-input:focus { border-color: var(--cw-border-strong); }
.cw-send { width: 37px; padding: 0; }
.cw-slash {
  position: absolute; left: 12px; right: 12px; bottom: calc(100% - 4px);
  display: flex; flex-direction: column; max-height: 240px; overflow-y: auto;
  background: var(--cw-bg); border: 1px solid var(--cw-border); border-radius: var(--cw-radius); box-shadow: var(--cw-shadow);
}
.cw-slash[hidden] { display: none; }
.cw-slash .cw-row[aria-selected="true"] { background: var(--cw-bg-soft); }
.cw-slash-empty { margin: 0; padding: 12px; color: var(--cw-muted); font-size: 13px; }

@media (prefers-reduced-motion: no-preference) {
  .cw-msg, .cw-new { animation: cw-in 0.18s ease-out both; }
  @keyframes cw-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
