/* widgets.css - chat thread view, floating Support/AI widgets, staff inbox. Loaded after app.css. */

/* ---------- floating buttons ---------- */
.fab-stack { position: fixed; right: max(14px, var(--sar)); bottom: calc(var(--tab-h) + var(--sab) + 14px); z-index: 70; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
@media (min-width: 700px) { .fab-stack { bottom: 24px; right: 24px; } }
.fab { position: relative; display: inline-flex; align-items: center; gap: 8px; height: 52px; min-width: 52px; padding: 0 16px; justify-content: center; border: 0; border-radius: 999px; color: #fff; font-weight: 700; font-size: .9rem; cursor: pointer; box-shadow: 0 8px 24px rgba(11,31,58,.3); -webkit-tap-highlight-color: transparent; transition: transform .15s; }
.fab:active { transform: scale(.95); } .fab-chat { background: var(--navy); } .fab-ai { background: var(--teal); }
.fab-lbl { display: none; } @media (min-width: 700px) { .fab-lbl { display: inline; } }
@media (max-width: 699px) { .fab { width: 48px; height: 48px; padding: 0; } }
.fab-badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: .7rem; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--ivory); } .fab-badge[hidden] { display: none; }

/* ---------- panel ---------- */
.widget-panel { position: fixed; z-index: 90; background: var(--paper); display: flex; flex-direction: column; box-shadow: var(--sh-3); overflow: hidden; inset: 0; animation: slideup .22s; }
.wp-head { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--sat)) 12px 10px 16px; background: var(--navy); color: #fff; } .wp-ai .wp-head { background: var(--teal-d); }
.wp-ic { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.15); }
.wp-x { border: 0; background: rgba(255,255,255,.12); color: #fff; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; } .wp-x:hover { background: rgba(255,255,255,.25); }
.wp-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-bottom: var(--sab); }
@media (min-width: 700px) { .widget-panel { inset: auto 24px 92px auto; width: 390px; height: min(600px, calc(100dvh - 120px)); border-radius: 18px; border: 1px solid var(--line); } .wp-head { padding-top: 10px; } .wp-ai { bottom: 92px; } }
body.widget-open { overflow: hidden; } @media (min-width: 700px) { body.widget-open { overflow: auto; } }
@media (max-width: 699px) { body.widget-open .fab-stack { display: none; } }

/* ---------- chat panel + thread view ---------- */
.chat-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--paper); }
.chat-panel.is-full { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; height: calc(100dvh - 230px); min-height: 380px; }
.cp-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--ivory); color: var(--muted); }
.cp-lbl { font-size: .78rem; font-weight: 700; } .cp-topic { flex: 1; min-width: 0; min-height: 40px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 10px; background: var(--paper); font: inherit; font-size: .88rem; color: var(--navy); }
.cp-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cp-new { padding: 16px; display: grid; gap: 12px; align-content: start; } .cp-hello p { margin: 4px 0 0; }
.cp-reopen { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 8px 12px; background: var(--amber-l); color: var(--amber); }
.tv { display: flex; flex-direction: column; flex: 1; min-height: 0; background: #F6F3EB; }
.tv-list { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.tv-empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; } .tv-empty p { margin: 8px 0 0; }
.tv-day { text-align: center; margin: 8px 0 4px; } .tv-day span { display: inline-block; font-size: .72rem; color: var(--muted); background: rgba(11,31,58,.06); padding: 2px 10px; border-radius: 999px; }
.tv-msg { max-width: 82%; align-self: flex-start; display: flex; flex-direction: column; gap: 2px; } .tv-msg.mine { align-self: flex-end; align-items: flex-end; }
.tv-name { font-size: .72rem; font-weight: 700; color: var(--muted); display: flex; gap: 6px; align-items: center; } .tv-role { background: var(--teal-l); color: var(--teal-d); border-radius: 999px; padding: 0 7px; font-size: .66rem; text-transform: capitalize; }
.tv-bubble { padding: 9px 13px; border-radius: 16px 16px 16px 4px; background: #fff; border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; font-size: .95rem; }
.tv-msg.mine .tv-bubble { background: var(--navy); color: #fff; border-color: var(--navy); border-radius: 16px 16px 4px 16px; } .tv-msg.staff .tv-bubble { background: #E9F5F3; border-color: #CBE6E2; }
.tv-msg.mine.staff .tv-bubble { background: var(--navy); border-color: var(--navy); color: #fff; }
.tv-time { font-size: .68rem; color: var(--muted); }
.tv-comp { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--sab)); border-top: 1px solid var(--line); background: var(--paper); } .tv-comp[hidden] { display: none; }
.tv-input { flex: 1; min-width: 0; resize: none; border: 1.5px solid var(--line-2); border-radius: 20px; padding: 10px 14px; font: inherit; font-size: 16px; line-height: 1.4; max-height: 120px; background: var(--paper); } .tv-input:focus { outline: none; border-color: var(--teal); } .tv-input.big { border-radius: 12px; width: 100%; }
.tv-send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--teal); color: #fff; cursor: pointer; display: grid; place-items: center; flex: none; } .tv-send:disabled { opacity: .5; }
.tv-closed { padding: 12px; text-align: center; color: var(--muted); background: var(--sand); font-size: .9rem; } .tv-closed[hidden] { display: none; }

/* ---------- AI panel ---------- */
.ai-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ai-log { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; background: #F6F3EB; -webkit-overflow-scrolling: touch; }
.ai-msg { max-width: 92%; padding: 10px 13px; border-radius: 14px; line-height: 1.5; font-size: .94rem; overflow-wrap: anywhere; }
.ai-msg.user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; } .ai-msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; } .ai-msg.bot.err { background: var(--red-l); border-color: #F3C3BE; color: #8B1A10; }
.ai-md p { margin: 0 0 .6em; } .ai-md p:last-child, .ai-md ul:last-child, .ai-md ol:last-child { margin-bottom: 0; } .ai-md ul, .ai-md ol { margin: 0 0 .6em; padding-left: 1.3em; } .ai-md h4 { margin: .4em 0; font-size: 1rem; }
.ai-md code { background: var(--sand); padding: 1px 5px; border-radius: 5px; font-size: .86em; }
.ai-code { position: relative; margin: .5em 0; padding: 12px; background: #0F1B2D; color: #E6EEF9; border-radius: 10px; overflow-x: auto; font-size: .82rem; } .ai-code code { background: none; padding: 0; color: inherit; white-space: pre; } .ai-copy { position: absolute; top: 6px; right: 6px; border: 0; border-radius: 6px; padding: 3px 9px; font-size: .7rem; background: rgba(255,255,255,.15); color: #fff; cursor: pointer; }
.typing .dots { display: inline-flex; gap: 4px; padding: 4px 2px; } .typing .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite; } .typing .dots i:nth-child(2) { animation-delay: .15s; } .typing .dots i:nth-child(3) { animation-delay: .3s; }
.ai-foot { padding: 8px 10px calc(8px + var(--sab)); border-top: 1px solid var(--line); background: var(--paper); display: grid; gap: 8px; }
.ai-form { display: flex; gap: 8px; align-items: flex-end; } .ai-form .tv-input { border-radius: 12px; } .ai-hint { margin: 0; text-align: center; }
.ai-ctx-chip { display: flex; align-items: center; gap: 8px; font-size: .82rem; padding: 6px 10px; border-radius: 10px; background: var(--teal-l); color: var(--teal-d); cursor: pointer; } .ai-ctx-chip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-sugg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; } .ai-sugg::-webkit-scrollbar { display: none; } .ai-sugg[hidden] { display: none; }
.chip-btn { border: 1px solid var(--line-2); background: var(--paper); border-radius: 999px; padding: 6px 12px; font-size: .8rem; font-weight: 600; color: var(--navy); cursor: pointer; white-space: nowrap; min-height: 34px; } .chip-btn:hover, .chip-btn.is-on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- staff inbox ---------- */
.view-inbox { max-width: 1280px; }
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); overflow: hidden; height: calc(100dvh - 190px); min-height: 440px; margin-top: 16px; }
.ib-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); } .ib-filters .tabs { padding: 0 8px; }
.ib-search { display: flex; align-items: center; gap: 8px; margin: 10px 12px 6px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 10px; color: var(--muted); } .ib-search input { flex: 1; border: 0; outline: none; min-height: 42px; font: inherit; font-size: 16px; background: none; min-width: 0; }
.ib-scope { display: flex; gap: 6px; padding: 4px 12px 10px; border-bottom: 1px solid var(--line); }
.ib-items { flex: 1; overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.ib-item { display: flex; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; align-items: flex-start; min-height: 68px; } .ib-item:hover { background: var(--ivory); } .ib-item.is-on { background: var(--teal-l); } .ib-item.is-unread b { color: var(--navy); } .ib-item.is-unread .ib-snip { font-weight: 700; color: var(--ink); }
.ib-main { flex: 1; min-width: 0; display: grid; gap: 1px; } .ib-row1, .ib-row3 { display: flex; align-items: center; gap: 8px; } .ib-row1 b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .ib-sub { font-size: .76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .ib-snip { flex: 1; min-width: 0; font-size: .86rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-none, .ib-placeholder { display: grid; justify-items: center; align-content: center; gap: 4px; padding: 32px 16px; text-align: center; color: var(--muted); } .ib-placeholder { height: 100%; }
.ib-conv { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ib-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; } .ib-title { display: flex; flex-direction: column; min-width: 0; } .ib-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .ib-title small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .ib-actions { display: flex; gap: 6px; flex-wrap: wrap; } .ib-back { display: none; }
.ib-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
@media (max-width: 899px) {
  .inbox { grid-template-columns: 1fr; height: calc(100dvh - 56px - var(--tab-h) - var(--sab) - 150px); min-height: 420px; }
  .inbox[data-pane=list] .ib-conv, .inbox[data-pane=conv] .ib-list { display: none; }
  .ib-back { display: inline-flex; }
}
.ib-head .spacer { display: none; } .ib-title { flex: 1 1 0; }
@media (max-width: 899px) { .ib-actions { flex: 0 0 100%; } .ib-head { gap: 8px; } }
