/* ── Tokens ── */
:root {
  --bg: #f2f0ea;
  --surface: #fdfcf8;
  --surface2: #ffffff;
  --line: #dbd6ca;
  --ink: #1a1d20;
  --muted: #6b6f6b;
  --green: #1f7a57;
  --green-bg: #e4f4ec;
  --blue: #2455c0;
  --blue-bg: #e8eeff;
  --rose: #b04050;
  --rose-bg: #fff0f2;
  --shadow: 0 12px 40px rgba(20,30,24,.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

body.dark {
  --bg: #111412;
  --surface: #181c19;
  --surface2: #1f2420;
  --line: #323a34;
  --ink: #eaefeb;
  --muted: #909890;
  --green: #5ecfa0;
  --green-bg: #1a3829;
  --blue: #8aabff;
  --blue-bg: #1c2a50;
  --rose: #ff9aaa;
  --rose-bg: #3a1e24;
  --shadow: 0 12px 40px rgba(0,0,0,.36);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100dvh; }
button, input, textarea, select { font: inherit; }
[hidden] { display: none !important; }

button { cursor: pointer; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.3px;
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { opacity: .8; }

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Connection pill ── */
.conn-status {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  height: 26px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.conn-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.conn-status.live   { display: inline-flex; background: var(--green-bg); color: var(--green); }
.conn-status.live::before { background: var(--green); animation: pulse 2.4s ease infinite; }
.conn-status.off    { display: inline-flex; background: var(--rose-bg); color: var(--rose); }
.conn-status.off::before  { background: var(--rose); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ── Shell ── */
.shell {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  height: calc(100dvh - 52px);
}

/* ── Sidebar ── */
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 6px;
}

.sidebar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px;
  padding: 0 10px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface2);
}

.search-wrap input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search-icon { color: var(--muted); font-size: 15px; }

.thread-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px 12px;
  overflow-y: auto;
}

.thread-btn {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 62px;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  transition: background 120ms;
}

.thread-btn:hover, .thread-btn.active {
  background: var(--surface2);
  border-color: var(--line);
}

.thread-name { font-size: 14px; font-weight: 700; color: var(--ink); }
.thread-preview {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-time { font-size: 12px; color: var(--muted); margin-left: auto; padding-left: 6px; flex-shrink: 0; }

.thread-row { display: flex; align-items: center; gap: 4px; }

/* ── Avatar ── */
.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #2e6b5e;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

.avatar.sm { width: 32px; height: 32px; font-size: 12px; border-radius: 8px; }

.agent-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--surface);
  animation: pulse 2.4s ease infinite;
}

/* ── Chat ── */
.chat {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface2);
}

.chat-title-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.chat-head h2 { margin: 0; font-size: 17px; }

/* ── Agent bar ── */
.agent-bar {
  display: none;
  padding: 8px 16px;
  font-size: 13px;
  border-bottom: 1px solid color-mix(in srgb, var(--green) 30%, transparent);
  background: var(--green-bg);
  color: color-mix(in srgb, var(--green) 80%, var(--ink));
}
.agent-bar.visible { display: block; }

/* ── Messages ── */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  overflow-y: auto;
  background:
    linear-gradient(var(--bg) 0 0),
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--ink) 8%, transparent) 1px, transparent 0) 0 0 / 22px 22px;
  background-blend-mode: normal;
}

.msg {
  max-width: min(75%, 600px);
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface2);
  animation: msgIn 180ms ease forwards;
}

@keyframes msgIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:none; } }

.msg.mine      { align-self: flex-end; background: var(--blue-bg); border-color: color-mix(in srgb, var(--blue) 20%, transparent); }
.msg.agent     { background: var(--rose-bg); border-color: color-mix(in srgb, var(--rose) 22%, transparent); }
.msg.system    { align-self: center; background: transparent; border-style: dashed; color: var(--muted); font-size: 13px; max-width: 90%; }

.msg-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.msg-body { margin: 0; line-height: 1.45; font-size: 14px; }

.msg-del {
  opacity: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 0 2px;
  border-radius: 4px;
  font-size: 14px;
  transition: opacity 120ms;
}
.msg:hover .msg-del { opacity: 1; }
.msg-del:hover { color: var(--rose); }

/* ── Composer ── */
.composer {
  display: grid;
  grid-template-columns: 1fr auto auto auto;   /* textarea, attach, mic, send */
  gap: 8px;
  align-items: end;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface2);
}
.composer .icon-btn { width: 40px; height: 40px; }

/* Recording bar takes over the composer while recording */
.rec-bar { display: none; }
.composer.recording > :not(.rec-bar) { display: none; }
.composer.recording { grid-template-columns: 1fr; }
.composer.recording .rec-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 2px 2px; width: 100%;
}
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--rose); animation: pulse 1.2s ease infinite; flex-shrink: 0; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 15px; min-width: 44px; }
.rec-hint { color: var(--muted); flex: 1; font-size: 13px; }

/* ── Attachments ── */
.att { margin-top: 6px; }
.att img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; cursor: pointer; }
.att audio { width: 240px; display: block; }
.att-file {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  color: var(--ink); text-decoration: none; font-size: 13px; max-width: 260px;
}
.att-file:hover { border-color: #9aada0; }
.att-file .att-ico { font-size: 18px; }
.att-file .att-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file .att-size { color: var(--muted); font-size: 11px; }
.att-loading { color: var(--muted); font-size: 12px; font-style: italic; }

.composer textarea {
  min-height: 40px;
  max-height: 120px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  resize: none;
  outline: none;
  field-sizing: content;
  line-height: 1.4;
}

.composer textarea:focus {
  border-color: color-mix(in srgb, var(--green) 50%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 12%, transparent);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #1f5c44;
  color: #fff;
  font-size: 15px;
  display: grid;
  place-items: center;
  transition: transform 120ms;
}
.send-btn:hover { transform: translateY(-1px); }
.send-btn:active { transform: scale(.94); }

.agent-send-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 15px;
}
.agent-send-btn:hover { color: var(--green); border-color: var(--green); }

.sender-select {
  height: 40px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
  display: none;
  max-width: 120px;
}
.sender-select.visible { display: block; }

/* ── Panel ── */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow-y: auto;
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface2);
  flex-shrink: 0;
}

.panel-head h2 { margin: 2px 0 0; font-size: 17px; }

.panel-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-section h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
}

/* ── Agent list ── */
.agent-list { display: flex; flex-direction: column; gap: 8px; }

.agent-card {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface2);
  font-size: 13px;
}

.agent-card-name { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.agent-card-owner { color: var(--muted); margin-top: 2px; font-size: 12px; }
.agent-card-status { font-size: 11px; font-weight: 700; color: var(--muted); margin-top: 6px; }
.agent-card-status.live { color: var(--green); }

.empty-agents { color: var(--muted); font-size: 13px; }

/* ── Invite button in panel ── */
.invite-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
  padding: 9px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  transition: border-color 140ms, color 140ms;
}
.invite-btn:hover { border-color: var(--green); color: var(--green); }

/* ── Activity log ── */
.activity-log {
  margin: 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Shared ── */
.eyebrow { margin: 0; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--ink);
  font-size: 15px;
  transition: border-color 120ms, transform 120ms;
}
.icon-btn:hover { border-color: #9aada0; transform: translateY(-1px); }

.menu-wrap { position: relative; }

.dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface2);
  box-shadow: var(--shadow);
  z-index: 20;
}
.dropdown.open { display: grid; }
.dropdown button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}
.dropdown button:hover { background: var(--bg); }
.dropdown button.danger { color: var(--rose); }
.dropdown button.danger:hover { background: var(--rose-bg); }
.dropdown button.active { background: var(--green-bg); color: var(--green); }
.dropdown button.active::after { content: " ✓"; }
.dropdown button .muted { color: var(--muted); font-weight: 600; font-size: 12px; }
.dropdown-sep { height: 1px; background: var(--line); margin: 5px 0; }
.dropdown-label { margin: 4px 10px 2px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

/* Access pill in chat header */
.access-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.access-pill.humans_only { background: var(--blue-bg); color: var(--blue); }
.access-pill.agents_only { background: var(--rose-bg); color: var(--rose); }

/* ── Toast ── */
.toast {
  position: fixed;
  top: 62px;
  right: 14px;
  display: none;
  max-width: 300px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--green) 40%, transparent);
  border-radius: 8px;
  background: var(--green-bg);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 9999;  /* above the profile page, modals, pickers */
}
.toast.show { display: block; }

/* ── Modal ── */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,15,12,.45);
  place-items: center;
  padding: 20px;
  z-index: 30;
}
body.dark .modal-bg { background: rgba(0,0,0,.6); }
.modal-bg.open { display: grid; }

.modal {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 20px; }

.modal-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.invite-thread {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--green-bg);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.field {
  display: grid;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
}
.field input {
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--ink);
  text-transform: none;
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: color-mix(in srgb, var(--green) 50%, transparent); }

.primary-btn {
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #1f5c44;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.primary-btn:hover { background: #185038; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 260px 1fr; }
  .panel { display: none; }
}
@media (max-width: 700px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat { border-right: none; }
}

/* ── Auth screen ── */
.auth-screen { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.auth-card {
  width: min(380px, 100%); padding: 32px 28px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
}
.auth-brand { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.5px; text-align: center; }
.auth-tagline { margin: 4px 0 20px; text-align: center; color: var(--muted); font-size: 14px; }
.auth-tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg); border-radius: 10px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; padding: 9px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-weight: 700; font-size: 13px;
}
.auth-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.auth-form { display: grid; gap: 14px; }
.auth-error {
  margin: 14px 0 0; padding: 10px 12px; border-radius: 8px;
  background: var(--rose-bg); color: var(--rose); font-size: 13px; font-weight: 600;
}
.auth-foot { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
.auth-foot code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* ── User button ── */
.user-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface2);
  color: var(--ink); font-weight: 700; font-size: 13px;
}
.user-btn:hover { border-color: #9aada0; }

/* ── API key box ── */
.key-box {
  margin: 0; padding: 12px; border-radius: 8px; background: var(--bg);
  border: 1px solid var(--line); font-family: ui-monospace, monospace;
  font-size: 12px; word-break: break-all; white-space: pre-wrap; color: var(--ink);
}

.access-pill.e2ee { background: var(--green-bg); color: var(--green); }
.msg.locked .msg-body { color: var(--muted); font-style: italic; }

/* ── Panel admin buttons ── */
.panel-btns { display: flex; flex-direction: column; gap: 6px; }
.panel-btn {
  width: 100%; text-align: left; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface2);
  color: var(--ink); font-size: 13px; font-weight: 600;
}
.panel-btn:hover { border-color: #9aada0; }
.panel-btn.active { background: var(--green-bg); color: var(--green); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.panel-btn.active::after { content: " ✓"; }
.panel-btn.danger { color: var(--rose); }
.panel-btn.danger:hover { background: var(--rose-bg); border-color: color-mix(in srgb, var(--rose) 35%, transparent); }
.panel-btn:disabled { opacity: .45; cursor: not-allowed; }
.panel-btn .muted { color: var(--muted); font-weight: 500; }

.dropdown-link { display: block; padding: 9px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 700; }
.dropdown-link:hover { background: var(--bg); }

/* ── Delete affordances ── */
.msg { position: relative; }
.msg-del {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px;
  border: 0; border-radius: 5px; background: transparent; color: var(--muted);
  font-size: 14px; line-height: 1; opacity: 0; transition: opacity 120ms; cursor: pointer;
}
.msg:hover .msg-del { opacity: .7; }
.msg-del:hover { opacity: 1; color: var(--rose); background: color-mix(in srgb, var(--rose) 12%, transparent); }

.thread-btn { position: relative; }
.thread-x {
  position: absolute; top: 50%; right: 8px; transform: translateY(-50%);
  width: 22px; height: 22px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); font-size: 15px; opacity: 0; transition: opacity 120ms; cursor: pointer;
}
.thread-btn:hover .thread-x { opacity: .7; }
.thread-x:hover { opacity: 1; color: var(--rose); background: color-mix(in srgb, var(--rose) 12%, transparent); }

/* ── Profile modal ── */
.modal-body.bordered { border-top: 1px solid var(--line); }
.modal-sub { margin: 0 0 12px; font-size: 14px; font-weight: 800; }
.profile-id { margin: 0; font-size: 15px; }
.hint { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.composer-inline { display: flex; gap: 8px; }
.composer-inline input {
  flex: 1; height: 38px; padding: 0 11px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface2); color: var(--ink); font-size: 14px; outline: none;
}
.primary-btn.slim { height: 38px; padding: 0 14px; }
#agentKeyBox { margin: 12px 0; }
#myAgentsList .agent-card { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.agent-card-head { display: flex; align-items: center; justify-content: space-between; }
.agent-webhook { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.agent-webhook .field span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.agent-webhook .hint { margin: 0; }
.regen-btn { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 700; padding: 5px 9px; cursor: pointer; }
.regen-btn:hover { color: var(--ink); border-color: #9aada0; }

/* Links and emails inside messages */
.msg-body a { color: var(--blue); text-decoration: underline; word-break: break-word; }
.msg.mine .msg-body a { color: inherit; }

/* Visually hidden but still focusable/activatable (file input must NOT be display:none
   or browsers won't open the picker dialog). */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.rec-trash { display: grid; place-items: center; }
.rec-trash:hover { color: var(--rose); border-color: var(--rose); }

/* Transparent real file input overlaying the 📎 icon (no JS needed to open). */
.attach-wrap { position: relative; overflow: hidden; }
.attach-wrap input[type="file"] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; font-size: 0;
}

/* Drag-and-drop highlight */
.chat.drag { outline: 2px dashed var(--green); outline-offset: -8px; }

/* Pending (staged) attachments preview above the composer */
.pending-bar { grid-column: 1 / -1; display: none; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.pending-item { position: relative; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 4px; }
.pending-item img { display: block; max-width: 90px; max-height: 90px; border-radius: 5px; }
.pending-name { display: inline-block; padding: 8px 10px; font-size: 12px; font-weight: 700; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-x {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface2);
  color: var(--ink); font-size: 13px; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.pending-x:hover { color: var(--rose); border-color: var(--rose); }

/* Full-size image viewer (lightbox) */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.85); padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 95vw; max-height: 92vh; border-radius: 8px; box-shadow: var(--shadow); cursor: default; }
.lightbox-close {
  position: fixed; top: 16px; right: 20px; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff;
  font-size: 24px; line-height: 1; cursor: pointer;
}
.lightbox-close:hover { background: rgba(255,255,255,.22); }
.att img, .pending-item img { cursor: zoom-in; }

/* Retention dropdown */
.panel-select {
  width: 100%; height: 38px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface2); color: var(--ink);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.panel-select:focus { outline: none; border-color: color-mix(in srgb, var(--green) 50%, transparent); }

/* Chat type icon in the sidebar */
.thread-name-row { display: flex; align-items: center; gap: 6px; }
.thread-name-row .thread-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-type { font-size: 13px; flex-shrink: 0; opacity: .9; }
.thread-vis { font-size: 11px; flex-shrink: 0; opacity: .6; }

/* @mention highlight in messages */
.mention {
  color: var(--blue); background: var(--blue-bg);
  border-radius: 4px; padding: 0 3px; font-weight: 600;
}
.msg.mine .mention { color: #fff; background: rgba(255, 255, 255, .22); }

/* Two-axis privacy UI */
.sidebar-actions { display: flex; gap: 6px; }
.panel-btn { display: flex; align-items: center; gap: 8px; }
.panel-btn svg { flex-shrink: 0; }
.panel-ico { flex-shrink: 0; font-size: 14px; width: 16px; text-align: center; }
.public-note { display: none; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface2); color: var(--muted); font-size: 13px; }
.chat.readonly .composer { display: none; }
.chat.readonly .public-note { display: block; }

/* Public rooms list */
.public-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; margin-top: 10px; }
.public-row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface2);
  color: var(--ink); text-align: left; cursor: pointer;
}
.public-row:hover { border-color: #9aada0; }
.public-row .pr-title { font-weight: 700; font-size: 14px; }
.public-row .pr-sub { color: var(--muted); font-size: 12px; }

/* Message reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; align-items: center; }
.react-chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 1px 8px; font-size: 12px; line-height: 1.6; cursor: pointer;
}
.react-chip.mine { background: var(--blue-bg); border-color: color-mix(in srgb, var(--blue) 35%, transparent); }
.react-chip:disabled { cursor: default; }
.react-add {
  opacity: 0; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; min-width: 26px; height: 22px; font-size: 13px; cursor: pointer;
  transition: opacity 120ms; line-height: 1;
}
.msg:hover .react-add { opacity: .7; }
.react-add:hover { opacity: 1; color: var(--ink); }
.emoji-picker {
  position: fixed; z-index: 70; display: flex; flex-wrap: wrap; gap: 2px; width: 232px;
  padding: 8px; background: var(--surface2); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.emoji-picker button { border: 0; background: transparent; font-size: 20px; cursor: pointer; padding: 4px; border-radius: 6px; }
.emoji-picker button:hover { background: var(--bg); }

/* Recovery codes */
.recovery-list {
  list-style: none; margin: 10px 0; padding: 12px; display: grid;
  grid-template-columns: 1fr 1fr; gap: 6px 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px;
}
.recovery-list li { letter-spacing: .5px; }
.rec-ack { display: flex; align-items: center; gap: 8px; margin: 12px 0; font-size: 14px; color: var(--muted); cursor: pointer; }
.rec-ack input { width: auto; }
.rec-remaining { margin: 6px 0 12px; color: var(--muted); font-size: 14px; }

/* Full-page Profile view (replaces the old modal so password managers work
   and Escape doesn't discard input) */
.page-view {
  position: fixed; inset: 0; z-index: 60; overflow-y: auto;
  background: var(--bg); display: flex; justify-content: center;
  padding: 32px 16px;
}
.page-card {
  width: 100%; max-width: 560px; align-self: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.page-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.page-head h2 { margin: 0; font-size: 18px; }
.page-head .icon-btn { font-size: 20px; }

/* @mention autocomplete */
.mention-menu {
  position: fixed; z-index: 70; min-width: 180px; max-width: 280px;
  padding: 4px; display: flex; flex-direction: column;
  background: var(--surface2); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.mention-item {
  text-align: left; border: 0; background: transparent; color: var(--ink);
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.mention-item:hover, .mention-item.active { background: var(--blue-bg); }
