/*
 * Mise 共用样式：widget（注入 shadow DOM）和全屏页面（<link>）共用这一份。
 * 改这里两边同时生效。各自的布局（宽度、高度、展开收起）写在各自文件里。
 *
 * 配色用 token。底色/文字色由需要自己背景的容器应用（全屏页面 body、悬浮面板）；
 * 内联 widget 没有背景，继承宿主页面的文字色，其余颜色都是半透明中性灰，
 * 在浅色和深色页面上都成立。
 */

:root, :host {
  --mise-bg: #fbfaf8;
  --mise-fg: #1d1d1f;
  --mise-border: rgba(127, 127, 127, .35);
  --mise-border-focus: rgba(127, 127, 127, .75);
  --mise-line: rgba(127, 127, 127, .2);
  --mise-fill: rgba(127, 127, 127, .12);
  --mise-fill-hover: rgba(127, 127, 127, .2);
  --mise-bubble: #007aff;      /* 访客消息：iMessage 蓝，深色模式下也不变 */
  --mise-bubble-fg: #fff;
  --mise-radius: 12px;
  --mise-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root, :host {
    --mise-bg: #161616;
    --mise-fg: #ececec;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- 输入框 ---------- */

.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 6px 8px 6px 18px;
  border: 1px solid var(--mise-border);
  border-radius: var(--mise-radius);
  transition: border-color .15s;
}
.bar:focus-within { border-color: var(--mise-border-focus); }
.bar input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 17px;
  line-height: 1.5;
  padding: 8px 0;
  text-overflow: ellipsis; /* 窄屏放不下 placeholder 时以 … 结尾 */
}
.bar input::placeholder { color: inherit; opacity: .5; }

.send {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  opacity: .55;
  transition: opacity .15s, background .15s;
}
.send:hover:not(:disabled) { opacity: 1; background: var(--mise-fill); }
.send:disabled { opacity: .25; cursor: default; }

.close, .expand {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: none;
  opacity: .55;
  transition: opacity .15s, background .15s;
}
.close:hover, .expand:hover { opacity: 1; background: var(--mise-fill); }

/* 展开到全屏页面：和 × 同样大小、同样颜色；提示文字出现时按钮变宽 */
.expand { width: auto; min-width: 32px; gap: 4px; padding: 0 7px; grid-auto-flow: column; }
.expand-label { font-size: 12px; white-space: nowrap; }

/* widget 容器下方的「Open Mise in a new page」：小字、浅色，不抢注意力 */
.newpage {
  display: block;
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  opacity: .5;
  text-decoration: none;
  transition: opacity .15s;
}
.newpage:hover { opacity: .85; text-decoration: underline; }
.newpage:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; opacity: .85; }

.send:focus-visible, .chip:focus-visible, .close:focus-visible, .expand:focus-visible, .bubble:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* ---------- 建议问题 ---------- */

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.chip {
  border: 0;
  border-radius: 999px;
  background: var(--mise-fill);
  font-size: 13px;
  line-height: 1.25;
  padding: 6px 11px;
  opacity: .85;
  transition: opacity .15s, background .15s;
}
.chip:hover { opacity: 1; background: var(--mise-fill-hover); }

/* ---------- 消息 ---------- */

.log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  font-size: 15px;
  line-height: 1.55;
}
.msg { max-width: 88%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  background: var(--mise-bubble);
  color: var(--mise-bubble-fg);
  border-radius: var(--mise-radius);
  padding: 8px 12px;
}
.msg.bot { align-self: flex-start; }

.typing { display: flex; gap: 4px; padding: 6px 0; }
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .3;
  animation: mise-blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes mise-blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: .7; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; } }

/* ---------- 手机端 ---------- */

@media (max-width: 480px) {
  .bar { padding-left: 14px; }
  .bar input { font-size: 16px; } /* iOS 聚焦时不自动缩放的下限 */
}
