/* Calls page */
.tv-calls-standalone{display:flex;flex-direction:column;gap:12px}
.tv-calls .tv-sidebar-block{margin-bottom:12px}
.tv-calls-tabs .tv-seg--compact{width:100%}
.tv-calls-tabs .tv-seg a{flex-direction:row;justify-content:center;align-items:center;gap:8px;padding:10px 14px;font-size:15px}
.tv-calls-tabs .tv-seg a .tv-seg__ico{font-size:20px}
.tv-calls-search .tv-input{width:100%}
.tv-calls-list{max-height:60vh;overflow:auto}
.tv-calls-list li{margin:0;padding:0}
.tv-calls-list li > button.tv-chatitem{width:100%;display:flex;text-align:left}
.tv-calls-empty{display:flex;align-items:center;justify-content:center;text-align:center;color:var(--tv-muted);min-height:120px}
.tv-calls-alert{background:#fff7ed;border:1px solid #f97316;color:#92400e;font-size:13px;padding:12px;border-radius:12px}
.tv-embed.tv-calls .tv-sidebar-block{background:transparent;border:none;padding:0}
.tv-embed.tv-calls .tv-sidebar-block + .tv-sidebar-block{margin-top:12px}
.tv-calls-tabs .tv-seg{width:100%}
.tv-body.is-calls .tv-calls-tabs .tv-seg{border-radius:12px}
.tv-calls-list{max-height:60vh;overflow:auto}
.tv-body.is-calls .tv-calls-list{background:transparent;border:none;padding:0}
.tv-calls-empty{display:flex;align-items:center;justify-content:center;text-align:center;color:var(--tv-muted);min-height:120px}
.tv-body.is-calls .tv-calls-empty{background:transparent;border:none;padding:24px 0}
.tv-calls-alert{background:#fff7ed;border:1px solid #f97316;color:#92400e;font-size:13px}
.tv-calls-embed{display:flex;flex-direction:column;gap:12px}
.tv-calls-embed .tv-sidebar-block{margin-bottom:12px}
.tv-calls__panel{padding:12px;display:flex;flex-direction:column;gap:12px}
.tv-calls__panel .tv-sidebar-block{margin-bottom:0}
.tv-calls__panel .tv-list{margin:0;padding:0}
.tv-calls__placeholder{padding:24px 12px;text-align:center;font-size:14px;color:var(--tv-muted)}

.tv-calls__alert{margin-bottom:12px;padding:10px 12px;border-radius:10px;border:1px solid #f97316;background:#fff7ed;color:#92400e;font-size:13px}
.tv-calls__content{flex:1;display:flex;align-items:center;justify-content:center;padding:24px}
.tv-calls__card{width:100%;max-width:520px;text-align:center;padding:32px;border:1px solid var(--tv-border);border-radius:16px;background:var(--tv-bg)}
.tv-calls__avatar{width:72px;height:72px;border-radius:50%;margin:0 auto 16px;background:var(--tv-orange);color:#fff;font-weight:800;font-size:28px;display:flex;align-items:center;justify-content:center}
.tv-calls__actions{margin-top:24px}
.tv-calls__form{display:flex;gap:12px;justify-content:center;flex-wrap:wrap}
.tv-inline-form{display:inline-block;margin:0}
.tv-calls__empty{font-size:16px;color:var(--tv-muted)}
.tv-contacts-standalone{min-height:calc(100vh - 80px);padding:12px;padding-bottom:calc(12px + env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:12px;background:var(--tv-bg);color:var(--tv-text)}
.tv-contacts-standalone .tv-embed{width:100%}
.tv-contacts-standalone .tv-sidebar-block{margin-bottom:12px}
.tv-body.theme-dark .tv-contacts-standalone{background:#0b0f14}
.tv-body.theme-dark .tv-contacts-standalone .tv-sidebar-block{background:#111827;border-color:#1f2937}

.tv-group-new{padding:16px 12px 8px;display:flex;justify-content:flex-end}
.tv-group-new__title{margin-right:auto;font-weight:700;font-size:14px;color:var(--tv-text);align-self:center}
.tv-group-btn{width:44px;height:44px;border-radius:14px;border:none;background:var(--tv-orange);color:#fff;font-size:22px;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px rgba(249,106,0,.25);transition:background .15s ease,transform .06s ease,opacity .15s ease}
.tv-group-btn:hover{background:var(--tv-orange-600)}
.tv-group-btn:active{transform:translateY(1px)}
.tv-group-btn:disabled{opacity:.6;cursor:wait}
.tv-group-meta{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
.tv-group-meta__label{font-size:12px;color:var(--muted2)}
.tv-group-meta__value{font-weight:600;font-size:14px}
.tv-group-meta__actions{display:flex;gap:8px}
.tv-group-meta__stats{display:flex;gap:16px;margin-top:12px}
.tv-group-manage{padding:12px;border-bottom:1px solid var(--tv-border);background:var(--tv-bg)}
.tv-group-manage__header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
.tv-group-members{display:flex;flex-direction:column;gap:10px;max-height:320px;overflow:auto}
.tv-group-member{display:flex;align-items:center;gap:12px;padding:10px;border:1px solid var(--tv-border);border-radius:10px;background:var(--tv-bg-soft)}
.tv-group-member__avatar{width:36px;height:36px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:var(--tv-orange);color:#fff;font-weight:700}
.tv-group-member__main{flex:1;min-width:0}
.tv-group-member__name{font-weight:600}
.tv-group-member__email{font-size:12px;color:var(--tv-muted)}
.tv-group-member__tags{display:flex;gap:6px;margin-top:4px;flex-wrap:wrap}
.tv-group-badge{font-size:11px;padding:2px 6px;border-radius:999px;background:rgba(15,118,110,0.1);color:#0f766e}
.tv-group-member__actions{display:flex;gap:8px;align-items:center}
.tv-group-member__select{border:1px solid var(--tv-border);border-radius:6px;padding:4px 6px;background:var(--tv-bg);color:var(--tv-text)}
.tv-group-member__btn{border:1px solid var(--tv-border);background:var(--tv-bg);color:var(--tv-text);padding:4px 8px;border-radius:6px;cursor:pointer;font-size:12px}
.tv-group-member__btn:hover{background:var(--tv-bg-soft)}
.tv-group-member__btn--danger{color:#b91c1c;border-color:#fca5a5}

@media (min-width: 901px){
  .tv-body.is-calls .tv-tabbar{display:none}
  .tv-body.is-calls .tv-main{padding:0}
  .tv-body.is-calls .tv-container.tv-calls{max-width:360px;padding-left:12px;padding-right:12px;margin:0 auto}
  .tv-body.is-calls .tv-calls .tv-sidebar-block{background:transparent;border:none;padding:0}
  .tv-body.is-calls .tv-calls-list{max-height:calc(100vh - 260px)}
  .tv-calls-standalone{min-height:100vh}
  .tv-tabbar{display:none !important}
}

.tv-call{display:flex;flex-direction:column;min-height:100vh;background:var(--tv-bg);color:var(--tv-text)}
.tv-call__header{display:flex;align-items:center;gap:16px;padding:16px;border-bottom:1px solid var(--tv-border)}
.tv-call__back{font-size:18px;text-decoration:none;color:var(--tv-text)}
.tv-call__title{font-weight:700;font-size:20px}
.tv-call__subtitle{font-size:14px;color:var(--tv-muted)}
.tv-call__status{margin-left:auto;font-size:13px;color:var(--tv-muted)}
.tv-call__body{flex:1;display:flex;gap:16px;padding:24px;flex-wrap:wrap}
.tv-call__participants{flex:0 0 260px;display:flex;flex-direction:column;gap:10px}
.tv-call__participant{display:flex;gap:10px;align-items:center;padding:10px;border:1px solid var(--tv-border);border-radius:10px;background:var(--tv-bg-soft)}
.tv-call__avatar{width:44px;height:44px;border-radius:50%;background:var(--tv-orange);color:#fff;font-weight:700;display:flex;align-items:center;justify-content:center}
.tv-call__meta{flex:1;min-width:0}
.tv-call__name{font-weight:600}
.tv-call__state{font-size:12px;color:var(--tv-muted)}
.tv-call__stage{flex:1;display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:16px;align-items:stretch}
.tv-call__video{position:relative;background:#000;border-radius:16px;overflow:hidden;display:flex;align-items:center;justify-content:center;color:#fff}
.tv-call__placeholder{padding:16px;font-size:14px;color:rgba(255,255,255,0.7);text-align:center}
.tv-call__controls{padding:16px;display:flex;gap:16px;justify-content:center;border-top:1px solid var(--tv-border)}
.tv-call__btn{width:56px;height:56px;border-radius:50%;border:none;background:var(--tv-bg-soft);color:var(--tv-text);font-size:20px;cursor:pointer;display:flex;align-items:center;justify-content:center}
.tv-call__btn--end{background:#ef4444;color:#fff}
:root{
  --tv-orange:#ff6a00; /* брендовый акцент (по мотивам сайта) */
  --tv-orange-600:#e85f00;
  --tv-text:#1f2937;
  --tv-muted:#6b7280;
  --tv-bg:#ffffff;
  --tv-bg-soft:#f8fafc;
  --tv-border:#e5e7eb;
  --tv-shadow:0 1px 2px rgba(0,0,0,.05),0 4px 10px rgba(0,0,0,.04);
  --radius:8px;
  /* aliases for in-template variables */
  --bg: var(--tv-bg);
  --text: var(--tv-text);
  --border: var(--tv-border);
  --muted2: var(--tv-muted);
  /* spacing/size tokens */
  --space-1: 6px;
  --space-2: 8px;
  --space-3: 10px;
  --space-4: 12px;
  --control-h: 44px;
  --control-h-sm: 36px;
}
/* Auth layout */
.auth-body{
  margin:0;
  min-height:100vh;
  font-family:"Inter","SF Pro Display","Segoe UI",Roboto,system-ui,-apple-system,BlinkMacSystemFont,sans-serif;
  background:radial-gradient(circle at top,#13223a 0%,#0b1220 45%,#050910 100%);
  color:#f5f7fb;
  display:flex;
  align-items:center;
  justify-content:center;
}
.auth-shell{
  width:100%;
  max-width:520px;
  padding:32px 16px;
}
.auth-card{
  background:rgba(15,23,42,0.85);
  border:1px solid rgba(148,163,184,0.3);
  border-radius:28px;
  box-shadow:0 30px 80px rgba(2,6,23,0.5);
  padding:36px;
  backdrop-filter:blur(18px);
}
@media (max-width:600px){
  .auth-card{padding:28px;border-radius:22px}
}
.auth-header{
  display:flex;
  align-items:center;
  gap:16px;
  margin-bottom:28px;
}
.auth-header{
  display:flex;
  align-items:center;
  gap:16px;
  margin-bottom:28px;
}
.auth-logo{
  width:60px;
  height:60px;
  border-radius:18px;
  background:rgba(255,255,255,0.08);
  padding:0;
  border:1px solid rgba(148,163,184,0.35);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  flex-shrink:0;
}
.auth-logo__img{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
}
.auth-product{
  margin:0;
  font-size:13px;
  text-transform:uppercase;
  letter-spacing:0.2em;
  color:#94a3b8;
}
.auth-heading{
  margin:4px 0 0;
  font-size:24px;
  font-weight:700;
  color:#f8fafc;
}
.auth-title{
  margin:0 0 6px 0;
  font-size:28px;
  font-weight:700;
  color:#f8fafc;
}
.auth-alert{
  margin-bottom:16px;
  padding:12px 16px;
  border-radius:14px;
  background:rgba(248,113,113,0.15);
  border:1px solid rgba(248,113,113,0.45);
  color:#fecaca;
  font-size:14px;
}
.auth-form{
  display:flex;
  flex-direction:column;
  gap:18px;
}
.auth-input{
  margin-top:6px;
  width:100%;
  border-radius:14px;
  border:1px solid rgba(148,163,184,0.4);
  background:rgba(15,23,42,0.65);
  color:#f8fafc;
  font-size:15px;
  padding:12px 16px;
  transition:border-color .2s ease,box-shadow .2s ease,background .2s ease;
}
.auth-input:focus{
  outline:none;
  border-color:#ff9f3f;
  box-shadow:0 0 0 3px rgba(255,159,63,0.25);
  background:rgba(15,23,42,0.85);
}
.auth-form label{
  font-size:13px;
  text-transform:uppercase;
  letter-spacing:0.08em;
  color:#cbd5f5;
  display:flex;
  flex-direction:column;
  gap:4px;
}
.auth-submit{
  margin-top:8px;
  border:none;
  border-radius:16px;
  padding:14px;
  font-size:15px;
  font-weight:600;
  cursor:pointer;
  color:#0b0f14;
  background:linear-gradient(135deg,#ffb347,#ff6a00);
  box-shadow:0 18px 35px rgba(255,106,0,0.35);
  transition:transform .12s ease,box-shadow .12s ease,filter .12s ease;
}
.auth-submit:hover{
  filter:brightness(1.05);
  box-shadow:0 22px 40px rgba(255,106,0,0.45);
}
.auth-submit:active{
  transform:translateY(1px);
}
.auth-switch{
  margin-top:18px;
  font-size:14px;
  color:#cbd5f5;
  text-align:center;
}
.auth-link{
  color:#ff9f3f;
  text-decoration:none;
  font-weight:600;
}
.auth-link:hover{
  text-decoration:underline;
}
.auth-footer{
  margin-top:24px;
  font-size:12px;
  color:#94a3b8;
  text-align:center;
}
*{box-sizing:border-box}
body.tv-body{margin:0;background:var(--tv-bg);color:var(--tv-text);font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;overflow-x:hidden}
@supports (padding:max(0px)){
  body.tv-body::before{
    content:"";
    position:fixed;
    top:0;
    left:0;
    right:0;
    height:env(safe-area-inset-top);
    background:var(--tv-bg);
    z-index:40;
    pointer-events:none;
  }
}
.tv-container{max-width:1440px;margin:0 auto;padding:16px}
.tv-header{border-bottom:1px solid var(--tv-border);background:var(--tv-bg);position:sticky;top:0;z-index:10}
@media (min-width: 901px){
  .tv-header{display:none}
}
.tv-header__inner{display:flex;align-items:center;gap:12px}
.tv-brand{color:var(--tv-orange);font-weight:800;letter-spacing:0.5px}
.tv-header__search{flex:1;display:flex}
.tv-input--search{max-width:560px;width:100%}
.tv-header__actions{display:flex;align-items:center;gap:10px}
.tv-avatar{width:32px;height:32px;border-radius:50%;background:var(--tv-orange);color:#fff;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700}
.tv-main{padding:16px}
/* ensure space for mobile tabbar */
.tv-main{padding-bottom:16px}
/* Messenger view: no outer paddings */
.tv-body.is-messenger .tv-main,
.tv-body.is-contacts .tv-main,
.tv-body.is-calls .tv-main,
.tv-body.is-settings .tv-main{padding:0}
.tv-body.is-messenger .tv-container,
.tv-body.is-contacts .tv-container,
.tv-body.is-calls .tv-container,
.tv-body.is-settings .tv-container{padding:0;max-width:none;width:100%}
/* Contacts/Settings: align widths with messenger aside */
.tv-body.is-contacts .tv-main,
.tv-body.is-settings .tv-main,
.tv-body.is-calls .tv-main{padding-left:0;padding-right:0}

/* Auth cards */
.tv-card{max-width:420px;margin:40px auto;padding:24px;border:1px solid var(--tv-border);border-radius:var(--radius);background:var(--tv-bg-soft)}
.tv-card h2{margin:0 0 12px 0}
.tv-field{margin:10px 0}
.tv-input{width:100%;padding:10px 12px;border:1px solid var(--tv-border);border-radius:var(--radius);outline:none}
.tv-input:focus{border-color:var(--tv-orange)}
.tv-input:focus-visible{outline:2px solid #ffca99; outline-offset:2px}
.tv-btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;padding:10px 14px;border:none;border-radius:var(--radius);background:var(--tv-orange);color:#fff;cursor:pointer}
.tv-btn:hover{background:var(--tv-orange-600)}
.tv-link{color:var(--tv-orange);text-decoration:none}
.tv-icon{width:18px;height:18px;display:inline-block}
.tv-hide-sm{display:inline}
.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}

/* Messenger */
.tv-split{display:flex;height:100vh;gap:0}
.tv-split,.tv-aside,.tv-chat{min-width:0}
.tv-split,.tv-aside,.tv-chat{min-width:0}
.tv-aside{width:340px;border-right:1px solid var(--tv-border);padding:12px;background:var(--tv-bg);display:flex;flex-direction:column;min-height:0; --aside-inner:100%}
@media (min-width: 901px){
  /* Fixed desktop aside: 360px, inner content 320px (12px left + 28px right) */
  .tv-aside{flex:0 0 360px; width:360px; align-items:flex-start; --aside-inner: 100%; padding-left:12px; padding-right:28px}
}
/* Desktop: standalone contacts/settings mimic aside width */
@media (min-width: 901px){
  .tv-body.is-contacts .tv-container,
  .tv-body.is-settings .tv-container{max-width:360px;padding-left:12px;padding-right:28px}
  .tv-body.is-contacts .tv-sidebar-block,
  .tv-body.is-settings .tv-sidebar-block{width:100%;margin-left:0;margin-right:0}
  /* Ensure embedded contacts/settings blocks inside messenger aside exactly match inner width (320px) */
  .tv-aside .tv-embed{width:100%}
  /* Fill available inner width; avoid 1px overflow from borders/paddings */
  .tv-aside .tv-embed .tv-sidebar-block{width:100% !important; max-width:100% !important; margin-left:0 !important; margin-right:0 !important}
}
.tv-sidebar-block{margin-bottom:12px;border:1px solid var(--tv-border);border-radius:var(--radius);padding:10px;background:#fff}
.tv-conv-title{margin:6px 0;font-weight:700}
.tv-list{list-style:none;margin:0;padding:0}
.tv-chatitem{display:flex;align-items:center;gap:10px;padding:8px 10px;border-radius:10px;cursor:pointer;text-decoration:none;color:inherit}
.tv-chatitem:hover{background:var(--tv-bg-soft)}
.tv-chatitem:focus-visible{outline:2px solid #ffca99; outline-offset:2px}
.tv-chatitem.is-active{background:#fff;border:1px solid var(--tv-border)}
.tv-avatar--list{width:40px;height:40px;border-radius:50%;background:var(--tv-bg-soft);border:1px solid var(--tv-border);display:flex;align-items:center;justify-content:center;font-weight:700;color:var(--tv-orange)}
.tv-chatitem__main{flex:1;min-width:0}
.tv-chatitem__top{display:flex;justify-content:space-between;gap:10px}
.tv-chatitem__title{font-weight:600}
.tv-chatitem__time{font-size:12px;color:var(--tv-muted)}
.tv-chatitem__preview{font-size:13px;color:var(--tv-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tv-chatitem__actions{display:flex;gap:8px;margin-left:auto}
.tv-badge{display:inline-flex;min-width:18px;height:18px;padding:0 6px;border-radius:9px;background:var(--tv-orange);color:#fff;font-size:12px;align-items:center;justify-content:center}

.tv-chat{flex:1;display:flex;flex-direction:column;background:var(--tv-bg)}
.tv-chat__header{padding:12px 16px;border-bottom:1px solid var(--tv-border);font-weight:600;display:flex;align-items:center;gap:8px}
.tv-back{display:none;padding:6px 10px;border:1px solid var(--tv-border);border-radius:6px;background:#fff}
.tv-chat__header .tv-typing{font-weight:400;color:var(--tv-muted);font-size:12px}
.tv-chat__messages{flex:1;overflow:auto;padding:16px;background:var(--tv-bg-soft);overscroll-behavior-y:contain}
.tv-date{display:flex;justify-content:center;margin:10px 0}
.tv-chat__messages .tv-date{position:sticky;top:-16px;z-index:3;background:var(--tv-bg-soft)}
.tv-date span{background:#fff;border:1px solid var(--tv-border);border-radius:999px;padding:4px 10px;color:var(--tv-muted);font-size:12px}
.tv-row{display:flex;margin:6px 0}
.tv-row--me{justify-content:flex-end}
.tv-bubble{--bubble-bg:#fff;--bubble-border:var(--tv-border);max-width:72%;padding:8px 10px;border-radius:14px;border:1px solid var(--bubble-border);background:var(--bubble-bg);position:relative}
@supports (max-width: min(10px, 10px)){
  .tv-bubble{max-width:min(720px,72%)}
}
.tv-bubble{overflow-wrap:anywhere;word-break:break-word}
.tv-bubble--me{--bubble-bg:#F4A261;--bubble-border:#F4A261;color:#fff;background:var(--bubble-bg);border-color:var(--bubble-border)}
.tv-bubble__meta{font-size:11px;color:var(--tv-muted);margin-top:4px}
.tv-bubble--me .tv-bubble__meta{color:#ffe7d5}
.tv-ticks{margin-left:6px}
.tv-reacts{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}
.tv-react{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--tv-border);background:#fff;border-radius:999px;padding:2px 6px;font-size:12px;cursor:pointer}
.tv-react.is-on{border-color:var(--tv-orange);background:#fff7f0}
.tv-react__count{color:var(--tv-muted)}
.tv-actions{display:flex;gap:8px;margin-left:10px}
.msg:not(.has-actions) .tv-actions{display:none}
.msg.has-actions .tv-actions{display:flex}
.tv-action{border:none;background:transparent;color:inherit;cursor:pointer;font-size:11px;opacity:.8}
.tv-action:hover{opacity:1}
.tv-row.is-highlight .tv-bubble{outline:2px solid var(--tv-orange)}
.tv-bubble:before,
.tv-bubble:after{content:"";position:absolute;top:18px;width:0;height:0;border-style:solid}
.tv-bubble:before{left:-12px;border-width:10px 12px 10px 0;border-color:transparent var(--bubble-border) transparent transparent}
.tv-bubble:after{left:-10px;border-width:10px 10px 10px 0;border-color:transparent var(--bubble-bg) transparent transparent}
.tv-row--me .tv-bubble:before{left:auto;right:-12px;border-width:10px 0 10px 12px;border-color:transparent transparent transparent var(--bubble-border)}
.tv-row--me .tv-bubble:after{left:auto;right:-10px;border-width:10px 0 10px 10px;border-color:transparent transparent transparent var(--bubble-bg)}
.tv-chat__form{display:flex;gap:8px;padding:12px;border-top:1px solid var(--tv-border);background:#fff;align-items:flex-end}
.tv-chat__form{padding-bottom:calc(23px + env(safe-area-inset-bottom))}
.tv-input--stretch{flex:1}

/* Center chat column on wide desktops */
@media (min-width: 1200px){
  .tv-chat__header,
  .tv-chat__messages,
  .tv-chat__form{
    align-self:stretch;
    width:100%;
    max-width:none;
  }
}

.tv-error{color:#b91c1c;margin:8px 0}

/* Composer toolbar */
.tv-composer{display:grid;grid-template-columns:auto 1fr auto;align-items:end;gap:8px;width:100%}
.tv-composer,.tv-composer__center{max-width:100%}
.tv-composer__left{display:flex;gap:6px;align-items:center}
.tv-composer__left,.tv-composer__right{flex-shrink:0}
.tv-composer__center{min-width:0}
.tv-composer__right{display:flex;gap:6px;align-items:center}
.tv-textarea{width:100%;min-height:var(--control-h);max-height:180px;resize:none;padding:11px 44px 11px 12px;border:1px solid var(--tv-border);border-radius:14px;outline:none;line-height:1.4;box-sizing:border-box;background:var(--tv-bg);color:var(--tv-text);position:relative;z-index:0}
.tv-textarea:focus{border-color:var(--tv-orange)}
.tv-textarea:focus-visible{outline:2px solid #ffca99; outline-offset:2px}
.tv-input::placeholder,.tv-textarea::placeholder{color:var(--tv-muted)}
.tv-iconbtn{width:44px;height:44px;display:inline-flex;align-items:center;justify-content:center;border:1px solid var(--tv-border);border-radius:10px;background:#fff;cursor:pointer}
.tv-iconbtn:hover{background:var(--tv-bg-soft)}
.tv-sendbtn{width:44px;height:44px;border-radius:12px;border:none;background:linear-gradient(135deg,#f97316,#fb923c);color:#fff;display:inline-flex;align-items:center;justify-content:center;box-shadow:0 6px 18px rgba(249,115,22,.25);cursor:pointer;transition:background .15s ease,box-shadow .15s ease,transform .06s ease}
.tv-sendbtn:hover{background:linear-gradient(135deg,#ea580c,#f97316)}
.tv-iconbtn:focus,.tv-btn:focus,.tv-sendbtn:focus{outline:2px solid #ffca99; outline-offset:2px}
.tv-btn,.tv-iconbtn,.tv-sendbtn{transition:background .15s ease, transform .06s ease}
.tv-iconbtn:active,.tv-btn:active,.tv-sendbtn:active{transform:translateY(1px)}
.tv-sendbtn .tv-icon{width:20px;height:20px}
.tv-sendbtn .tv-icon svg{width:100%;height:100%;fill:currentColor}
.tv-voicebtn{width:44px;min-width:44px;height:44px;border-radius:12px;border:none;background:linear-gradient(135deg,#2563eb,#7c3aed);color:#fff;display:inline-flex;align-items:center;justify-content:center;box-shadow:0 6px 18px rgba(37,99,235,.25);transition:background .15s ease,border-color .15s ease,box-shadow .15s ease,transform .06s ease,padding .15s ease,border-radius .2s ease;gap:8px;padding:0}
.tv-voicebtn__icon{display:inline-flex;width:20px;height:20px}
.tv-voicebtn__icon svg{fill:currentColor;width:100%;height:100%}
.tv-voicebtn__stop{font-weight:600;font-size:14px;letter-spacing:.01em}
.tv-voicebtn__stop[hidden]{display:none !important}
.tv-voicebtn.is-pointer{transform:scale(.97)}
.tv-voicebtn.is-cancel{background:#ef4444;border-color:#ef4444;box-shadow:0 6px 18px rgba(239,68,68,.35)}
.tv-voicebtn:hover{background:linear-gradient(135deg,#1d4ed8,#5b21b6);border-color:rgba(37,99,235,.35)}
.tv-voicebtn.is-recording{background:#ef4444;color:#fff;border-color:#ef4444;box-shadow:0 6px 18px rgba(239,68,68,.35);width:auto;min-width:90px;padding:0 18px;border-radius:999px}
.tv-voicebtn.is-recording .tv-voicebtn__icon{display:none}
.tv-voicebtn.is-recording .tv-voicebtn__stop[hidden]{display:inline !important}
.tv-voicebtn.is-recording .tv-voicebtn__stop{display:inline}
.tv-voicebtn.is-disabled,.tv-voicebtn:disabled,.tv-voicebtn[aria-disabled="true"]{opacity:.5;cursor:not-allowed;background:var(--tv-bg-soft);color:var(--tv-muted);box-shadow:none;transform:none}
.tv-voice-indicator{display:flex;flex-direction:column;align-items:center;margin-left:4px;font-size:12px;color:var(--tv-muted)}
.tv-voice-indicator[hidden]{display:none !important}
.tv-voice-indicator__dot{width:10px;height:10px;border-radius:50%;background:#ef4444;animation:tvPulse 1s ease-in-out infinite alternate}
.tv-voice-indicator__timer{font-variant-numeric:tabular-nums;margin-top:2px}
.tv-icon--mic svg{width:100%;height:100%}

.tv-body.theme-dark .tv-voicebtn{background:linear-gradient(135deg,#0ea5e9,#6366f1);border:none;color:#fff}
.tv-body.theme-dark .tv-voicebtn:hover{background:linear-gradient(135deg,#0284c7,#4c1d95)}
.tv-body.theme-dark .tv-voicebtn.is-recording{background:#ef4444;color:#fff;border:none}
.tv-body.theme-dark .tv-voicebtn.is-disabled,.tv-body.theme-dark .tv-voicebtn:disabled,.tv-body.theme-dark .tv-voicebtn[aria-disabled="true"]{background:#1f2937;color:#9aa6c5;box-shadow:none;transform:none}
.tv-body.theme-dark .tv-sendbtn{background:linear-gradient(135deg,#fb923c,#f97316);box-shadow:0 6px 18px rgba(249,115,22,.35);color:#fff}
.tv-body.theme-dark .tv-sendbtn:hover{background:linear-gradient(135deg,#f97316,#fb923c)}
.tv-body.theme-dark .tv-voice-indicator{color:#9aa6c5}

.tv-voice-panel{margin-top:6px;border:1px solid var(--tv-border);border-radius:12px;background:var(--tv-bg-soft);padding:8px 10px;display:flex;flex-direction:column;gap:6px;opacity:0;transform:translateY(6px);pointer-events:none;transition:opacity .18s ease,transform .18s ease,border-color .18s ease,box-shadow .18s ease}
.tv-voice-panel.is-visible{opacity:1;transform:translateY(0);pointer-events:auto}
.tv-voice-panel.is-recording{border-color:#f97316;box-shadow:0 16px 32px rgba(249,115,22,.18)}
.tv-voice-panel.is-preview{border-color:rgba(59,130,246,.35);box-shadow:0 16px 32px rgba(59,130,246,.14)}
.tv-voice-panel[hidden]{display:none !important}
.tv-voice-panel__recording,.tv-voice-panel__preview{display:flex;flex-direction:column;gap:6px}
.tv-voice-panel__recording[hidden],.tv-voice-panel__preview[hidden]{display:none !important}
.tv-voice-permission{margin-top:6px;border:1px solid var(--tv-border);border-radius:12px;background:var(--tv-bg-soft);padding:10px 12px;display:flex;flex-direction:column;gap:6px}
.tv-voice-permission[hidden]{display:none !important}
.tv-voice-permission__text{font-size:13px;line-height:1.5;color:var(--tv-muted)}
.tv-voice-permission .tv-btn{align-self:flex-start}
.tv-voice-note{font-size:13px;color:var(--tv-muted);line-height:1.4;margin-top:6px}
.tv-voice-note[hidden]{display:none !important}
.tv-voice-meta{font-size:12px;color:var(--tv-muted);margin:4px 0 8px}
.tv-voice-meta[hidden]{display:none !important}
.tv-voice-progress{position:relative;width:100%;height:4px;border-radius:999px;background:var(--tv-border);overflow:hidden;transition:background .2s ease;margin-top:4px}
.tv-voice-progress__bar{position:absolute;inset:0;background:linear-gradient(90deg,#2563eb,#7c3aed);transform-origin:left center;transform:scaleX(0);transition:transform .2s ease}
.tv-voice-progress.is-warning{background:rgba(249,115,22,.2);}
.tv-voice-progress.is-warning .tv-voice-progress__bar{background:linear-gradient(90deg,#f97316,#fb923c);}
.tv-voice-limit{font-size:12px;color:var(--tv-muted);font-variant-numeric:tabular-nums;margin-top:4px}
.tv-voice-limit[hidden]{display:none !important}
.tv-voice-limit.is-warning{color:#f97316;}
.tv-voice-dot{width:12px;height:12px;border-radius:50%;background:#ef4444;animation:tvPulse .9s ease-in-out infinite alternate}
.tv-voice-timer{font-variant-numeric:tabular-nums;font-size:14px;color:var(--tv-text)}
.tv-voice-hint{font-size:12px;color:var(--tv-muted);text-align:center}
.tv-voice-hint[hidden]{display:none !important}
.tv-voice-input{width:100%;padding:8px 10px;border:1px solid var(--tv-border);border-radius:10px;background:#fff;color:var(--tv-text);font-size:14px}
.tv-voice-input:focus{border-color:var(--tv-orange);outline:none;box-shadow:0 0 0 2px rgba(244,162,97,.2)}
.tv-voice-panel__actions{display:flex;gap:10px}
.tv-btn--ghost{background:transparent;color:var(--tv-text);border:1px solid var(--tv-border)}
.tv-btn--ghost:hover{background:var(--tv-bg-soft);border-color:var(--tv-border)}
.tv-body.theme-dark .tv-voice-panel{background:#111827;border-color:#1f2937}
.tv-body.theme-dark .tv-voice-panel.is-recording{border-color:#f97316;}
.tv-body.theme-dark .tv-voice-panel.is-preview{border-color:rgba(96,165,250,.45);}
.tv-body.theme-dark .tv-btn--ghost{color:#e2e8f0;border-color:#1f2937}
.tv-body.theme-dark .tv-btn--ghost:hover{background:#1e293b}
.tv-body.theme-dark .tv-voice-input{background:#0f141a;border-color:#1f2937;color:#e2e8f0}
.tv-body.theme-dark .tv-voice-input:focus{border-color:#f97316;box-shadow:0 0 0 2px rgba(249,115,22,.25)}
.tv-body.theme-dark .tv-voice-hint{color:#9aa6c5}
.tv-body.theme-dark .tv-voice-note{color:#9aa6c5}
.tv-body.theme-dark .tv-voice-meta{color:#9aa6c5}
.tv-body.theme-dark .tv-voice-progress{background:#1f2937;}
.tv-body.theme-dark .tv-voice-progress.is-warning{background:rgba(249,115,22,.25);}
.tv-body.theme-dark .tv-voice-limit{color:#9aa6c5}
.tv-body.theme-dark .tv-voice-limit.is-warning{color:#fb923c}
.tv-record-strip{display:flex;align-items:center;gap:12px;border:1px solid var(--tv-border);border-radius:12px;background:var(--tv-bg-soft);padding:8px 12px;box-shadow:0 8px 16px rgba(15,23,42,.08);}
.tv-record-strip__progress{flex:1;height:6px;border-radius:999px;background:var(--tv-border);overflow:hidden;position:relative}
.tv-record-strip__bar{position:absolute;inset:0;background:linear-gradient(90deg,#2563eb,#7c3aed);transform-origin:left center;transform:scaleX(0);transition:transform .2s ease}
.tv-record-strip__meta{display:flex;align-items:center;gap:10px}
.tv-record-strip__timer{font-size:14px;font-variant-numeric:tabular-nums;color:var(--tv-text)}
.tv-composer__center #composer-recording-strip{display:none}
.tv-composer__center.is-recording #composer-input-wrap{display:none}
.tv-composer__center.is-recording #composer-recording-strip{display:flex}
.tv-body.theme-dark .tv-record-strip{border-color:#1f2937;background:#0f172a}
.tv-body.theme-dark .tv-record-strip__timer{color:#f8fafc}

.tv-modal{position:fixed;inset:0;z-index:1800;display:flex;align-items:center;justify-content:center;padding:16px}
.tv-modal[hidden]{display:none !important}
.tv-modal__backdrop{position:absolute;inset:0;background:rgba(15,23,42,.55)}
.tv-modal__card{position:relative;z-index:1;width:min(420px,100%);background:var(--tv-bg);border:1px solid var(--tv-border);border-radius:20px;padding:24px;box-shadow:0 20px 60px rgba(15,23,42,.25);display:flex;flex-direction:column;gap:16px}
.tv-modal__title{margin:0;font-size:18px;font-weight:600;color:var(--tv-text)}
.tv-modal__text{margin:0;font-size:14px;line-height:1.6;color:var(--tv-muted)}
.tv-modal__close{position:absolute;top:12px;right:12px;border:0;background:transparent;font-size:18px;line-height:1;color:var(--tv-muted);cursor:pointer}
.tv-modal__close:hover{color:var(--tv-text)}
.tv-body.theme-dark .tv-modal__card{background:#111827;border-color:#1f2937}
.tv-body.theme-dark .tv-modal__text{color:#e2e8f0}
@media (prefers-reduced-motion:reduce){.tv-voice-panel{transition:none;}.tv-voice-progress__bar{transition:none;}}

.tv-voice-panel__preview audio{width:100%}

@keyframes tvPulse{
  from{opacity:.6;transform:scale(1)}
  to{opacity:1;transform:scale(1.15)}
}

/* Attachments uploader */
.tv-attach-list{display:flex;gap:8px;flex-wrap:wrap;margin:6px 0}
.tv-attach-list:empty{display:none;margin:0}
.tv-attach{position:relative;min-width:140px;max-width:220px;background:#fff;border:1px solid var(--tv-border);border-radius:10px;padding:8px}
.tv-attach__name{font-size:12px;color:var(--tv-text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tv-attach__meta{font-size:11px;color:var(--tv-muted);margin-top:4px}
.tv-attach__actions{position:absolute;top:6px;right:6px;display:flex;gap:6px}
.tv-attach__btn{border:none;background:transparent;color:var(--tv-muted);cursor:pointer}
.tv-attach__bar{position:absolute;left:0;right:0;bottom:0;height:3px;background:var(--tv-bg-soft);border-bottom-left-radius:10px;border-bottom-right-radius:10px;overflow:hidden}
.tv-attach__bar > span{display:block;height:100%;width:0%;background:var(--tv-orange);transition:width .1s linear}
.tv-attach.is-error{border-color:#ef4444}
.tv-attach.is-done{border-color:#10b981}
.msg--upload .tv-actions,.msg--upload .tv-selectbox{display:none}
.tv-bubble--upload{border:1px dashed var(--tv-border);background:var(--tv-bg-soft);min-width:220px}
.msg--upload-error .tv-bubble--upload{border-color:#dc2626;background:rgba(220,38,38,.08)}
.tv-upload__title{font-weight:600;font-size:14px;color:var(--tv-text);margin-bottom:4px}
.tv-upload__meta{font-size:12px;color:var(--tv-muted);margin-bottom:8px;font-variant-numeric:tabular-nums}
.tv-upload-progress{height:6px;border-radius:999px;background:rgba(15,23,42,.1);overflow:hidden}
.tv-upload-progress__fill{height:100%;width:0;background:var(--tv-orange);transition:width .12s ease}
.tv-upload-progress__label{margin-top:6px;font-size:12px;color:var(--tv-muted);font-variant-numeric:tabular-nums}
.msg--upload-ready .tv-upload-progress__label{color:var(--tv-text)}
.msg--upload-error .tv-upload-progress__fill{background:#dc2626}

/* Emoji picker */
.tv-emoji{position:absolute;bottom:56px;left:12px;right:auto;background:#fff;border:1px solid var(--tv-border);border-radius:12px;box-shadow:var(--tv-shadow);padding:8px;display:none;max-width:260px}
.tv-emoji{max-width:min(320px, calc(100vw - 24px)); width:min(320px, calc(100vw - 24px))}
.tv-emoji.open{display:block}
.tv-emoji__grid{display:grid;grid-template-columns:repeat(8, 1fr);gap:6px;max-height:180px;overflow:auto}
.tv-emoji__item{cursor:pointer;text-align:center;font-size:18px;line-height:28px}

/* Scroll to bottom */
.tv-scrollbottom{position:absolute;right:16px;bottom:76px;display:none}
.tv-scrollbottom.show{display:inline-flex}

/* Typing indicator */
.tv-typing{font-size:12px;color:var(--tv-muted)}
.tv-files{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px}
.tv-file{font-size:12px;color:var(--tv-text);background:#fff;border:1px solid var(--tv-border);border-radius:8px;padding:6px 8px}
.tv-file a{color:inherit;text-decoration:none}
.tv-chat__messages img,.tv-chat__messages video{max-width:100%;height:auto;border-radius:8px}
.tv-file img,.tv-file video{max-width:100%;height:auto;display:block}

/* Overlays: ensure no viewport overflow */
#img-overlay,#video-overlay,#pdf-overlay{max-width:100vw !important;max-height:100vh !important}

/* Animations */
.tv-fade-in{animation:tvFade .18s ease-out}
@keyframes tvFade{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}

/* Modal */
.tv-modal{position:fixed;inset:0;display:none;align-items:center;justify-content:center;background:rgba(0,0,0,.35)}
.tv-modal{z-index:2500}
.tv-modal.open{display:flex}
.tv-modal__card{width:420px;max-width:calc(100vw - 40px);background:#fff;border-radius:12px;box-shadow:var(--tv-shadow);padding:16px;border:1px solid var(--tv-border);outline:0}
.tv-modal__title{font-weight:700;margin-bottom:8px}
.tv-modal__actions{display:flex;justify-content:flex-end;gap:8px;margin-top:12px}

/* Search results */
.tv-search-results{margin-bottom:12px;border:1px solid var(--tv-border);border-radius:var(--radius);background:#fff}
.tv-search-results .tv-list{max-height:280px;overflow:auto}
.tv-search-item{display:block;padding:8px 10px;color:inherit;text-decoration:none;border-bottom:1px solid var(--tv-border)}
.tv-search-item:last-child{border-bottom:none}
.tv-search-item:hover{background:var(--tv-bg-soft)}
.tv-search-item__meta{font-size:12px;color:var(--tv-muted)}

/* Overflow guards for popovers/menus */
.tv-ctx{max-width:calc(100vw - 24px);word-break:break-word}

/* Responsive */
@media (max-width: 900px){
  .tv-header__search{display:none}
  .tv-hide-sm{display:none}
  .tv-split{min-height:calc(100vh - 64px)}
  .tv-chat__header{padding-top:calc(12px + env(safe-area-inset-top))}
  .tv-header{padding-top:env(safe-area-inset-top)}
  .tv-chat{display:none}
  .tv-aside{width:100%;flex:1;border-right:none}
  .tv-has-conv .tv-aside{display:none}
  .tv-has-conv .tv-chat{display:flex}
  .tv-back{display:inline-flex}
  .tv-main{padding-bottom:calc(60px + env(safe-area-inset-bottom))}
  .tv-body.is-messenger .tv-container{padding-left:0;padding-right:0}
  .tv-body.is-contacts .tv-main,
  .tv-body.is-settings .tv-main,
  .tv-body.is-calls .tv-main{padding-left:0;padding-right:0}
  /* Contacts/Settings standalone pages: side gutters 12px */
  .tv-body.is-contacts .tv-container,
  .tv-body.is-settings .tv-container,
  .tv-body.is-calls .tv-container{padding-left:12px;padding-right:12px}
  .tv-chat__messages{padding-left:12px;padding-right:12px}
  .tv-chat__header{padding-left:12px;padding-right:12px}
  .tv-chat__form{padding-left:12px;padding-right:12px}
  /* In chat view, tabbar hidden -> remove reserved space */
  .tv-has-conv .tv-main{padding-bottom:env(safe-area-inset-bottom)}
  .tv-tabbar{display:flex}
  .tv-has-conv .tv-tabbar{display:none}
  .tv-calls-list{max-height:none}
}

/* Emoji button inside textarea */
.tv-composer__center{position:relative;display:flex;flex-direction:column;justify-content:flex-end}
.tv-emoji-in{position:absolute;right:10px;bottom:auto;top:50%;transform:translateY(-50%);width:28px;height:28px;border:0;background:transparent;cursor:pointer}
.tv-emoji-in .tv-icon{width:20px;height:20px}
.tv-ico-emoji{font-size:18px;line-height:1}


/* Dark theme for users who follow system preference */
@media (prefers-color-scheme: dark){
  .tv-body:not(.theme-light):not(.theme-hc){
    --tv-bg:#0b0f14;
    --tv-bg-soft:#0f141a;
    --tv-text:#e5e7eb;
    --tv-muted:#94a3b8;
    --tv-border:#1f2937;
  }
  .tv-body:not(.theme-light):not(.theme-hc) .tv-avatar--list{border-color:#2a3644}
  .tv-body:not(.theme-light):not(.theme-hc) .tv-modal__card{background:#0f141a;border-color:#1f2937}
  .tv-body:not(.theme-light):not(.theme-hc) .tv-input,
  .tv-body:not(.theme-light):not(.theme-hc) .tv-textarea{background:#0f141a;color:var(--tv-text);border-color:#26323f}
  .tv-body:not(.theme-light):not(.theme-hc) .tv-input::placeholder,
  .tv-body:not(.theme-light):not(.theme-hc) .tv-textarea::placeholder{color:#8aa0b6}
  .tv-body:not(.theme-light):not(.theme-hc) .tv-chat__messages{background:#0b0f14}
  .tv-body:not(.theme-light):not(.theme-hc) .tv-bubble{--bubble-bg:#0f141a;--bubble-border:#26323f;background:var(--bubble-bg);border-color:var(--bubble-border)}
  .tv-body:not(.theme-light):not(.theme-hc) .tv-date span{background:#0f141a;border-color:#26323f;color:#94a3b8}
}

/* Explicit theme overrides */
.tv-body.theme-dark{ --tv-bg:#0b0f14; --tv-bg-soft:#0f141a; --tv-text:#e5e7eb; --tv-muted:#94a3b8; --tv-border:#1f2937; --bg:#0b0f14; --text:#e5e7eb; --border:#1f2937; --muted2:#94a3b8; --card:#111827 }
.tv-body.theme-dark .tv-modal__card{background:#0f141a;border-color:#1f2937}
.tv-body.theme-dark .tv-input,.tv-body.theme-dark .tv-textarea{background:#0f141a;color:var(--tv-text);border-color:#26323f}
.tv-body.theme-dark .tv-input::placeholder,.tv-body.theme-dark .tv-textarea::placeholder{color:#8aa0b6}
.tv-body.theme-dark .tv-chat__messages{background:#0b0f14}
.tv-body.theme-dark .tv-chat__messages .tv-date{background:#0b0f14}
.tv-body.theme-dark .tv-bubble{--bubble-bg:#0f141a;--bubble-border:#26323f;background:var(--bubble-bg);border-color:var(--bubble-border)}
.tv-body.theme-dark .tv-bubble--me{--bubble-bg:#00b7f1;--bubble-border:#00b7f1;color:#01212f}
.tv-body.theme-dark .tv-bubble--me .tv-bubble__meta{color:#013d4f}
.tv-body.theme-dark .tv-bubble--me .tv-ticks{color:#013d4f}
.tv-body.theme-dark .tv-date span{background:#0f141a;border-color:#26323f;color:#94a3b8}
.tv-body.theme-dark .tv-container,
.tv-body.theme-dark .tv-main,
.tv-body.theme-dark .tv-sidebar-block,
.tv-body.theme-dark .tv-chat__header,
.tv-body.theme-dark .tv-chat__form,
.tv-body.theme-dark .tv-tabbar,
.tv-body.theme-dark .tv-aside-tabs,
.tv-body.theme-dark .tv-embed{background:#0b0f14}
.tv-body.theme-dark .tv-sidebar-block,
.tv-body.theme-dark .tv-tabbar,
.tv-body.theme-dark .tv-aside-tabs,
.tv-body.theme-dark .tv-chat__header,
.tv-body.theme-dark .tv-chat__form,
.tv-body.theme-dark .tv-embed .tv-sidebar-block,
.tv-body.theme-dark .tv-emoji,
.tv-body.theme-dark .tv-attach,
.tv-body.theme-dark .tv-chatitem,
.tv-body.theme-dark .tv-iconbtn{background:#111827;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark .tv-group-btn{background:#ff8b27;color:#111}
.tv-body.theme-dark .tv-group-btn:hover{background:#ff9f4d}
.tv-body.theme-dark .tv-group-member{background:#172033;border-color:#1f2937}
.tv-body.theme-dark .tv-group-member__btn{background:#111827;border-color:#26323f;color:var(--tv-text)}
.tv-body.theme-dark .tv-group-member__btn:hover{background:#1f2a3d}
.tv-body.theme-dark .tv-group-member__select{background:#111827;border-color:#26323f;color:var(--tv-text)}
.tv-body.theme-dark .tv-back{background:#172033;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark .tv-back:hover{background:#1f2a3d}
.tv-settings-page{min-height:calc(100vh - 80px);padding:12px 18px;padding-bottom:calc(200px + env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:12px;background:var(--tv-bg);color:var(--tv-text);overflow-y:auto;-webkit-overflow-scrolling:touch}
.tv-settings-page #tv-settings-panel{width:100%}
@media (max-width:640px){
  #tv-settings-panel{
    border:none !important;
    padding:0 !important;
    background:transparent !important;
    box-shadow:none !important;
  }
}
.tv-settings-page .tv-settings__panel{background:transparent;border:none;padding:0}
.tv-settings-page .tv-settings{padding:0}
.tv-body.theme-dark .tv-settings-page{background:#111827}
.tv-body.theme-dark #tv-settings-panel{background:#111827;border-color:#1f2937}
.tv-body.theme-dark .tv-emoji-in .tv-icon svg{fill:#9aa6c5}
.tv-body.theme-dark .tv-emoji-in{color:#9aa6c5}
.tv-body.theme-dark #tv-settings-panel label{color:var(--tv-text)}
.tv-body.theme-dark #inchat-search{background:#111827;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark #inchat-search input{background:#0f141a;border:1px solid #26323f;color:var(--tv-text)}
.tv-body.theme-dark #inchat-search button{background:#172033;border:1px solid #1f2937;color:var(--tv-text)}
.tv-body.theme-dark #inchat-search button:hover{background:#1f2a3d}
.tv-body.theme-dark #search-panel{background:#111827;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark #search-panel .tv-seg a{color:var(--tv-text)}
.tv-body.theme-dark #search-panel input{background:#0f141a;border:1px solid #26323f;color:var(--tv-text)}
.tv-body.theme-dark #search-panel button{background:#172033;border:1px solid #1f2937;color:var(--tv-text)}
.tv-body.theme-dark #search-panel button:hover{background:#1f2a3d}
.tv-body.theme-dark #profile-drawer .tv-profile__tabs button{background:#172033;border:1px solid #1f2937;color:var(--tv-text)}
.tv-body.theme-dark #profile-drawer .tv-profile__tabs button.is-active{background:#1f2a3d;border-color:#ff8b27;color:#fff}
.tv-body.theme-dark #profile-drawer{background:#0b0f14;border-color:#1f2937}
.tv-body.theme-dark #profile-drawer .tv-sidebar-block{background:#111827;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark #profile-drawer label{color:var(--tv-text)}
.tv-body.theme-dark #profile-drawer input{background:#0f141a;border:1px solid #26323f;color:var(--tv-text)}
 .tv-body.theme-dark .tv-tabbar{background:#111827;border-color:#1f2937}
.tv-body.theme-dark .tv-prof__item,
.tv-body.theme-dark .tv-prof__list .tv-prof__row{background:#111827;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark .tv-prof__item:hover,
.tv-body.theme-dark .tv-prof__list .tv-prof__row:hover{background:#172033}
.tv-body.theme-dark .tv-prof__meta{color:#9aa6c5}
.tv-body.theme-dark .tv-prof__check{background:#0b0f14;border-color:#1f2937}
.tv-body.theme-dark .tv-profile-header{background:#111827;border:1px solid #1f2937;color:var(--tv-text)}
.tv-body.theme-dark .tv-profile-header__quick button{background:#172033;border:1px solid #1f2937;color:var(--tv-text)}
.tv-body.theme-dark .tv-profile-header__quick button:hover{background:#1f2a3d}
.tv-body.theme-dark .tv-search-results{background:#111827;border-color:#1f2937}
.tv-body.theme-dark .tv-search-item:hover{background:#172033}
.tv-body.theme-dark .tv-search-item__meta{color:#9aa6c5}
.tv-body.theme-dark #inchat-search,
.tv-body.theme-dark .tv-pop,
.tv-body.theme-dark .tv-theme-pop{background:#111827;border:1px solid #1f2937;color:var(--tv-text)}
.tv-body.theme-dark #inchat-search input,
.tv-body.theme-dark #inchat-search select{background:#0f141a;color:var(--tv-text);border-color:#26323f}
.tv-body.theme-dark #inchat-search button{background:#172033;border:1px solid #1f2937;color:var(--tv-text)}
.tv-body.theme-dark #inchat-search button:hover{background:#1f2a3d}
.tv-body.theme-dark .tv-chat__form{border-top-color:#1f2937}
.tv-body.theme-dark .tv-chatitem:hover{background:#172033}
.tv-body.theme-dark .tv-react{background:#172033;border-color:#26323f}
.tv-body.theme-dark .tv-react.is-on{background:#1f2a3d;border-color:#ff8b27}
.tv-body.theme-dark .tv-tabbar a{color:var(--tv-text)}
.tv-body.theme-dark .tv-btn{color:#fff}
.tv-body.theme-dark .tv-embed .tv-sidebar-block input,
.tv-body.theme-dark .tv-embed .tv-sidebar-block .tv-input,
.tv-body.theme-dark .tv-embed .tv-sidebar-block .tv-btn,
.tv-body.theme-dark .tv-embed .tv-sidebar-block label{color:var(--tv-text);border-color:#26323f}
.tv-body.theme-dark .tv-embed .tv-sidebar-block .tv-btn{background:#111827}
.tv-body.theme-dark .tv-profile__tabs button{background:#111827;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark .tv-sidebar-block,
.tv-body.theme-dark .tv-tabbar,
.tv-body.theme-dark .tv-aside-tabs,
.tv-body.theme-dark .tv-chat__header,
.tv-body.theme-dark .tv-chat__form,
.tv-body.theme-dark .tv-emoji,
.tv-body.theme-dark .tv-attach,
.tv-body.theme-dark .tv-chatitem,
.tv-body.theme-dark .tv-iconbtn{background:#111827;border-color:#1f2937;color:var(--tv-text)}
.tv-body.theme-dark .tv-chat__form{border-top-color:#1f2937}
.tv-body.theme-dark .tv-chatitem:hover{background:#172033}
.tv-body.theme-dark .tv-react{background:#172033;border-color:#26323f}
.tv-body.theme-dark .tv-react.is-on{background:#1f2a3d;border-color:#ff8b27}
.tv-body.theme-dark .tv-tabbar a{color:var(--tv-text)}
.tv-body.theme-dark .tv-btn{color:#fff}
.tv-body.theme-dark .tv-emoji-in{background:transparent}

.tv-body.theme-light{ --tv-bg:#ffffff; --tv-bg-soft:#f8fafc; --tv-text:#1f2937; --tv-muted:#6b7280; --tv-border:#e5e7eb }

/* Optional high-contrast switch */
.tv-body.theme-hc{ --tv-bg:#000; --tv-bg-soft:#0b0b0b; --tv-text:#ffffff; --tv-muted:#d1d5db; --tv-border:#374151 }
.tv-body.theme-hc .tv-bubble--me{background:#ff6a00;border-color:#ff6a00;color:#fff}

/* Mobile bottom tabbar */
.tv-tabbar{position:fixed;left:0;right:0;bottom:0;z-index:20;border-top:1px solid var(--tv-border);background:var(--tv-bg);display:flex;padding:6px 8px;padding-bottom:calc(23px + env(safe-area-inset-bottom));
  align-items:center;gap:6px}
.tv-tab{appearance:none;border:0;background:transparent;color:var(--tv-text);text-decoration:none;display:flex;flex-direction:column;align-items:center;gap:3px;padding:6px 10px;border-radius:8px;flex:1;min-width:0}
.tv-tab__icon{width:22px;height:22px;display:inline-flex;align-items:center;justify-content:center;line-height:22px;font-size:18px}
.tv-tab__label{font-size:11px}
.tv-tab:focus{outline:2px solid #ffca99;outline-offset:2px}
.tv-tab:focus-visible{outline:2px solid #ffca99;outline-offset:2px}
.tv-tab:hover{background:var(--tv-bg-soft)}
.tv-tab.is-active{color:var(--tv-orange)}
.tv-tab__badge{position:absolute;margin-top:-18px;margin-left:14px;display:inline-flex;min-width:16px;height:16px;padding:0 4px;border-radius:8px;background:var(--tv-orange);color:#fff;font-size:11px;align-items:center;justify-content:center}
.kb-open .tv-tabbar{display:none !important}

/* Mobile profile sheet */
@media (max-width: 900px){
  #profile-drawer{display:none;align-items:flex-end}
  #profile-drawer > div{margin:0 auto !important;width:100% !important;max-width:100% !important;height:85vh !important;border-left:none !important;border-top:1px solid var(--tv-border) !important;border-radius:12px 12px 0 0 !important}
}

/* Force tabbar visible on mobile (override base rule order) */
@media (max-width: 900px){
  .tv-tabbar{display:flex !important}
  .tv-has-conv .tv-tabbar{display:none !important}
}

@media (max-width: 420px){
  .tv-tabbar{gap:2px;padding:6px 4px;padding-bottom:calc(17px + env(safe-area-inset-bottom))}
  .tv-tabbar .tv-tab{padding:6px 4px}
  .tv-tabbar .tv-tab__label{display:none}
}

/* Profile panel */
.tv-prof__grid{display:grid;grid-template-columns:repeat(3, 1fr);gap:6px}
.tv-prof__item{position:relative;border:1px solid var(--tv-border);border-radius:8px;overflow:hidden;background:#fff;cursor:pointer}
.tv-prof__item img,.tv-prof__item video{width:100%;height:100%;object-fit:cover;display:block}
.tv-prof__meta{font-size:12px;color:var(--tv-muted);padding:6px 8px}
.tv-prof__check{position:absolute;top:6px;left:6px;width:18px;height:18px;border-radius:50%;border:2px solid var(--tv-bg);box-shadow:0 0 0 1px var(--tv-border) inset;background:rgba(255,255,255,.9);display:none;align-items:center;justify-content:center}
.tv-prof__item.is-selectable .tv-prof__check{display:flex}
.tv-prof__item.is-selected .tv-prof__check{background:var(--tv-orange);color:#fff;border-color:var(--tv-orange)}
.tv-prof__list .tv-prof__row{display:flex;align-items:center;gap:8px;border:1px solid var(--tv-border);border-radius:8px;padding:8px 10px;background:#fff;cursor:pointer}
.tv-prof__list .tv-prof__row:hover{background:var(--tv-bg-soft)}


/* Desktop aside tabs */
.tv-aside-tabs{display:none !important;margin:12px 0 0;position:sticky;bottom:8px;padding-top:6px;background:var(--tv-bg);z-index:2}
/* Unified inner width and centering for aside contents */
.tv-aside .tv-sidebar-block,
.tv-aside .tv-aside-tabs,
.tv-aside .tv-aside-scroll,
.tv-aside .tv-search-results{width:100%; margin:0}

/* Form utilities for sidebar cards */
.tv-form{display:grid;gap:10px}
.tv-legend{font-size:12px;color:var(--muted2);margin-bottom:4px}
.tv-formgrid-2{display:grid;grid-template-columns:1fr 1fr;column-gap:12px;row-gap:6px}
.tv-rad-row{display:flex;align-items:center;gap:6px;white-space:nowrap}
.tv-rad-row input{margin:0}
.tv-aside .tv-sidebar-block .tv-input{height:var(--control-h-sm)}
.tv-aside .tv-sidebar-block .tv-btn{height:var(--control-h-sm);padding:0 12px}
/* Ensure embedded Settings/Contacts blocks match width even if wrapped in .tv-container */
.tv-aside .tv-container .tv-sidebar-block{width:100%; margin-left:0; margin-right:0}
/* Ensure embedded Settings/Contacts cards fill full inner width of aside */
.tv-aside .tv-embed{width:100%}
.tv-aside .tv-embed.tv-settings .tv-sidebar-block,
.tv-aside .tv-embed.tv-contacts .tv-sidebar-block{width:100%; margin:0}
/* Desktop: set embed root to match visible width of dialogs blocks (compensate for 32px left shift) */
@media (min-width: 901px){
  .tv-aside .tv-embed.tv-settings,
  .tv-aside .tv-embed.tv-contacts{width:318px;max-width:318px;margin-left:auto !important;margin-right:auto !important;align-self:flex-start}
}
.tv-aside-tabs .tv-seg{width:100%;box-sizing:border-box}
.tv-seg{display:flex;border:1px solid var(--tv-border);border-radius:10px;overflow:hidden;background:#fff}
.tv-body.theme-dark .tv-seg{background:#111827;border-color:#1f2937}
/* Harden segmented control styling to never appear as plain links */
.tv-seg a{flex:1;text-align:center;text-decoration:none !important;color:inherit;padding:6px 8px;display:flex !important;flex-direction:column;align-items:center;gap:2px;min-height:46px}
.tv-body.theme-dark .tv-seg a{color:var(--tv-text)}
.tv-seg__ico{font-size:16px;line-height:1}
.tv-seg__lbl{line-height:1.2;font-size:12px}
.tv-seg a:hover{background:var(--tv-bg-soft)}
.tv-seg a.is-active{background:var(--tv-bg-soft);font-weight:600}
.tv-body.theme-dark .tv-seg a:hover{background:#1f2a3d}
.tv-body.theme-dark .tv-seg a.is-active{background:#1e293b}
@media (min-width: 901px){ .tv-aside .tv-aside-tabs{display:block !important} }

/* Standalone segmented control for full pages like /contacts and /settings */
.tv-aside-tabs.is-standalone{display:block !important;margin:0;position:sticky;bottom:8px;padding-top:0;background:transparent;z-index:2}

/* Scrollable middle section in aside */
.tv-aside-scroll{flex:1;min-height:0;overflow:auto}

/* Embedded views (inside aside) */
.tv-embed{font-size:14px}
.tv-embed .tv-sidebar-block{margin-bottom:10px;padding:10px}
.tv-embed .tv-chatitem{padding:6px 8px}
.tv-embed .tv-chatitem__preview{font-size:12px}

@media (max-width: 900px){
  .tv-aside-tabs.is-standalone{display:none !important}
}

@media (max-width: 900px){
  input[type="text"],
  input[type="email"],
  input[type="search"],
  input[type="password"],
  input[type="number"],
  select,
  textarea,
  .tv-input,
  .tv-textarea,
  .tv-voice-input,
  #msg{
    font-size:16px;
    line-height:1.4;
  }
}
