#tm-ai {
    --tm-ai-bg: #0d1117;
    --tm-ai-surface: #161b22;
    --tm-ai-border: #30363d;
    --tm-ai-text: #e6edf3;
    --tm-ai-muted: #9da7b3;
    --tm-ai-accent: #f59e0b;
    color: var(--tm-ai-text);
    font: 14px/1.6 system-ui, sans-serif;
    letter-spacing: 0;
}
#tm-ai *, #tm-ai *::before, #tm-ai *::after { box-sizing: border-box; }
#tm-ai [hidden] { display: none !important; }
#tm-ai button { cursor: pointer; font: inherit; color: inherit; border: 1px solid var(--tm-ai-border); background: transparent; border-radius: 10px; padding: 8px 12px; transition: background .18s, border-color .18s, color .18s; }
#tm-ai button:hover { background: #212832; border-color: #59616b; }
#tm-ai button:disabled { opacity: .45; cursor: default; }
#tm-ai button:focus-visible, #tm-ai textarea:focus-visible { outline: 2px solid var(--tm-ai-accent); outline-offset: 3px; }
#tm-ai svg { display: block; flex-shrink: 0; width: 20px; height: 20px; }
#tm-ai-open {
    position: fixed; bottom: 0; left: max(16px, env(safe-area-inset-left)); z-index: 1000;
    display: flex; align-items: center; gap: 10px; min-height: 48px;
    padding: 10px 18px calc(10px + env(safe-area-inset-bottom)) !important;
    background: var(--tm-ai-surface) !important; border-color: #61502e !important;
    border-top: 2px solid var(--tm-ai-accent) !important; border-bottom: 0 !important;
    border-radius: 12px 12px 0 0 !important;
    box-shadow: 0 -4px 24px #0003; font-weight: 600 !important;
}
#tm-ai-open svg { color: var(--tm-ai-accent); }
#tm-ai-open:hover, #tm-ai-open[aria-expanded="true"] { border-color: var(--tm-ai-accent) !important; background: #241f16 !important; }
#tm-ai-panel {
    position: fixed; bottom: calc(64px + env(safe-area-inset-bottom)); left: 16px; z-index: 1001; width: min(440px, calc(100vw - 88px));
    height: min(640px, calc(100dvh - 160px)); min-height: 240px;
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--tm-ai-bg); border: 1px solid var(--tm-ai-border); border-radius: 18px;
    box-shadow: 0 24px 80px #0008; animation: tm-ai-appear .22s ease-out;
}
#tm-ai .tm-ai-content { display: flex; flex-direction: column; flex: 1; min-height: 0; transition: filter .18s, opacity .18s; }
#tm-ai-panel.tm-ai-modal-open > .tm-ai-content { filter: blur(4px); opacity: .45; pointer-events: none; user-select: none; }
#tm-ai-panel.tm-ai-wide { width: min(760px, calc(100vw - 88px)); }
#tm-ai .tm-ai-header { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--tm-ai-border); background: var(--tm-ai-surface); flex-shrink: 0; }
#tm-ai .tm-ai-mark { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #f59e0b33; background: #f59e0b0d; color: var(--tm-ai-accent); border-radius: 12px; flex-shrink: 0; }
#tm-ai .tm-ai-heading { flex: 1; min-width: 0; }
#tm-ai .tm-ai-heading strong { display: block; font-size: 13px; font-weight: 650; line-height: 1.4; }
#tm-ai .tm-ai-heading > span { display: block; font-size: 11px; color: var(--tm-ai-muted); margin-top: 2px; }
#tm-ai .tm-ai-icon { display: grid; place-items: center; padding: 8px; width: 34px; height: 34px; border-color: transparent; color: var(--tm-ai-muted); flex-shrink: 0; }
#tm-ai .tm-ai-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--tm-ai-border) transparent; padding: 22px 20px; }
#tm-ai-welcome { display: flex; flex-direction: column; justify-content: center; min-height: 100%; padding: 10px 4px; }
#tm-ai .tm-ai-welcome-icon { width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid #f59e0b33; border-radius: 16px; color: var(--tm-ai-accent); background: #f59e0b0a; margin-bottom: 20px; }
#tm-ai .tm-ai-welcome-icon svg { width: 26px; height: 26px; }
#tm-ai .tm-ai-eyebrow { margin: 0 0 8px; color: var(--tm-ai-accent); font-size: 10px; font-weight: 650; letter-spacing: 0; }
#tm-ai-welcome h2 { font: 650 22px/1.3 system-ui, sans-serif; letter-spacing: 0; margin: 0 0 10px; color: var(--tm-ai-text); }
#tm-ai-welcome > p:not(.tm-ai-eyebrow) { color: var(--tm-ai-muted); font-size: 13px; max-width: 310px; margin: 0 0 24px; }
#tm-ai .tm-ai-suggestions { display: grid; gap: 8px; }
#tm-ai .tm-ai-suggestions button { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; font-size: 12px; padding: 10px 12px; background: var(--tm-ai-surface); }
#tm-ai .tm-ai-suggestions span { color: var(--tm-ai-muted); }
#tm-ai-messages { display: flex; flex-direction: column; gap: 20px; }
#tm-ai-messages article { min-width: 0; max-width: 100%; }
#tm-ai-messages strong { display: block; color: var(--tm-ai-accent); font-size: 11px; font-weight: 600; margin-bottom: 6px; }
#tm-ai-messages article > div { white-space: pre-wrap; overflow-wrap: anywhere; }
#tm-ai-messages .tm-ai-user { align-self: flex-end; max-width: 88%; background: #212832; border: 1px solid #30363d; padding: 10px 14px; border-radius: 14px 14px 4px 14px; }
#tm-ai-messages .tm-ai-user strong { color: var(--tm-ai-muted); }
#tm-ai-messages .tm-ai-answer { align-self: flex-start; max-width: 94%; background: var(--tm-ai-surface); border: 1px solid var(--tm-ai-border); padding: 10px 14px; border-radius: 14px 14px 14px 4px; }
#tm-ai-pending { display: flex; align-items: flex-start; gap: 10px; color: var(--tm-ai-muted); font-size: 12px; padding-top: 18px; }
#tm-ai .tm-ai-dots { display: flex; gap: 4px; margin-top: 7px; flex-shrink: 0; }
#tm-ai .tm-ai-progress { min-width: 0; flex: 1; }
#tm-ai-pending-label { color: var(--tm-ai-text); font-weight: 500; }
#tm-ai-progress-history { margin-top: 5px; font-size: 10px; line-height: 1.5; opacity: .8; max-height: 64px; overflow-y: auto; overflow-wrap: anywhere; }
#tm-ai .tm-ai-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--tm-ai-accent); animation: tm-ai-pulse 1.2s ease-in-out infinite; }
#tm-ai .tm-ai-dots i:nth-child(2) { animation-delay: .15s; }
#tm-ai .tm-ai-dots i:nth-child(3) { animation-delay: .3s; }
#tm-ai .tm-ai-composer { flex-shrink: 0; padding: 14px 16px 12px; border-top: 1px solid var(--tm-ai-border); background: var(--tm-ai-surface); }
#tm-ai form { display: flex; align-items: flex-end; gap: 8px; padding: 8px; border: 1px solid #484f58; border-radius: 12px; background: var(--tm-ai-bg); }
#tm-ai form:focus-within { border-color: #b58130; }
#tm-ai textarea { flex: 1; min-width: 0; height: 38px; max-height: 144px; resize: none; color: var(--tm-ai-text); background: transparent; border: 0; border-radius: 6px; padding: 8px 6px; font: inherit; line-height: 22px; }
#tm-ai textarea::placeholder { color: var(--tm-ai-muted); }
#tm-ai textarea:focus-visible { outline: none; }
#tm-ai-send { display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; padding: 8px !important; color: #17120a !important; background: var(--tm-ai-accent) !important; border-color: var(--tm-ai-accent) !important; }
#tm-ai-send:hover:not(:disabled) { background: #fbbf24 !important; }
#tm-ai .tm-ai-input-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 7px; font-size: 10px; color: var(--tm-ai-muted); }
#tm-ai .tm-ai-notice { margin: 8px 0 0; color: var(--tm-ai-muted); font-size: 10px; line-height: 1.5; }
#tm-ai-error-box { padding: 10px 16px; background: #351b1b; border-top: 1px solid #713737; flex-shrink: 0; max-height: 140px; overflow-y: auto; }
#tm-ai-error { margin: 0; color: #ffc5c5; font-size: 12px; overflow-wrap: anywhere; }
#tm-ai-reload { margin-top: 8px; font-size: 11px !important; }
#tm-ai-reset-confirm { position: absolute; inset: 0; z-index: 5; display: grid; justify-items: center; align-items: safe center; padding: 18px; overflow-y: auto; background: #0d111766; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); border-radius: inherit; }
#tm-ai .tm-ai-reset-card { box-sizing: border-box; width: 100%; max-width: 320px; padding: 24px; border: 1px solid #61502e; border-radius: 16px; background: var(--tm-ai-surface); box-shadow: 0 18px 48px #0008; text-align: center; animation: tm-ai-appear .18s ease-out; }
#tm-ai .tm-ai-reset-mark { display: grid; place-items: center; width: 42px; height: 42px; margin: 0 auto 14px; color: var(--tm-ai-accent); background: #f59e0b12; border: 1px solid #f59e0b33; border-radius: 12px; }
#tm-ai-reset-title { margin: 0; color: var(--tm-ai-text); font: 650 18px/1.35 system-ui, sans-serif; }
#tm-ai-reset-description { margin: 10px 0 0; color: var(--tm-ai-muted); font-size: 12px; line-height: 1.6; }
#tm-ai .tm-ai-reset-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
#tm-ai .tm-ai-reset-actions button { flex: 1 1 100px; min-width: 0; padding: 9px 10px; font-size: 12px; }
#tm-ai-reset-yes { color: #17120a !important; background: var(--tm-ai-accent) !important; border-color: var(--tm-ai-accent) !important; font-weight: 600 !important; }
#tm-ai-reset-yes:hover { background: #fbbf24 !important; }
#tm-ai .tm-ai-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
@keyframes tm-ai-appear { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes tm-ai-pulse { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
@media (max-width: 600px) {
    #tm-ai-open { left: max(12px, env(safe-area-inset-left)); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)) !important; font-size: 12px !important; }
    #tm-ai-panel, #tm-ai-panel.tm-ai-wide { left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: auto; height: min(720px, calc(100dvh - 80px)); min-height: 0; border-radius: 16px; }
    #tm-ai .tm-ai-header { padding: 12px; gap: 7px; }
    #tm-ai .tm-ai-heading strong { font-size: 12px; }
    #tm-ai-expand { display: none !important; }
    #tm-ai textarea { font-size: 16px; }
    #tm-ai .tm-ai-input-meta { font-size: 9px; }
    #tm-ai .tm-ai-scroll { padding: 18px 16px; }
}
@media (max-height: 500px) {
    #tm-ai-panel { top: 8px; bottom: 8px; height: auto; min-height: 0; overflow-y: auto; }
    #tm-ai .tm-ai-header { padding: 8px 12px; }
    #tm-ai .tm-ai-composer { padding: 8px 12px; }
    #tm-ai .tm-ai-scroll { min-height: 64px; }
}
@media (prefers-reduced-motion: reduce) { #tm-ai *, #tm-ai *::before, #tm-ai *::after { animation: none !important; transition: none !important; } }
