/* ============================================================
   WEBCHAT THEME — WorkOne AI

   Design: Light pastel gradient, white card, minimal
   Palette: Teal accent, coral send button
   ============================================================ */


/* === 1. Color System — Force light === */

:root,
:root[data-theme=dark],
:root[data-theme=light] {
  --bg: #ffffff;
  --bg-accent: #f8f9fa;
  --bg-elevated: #ffffff;
  --bg-hover: #f0f1f3;
  --bg-muted: #f0f1f3;
  --bg-content: #ffffff;
  --card: #f8f9fa;
  --card-foreground: #3d3d3d;
  --card-highlight: transparent;
  --panel: #ffffff;
  --panel-strong: #f8f9fa;
  --panel-hover: #f0f1f3;
  --chrome: rgba(255,255,255,0.96);
  --chrome-strong: rgba(255,255,255,0.98);
  --popover: #ffffff;
  --popover-foreground: #3d3d3d;
  --secondary: #f0f1f3;
  --secondary-foreground: #3d3d3d;

  --text: #666;
  --text-strong: #3d3d3d;
  --chat-text: #444;
  --muted: #999;
  --muted-strong: #bbb;
  --muted-foreground: #999;

  --border: rgba(0,0,0,0.06);
  --border-strong: rgba(0,0,0,0.1);
  --border-hover: rgba(0,0,0,0.15);
  --input: rgba(0,0,0,0.04);

  --accent: #5bbfb5;
  --accent-hover: #4db0a6;
  --accent-muted: #5bbfb5;
  --accent-subtle: rgba(91,191,181,0.08);
  --accent-foreground: #ffffff;
  --accent-glow: rgba(91,191,181,0.06);
  --ring: #5bbfb5;
  --primary: #5bbfb5;
  --primary-foreground: #ffffff;

  --accent-2: #34b88c;
  --accent-2-muted: rgba(52,184,140,0.7);
  --accent-2-subtle: rgba(52,184,140,0.08);
  --ok: #34b88c;
  --danger: #e5534b;
  --destructive: #e5534b;
  --destructive-foreground: #ffffff;
  --warn: #d4952a;
  --warn-subtle: rgba(212,149,42,0.08);
  --info: #5bbfb5;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 20px rgba(0,0,0,0.08);
  --shadow-xl: 0 12px 32px rgba(0,0,0,0.1);
  --shadow-glow: none;
  --focus: rgba(91,191,181,0.15);
  --focus-ring: 0 0 0 2px #fff, 0 0 0 3.5px #5bbfb5;
  --focus-glow: 0 0 0 2px #fff, 0 0 0 3.5px #5bbfb5;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  --radius: 8px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 0.1s;
  --duration-normal: 0.15s;

  /* Webchat-specific */
  --wc-teal: #5bbfb5;
  --wc-coral: #f4845f;

  color-scheme: light;
}


/* === 2. Document Level — Gradient background === */

body {
  margin: 0 !important;
  padding: 0 !important;
  background: linear-gradient(160deg, #d4f0ef 0%, #c8e6e4 30%, #d8ddf0 70%, #e6dff5 100%) !important;
  min-height: 100vh !important;
}

openclaw-app {
  background: transparent !important;
}


/* === 3. Custom Header — Search + icons === */

#wc-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  font-family: var(--font-body);
  background: #ffffff;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.wc-h-title {
  font-size: 16px;
  font-weight: 700;
  color: #3d3d3d;
}

.wc-new-session {
  background: transparent;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 9999px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.15s ease;
}

.wc-new-session:hover {
  background: #f0f1f3;
  border-color: rgba(0,0,0,0.15);
  color: #3d3d3d;
}


/* === 4. Layout — White rounded card === */

.topbar {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

.nav {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.shell {
  display: grid !important;
  grid-template-columns: 1fr !important;
  grid-template-rows: 1fr !important;
  grid-template-areas: "content" !important;
  background: #ffffff !important;
  border-radius: 0 !important;
  margin: 0 !important;
  height: 100vh !important;
  min-height: 100vh !important;
  max-height: 100vh !important;
  box-shadow: none !important;
  overflow: hidden !important;
  padding: 44px 0 0 0 !important;
  box-sizing: border-box !important;
}

.content {
  grid-area: content !important;
  padding: 0 !important;
  gap: 0 !important;
  background: #ffffff !important;
}

.content--chat {
  padding: 0 !important;
}

.content-header {
  display: none !important;
}

.chat-focus-exit {
  display: none !important;
}

/* Hide original new session button — replaced by avatar */
.chat-compose__actions .btn:not(.primary):not(.danger) {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  border: 0 !important;
  padding: 0 !important;
  margin: -1px !important;
}


/* === 5. Tab Bar (injected via JS) === */

.wc-tabs {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 6px;
}

.wc-tab {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: #c0c0c0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
  font-family: var(--font-body);
}

.wc-tab:hover {
  background: #f0f1f3;
  color: #888;
}

.wc-tab.active {
  background: #2d2d2d;
  color: #ffffff;
}

.wc-tab svg {
  display: block;
}


/* === 6. Welcome State (injected via JS) === */

.wc-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
  gap: 8px;
  pointer-events: none;
  user-select: none;
}

.wc-welcome-title {
  font-size: 22px;
  font-weight: 600;
  color: #3d3d3d;
  font-family: var(--font-body);
}

.wc-welcome-sub {
  font-size: 15px;
  color: var(--wc-teal);
  font-family: var(--font-body);
}


/* === 7. Chat Thread & Bubbles === */

.chat-thread {
  max-width: 100%;
  margin: 0;
  padding: 4px 12px 8px;
  width: 100%;
  box-sizing: border-box;
}

.chat-group {
  margin-bottom: 4px;
}

.chat-bubble {
  border-radius: 14px !important;
  line-height: 1.6 !important;
  font-size: 14px !important;
}

.chat-group.user .chat-bubble {
  background: rgba(91,191,181,0.08) !important;
  border: none !important;
}

.chat-group.assistant .chat-bubble,
.chat-group.other .chat-bubble {
  background: #f8f9fa !important;
  border: 1px solid rgba(0,0,0,0.04) !important;
}

.chat-sender-name {
  font-size: 12px !important;
  font-weight: 600 !important;
  color: #3d3d3d !important;
  letter-spacing: -0.01em !important;
}

/* Replace "Claw" name with "AI" for non-user messages */
.chat-group:not(.user) .chat-sender-name {
  font-size: 0 !important;
  line-height: 0 !important;
}

.chat-group:not(.user) .chat-sender-name::after {
  content: "AI" !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  color: #3d3d3d !important;
  line-height: normal !important;
}

.chat-group-timestamp {
  font-size: 11px !important;
  color: #999 !important;
  font-weight: 400 !important;
}

.chat-avatar {
  width: 28px !important;
  height: 28px !important;
  border-radius: 50% !important;
  font-size: 13px !important;
}

/* Replace crab avatar with "AI" for non-user messages */
.chat-group:not(.user) .chat-avatar {
  font-size: 0 !important;
  background: var(--wc-teal) !important;
  color: white !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  overflow: hidden !important;
}

.chat-group:not(.user) .chat-avatar::after {
  content: "AI" !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  color: white !important;
  letter-spacing: -0.02em !important;
}

.chat-text {
  font-size: 14px !important;
  line-height: 1.65 !important;
  color: #444 !important;
}


/* === 8. Tool Cards === */

.chat-tool-card {
  background: #f8f9fa !important;
  border: 1px solid rgba(0,0,0,0.05) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
  position: relative !important;
  overflow: hidden !important;
}

.chat-tool-card::before {
  content: '' !important;
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  bottom: 0 !important;
  width: 3px !important;
  background: var(--wc-teal) !important;
}

.chat-tool-card__title {
  font-size: 13px !important;
  font-weight: 600 !important;
  color: #3d3d3d !important;
}

.chat-tool-card__status-text {
  font-size: 11px !important;
  color: var(--wc-teal) !important;
}

.chat-tool-card__preview {
  font-size: 12px !important;
  line-height: 1.5 !important;
  opacity: 0.6 !important;
}


/* === 9. Streaming Cursor === */

.streaming-cursor::after {
  content: '\2502' !important;
  animation: wc-blink 1s steps(2) infinite !important;
  color: var(--wc-teal) !important;
  margin-left: 1px;
}

@keyframes wc-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}


/* === 10. Compose Area — ChatGPT-style vertical layout === */

.chat-compose,
.shell--chat .chat-compose,
.shell--chat-focus .chat-compose {
  padding: 4px 12px 8px !important;
  padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
  background: #ffffff !important;
  gap: 0 !important;
  margin-top: 0 !important;
  bottom: 0 !important;
  border-radius: 0 !important;
}

.chat-compose__row {
  max-width: 100%;
  margin: 0;
  width: 100%;
  gap: 0 !important;
  background: #f0f1f3 !important;
  border: 1px solid rgba(0,0,0,0.08) !important;
  border-radius: 16px !important;
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  align-items: stretch !important;
  padding: 0 !important;
  transition: border-color 0.15s ease;
  overflow: hidden !important;
}

.chat-compose__row:focus-within {
  border-color: rgba(0,0,0,0.18) !important;
  box-shadow: none !important;
}

.chat-compose__field {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  display: flex !important;
  align-items: stretch !important;
  gap: 0 !important;
  width: 100% !important;
}

.chat-compose__field textarea,
.chat-compose .chat-compose__field textarea {
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  outline: none !important;
  resize: none !important;
  min-height: 36px !important;
  height: auto !important;
  max-height: 120px !important;
  width: 100% !important;
  font-family: var(--font-body) !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  color: #3d3d3d !important;
  padding: 12px 14px 6px !important;
}

.chat-compose__field textarea:focus,
.chat-compose .chat-compose__field textarea:focus {
  box-shadow: none !important;
  border: none !important;
  outline: none !important;
}

.chat-compose .chat-compose__field textarea::placeholder {
  color: #bbb !important;
  font-weight: 400 !important;
}

/* Actions: bottom toolbar row */
.chat-compose__actions {
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center !important;
  align-self: stretch !important;
  justify-content: flex-end !important;
  padding: 4px 6px !important;
  gap: 4px !important;
  border-top: 1px solid rgba(0,0,0,0.06) !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

/* Toolbar icons (injected via JS) */
.wc-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
}

.wc-toolbar-btn {
  background: transparent;
  border: none;
  color: #999;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 6px;
  padding: 0;
  transition: color 0.12s ease, background 0.12s ease;
}

.wc-toolbar-btn:hover {
  color: #555;
  background: rgba(0,0,0,0.05);
}

.wc-toolbar-btn svg {
  display: block;
}

/* Send button */
.chat-compose__actions .btn.primary {
  background: #3d3d3d !important;
  color: transparent !important;
  border-radius: 50% !important;
  width: 30px !important;
  height: 30px !important;
  min-width: 30px !important;
  min-height: 30px !important;
  max-height: 30px !important;
  padding: 0 !important;
  font-size: 0 !important;
  line-height: 0 !important;
  text-indent: -9999px !important;
  overflow: hidden !important;
  box-shadow: none !important;
  transition: opacity 0.15s ease !important;
  border: none !important;
  position: relative !important;
  flex-shrink: 0 !important;
}

/* Arrow-up send icon — absolute center */
.chat-compose__actions .btn.primary::after {
  content: '' !important;
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: 16px !important;
  height: 16px !important;
  text-indent: 0 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5'/%3E%3Cpath d='m5 12 7-7 7 7'/%3E%3C/svg%3E") !important;
  background-size: contain !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
}

.chat-compose__actions .btn.primary:hover {
  opacity: 0.7 !important;
}

.chat-compose__actions .btn.primary:disabled {
  background: #ccc !important;
  opacity: 1 !important;
}

.chat-compose__actions .btn.primary:disabled::after {
  opacity: 0.5 !important;
}

/* Hide keyboard hint */
.btn-kbd {
  display: none !important;
}

/* Stop button */
.chat-compose__actions .btn.danger {
  background: #3d3d3d !important;
  color: transparent !important;
  border-radius: 50% !important;
  width: 30px !important;
  height: 30px !important;
  min-width: 30px !important;
  min-height: 30px !important;
  padding: 0 !important;
  font-size: 0 !important;
  line-height: 0 !important;
  text-indent: -9999px !important;
  overflow: hidden !important;
  border: none !important;
  position: relative !important;
  flex-shrink: 0 !important;
}

.chat-compose__actions .btn.danger::after {
  content: '' !important;
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: 14px !important;
  height: 14px !important;
  text-indent: 0 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='14' height='14' x='5' y='5' rx='1'/%3E%3C/svg%3E") !important;
  background-size: contain !important;
  background-repeat: no-repeat !important;
}

.chat-controls {
  max-width: 100%;
  margin: 0;
}


/* === 11. Suggestion Buttons === */

.wc-suggestions {
  display: flex;
  gap: 8px;
  padding: 0 0 4px;
  flex-wrap: wrap;
  max-width: 100%;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

.wc-suggestion-btn {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: var(--radius-full);
  color: #666;
  font-size: 13px;
  padding: 7px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-body);
  white-space: nowrap;
  line-height: 1.3;
}

.wc-suggestion-btn:hover {
  border-color: var(--wc-teal);
  color: var(--wc-teal);
  background: rgba(91,191,181,0.04);
}

.wc-suggestion-btn:active {
  transform: scale(0.97);
}


/* === 12. Prose / Markdown === */

.prose {
  font-size: 14px !important;
  line-height: 1.65 !important;
  color: #444 !important;
}

.prose pre {
  background: #f8f9fa !important;
  border: 1px solid rgba(0,0,0,0.05) !important;
  border-radius: 8px !important;
  font-size: 13px !important;
  box-shadow: none !important;
}

.prose code {
  font-family: var(--mono) !important;
  font-size: 12.5px !important;
}

.prose p code {
  background: rgba(0,0,0,0.04) !important;
  border: 1px solid rgba(0,0,0,0.06) !important;
  border-radius: 4px !important;
  padding: 0.1em 0.35em !important;
  font-size: 12.5px !important;
  color: #3d3d3d !important;
}

.prose a {
  color: var(--wc-teal) !important;
  text-decoration: none !important;
}

.prose a:hover {
  text-decoration: underline !important;
}

.prose blockquote {
  border-left: 2px solid rgba(0,0,0,0.1) !important;
  color: #999 !important;
}

.prose th {
  background: #f8f9fa !important;
  font-size: 12px !important;
  font-weight: 600 !important;
}


/* === 13. Scrollbar === */

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.07);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.14);
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.07) transparent;
}

::selection {
  background: rgba(91,191,181,0.15);
}


/* === 14. Misc === */

.chat-reading-indicator {
  color: var(--wc-teal) !important;
}

.chat-thinking {
  border-color: rgba(0,0,0,0.05) !important;
  background: #f8f9fa !important;
  font-size: 12px !important;
}

body::before {
  display: none !important;
}

.callout {
  border-radius: 10px !important;
  font-size: 13px !important;
}

.btn {
  border-radius: var(--radius-md) !important;
  font-weight: 500 !important;
  letter-spacing: 0 !important;
}


/* === 15. Visual Stability — 스트리밍 중 깜빡임 방지 === */

/* 쉘/그리드 전환 애니메이션 제거 */
.shell,
.shell--chat,
.shell--chat-focus {
  transition: none !important;
}

/* content-header 높이 전환 제거 (레이아웃 시프트 원인) */
.content-header {
  transition: none !important;
  max-height: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

/* 채팅 스레드 레이아웃 격리 — 내부 변경이 외부에 영향 안 줌 */
.chat-thread {
  contain: layout style !important;
  overflow-anchor: auto !important;
}

/* 스트리밍 버블 border 애니메이션을 부드러운 opacity로 교체 */
.chat-bubble.streaming {
  animation: none !important;
  border-color: transparent !important;
}

/* 채팅 그룹 전환 애니메이션 제거 */
.chat-group {
  animation: none !important;
  transition: none !important;
}

/* Lit 컴포넌트 재렌더링 시 레이아웃 시프트 방지 */
.chat-group-messages {
  contain: layout style !important;
}

/* 커서 깜빡임만 유지 (GPU 합성 — opacity만 사용) */
.streaming-cursor::after {
  will-change: opacity !important;
}

/* focus 모드 전환 애니메이션 제거 */
.nav,
.topbar {
  transition: none !important;
}


/* === 16. Responsive === */

@media (max-width: 640px) {
  #wc-header {
    padding: 0 12px;
    height: 50px;
  }

  .shell {
    margin: 0 !important;
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    padding: 44px 0 0 0 !important;
  }

  .chat-thread {
    padding: 4px 10px 8px;
    max-width: 100%;
  }

  .chat-compose__row {
    max-width: 100%;
  }

  .chat-compose {
    padding: 4px 10px 6px !important;
  }

  .chat-bubble {
    font-size: 13.5px !important;
  }

  .wc-welcome-title {
    font-size: 20px;
  }
}

@media (max-width: 400px) {
  .shell {
    margin: 0 !important;
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    padding: 44px 0 0 0 !important;
  }

  .chat-compose {
    padding: 6px 10px 10px !important;
  }

  .wc-h-right {
    gap: 6px;
  }
}
