/* ====================================================================
   ManyWe Agent-Facing Surface — styles.css
   Renders MCP tool responses as chat-bubble UI inside host environments.
   Light + dark themes; all tokens derived from ../../colors_and_type.css
   ==================================================================== */

:root {
  /* Re-declare the brand tokens locally so this kit can stand alone.
     Keep values in sync with /colors_and_type.css. */
  --mw-brand-green:      #4CAF50;
  --mw-brand-green-dark: #3d8b40;
  --mw-brand-teal:       #26A69A;
  --mw-sky-blue:         #4A9BD9;
  --mw-sea-green:        #6BC5B8;
  --mw-gradient-hero:    linear-gradient(135deg, #4A9BD9, #6BC5B8);

  /* Light theme (default) */
  --as-bg:        #f7faf9;
  --as-surface:   #ffffff;
  --as-surface-2: #eef5f3;
  --as-ink:       #1a2e28;
  --as-muted:     #5d6e66;
  --as-line:      #d4e0dc;
  --as-line-soft: #e6ede9;
  --as-user-bubble: #eef5f3;
  --as-host-bubble: #ffffff;
  --as-system-bubble: #fff8e6;
  --as-system-ink: #8a5a00;
  --as-system-border: #f1d88a;
  --as-shadow-sm: 0 2px 8px rgba(26, 46, 40, 0.06);
  --as-shadow-md: 0 8px 24px rgba(26, 46, 40, 0.08);
  --as-shadow-lg: 0 20px 48px rgba(26, 46, 40, 0.12);
  --as-soon:      #e67e22;
  --as-danger:    #dc2626;
  --as-chip-bg:   #eef5f3;
  --as-chip-ink:  #1a4a3a;

  --as-radius-sm: 8px;
  --as-radius-md: 12px;
  --as-radius-lg: 16px;
  --as-radius-xl: 24px;
  --as-radius-pill: 9999px;

  --as-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
             "Helvetica Neue", Arial, sans-serif;
  --as-font-mono: "SFMono-Regular", "JetBrains Mono", "IBM Plex Mono",
                  "Cascadia Code", Menlo, monospace;
}

[data-theme="dark"] {
  --as-bg:        #0f1a16;
  --as-surface:   #162620;
  --as-surface-2: #1d3028;
  --as-ink:       #e8f1ec;
  --as-muted:     #8fa69b;
  --as-line:      #24372e;
  --as-line-soft: #1a2a22;
  --as-user-bubble: #1d3028;
  --as-host-bubble: #162620;
  --as-system-bubble: #2a2212;
  --as-system-ink: #f1c242;
  --as-system-border: #55421a;
  --as-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --as-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --as-shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
  --as-chip-bg:   #1d3028;
  --as-chip-ink:  #9fd1be;
}

/* Root container — every preview tile opts in with `.as` */
.as {
  font-family: var(--as-font);
  color: var(--as-ink);
  background: var(--as-bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-size: 14.5px;
}
.as *, .as *::before, .as *::after { box-sizing: border-box; }

/* ============================================================
   Chat bubble shells
   ============================================================ */
.as-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}
.as-row {
  display: flex;
  gap: 10px;
  max-width: 100%;
}
.as-row.user { justify-content: flex-end; }
.as-row.host { justify-content: flex-start; }
.as-row.system { justify-content: center; }

.as-avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  color: #fff;
}
.as-avatar.host {
  background: linear-gradient(180deg,#52b855 0%,#43a046 100%);
}
.as-avatar.user {
  background: var(--as-surface-2);
  color: var(--as-ink);
  border: 1px solid var(--as-line);
}

.as-bubble {
  border-radius: 14px;
  padding: 12px 14px;
  max-width: 520px;
  box-shadow: var(--as-shadow-sm);
  border: 1px solid var(--as-line);
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.as-bubble.host {
  background: var(--as-host-bubble);
  border-top-left-radius: 4px;
}
.as-bubble.user {
  background: var(--as-user-bubble);
  border-top-right-radius: 4px;
  border-color: var(--as-line-soft);
}
.as-bubble.system {
  background: var(--as-system-bubble);
  color: var(--as-system-ink);
  border-color: var(--as-system-border);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 10px;
  max-width: 80%;
  text-align: center;
  box-shadow: none;
}
.as-bubble p { margin: 0; }
.as-bubble p + * { margin-top: 8px; }

/* ============================================================
   Tool-result card (inside a host bubble)
   ============================================================ */
.as-tool {
  background: var(--as-surface);
  border: 1px solid var(--as-line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--as-shadow-sm);
  margin-top: 6px;
}
.as-tool-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--as-line-soft);
}
.as-tool-header .as-tile {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: linear-gradient(180deg,#52b855 0%,#43a046 100%);
  box-shadow: 0 2px 6px rgba(76,175,80,0.28), inset 0 1px 0 rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.as-tool-header .as-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
}
.as-tool-header .as-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--as-chip-bg);
  color: var(--as-chip-ink);
  font-weight: 600;
}
.as-tool-body {
  padding: 12px 14px 14px;
  font-size: 14px;
}
.as-tool-meta {
  padding: 8px 14px;
  background: var(--as-surface-2);
  border-top: 1px solid var(--as-line-soft);
  font-size: 12px;
  color: var(--as-muted);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.as-tool-meta span { display: inline-flex; align-items: center; gap: 5px; }

.as-row-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--as-line-soft);
}

/* Buttons */
.as-btn {
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--as-font);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
  border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 6px;
}
.as-btn:active { transform: translateY(1px); }
.as-btn.primary {
  background: var(--mw-brand-green);
  color: #fff;
  box-shadow: 0 4px 12px rgba(76,175,80,0.25);
}
.as-btn.primary:hover { background: var(--mw-brand-green-dark); }
.as-btn.ghost {
  background: transparent;
  border-color: var(--as-line);
  color: var(--as-ink);
}
.as-btn.ghost:hover { background: var(--as-surface-2); }
.as-btn.danger {
  background: transparent;
  border-color: var(--as-line);
  color: var(--as-danger);
}
.as-btn.danger:hover { background: rgba(220,38,38,0.08); }

/* ============================================================
   Specialized components
   ============================================================ */

/* Invite link row */
.as-invite-link {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--as-surface-2);
  border-radius: 8px;
  font-family: var(--as-font-mono);
  font-size: 13px;
  color: var(--as-ink);
  border: 1px solid var(--as-line-soft);
}
.as-invite-link .url { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-copy-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--as-muted);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  transition: color 0.2s, background 0.2s;
}
.as-copy-btn:hover { color: var(--mw-brand-teal); background: var(--as-surface); }

/* QR tile */
.as-qr {
  display: flex; gap: 14px; align-items: center;
  padding: 4px 0;
}
.as-qr .qr-art {
  width: 112px; height: 112px;
  background: #fff;
  border: 1px solid var(--as-line);
  border-radius: 8px;
  padding: 8px;
  flex-shrink: 0;
}
.as-qr .qr-info { flex: 1; font-size: 13px; color: var(--as-ink); }
.as-qr .qr-info .u { font-family: var(--as-font-mono); font-size: 12px; color: var(--as-muted); margin-top: 4px; word-break: break-all; }

/* Pairing code */
.as-paircode {
  text-align: center;
  padding: 6px 0 4px;
}
.as-paircode .digits {
  font-family: var(--as-font-mono);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 10px;
  color: var(--as-ink);
  margin-left: 10px; /* optical correction for letter-spacing */
}
.as-paircode .timer {
  font-size: 13px;
  color: var(--as-muted);
  margin-top: 6px;
}
.as-paircode .timer strong { color: var(--mw-brand-teal); font-variant-numeric: tabular-nums; }

/* Handshake / pairing-success */
.as-handshake {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 10px 0;
}
.as-handshake .node {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.as-handshake .av {
  width: 46px; height: 46px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700;
  background: var(--mw-gradient-hero);
  box-shadow: 0 4px 14px rgba(74,155,217,0.28);
}
.as-handshake .av.me {
  background: linear-gradient(180deg,#52b855 0%,#43a046 100%);
  box-shadow: 0 4px 14px rgba(76,175,80,0.28);
}
.as-handshake .nm { font-size: 12px; color: var(--as-muted); }
.as-handshake .link {
  width: 40px; height: 2px;
  background: repeating-linear-gradient(90deg, var(--mw-brand-teal) 0 6px, transparent 6px 10px);
  align-self: flex-start;
  margin-top: 22px;
}

/* Contact row */
.as-contact {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background 0.15s;
}
.as-contact:hover { background: var(--as-surface-2); }
.as-contact + .as-contact { border-top: 1px solid var(--as-line-soft); }
.as-contact .ca {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--as-surface-2);
  color: var(--as-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  border: 1px solid var(--as-line);
}
.as-contact .ca.g { background: linear-gradient(180deg,#52b855 0%,#43a046 100%); color: #fff; border: none; }
.as-contact .ca.b { background: var(--mw-gradient-hero); color: #fff; border: none; }
.as-contact .body { flex: 1; min-width: 0; }
.as-contact .name { font-weight: 600; font-size: 14px; }
.as-contact .alias { color: var(--as-muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.as-contact .tags {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px;
}
.as-contact .tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--as-chip-bg);
  color: var(--as-chip-ink);
  font-weight: 500;
}

/* Inbox row */
.as-inbox-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: default;
}
.as-inbox-row + .as-inbox-row { border-top: 1px solid var(--as-line-soft); }
.as-inbox-row .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--mw-brand-green);
  margin-top: 6px; flex-shrink: 0;
}
.as-inbox-row.read .dot { background: transparent; }
.as-inbox-row .body { flex: 1; min-width: 0; }
.as-inbox-row .head { display: flex; justify-content: space-between; gap: 10px; }
.as-inbox-row .nm { font-weight: 600; font-size: 14px; }
.as-inbox-row .ts { color: var(--as-muted); font-size: 12px; flex-shrink: 0; }
.as-inbox-row .prev {
  color: var(--as-muted); font-size: 13px;
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 340px;
}

/* Onboarding stepper */
.as-stepper {
  display: flex;
  gap: 0;
  padding: 4px 0;
}
.as-step {
  flex: 1;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--as-muted);
  position: relative;
}
.as-step + .as-step::before {
  content: "";
  position: absolute;
  left: -8px; right: calc(100% - 0px);
  top: 11px; height: 2px;
  background: var(--as-line);
  width: 16px;
}
.as-step .dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--as-surface-2);
  border: 1.5px solid var(--as-line);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: var(--as-muted);
}
.as-step.done .dot {
  background: var(--mw-brand-green);
  border-color: var(--mw-brand-green);
  color: #fff;
}
.as-step.current .dot {
  background: #fff;
  border-color: var(--mw-brand-green);
  color: var(--mw-brand-green);
  box-shadow: 0 0 0 4px rgba(76,175,80,0.15);
}
.as-step.done, .as-step.current { color: var(--as-ink); font-weight: 500; }
[data-theme="dark"] .as-step.current .dot { background: var(--as-surface); }

/* Upgrade card */
.as-upgrade-line {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--as-font-mono);
  font-size: 13px;
}
.as-upgrade-line .from { color: var(--as-muted); text-decoration: line-through; }
.as-upgrade-line .arrow { color: var(--as-muted); }
.as-upgrade-line .to { color: var(--mw-brand-green); font-weight: 700; }

.as-signed-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--as-chip-bg);
  color: var(--as-chip-ink);
  font-weight: 600;
  margin-top: 6px;
}

/* Chat-first footnote */
.as-chat-first-note {
  font-size: 11.5px;
  color: var(--as-muted);
  padding: 6px 14px;
  display: flex; align-items: center; gap: 6px;
  background: var(--as-surface-2);
  border-top: 1px solid var(--as-line-soft);
  font-style: italic;
}

/* Typed input preview (the box at the bottom of host frames) */
.as-composer {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--as-line);
  border-radius: 12px;
  background: var(--as-surface);
  margin: 8px 20px 16px;
}
.as-composer input {
  flex: 1;
  border: none; outline: none; background: transparent;
  font-family: var(--as-font);
  font-size: 14px;
  color: var(--as-ink);
}
.as-composer input::placeholder { color: var(--as-muted); }
.as-composer .send {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--mw-brand-green);
  color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ============================================================
   Host frames — chrome around the thread
   ============================================================ */

/* Shared */
.as-host {
  background: var(--as-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--as-shadow-md);
  border: 1px solid var(--as-line);
  display: flex; flex-direction: column;
}

/* Claude-Desktop-like (neutral) */
.as-host.desktop { width: 720px; height: 560px; }
.as-host.desktop .chrome {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--as-surface);
  border-bottom: 1px solid var(--as-line);
}
.as-host.desktop .lights { display: flex; gap: 6px; }
.as-host.desktop .lights span {
  width: 11px; height: 11px; border-radius: 50%; display: block;
}
.as-host.desktop .lights .r { background: #ff5f57; }
.as-host.desktop .lights .y { background: #febc2e; }
.as-host.desktop .lights .g { background: #28c840; }
.as-host.desktop .app-title {
  font-size: 13px; color: var(--as-muted); font-weight: 500;
  margin-left: 6px;
}
.as-host.desktop .main {
  display: grid;
  grid-template-columns: 180px 1fr;
  flex: 1; min-height: 0;
}
.as-host.desktop .sidebar {
  background: var(--as-surface-2);
  border-right: 1px solid var(--as-line);
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px;
}
.as-host.desktop .sidebar .s-head {
  font-size: 11px; text-transform: uppercase;
  color: var(--as-muted); letter-spacing: 0.08em;
  padding: 8px 8px 4px; font-weight: 700;
}
.as-host.desktop .sidebar .s-item {
  padding: 7px 9px; border-radius: 8px; color: var(--as-ink);
  display: flex; align-items: center; gap: 8px;
  cursor: default;
}
.as-host.desktop .sidebar .s-item.active { background: var(--as-surface); box-shadow: var(--as-shadow-sm); font-weight: 600; }
.as-host.desktop .sidebar .s-item .mini {
  width: 18px; height: 18px; border-radius: 4px;
  background: linear-gradient(180deg,#52b855 0%,#43a046 100%);
  flex-shrink: 0;
}
.as-host.desktop .content {
  display: flex; flex-direction: column; min-height: 0;
  overflow: hidden;
}
.as-host.desktop .content .thread-wrap {
  flex: 1; overflow-y: auto;
}

/* IM (OpenClaw-in-QQ/Feishu-like) */
.as-host.im { width: 420px; height: 640px; }
.as-host.im .chrome {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--as-surface);
  border-bottom: 1px solid var(--as-line);
}
.as-host.im .chrome .back { color: var(--as-muted); font-size: 16px; }
.as-host.im .chrome .title { font-weight: 700; font-size: 15px; }
.as-host.im .chrome .sub { font-size: 11px; color: var(--as-muted); }
.as-host.im .chrome .menu { margin-left: auto; color: var(--as-muted); }
.as-host.im .thread-wrap { flex: 1; overflow-y: auto; }

/* Scrollbar styling */
.as-host .thread-wrap::-webkit-scrollbar { width: 8px; }
.as-host .thread-wrap::-webkit-scrollbar-thumb { background: var(--as-line); border-radius: 4px; }
.as-host .thread-wrap::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   Design-canvas host: give artboards the correct bg tone.
   ============================================================ */
.as-canvas-light { background: #f7faf9; }
.as-canvas-dark  { background: #0f1a16; }

/* Icon-tile from Icons.jsx sits naturally on both; small tweak for dark */
[data-theme="dark"] .icon-tile {
  box-shadow: 0 2px 6px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.14);
}
