/* =============================================================================
   Elivapro Connect — CRM Inbox design system
   A single, token-driven stylesheet. Everything keys off CSS custom properties
   so theming (light/dark) and rebranding are one-line changes.
   ============================================================================= */

/* ------------------------------- Design tokens ---------------------------- */
:root {
  /* Brand — Elivapro teal/green WhatsApp lineage, but desaturated for a CRM */
  --brand:        #0b8a6f;
  --brand-strong: #075e54;
  --brand-soft:   #e7f5f1;
  --accent:       #25d366;

  /* Neutrals (light theme) */
  --bg:        #f0f2f5;
  --surface:   #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --border:    #e4e7eb;
  --border-strong: #d2d7de;

  --text:        #111b21;
  --text-soft:   #54656f;
  --text-faint:  #8696a0;
  --on-brand:    #ffffff;

  /* Chat bubbles */
  --bubble-in:  #ffffff;
  --bubble-out: #d9fdd3;
  --chat-bg:    #efeae2;

  /* Status / feedback */
  --danger:  #d92d20;
  --warning: #dc8a00;
  --success: #0b8a6f;
  --info:    #2563eb;
  --read:    #53bdeb;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(11, 27, 33, .06);
  --shadow-md: 0 4px 16px rgba(11, 27, 33, .10);
  --shadow-lg: 0 12px 40px rgba(11, 27, 33, .16);

  /* Geometry */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --sidebar-w: 384px;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
          "Apple Color Emoji", "Segoe UI Emoji", sans-serif;

  --speed: 160ms;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0b141a;
    --surface:   #111b21;
    --surface-2: #1a242b;
    --surface-3: #202c33;
    --border:    #222d34;
    --border-strong: #2a3942;

    --text:        #e9edef;
    --text-soft:   #aebac1;
    --text-faint:  #8696a0;

    --brand-soft: #14342c;

    --bubble-in:  #1f2c33;
    --bubble-out: #144d37;
    --chat-bg:    #0b141a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  }
}

/* ------------------------------- Reset / base ----------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--brand-soft); }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Scrollbars (webkit) */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
*::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------- Buttons -------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font-weight: 600; font-size: 14px;
  background: var(--surface-3); color: var(--text);
  transition: background var(--speed) var(--ease), transform var(--speed) var(--ease),
              box-shadow var(--speed) var(--ease), opacity var(--speed) var(--ease);
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-block { width: 100%; }
.btn-icon {
  width: 40px; height: 40px; padding: 0; border: none; border-radius: var(--radius-pill);
  background: transparent; color: var(--text-soft); flex: 0 0 auto;
}
.btn-icon:hover { background: var(--surface-3); color: var(--text); }
.btn-icon:focus-visible { outline: none; background: var(--surface-3); }
.btn-icon svg { width: 22px; height: 22px; }

/* Spinner */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
.spinner.lg { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------- Avatar --------------------------------- */
.avatar {
  width: 49px; height: 49px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; font-weight: 600;
  font-size: 17px; user-select: none; letter-spacing: .2px;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }

/* =============================================================================
   App shell
   ============================================================================= */
#app { height: 100dvh; display: flex; flex-direction: column; }

/* -------- Full-screen states (auth, org picker, loading) ------------------ */
.screen {
  flex: 1; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), transparent 60%),
    var(--bg);
}
.card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 36px 32px;
}
.brand-lockup { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--brand-strong));
  display: grid; place-items: center; color: #fff; box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 26px; height: 26px; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: -.2px; }
.card h1 { font-size: 22px; margin: 22px 0 6px; letter-spacing: -.3px; }
.card .muted { color: var(--text-soft); margin: 0 0 24px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--text-faint); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.btn-google {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
}
.btn-google:hover { background: var(--surface-2); }
.btn-google svg { width: 18px; height: 18px; }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger); margin-bottom: 16px;
}
.alert.info { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 30%, transparent); color: var(--brand-strong); }

/* Org picker list */
.org-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.org-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
  transition: border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.org-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.org-item .meta { flex: 1; min-width: 0; }
.org-item .name { font-weight: 600; }
.org-item .sub { font-size: 12.5px; color: var(--text-soft); }
.org-item .chev { color: var(--text-faint); }
.tag {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--surface-3); color: var(--text-soft);
}

/* =============================================================================
   Workspace (two-pane inbox)
   ============================================================================= */
.workspace { flex: 1; display: flex; min-height: 0; background: var(--bg); }

/* ----------------------------- Sidebar (list) ----------------------------- */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border);
}
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  min-height: 60px;
}
.topbar .who { flex: 1; min-width: 0; }
.topbar .who .name { font-weight: 600; font-size: 14px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who .org { font-size: 12px; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search-row { padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.search {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--surface-3); border-radius: var(--radius-pill);
}
.search svg { width: 18px; height: 18px; color: var(--text-faint); flex: 0 0 auto; }
.search input { flex: 1; border: none; background: transparent; outline: none; min-width: 0; }

.filters { display: flex; gap: 6px; padding: 8px 12px; background: var(--surface);
  border-bottom: 1px solid var(--border); }
.chip {
  padding: 5px 13px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 600;
  background: var(--surface-3); color: var(--text-soft); border: 1px solid transparent;
}
.chip[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-strong);
  border-color: color-mix(in srgb, var(--brand) 25%, transparent); }

/* Conversation list */
.conv-list { flex: 1; overflow-y: auto; min-height: 0; }
.conv {
  display: flex; align-items: center; gap: 13px; padding: 11px 16px;
  cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background var(--speed) var(--ease);
}
.conv:hover { background: var(--surface-2); }
.conv[aria-current="true"] { background: var(--surface-3); }
.conv .body { flex: 1; min-width: 0; }
.conv .line1 { display: flex; align-items: baseline; gap: 8px; }
.conv .title { font-weight: 600; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 12px; color: var(--text-faint); flex: 0 0 auto; }
.conv[data-unread="true"] .time { color: var(--brand); font-weight: 600; }
.conv .line2 { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.conv .preview { flex: 1; min-width: 0; font-size: 13.5px; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv[data-unread="true"] .preview { color: var(--text); }
.badge {
  flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--radius-pill); background: var(--accent); color: #04270f;
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.tick { flex: 0 0 auto; display: inline-flex; color: var(--text-faint); }
.tick svg { width: 16px; height: 16px; }
.tick.read { color: var(--read); }
.tick.failed { color: var(--danger); }

/* ----------------------------- Chat pane ---------------------------------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--chat-bg);
  background-image:
    radial-gradient(circle at 25% 15%, rgba(11,138,111,.04), transparent 25%),
    radial-gradient(circle at 80% 70%, rgba(11,138,111,.04), transparent 25%);
}
.chat-header {
  display: flex; align-items: center; gap: 13px; padding: 9px 16px; min-height: 60px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.chat-header .body { flex: 1; min-width: 0; }
.chat-header .title { font-weight: 600; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header .sub { font-size: 12.5px; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-btn { display: none; }

.messages { flex: 1; overflow-y: auto; min-height: 0; padding: 18px 7% 10px; }
.day-sep { text-align: center; margin: 16px 0; }
.day-sep span {
  background: var(--surface); color: var(--text-soft); font-size: 12px; font-weight: 600;
  padding: 5px 12px; border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
}

.bubble-row { display: flex; margin: 2px 0; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: min(75%, 560px); padding: 7px 10px 8px; border-radius: var(--radius);
  background: var(--bubble-in); box-shadow: var(--shadow-sm); position: relative;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.bubble-row.out .bubble { background: var(--bubble-out); }
.bubble.first-in  { border-top-left-radius: 4px; }
.bubble.first-out { border-top-right-radius: 4px; }
.bubble .text { white-space: pre-wrap; }
.bubble .caption { white-space: pre-wrap; margin-top: 4px; }
.bubble a { color: var(--info); }
.bubble .media-thumb {
  max-width: 100%; border-radius: var(--radius-sm); display: block; margin: 2px 0;
  background: var(--surface-3);
}
.bubble .attach {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px; min-width: 200px;
}
.bubble .attach .ico { width: 38px; height: 38px; border-radius: 9px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--surface-3); color: var(--text-soft); }
.bubble .attach .ico svg { width: 20px; height: 20px; }
.bubble .meta {
  display: flex; align-items: center; gap: 4px; justify-content: flex-end;
  font-size: 11px; color: var(--text-faint); margin-top: 2px; user-select: none;
}
.bubble .meta .tick svg { width: 15px; height: 15px; }
.bubble .system { font-style: italic; color: var(--text-soft); }
.context-quote {
  border-left: 3px solid var(--brand); padding: 3px 8px; margin-bottom: 4px;
  background: color-mix(in srgb, var(--brand) 8%, transparent); border-radius: 4px;
  font-size: 13px; color: var(--text-soft); white-space: pre-wrap;
}

/* Composer */
.composer {
  flex: 0 0 auto; padding: 10px 16px; background: var(--surface-2);
  border-top: 1px solid var(--border); display: flex; align-items: flex-end; gap: 10px;
}
.composer .input-wrap {
  flex: 1; display: flex; align-items: flex-end; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: 6px 8px 6px 14px;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.composer .input-wrap:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.composer textarea {
  flex: 1; border: none; background: transparent; resize: none; outline: none;
  max-height: 140px; padding: 5px 0; line-height: 1.4;
}
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; flex: 0 0 auto; background: var(--brand);
  color: #fff; display: grid; place-items: center; border: none;
  transition: background var(--speed) var(--ease), transform var(--speed) var(--ease);
}
.send-btn:hover { background: var(--brand-strong); }
.send-btn:disabled { background: var(--border-strong); cursor: not-allowed; }
.send-btn svg { width: 22px; height: 22px; }

.composer-note {
  padding: 8px 16px; background: var(--surface-2); border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-soft); display: flex; gap: 8px; align-items: center;
}
.composer-note.warn { color: var(--warning); }

/* ----------------------------- Contact panel ------------------------------ */
.contact-panel {
  width: 340px; flex: 0 0 340px; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border);
}
.contact-panel[hidden] { display: none; }
.panel-head {
  display: flex; align-items: center; min-height: 60px; padding: 9px 12px 9px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); gap: 8px;
}
.panel-head .title { flex: 1; font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; min-height: 0; }
.contact-hero { display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 24px 16px 18px; text-align: center; border-bottom: 1px solid var(--border); }
.contact-hero .avatar { width: 76px; height: 76px; font-size: 28px; }
.contact-hero .name { font-size: 18px; font-weight: 700; }
.contact-hero .phone { color: var(--text-soft); font-size: 14px; }
.contact-hero .actions { display: flex; gap: 8px; margin-top: 6px; }

.section { padding: 16px; border-bottom: 1px solid var(--border); }
.section h3 {
  margin: 0 0 12px; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-faint); display: flex; align-items: center; gap: 6px;
}
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 14px; }
.kv .k { color: var(--text-soft); flex: 0 0 auto; }
.kv .v { text-align: right; word-break: break-word; }

/* Status segmented control */
.segmented { display: flex; background: var(--surface-3); border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.segmented button {
  flex: 1; padding: 7px 0; border: none; background: transparent; border-radius: 6px;
  font-size: 13px; font-weight: 600; color: var(--text-soft);
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Assignment select */
.select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text);
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%238696a0' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.assignee-line { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.assignee-line .who { flex: 1; min-width: 0; }
.assignee-line .who .n { font-weight: 600; font-size: 14px; }
.assignee-line .who .r { font-size: 12px; color: var(--text-soft); }

/* Tags */
.tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 11px;
  border-radius: var(--radius-pill); font-size: 13px; font-weight: 600;
  background: var(--brand-soft); color: var(--brand-strong);
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
}
.tag-pill button { border: none; background: none; color: inherit; opacity: .65; display: grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%; }
.tag-pill button:hover { opacity: 1; background: color-mix(in srgb, var(--brand) 18%, transparent); }
.tag-pill button svg { width: 13px; height: 13px; }
.tag-input {
  width: 100%; margin-top: 10px; padding: 9px 12px; border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm); background: transparent; color: var(--text);
}
.tag-input:focus { outline: none; border-style: solid; border-color: var(--brand); }

/* Notes */
.notes-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.note {
  background: #fff7e0; border: 1px solid #f3e3a8; border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13.5px; position: relative;
}
@media (prefers-color-scheme: dark) {
  .note { background: #2a2410; border-color: #4a3f15; }
}
.note .note-text { white-space: pre-wrap; word-break: break-word; color: var(--text); }
.note .note-foot { display: flex; align-items: center; gap: 6px; margin-top: 7px;
  font-size: 11.5px; color: var(--text-soft); }
.note .note-foot .del { margin-left: auto; border: none; background: none; color: var(--text-faint);
  opacity: 0; transition: opacity var(--speed); padding: 2px; border-radius: 4px; }
.note:hover .note-foot .del { opacity: 1; }
.note .note-foot .del:hover { color: var(--danger); }
.note .note-foot .del svg { width: 14px; height: 14px; display: block; }
.note-compose { display: flex; flex-direction: column; gap: 8px; }
.note-compose textarea {
  width: 100%; min-height: 64px; resize: vertical; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); outline: none;
}
.note-compose textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.muted-empty { color: var(--text-faint); font-size: 13px; font-style: italic; }

/* --------------------------- Empty / placeholder -------------------------- */
.placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 14px; padding: 40px; color: var(--text-soft);
}
.placeholder .glyph {
  width: 96px; height: 96px; border-radius: 28px; display: grid; place-items: center;
  background: var(--surface); box-shadow: var(--shadow-md); color: var(--brand);
}
.placeholder .glyph svg { width: 48px; height: 48px; }
.placeholder h2 { margin: 6px 0 0; color: var(--text); font-weight: 700; }
.placeholder p { margin: 0; max-width: 340px; }

.list-empty { padding: 40px 24px; text-align: center; color: var(--text-soft); }
.list-skeleton { padding: 8px 0; }
.skel-row { display: flex; gap: 13px; padding: 11px 16px; }
.skel { background: var(--surface-3); border-radius: 6px; animation: pulse 1.4s ease-in-out infinite; }
.skel.circle { width: 49px; height: 49px; border-radius: 50%; flex: 0 0 auto; }
.skel.line { height: 12px; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* --------------------------------- Toasts --------------------------------- */
.toast-stack { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  background: var(--text); color: var(--surface); padding: 11px 18px; border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  animation: toast-in var(--speed) var(--ease);
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --------------------------------- Modal ---------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11, 27, 33, .55); z-index: 200;
  display: grid; place-items: center; padding: 20px; animation: fade .15s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 480px; max-height: 80vh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; animation: pop .18s var(--ease);
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 14px 16px; overflow-y: auto; }

.tpl-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); margin-bottom: 8px;
  transition: border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.tpl-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.tpl-item .chev { color: var(--text-faint); }
.tpl-name { font-weight: 600; }
.tpl-body { font-size: 13px; color: var(--text-soft); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tpl-preview {
  margin-top: 6px; padding: 10px 12px; background: var(--bubble-out); color: var(--text);
  border-radius: var(--radius); white-space: pre-wrap; font-size: 14px; min-height: 20px;
}

.media-slot { min-width: 160px; }
.load-older { display: grid; place-items: center; padding: 8px 0 14px; }

/* -------- Connection banner -------- */
.conn-banner {
  background: var(--warning); color: #2a1a00; text-align: center; padding: 6px;
  font-size: 13px; font-weight: 600;
}

/* =============================================================================
   Responsive — collapse to single pane on mobile
   ============================================================================= */
/* Hide the contact panel on narrower desktops to keep the chat readable; it
   toggles open via the info button. On wide screens it can stay pinned. */
@media (max-width: 1180px) {
  .contact-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 20;
    box-shadow: var(--shadow-lg); }
  .chat { position: relative; }
}
.workspace { position: relative; }

@media (max-width: 820px) {
  :root { --sidebar-w: 100%; }
  .sidebar { border-right: none; }
  .workspace[data-view="thread"] .sidebar { display: none; }
  .workspace[data-view="list"] .chat-slot { display: none; }
  .back-btn { display: inline-flex; }
  .messages { padding-left: 12px; padding-right: 12px; }
  .bubble { max-width: 85%; }
  .contact-panel { width: 100%; flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
