/* Token Cafe AI Support floating widget */
.tc-ai-root {
  --tc-ai-z: 9200;
  --tc-ai-fab: 56px;
  position: relative;
  z-index: var(--tc-ai-z);
  font-family: var(--sans, "Noto Sans TC", "Segoe UI", system-ui, sans-serif);
  color: var(--text, #D8D2C4);
}

.tc-ai-fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: var(--tc-ai-fab);
  height: var(--tc-ai-fab);
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent, #C8A84E) 55%, transparent);
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.12), transparent 45%),
    linear-gradient(145deg, color-mix(in srgb, var(--accent, #C8A84E) 88%, #1a1520), #8a6d2e);
  color: #0A0E14;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(200, 168, 78, 0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  z-index: calc(var(--tc-ai-z) + 2);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.tc-ai-fab:hover { transform: translateY(-2px) scale(1.03); }
.tc-ai-fab:active { transform: translateY(0) scale(0.98); }
.tc-ai-fab[aria-expanded="true"] {
  background: var(--panel-3, #1A2535);
  color: var(--accent, #C8A84E);
}

.tc-ai-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tc-ai-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
}

.tc-ai-mark svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tc-ai-mark-orbit {
  opacity: 0.94;
}

.tc-ai-mark-core {
  fill: color-mix(in srgb, currentColor 18%, transparent);
}

.tc-ai-mark-ray {
  opacity: 0.58;
}

.tc-ai-mark-dot {
  fill: currentColor;
  stroke: none;
}

/* Account SPA: clear bottom nav */
body.account-spa .tc-ai-fab,
.tc-ai-root[data-surface="account"] .tc-ai-fab {
  bottom: calc(var(--bottom-nav-h, 64px) + 12px + env(safe-area-inset-bottom, 0px));
}

.tc-ai-panel {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(var(--tc-ai-fab) + 28px + env(safe-area-inset-bottom, 0px));
  width: min(400px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 100px));
  display: none;
  flex-direction: column;
  border-radius: 16px;
  border: 1px solid var(--line, #1E2A38);
  background: color-mix(in srgb, var(--bg, #0A0E14) 92%, #111820);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(200, 168, 78, 0.08);
  overflow: hidden;
  z-index: calc(var(--tc-ai-z) + 1);
  backdrop-filter: blur(12px);
}
.tc-ai-root[data-surface="account"] .tc-ai-panel {
  bottom: calc(var(--bottom-nav-h, 64px) + var(--tc-ai-fab) + 20px + env(safe-area-inset-bottom, 0px));
  height: min(520px, calc(100vh - 140px));
}
.tc-ai-panel.is-open { display: flex; }

.tc-ai-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line, #1E2A38);
  background: color-mix(in srgb, var(--panel, #111820) 90%, transparent);
}
.tc-ai-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-bright, #F0EDE6);
  flex: 1;
}
.tc-ai-head .tc-ai-sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted, #8891A0);
  margin-top: 2px;
}
.tc-ai-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent-dim, rgba(200, 168, 78, 0.14));
  color: var(--accent, #C8A84E);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent, #C8A84E) 20%, transparent);
}

.tc-ai-icon .tc-ai-mark {
  width: 22px;
  height: 22px;
}
.tc-ai-head button {
  border: 0;
  background: transparent;
  color: var(--muted, #8891A0);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13px;
}
.tc-ai-head button:hover { background: rgba(255,255,255,0.04); color: var(--text, #D8D2C4); }

.tc-ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 0;
}
.tc-ai-chip {
  border: 1px solid var(--line, #1E2A38);
  background: var(--panel-2, rgba(22, 29, 40, 0.94));
  color: var(--text, #D8D2C4);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
  line-height: 1.3;
}
.tc-ai-chip:hover {
  border-color: color-mix(in srgb, var(--accent, #C8A84E) 50%, transparent);
  color: var(--accent-2, #D4BC6A);
}

.tc-ai-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.tc-ai-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;
}
.tc-ai-msg.user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--accent, #C8A84E) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent, #C8A84E) 28%, transparent);
  color: var(--text-bright, #F0EDE6);
}
.tc-ai-msg.bot {
  align-self: flex-start;
  background: var(--panel-2, rgba(22, 29, 40, 0.94));
  border: 1px solid var(--line, #1E2A38);
}
.tc-ai-msg.bot a {
  color: var(--accent-2, #D4BC6A);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.tc-ai-msg.sys {
  align-self: center;
  max-width: 100%;
  font-size: 12px;
  color: var(--muted, #8891A0);
  background: transparent;
  border: 0;
  padding: 4px 8px;
}
.tc-ai-msg .tc-ai-md p { margin: 0 0 0.5em; }
.tc-ai-msg .tc-ai-md p:last-child { margin-bottom: 0; }
.tc-ai-msg .tc-ai-md ul, .tc-ai-msg .tc-ai-md ol { margin: 0.3em 0; padding-left: 1.2em; }
.tc-ai-msg .tc-ai-md code {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 0.9em;
  background: rgba(0,0,0,0.25);
  padding: 1px 4px;
  border-radius: 4px;
}
.tc-ai-msg .tc-ai-md pre {
  overflow-x: auto;
  background: rgba(0,0,0,0.3);
  padding: 8px;
  border-radius: 8px;
  font-size: 11px;
}
.tc-ai-msg .tc-ai-md pre code { background: none; padding: 0; }

.tc-ai-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.tc-ai-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--line, #1E2A38);
  color: var(--accent-2, #D4BC6A);
  text-decoration: none;
  background: rgba(0,0,0,0.15);
}
.tc-ai-link:hover { border-color: var(--accent, #C8A84E); }

.tc-ai-confirm {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent, #C8A84E) 40%, transparent);
  background: var(--accent-dim, rgba(200, 168, 78, 0.12));
}
.tc-ai-confirm strong { display: block; margin-bottom: 6px; font-size: 12px; }
.tc-ai-confirm .tc-ai-args {
  font-size: 11px;
  color: var(--muted, #8891A0);
  margin-bottom: 8px;
  font-family: var(--mono, ui-monospace, monospace);
  white-space: pre-wrap;
}
.tc-ai-confirm-actions { display: flex; gap: 8px; }
.tc-ai-confirm-actions button {
  flex: 1;
  border-radius: 8px;
  border: 1px solid var(--line, #1E2A38);
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  background: var(--panel, #111820);
  color: var(--text, #D8D2C4);
}
.tc-ai-confirm-actions button.primary {
  background: var(--accent, #C8A84E);
  color: #0A0E14;
  border-color: transparent;
  font-weight: 700;
}
.tc-ai-confirm-actions button:disabled { opacity: 0.5; cursor: not-allowed; }

.tc-ai-secret {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--ok, #4A9A78) 50%, transparent);
  background: color-mix(in srgb, var(--ok, #4A9A78) 12%, transparent);
}
.tc-ai-secret code {
  display: block;
  word-break: break-all;
  font-size: 11px;
  margin: 6px 0;
  padding: 8px;
  border-radius: 6px;
  background: rgba(0,0,0,0.35);
  font-family: var(--mono, ui-monospace, monospace);
}
.tc-ai-secret button {
  border: 0;
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--ok, #4A9A78);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}

.tc-ai-foot {
  border-top: 1px solid var(--line, #1E2A38);
  padding: 10px;
  display: flex;
  gap: 8px;
  background: color-mix(in srgb, var(--panel, #111820) 95%, transparent);
}
.tc-ai-foot textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 96px;
  border-radius: 10px;
  border: 1px solid var(--line, #1E2A38);
  background: var(--bg, #0A0E14);
  color: var(--text, #D8D2C4);
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.4;
}
.tc-ai-foot textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent, #C8A84E) 55%, transparent);
}
.tc-ai-foot button.send {
  align-self: flex-end;
  min-width: 72px;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: var(--accent, #C8A84E);
  color: #0A0E14;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.tc-ai-foot button.send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.tc-ai-hint {
  font-size: 10px;
  color: var(--muted-2, #5A6578);
  padding: 0 12px 8px;
  text-align: center;
}

.tc-ai-typing {
  align-self: flex-start;
  font-size: 12px;
  color: var(--muted, #8891A0);
  padding: 4px 8px;
}

@media (max-width: 480px) {
  .tc-ai-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: min(78vh, 640px);
    border-radius: 16px 16px 0 0;
  }
  .tc-ai-root[data-surface="account"] .tc-ai-panel {
    bottom: 0;
    height: min(75vh, 620px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tc-ai-fab { transition: none; }
}
