/* Teams Chat Browser & Backup — leans on ../css/protium-ui.css tokens.
 * `--muted` is kept as an alias because teams.js writes it into inline styles. */

:root { --muted: var(--text-muted); }

.nav-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.nav-tools .pt-badge { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Token screen ---------------------------------------------------------- */
#tokenScreen { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto; }
.token-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 26px; width: 100%; max-width: 580px;
}
.token-card h2 { font-family: var(--font-display); font-size: 19px; margin-bottom: 7px; }
.token-card p { font-size: 13.5px; color: var(--text-muted); line-height: 1.6; }
.token-card a { color: var(--accent); }
.token-card textarea {
  width: 100%; margin: 14px 0 4px; padding: 11px 12px;
  background: var(--field); border: 1px solid var(--border); border-radius: var(--r-md);
  color: var(--text); font-family: var(--font-mono); font-size: 12px;
  min-height: 84px; resize: vertical; outline: none;
  transition: border-color var(--t);
}
.token-card textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
#tokenError { color: var(--bad); font-size: 12.5px; margin-top: 8px; display: none; }
.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-faint); font-size: 11px; letter-spacing: 0.08em;
  margin: 18px 0 12px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* App shell ------------------------------------------------------------- */
#app { flex: 1; display: none; min-height: 0; }
#app.active { display: flex; }

#sidebar {
  width: 320px; flex-shrink: 0;
  background: var(--nav); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
#sidebarTop { padding: 10px; border-bottom: 1px solid var(--border); }
#chatSearch {
  width: 100%; padding: 8px 12px; font-size: 13px;
  background: var(--field); border: 1px solid var(--border-faint); border-radius: var(--r-md);
  color: var(--text); outline: none; transition: border-color var(--t);
}
#chatSearch::placeholder, #msgSearch::placeholder { color: var(--text-faint); }
#chatSearch:focus { border-color: var(--accent); }

#typeChips { display: flex; gap: 6px; margin-top: 8px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border-faint); color: var(--text-muted);
  font-family: inherit; font-size: 11.5px; padding: 4px 11px; border-radius: 99px; cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.chip:hover { border-color: var(--border-strong); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

#chatList { flex: 1; overflow-y: auto; }
.chat-item {
  width: 100%; display: flex; gap: 10px; padding: 10px 12px;
  background: none; border: none; cursor: pointer; text-align: left; align-items: flex-start;
  color: var(--text); font-family: inherit;
  transition: background var(--t);
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent-soft); }
.chat-item .meta { min-width: 0; flex: 1; }
.chat-item .name-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-item .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .date { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }
.chat-item .sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.avatar {
  border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0; width: 34px; height: 34px; font-size: 13px;
}
.avatar.group { background: var(--accent-soft) !important; color: var(--accent); font-size: 15px; }

#sidebarFoot { padding: 10px; border-top: 1px solid var(--border); }
#sidebarFoot .pt-btn { width: 100%; justify-content: center; }
#sidebarFoot .note { font-size: 11px; color: var(--text-faint); text-align: center; margin-top: 7px; }

/* Chat pane ------------------------------------------------------------- */
#chatPane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chatHeader {
  background: var(--nav); border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: none; align-items: center; gap: 12px;
}
#chatHeader.active { display: flex; }
#chatHeader .info { min-width: 0; flex: 1; }
#chatHeader .info .name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chatHeader .info .sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#msgSearch {
  width: 170px; padding: 7px 10px; font-size: 12px;
  background: var(--field); border: 1px solid var(--border); border-radius: var(--r-md);
  color: var(--text); outline: none; transition: border-color var(--t);
}
#msgSearch:focus { border-color: var(--accent); }

#messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
#emptyPane {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13.5px; gap: 10px; text-align: center; padding: 24px;
}
.empty-icon { width: 40px; height: 40px; color: var(--text-faint); }

.day-sep { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--border-faint); }
.day-sep span { font-size: 11px; color: var(--text-faint); font-weight: 500; }

.msg-group { display: flex; gap: 10px; max-width: 100%; }
.msg-group.me { flex-direction: row-reverse; }
.msg-col { display: flex; flex-direction: column; gap: 3px; max-width: 68%; }
.msg-group.me .msg-col { align-items: flex-end; }
.msg-head { font-size: 11px; color: var(--text-faint); padding: 0 4px; }
.msg-head b { color: var(--text-muted); font-weight: 600; }
.bubble {
  background: var(--surface); border: 1px solid var(--border-faint);
  border-radius: var(--r-md); padding: 8px 12px;
  font-size: 13.5px; line-height: 1.55; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.msg-group.me .bubble { background: var(--accent-soft); border-color: var(--accent-ring); }
.bubble mark { background: var(--warn-soft); color: var(--text); border-radius: 3px; padding: 0 2px; }
.bubble a { color: var(--accent); text-decoration: underline; }
/* quoted original of a reply (messageReference attachment) */
.bubble .quote {
  border-left: 3px solid var(--border-strong); background: var(--surface-2);
  /* bottom spacing is a transparent border: the line clamp cuts at the padding
     edge, so bottom padding would show a sliver of the 4th line */
  border-radius: var(--r-sm); padding: 4px 8px 0; border-bottom: 4px solid transparent; margin-bottom: 6px;
  font-size: 12.5px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.bubble .quote b { display: block; font-weight: 600; color: var(--text); }
.attachment {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--accent); background: var(--accent-soft);
  border-radius: var(--r-sm); padding: 3px 8px; margin-top: 6px;
}

#loadingMsgs { display: none; padding: 14px; text-align: center; font-size: 12px; color: var(--text-muted); }
.spinner {
  width: 15px; height: 15px; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; vertical-align: -3px;
}
.spinner.dark { border-color: var(--border-strong); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--field) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Backup overlay -------------------------------------------------------- */
#overlay {
  position: fixed; inset: 0; background: rgba(8, 10, 20, 0.6);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
#overlay.active { display: flex; }
.overlay-card {
  background: var(--elevated); border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  padding: 22px; width: 100%; max-width: 480px;
}
.overlay-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.bar-outer { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-inner { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s; }
#overlayLog {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted);
  margin-top: 10px; max-height: 170px; overflow-y: auto; white-space: pre-wrap;
}
.overlay-card .row { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
#resumeToken {
  width: 100%; padding: 8px 10px; min-height: 56px; resize: vertical; outline: none;
  background: var(--field); border: 1px solid var(--border); border-radius: var(--r-md);
  color: var(--text); font-family: var(--font-mono); font-size: 11.5px;
}
.resume-note { font-size: 12.5px; color: var(--bad); margin-bottom: 6px; line-height: 1.5; }

/* Toast — teams.js flips display between none and block. ---------------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--status-h) + 16px); transform: translateX(-50%);
  background: var(--elevated); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  color: var(--text); font-size: 13px; padding: 10px 18px;
  display: none; z-index: 60; max-width: 90vw;
}

@media (max-width: 900px) {
  #app.active { flex-direction: column; }
  #sidebar { width: 100%; max-height: 45%; border-right: none; border-bottom: 1px solid var(--border); }
  #theme-label { display: none; }
  .msg-col { max-width: 84%; }
  /* the long mode pill shrinks with an ellipsis instead of wrapping onto 4 lines */
  #modeBadge { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-tools { flex: none; }
}
@media (max-width: 600px) {
  /* phone: keep the nav on one row inside the screen width */
  .pt-nav-inner { padding: 0 12px; gap: 8px; }
  .pt-nav .pt-brand::after { display: none; }      /* drop the "Tools" wordmark */
  .pt-nav .pt-badge { display: none; }              /* tool name is in the <title> */
  /* chat header: name on its own row, search + backup below */
  #chatHeader { flex-wrap: wrap; padding: 10px 12px; }
  #chatHeader .info { flex: 1 1 calc(100% - 50px); }
  #msgSearch { flex: 1 1 auto; width: auto; min-width: 0; }
  /* footer: one line inside its 30px bar, so it never spills over the messages */
  .pt-statusbar { padding: 0 12px; gap: 10px; }
  .pt-statusbar span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
