/* aref Trip — internal chat. Uses the app's design tokens (light + dark) and logical properties (RTL ready). */
#view:has(.chat){padding-bottom:12px}
#app:has(.chat) #foot{display:none}

.chat{display:grid;grid-template-columns:1fr;height:calc(100vh - 150px);height:calc(100dvh - 150px);min-height:380px;background:var(--card);border:1px solid var(--line);border-radius:var(--r);box-shadow:var(--sh);overflow:hidden}
.chat-list,.chat-main{min-height:0;display:flex;flex-direction:column;position:relative}
/* phones: one pane at a time */
.chat.has-thread .chat-list{display:none}
.chat:not(.has-thread) .chat-main{display:none}
@media(min-width:860px){
  .chat{grid-template-columns:340px 1fr;height:calc(100vh - 130px);height:calc(100dvh - 130px)}
  .chat.has-thread .chat-list,.chat:not(.has-thread) .chat-main{display:flex}
  .chat-list{border-inline-end:1px solid var(--line)}
  .ch-back{display:none!important}
}

/* list */
.chat-list-h{padding:14px 16px 6px}.chat-list-h h2{margin:0}
.chat-items{overflow-y:auto;flex:1}
.ci{display:flex;align-items:center;gap:12px;padding:12px 16px;color:inherit;border-bottom:1px solid var(--line);position:relative}
.ci:hover,.ci.on{background:var(--primary-l)}
.ci-body{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
.ci-top{display:flex;justify-content:space-between;gap:8px;align-items:baseline}
.ci-top b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ci-top small{color:var(--muted);flex:0 0 auto;font-size:.72rem}
.ci-last{color:var(--muted);font-size:.86rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ci-last.un{color:var(--text);font-weight:700}
.ci-n{background:var(--primary);color:#fff;border-radius:999px;min-width:22px;height:22px;display:grid;place-items:center;font-size:.72rem;font-weight:700;padding:0 6px}
.chat-none,.chat-ph{flex:1;display:grid;place-items:center;padding:20px}

/* avatar */
.ch-wrap{position:relative;flex:0 0 auto;display:inline-block}
.ch-av{width:44px;height:44px;border-radius:50%;display:grid;place-items:center;color:#fff;font-weight:800;background-size:cover;background-position:center;flex:0 0 auto}
.ch-dot{position:absolute;inset-inline-end:0;bottom:0;width:12px;height:12px;border-radius:50%;background:var(--ok);border:2px solid var(--card)}
.ch-dot[hidden]{display:none}

/* header */
.chat-h{display:flex;align-items:center;gap:10px;padding:10px 14px;border-bottom:1px solid var(--line);background:var(--card);flex-wrap:wrap}
.chat-h .ch-av{width:40px;height:40px}
.ch-back{width:36px;height:36px;border-radius:10px;display:grid;place-items:center;color:var(--primary-d);font-size:1.3rem;font-weight:700}
:root[dir=rtl] .ch-back{transform:scaleX(-1)}
.ch-who{display:flex;flex-direction:column;line-height:1.2;min-width:0;flex:1}
.ch-who b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-who small{font-size:.75rem;min-height:1em}
.ch-ctx{display:flex;gap:6px;flex-wrap:wrap;max-width:100%}
.ch-chip{border:1px solid var(--line);background:var(--primary-l);color:var(--primary-d);border-radius:999px;padding:3px 10px;font-size:.76rem;font-weight:600;max-width:240px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* messages */
.chat-msgs{flex:1;overflow-y:auto;padding:14px;display:flex;flex-direction:column;gap:6px;background:var(--bg);overscroll-behavior:contain}
.day{text-align:center;margin:10px 0 4px}.day span{background:var(--card);border:1px solid var(--line);color:var(--muted);font-size:.72rem;font-weight:600;border-radius:999px;padding:2px 12px}
.msg{max-width:min(78%,520px);display:flex;flex-direction:column;gap:2px}
.msg.mine{align-self:flex-end}.msg.theirs{align-self:flex-start}
.mb{padding:8px 12px;border-radius:16px;word-break:break-word;overflow-wrap:anywhere;line-height:1.45}
.mine .mb{background:var(--primary);color:#fff;border-end-end-radius:4px}
.theirs .mb{background:var(--card);border:1px solid var(--line);border-end-start-radius:4px}
.mine .mb a{color:#fff;text-decoration:underline}
.mm{display:flex;gap:6px;font-size:.68rem;color:var(--muted);padding-inline:4px}
.mine .mm{justify-content:flex-end}
.tick.read{color:var(--primary)}
:root[data-theme="dark"] .tick.read{color:#7fe0d3}
.msg.pending .mb{opacity:.65}
.msg.failed .mb{background:var(--danger);cursor:pointer}
.chat-hello{margin:auto;color:var(--muted);text-align:center}
.ch-older{align-self:center;border:1px solid var(--line);background:var(--card);border-radius:999px;padding:6px 14px;font-size:.8rem;cursor:pointer;color:var(--primary-d)}
.chat-new{position:absolute;inset-inline:0;margin-inline:auto;width:max-content;bottom:76px;border:0;border-radius:999px;background:var(--primary);color:#fff;padding:7px 14px;font-size:.8rem;font-weight:700;box-shadow:var(--sh2);cursor:pointer}
.chat-new[hidden]{display:none}

/* composer */
.chat-in{display:flex;gap:8px;align-items:flex-end;padding:10px 12px calc(10px + env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--card)}
.chat-in textarea{flex:1;resize:none;max-height:130px;border:1px solid var(--line);border-radius:18px;padding:10px 14px;background:var(--bg);color:var(--text);outline:none;font-size:1rem;line-height:1.4}
.chat-in textarea:focus{border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-l)}
.chat-in .btn{width:44px;height:44px;padding:0;border-radius:50%;flex:0 0 auto}
:root[dir=rtl] .chat-in .btn{transform:scaleX(-1)}

/* shell: unread dots / header shortcut (desktop only, phones use the tab bar) */
.chat-top{display:none}
@media(min-width:860px){.chat-top{display:grid}}
