.tg-page { display:grid; gap:14px; color:var(--crm-ink); }
.tg-page :is(h1,h2,p) { margin:0; }
.tg-page h1 { font-size:clamp(1.5rem, 2.5vw, 1.9rem); letter-spacing:-.035em; }
.tg-page h2 { font-size:1.06rem; letter-spacing:-.015em; }
.tg-heading,.tg-account,.tg-sidebar-head,.tg-thread-head,.tg-setup-header {
  display:flex; align-items:center; gap:12px;
}
.tg-heading,.tg-sidebar-head { justify-content:space-between; }
.tg-account { flex-wrap:wrap; }
.tg-account > span { display:inline-flex; align-items:center; gap:7px; padding:7px 11px; border-radius:9px; background:#eaf7fb; color:#19456a; }
.tg-page .button.primary { background:var(--crm-gradient); color:white; }
.tg-layout { display:grid; grid-template-columns:minmax(245px, 300px) minmax(0,1fr); gap:14px; min-width:0; }
.tg-panel {
  min-width:0; border:1px solid var(--crm-border); border-radius:var(--crm-radius);
  background:linear-gradient(135deg, rgba(241,237,255,.91), transparent 54%),
    linear-gradient(225deg, rgba(223,249,253,.82), transparent 56%), var(--crm-surface);
  box-shadow:var(--crm-shadow);
}
.tg-sidebar { display:flex; flex-direction:column; gap:12px; padding:14px; max-height:max(510px, calc(100dvh - 130px)); }
.tg-sidebar-head,.tg-search { flex-shrink:0; }
.tg-search { display:flex; align-items:center; gap:8px; padding-inline:10px; border:1px solid var(--crm-border); border-radius:9px; background:white; color:var(--crm-muted); }
.tg-search:focus-within { border-color:var(--crm-indigo); box-shadow:var(--crm-focus); }
.tg-search input { border:0; padding:8px 0; min-width:0; width:100%; background:transparent; outline:0; box-shadow:none; }
.tg-contacts { display:grid; align-content:start; gap:4px; overflow:auto; }
.tg-contacts > p { padding:10px; color:var(--crm-muted); font-size:.88rem; }
.tg-contact {
  display:flex; align-items:center; gap:10px; min-width:0; width:100%; padding:8px;
  border:1px solid transparent; border-radius:9px; background:transparent; color:var(--crm-ink); font:inherit; text-align:left; cursor:pointer;
}
.tg-contact:hover { background:#f7f5ff; }
.tg-contact[aria-pressed="true"] { border-color:#a498f9; background:linear-gradient(110deg,#eae3ff,#edf8ff); }
.tg-contact:focus-visible { outline:2px solid var(--crm-indigo); outline-offset:-2px; }
.tg-contact-label,.tg-thread-head > div { display:grid; min-width:0; gap:3px; }
.tg-contact-label > *,.tg-thread-head > div > * { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.tg-contact-label small,.tg-thread-head p,.tg-candidate small { color:var(--crm-muted); font-size:.8rem; }
.tg-avatar,.tg-mark { flex:none; display:grid; place-items:center; width:36px; height:36px; border-radius:10px; color:#4433bf; background:#eae4fe; font-weight:700; }
.tg-mark { width:44px; height:44px; color:white; background:var(--crm-gradient); box-shadow:0 4px 12px #5145e548; }
.tg-workspace { height:max(510px, calc(100dvh - 130px)); overflow:hidden; }
.tg-thread { display:flex; flex-direction:column; height:100%; }
.tg-thread-head { padding:12px 15px; border-bottom:1px solid var(--crm-border); background:#ffffffa8; }
.tg-thread-head .button { flex-shrink:0; margin-left:auto; }
.tg-history {
  flex:1; min-height:0; overflow:auto; overflow-anchor:none; display:flex; flex-direction:column;
  padding:16px; background:linear-gradient(135deg,#f2f3fc,#edf5fc 70%,#f7f5fc);
}
.tg-older { flex:none; align-self:center; margin-bottom:12px; }
.tg-page [hidden] { display:none; }
.tg-messages { flex:none; display:grid; gap:10px; margin-top:auto; }
.tg-message {
  justify-self:start; max-width:min(85%, 670px); padding:8px 11px;
  border:1px solid #dce1ef; border-radius:3px 12px 12px 12px; background:white; color:var(--crm-ink);
  box-shadow:0 2px 6px rgba(46,51,111,.05);
}
.tg-message p { white-space:pre-wrap; overflow-wrap:anywhere; }
.tg-message.is-outgoing { justify-self:end; border-color:#ccc2fa; border-radius:12px 3px 12px 12px; background:#eae5ff; }
.tg-message time { display:block; margin-top:5px; color:#535c76; font-size:.72rem; text-align:right; font-variant-numeric:tabular-nums; }
.tg-message .tg-media { display:flex; align-items:center; gap:6px; color:#4f4078; font-size:.84rem; margin-top:3px; }
.tg-history-state,.tg-empty p,.tg-readonly { color:var(--crm-muted); text-align:center; }
.tg-compose { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:end; gap:8px; padding:12px; border-top:1px solid var(--crm-border); background:white; }
.tg-compose .field { margin:0; }
.tg-compose textarea { width:100%; min-height:42px; max-height:140px; height:auto; resize:vertical; }
.tg-compose .form-error { grid-column:1/-1; }
.tg-thread-error,.tg-readonly { padding:8px 12px; }
.tg-visually-hidden { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
.tg-empty { height:100%; padding:20px; display:grid; place-content:center; justify-items:center; gap:8px; text-align:center; }
.tg-link,.tg-setup { display:grid; gap:14px; align-content:start; padding:20px; }
.tg-link { height:100%; overflow:auto; }
.tg-setup { width:min(100%, 500px); }
.tg-setup-header { align-items:flex-start; }
.tg-setup-header p,.tg-form p,.tg-qr p { margin-top:4px; color:var(--crm-muted); }
.tg-form { display:grid; justify-items:start; gap:12px; width:min(100%, 450px); }
.tg-form .field { width:100%; margin:0; }
.tg-setup > .button { justify-self:start; }
.tg-credentials summary { margin-bottom:8px; color:#4433bf; cursor:pointer; }
.tg-qr { display:flex; flex-wrap:wrap; align-items:center; gap:12px; }
.tg-qr img { width:208px; height:208px; border:1px solid var(--crm-border); border-radius:9px; background:white; }
.tg-qr p { max-width:27ch; }
.tg-candidate { display:flex; flex-wrap:wrap; align-items:center; gap:10px; width:min(100%, 450px); padding:9px; border:1px solid #c5b9ff; border-radius:10px; background:#f7f3ff; }
.tg-candidate > div { display:grid; gap:3px; flex:1; min-width:100px; overflow-wrap:anywhere; }
@media (max-width:800px) {
  .tg-layout { grid-template-columns:1fr; }
  .tg-contacts { max-height:140px; }
  .tg-sidebar { padding:10px; gap:8px; }
  .tg-workspace { height:510px; }
}
@media (max-width:460px) {
  .tg-heading,.tg-account { align-items:flex-start; }
  .tg-account { justify-content:flex-end; gap:6px; }
  .tg-history,.tg-thread-head { padding:9px; }
  .tg-message { max-width:95%; }
}
