/* 桌伴本機助手 UI */
.tm-mate-fab {
  position: fixed;
  right: 16px;
  bottom: 88px;
  z-index: 15050;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #0ea5e9, #0369a1);
  color: #fff;
  box-shadow: 0 8px 24px rgba(3, 105, 161, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tm-mate-fab:hover { transform: translateY(-2px) scale(1.04); }
.tm-mate-fab:focus-visible { outline: 2px solid #38bdf8; outline-offset: 3px; }
.tm-mate-fab .icon-svg,
.tm-mate-fab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; }

.tm-mate-panel {
  position: fixed;
  right: 16px;
  bottom: 152px;
  z-index: 15060;
  width: min(380px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 180px));
  display: none;
  flex-direction: column;
  background: var(--card-bg, #fff);
  color: var(--text-main, #0f172a);
  border: 1px solid var(--border-soft, #e2e8f0);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
  overflow: hidden;
}
.tm-mate-panel.is-open { display: flex; }

.tm-mate-panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(120deg, #0ea5e9, #0284c7);
  color: #fff;
}
.tm-mate-panel__head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  flex: 1;
  line-height: 1.3;
}
.tm-mate-panel__head .tm-mate-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  opacity: 0.92;
}
.tm-mate-panel__head .tm-mate-llm-status {
  display: block;
  font-size: 10px;
  font-weight: 600;
  margin-top: 2px;
  opacity: 0.88;
}
.tm-mate-panel__head button {
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tm-mate-panel__head button svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

.tm-mate-panel__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft, #e2e8f0);
  background: var(--bg-surface, #f8fafc);
}
.tm-mate-chip {
  border: 1px solid var(--border-soft, #cbd5e1);
  background: var(--card-bg, #fff);
  color: var(--color-brand, #0369a1);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.tm-mate-chip:hover { background: var(--info-bg, #e0f2fe); }

.tm-mate-panel__log {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-main, #f1f5f9);
}
.tm-mate-msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.tm-mate-msg--bot {
  align-self: flex-start;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border-soft, #e2e8f0);
  color: var(--text-main, #0f172a);
}
.tm-mate-msg--user {
  align-self: flex-end;
  background: #0ea5e9;
  color: #fff;
  border: none;
}
.tm-mate-msg a { color: var(--color-brand, #0369a1); font-weight: 700; }
.tm-mate-msg--user a { color: #e0f2fe; }

.tm-mate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.tm-mate-action {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--info-border, #7dd3fc);
  background: var(--info-bg, #e0f2fe);
  color: var(--info-text, #0369a1) !important;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none !important;
}
.tm-mate-action:hover { filter: brightness(1.08); }

.tm-mate-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-soft, #e2e8f0);
}
.tm-mate-follow {
  border: 1px solid var(--border-soft, #cbd5e1);
  background: var(--bg-surface, #f8fafc);
  color: var(--text-main, #334155);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.tm-mate-follow:hover { background: var(--info-bg, #e0f2fe); border-color: var(--info-border, #7dd3fc); color: var(--info-text, #0369a1); }

.tm-mate-msg--status {
  opacity: 0.92;
  font-size: 12px;
  color: var(--text-muted, #64748b);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tm-mate-dots {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #0ea5e9;
  display: inline-block;
  animation: tm-mate-pulse 1s ease-in-out infinite;
}
@keyframes tm-mate-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

.tm-mate-upload {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-soft, #cbd5e1);
  background: var(--bg-surface, #f8fafc);
  color: var(--color-brand, #0369a1);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tm-mate-upload:hover { background: var(--info-bg, #e0f2fe); }
.tm-mate-upload-preview {
  display: block;
  margin-top: 8px;
  max-width: 160px;
  max-height: 160px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(255,255,255,0.35);
}

.tm-mate-panel__foot {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border-soft, #e2e8f0);
  background: var(--card-bg, #fff);
  align-items: flex-end;
}
.tm-mate-panel__foot textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  resize: vertical;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft, #cbd5e1);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  background: var(--bg-surface, #fff);
  color: var(--text-main, #0f172a);
}
.tm-mate-panel__foot input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft, #cbd5e1);
  font-size: 14px;
  background: var(--bg-surface, #fff);
  color: var(--text-main, #0f172a);
}
.tm-mate-panel__foot button.tm-mate-send {
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  background: #0284c7;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

/* 獨立頁 */
.tm-mate-page {
  min-height: 100vh;
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background:
    radial-gradient(900px 400px at 10% -10%, #bae6fd 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 0%, #e0f2fe 0%, transparent 50%),
    #f8fafc;
  color: #0f172a;
}
.tm-mate-page__wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
.tm-mate-page__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.tm-mate-page__brand img { width: 40px; height: 40px; border-radius: 10px; }
.tm-mate-page__brand h1 { margin: 0; font-size: 22px; }
.tm-mate-page__brand p { margin: 2px 0 0; font-size: 13px; color: #64748b; }
.tm-mate-page .tm-mate-panel {
  position: relative;
  right: auto;
  bottom: auto;
  width: 100%;
  height: min(70vh, 640px);
  display: flex;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
}
.tm-mate-teach {
  margin-top: 18px;
  padding: 16px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid #e2e8f0;
}
.tm-mate-teach h3 { margin: 0 0 8px; font-size: 15px; }
.tm-mate-teach textarea,
.tm-mate-teach input {
  width: 100%;
  box-sizing: border-box;
  margin: 6px 0;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  font-size: 14px;
}
.tm-mate-teach textarea { min-height: 88px; resize: vertical; }
.tm-mate-teach .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.tm-mate-teach button {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: #0284c7;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.tm-mate-teach button.secondary { background: #64748b; }

@media (max-width: 640px) {
  .tm-mate-fab { bottom: 76px; right: 12px; }
  .tm-mate-panel {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 140px;
    height: min(62vh, 520px);
  }
}
