.chat-workspace { min-height: min(680px, calc(100vh - 160px)); }
#workspace[data-tab="chat"] .phone-layout { grid-template-columns: minmax(0,1fr); }
#workspace[data-tab="chat"] .dialler { display: none; }
.chat-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: inherit; overflow: hidden; border: 1px solid #d9e4f0; border-radius: 16px; background: #fff; box-shadow: 0 14px 38px rgba(10, 35, 66, .07); }
.chat-rail { min-width: 0; border-right: 1px solid #e2eaf3; background: #f7faff; }
.chat-rail-head, .chat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 72px; padding: 15px 17px; border-bottom: 1px solid #e2eaf3; }
.chat-rail-head h2, .chat-header h2 { margin: 0; font-size: 1.05rem; }
.chat-thread-list { display: grid; gap: 4px; padding: 9px; }
.chat-thread { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; min-height: 58px; padding: 9px 10px; border: 1px solid transparent; border-radius: 11px; background: transparent; text-align: left; }
.chat-thread:hover, .chat-thread[data-active="true"] { border-color: #cfe0f2; background: #fff; box-shadow: 0 5px 16px rgba(13, 46, 83, .06); }
.chat-avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: #035579; background: linear-gradient(145deg,#dff8fa,#dbeafe); font-weight: 700; }
.chat-thread-copy { min-width: 0; display: grid; gap: 3px; }
.chat-thread-copy strong, .chat-thread-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-thread-copy small { color: #71849b; }
.chat-unread { display: grid; place-items: center; min-width: 21px; height: 21px; padding: 0 6px; border-radius: 20px; color: #fff; background: #0b75e5; font-size: .72rem; }
.chat-list-empty { padding: 20px 10px; color: #71849b; }
.chat-conversation { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.chat-empty { display: grid; place-items: center; grid-row: 1 / 4; min-height: 500px; color: #71849b; background: radial-gradient(circle at 50% 45%,#f7fcff,#fff 55%); }
.chat-header p { margin: 4px 0 0; font-size: .8rem; }
.chat-header-actions { display: flex; gap: 8px; }
.chat-messages { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 20px; background: #fbfdff; }
.chat-message { align-self: flex-start; max-width: min(72%, 650px); padding: 11px 13px; border: 1px solid #dce6f1; border-radius: 5px 14px 14px; background: #fff; box-shadow: 0 4px 13px rgba(20, 50, 82, .04); }
.chat-message[data-own="true"] { align-self: flex-end; border-color: #b8dcf1; border-radius: 14px 5px 14px 14px; background: #eaf7fd; }
.chat-message-meta { display: flex; justify-content: space-between; gap: 18px; color: #647990; font-size: .72rem; }
.chat-message p { margin: 7px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-attachment { display: block; margin-top: 9px; padding: 9px 11px; border: 1px solid #c8dbea; border-radius: 9px; background: rgba(255,255,255,.78); font-size: .82rem; font-weight: 600; overflow-wrap: anywhere; }
.chat-compose { position: relative; display: grid; gap: 8px; padding: 13px; border-top: 1px solid #e2eaf3; background: #fff; }
.chat-compose textarea { min-height: 58px; max-height: 150px; resize: vertical; }
.chat-compose-actions, .chat-compose-tools { display: flex; align-items: center; gap: 8px; }
.chat-compose-actions { justify-content: space-between; }
.chat-selected-file { max-width: 260px; color: #536c87; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-emoji-panel { position: absolute; left: 14px; bottom: 58px; z-index: 3; grid-template-columns: repeat(6, 38px); gap: 4px; padding: 8px; border: 1px solid #ceddea; border-radius: 12px; background: #fff; box-shadow: 0 14px 35px rgba(10,35,66,.17); }
.chat-emoji-panel:not([hidden]) { display: grid; }
.chat-emoji-panel button { min-width: 38px; padding: 7px; font-size: 1.1rem; }
.chat-dialog { width: min(520px,calc(100vw - 30px)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 25px 70px rgba(4,25,50,.28); }
.chat-dialog form { display: grid; gap: 16px; padding: 22px; }
.chat-dialog-head, .chat-dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chat-dialog-head h2 { margin: 3px 0 0; }
.chat-dialog fieldset { min-width: 0; max-height: 290px; overflow-y: auto; border: 1px solid #d8e3ee; border-radius: 11px; }
.chat-member-options { display: grid; gap: 5px; }
.chat-member-option { display: flex; align-items: center; gap: 10px; padding: 7px; border-radius: 8px; }
.chat-member-option:hover { background: #f2f7fc; }
.chat-member-option input { width: auto; }
.chat-dialog-actions { justify-content: flex-end; padding-top: 4px; }
@media (max-width:800px){
 .chat-workspace { min-height: calc(100vh - 125px); }
 .chat-shell { grid-template-columns: 108px minmax(0,1fr); border-radius: 11px; }
 .chat-rail-head { align-items: stretch; flex-direction: column; padding: 9px; }
 .chat-rail-head h2 { font-size: .9rem; }
 .chat-thread-list { padding: 5px; }
 .chat-thread { grid-template-columns: 34px minmax(0,1fr); padding: 7px 5px; }
 .chat-avatar { width: 34px; height: 34px; }
 .chat-thread-copy small { display: none; }
 .chat-thread-copy strong { font-size: .72rem; }
 .chat-unread { grid-column: 1; grid-row: 1; justify-self: end; align-self: start; min-width: 17px; height: 17px; padding: 0 4px; }
 .chat-header { align-items: flex-start; padding: 10px; }
 .chat-header p { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
 .chat-header-actions { flex-direction: column; }
 .chat-header-actions button { padding: 6px 8px; font-size: .7rem; }
 .chat-messages { padding: 10px; }
 .chat-message { max-width: 88%; }
 .chat-compose { padding: 9px; }
 .chat-selected-file { max-width: 100px; }
}

/* Premium chat layer. Existing structural rules remain above for compatibility. */
.chat-workspace{height:min(720px,calc(100vh - 150px));min-height:540px;--chat-navy:#102842;--chat-copy:#536b84;--chat-line:#dce6f1;--chat-blue:#1769db}
#workspace[data-tab=chat] .phone-main{max-width:none}
.chat-shell{grid-template-columns:330px minmax(0,1fr);height:100%;border-color:#d7e2ef;border-radius:20px;box-shadow:0 22px 55px #10284212,0 2px 8px #10284208}
.chat-rail{border-color:var(--chat-line);background:linear-gradient(180deg,#f7faff 0%,#f3f7fc 100%)}
.chat-rail-head,.chat-header{min-height:78px;padding:16px 20px;border-color:var(--chat-line);background:#ffffffed;backdrop-filter:blur(12px)}
.chat-rail-head h2,.chat-header h2{color:var(--chat-navy);font-size:1.08rem;letter-spacing:-.02em}.chat-rail-head .primary{min-height:40px;padding:9px 14px;border-radius:11px}
.chat-thread-list{gap:6px;padding:11px}.chat-thread{position:relative;grid-template-columns:44px minmax(0,1fr) auto;gap:11px;min-height:70px;padding:10px 11px;border-radius:14px;background:transparent;box-shadow:none;transition:background .15s,border-color .15s,box-shadow .15s,transform .15s}.chat-thread:hover{border-color:#d2dfed;background:#ffffffc9;box-shadow:0 7px 20px #1735530b;transform:translateY(-1px)}.chat-thread[data-active=true]{border-color:#b9d5f4;background:#fff;box-shadow:0 8px 24px #17477612,inset 3px 0 #2772d8}
.chat-avatar{width:44px;height:44px;border:1px solid #d3e7f4;border-radius:14px;background:linear-gradient(145deg,#ddfbf8,#dbeaff);font-size:.78rem;font-weight:800;box-shadow:inset 0 1px #fff,0 4px 12px #153d6410}.chat-thread-copy{gap:5px}.chat-thread-line{display:flex;align-items:baseline;justify-content:space-between;gap:8px;min-width:0}.chat-thread-copy strong{color:#17324f;font-size:.8rem}.chat-thread-copy small{font-size:.7rem}.chat-thread-line time{flex:none;color:#8a9aab;font-size:.62rem}
.chat-unread,#chat-unread:not(:empty){display:grid;place-items:center;box-sizing:border-box;min-width:22px;height:22px;padding:0 6px;border:2px solid #fff;border-radius:999px;color:#fff;background:linear-gradient(180deg,#f04444,#d92532);font-size:.67rem;font-weight:800;line-height:1;box-shadow:0 4px 10px #dc2f3c35}.phone-sidebar nav button #chat-unread:not(:empty){margin-left:auto}.chat-list-empty{margin:12px;padding:30px 14px;border:1px dashed #cfdae7;border-radius:13px;background:#ffffff80;text-align:center;line-height:1.6}
.chat-conversation{background:#f8fbfe}.chat-empty{min-height:520px;padding:30px;background:radial-gradient(circle at 55% 45%,#eaf7ff 0,#f7fbff 28%,#fff 68%);text-align:center}.chat-empty::before{content:'💬';display:grid;place-items:center;width:74px;height:74px;margin:0 auto 16px;border:1px solid #d5e6f5;border-radius:24px;background:#fff;font-size:30px;box-shadow:0 15px 36px #183b5f14}.chat-header{z-index:2;padding-inline:22px;box-shadow:0 3px 12px #10284208}.chat-header p{font-size:.72rem}.chat-header-actions button{min-height:38px;padding:8px 12px}
.chat-messages{gap:10px;padding:24px clamp(16px,3vw,42px);overscroll-behavior:contain;background-color:#f6faff;background-image:radial-gradient(#6ea2d115 .8px,transparent .8px);background-size:20px 20px;scrollbar-color:#bfd0e1 transparent}.chat-date-divider{display:flex;align-items:center;align-self:center;margin:7px 0;padding:5px 11px;border:1px solid #dfe8f1;border-radius:999px;color:#728397;background:#ffffffdb;font-size:.62rem;font-weight:700;box-shadow:0 3px 10px #10284208;backdrop-filter:blur(8px)}
.chat-message{max-width:min(72%,680px);padding:11px 14px 12px;border-color:#dbe5ef;border-radius:5px 17px 17px;box-shadow:0 6px 18px #1735520b}.chat-message[data-own=true]{border-color:#b9def0;border-radius:17px 5px 17px 17px;background:linear-gradient(145deg,#e8f8fc,#eaf4ff)}.chat-message-meta{color:#6c8095;font-size:.64rem}.chat-message-meta strong{color:#375675;font-weight:750}.chat-message-meta time{white-space:nowrap}.chat-message p{color:#17304d;font-size:.82rem;line-height:1.55}.chat-attachment{display:flex;align-items:center;gap:8px;padding:10px 12px;border-radius:11px;background:#ffffffd9;font-size:.74rem}.chat-attachment::before{content:'↧';display:grid;place-items:center;width:24px;height:24px;flex:none;border-radius:8px;background:#e8f2fc;color:#1d63aa}
.chat-compose{gap:9px;padding:14px 16px 16px;border-color:var(--chat-line);box-shadow:0 -5px 18px #10284208}.chat-compose textarea{box-sizing:border-box;width:100%;min-height:66px;margin:0;padding:14px 15px;border-color:#cad9e8;border-radius:14px;background:#fbfdff;font-size:.82rem;line-height:1.45;box-shadow:inset 0 1px 2px #10284208}.chat-compose textarea:focus{background:#fff}.chat-compose-tools button{min-height:38px;padding:8px 12px;border-radius:10px}.chat-emoji-button{width:40px;padding:7px!important;font-size:1.15rem!important}.chat-selected-file{max-width:280px;font-size:.72rem}.chat-compose .primary[type=submit]{min-width:82px;min-height:40px}
.chat-emoji-panel{left:15px;bottom:72px;z-index:20;box-sizing:border-box;width:min(440px,calc(100% - 30px));overflow:hidden;padding:0;border-color:#cbd9e7;border-radius:16px;box-shadow:0 22px 60px #08233e30}.chat-emoji-panel:not([hidden]){display:grid;grid-template-rows:auto auto minmax(190px,310px)}.chat-emoji-head{display:grid;grid-template-columns:minmax(0,1fr) 38px;gap:8px;padding:11px;border-bottom:1px solid #e3eaf2}.chat-emoji-head input{min-height:40px;margin:0;padding:9px 12px;font-size:.75rem}.chat-emoji-head button{min-width:38px;min-height:38px;padding:0;font-size:1.1rem}.chat-emoji-tabs{display:flex;gap:2px;padding:7px 8px;overflow-x:auto;border-bottom:1px solid #e5ecf3;background:#f7f9fc;scrollbar-width:thin}.chat-emoji-tabs button{min-width:38px;min-height:36px;padding:5px;border:0;border-radius:9px;background:transparent;font-size:1rem}.chat-emoji-tabs button[aria-selected=true]{background:#fff;box-shadow:0 2px 8px #10284217}.chat-emoji-grid{display:grid;grid-template-columns:repeat(8,minmax(34px,1fr));align-content:start;gap:2px;padding:9px;overflow-y:auto}.chat-emoji-grid button{min-width:34px;min-height:36px;padding:4px;border:0;border-radius:8px;background:transparent;font-size:1.18rem}.chat-emoji-grid button:hover{background:#eaf3fd}.chat-emoji-empty{grid-column:1/-1;padding:35px 15px;color:#708399;text-align:center;font-size:.75rem}
.chat-notifications{position:fixed;top:88px;right:22px;z-index:80;display:grid;gap:9px;width:min(370px,calc(100vw - 28px));pointer-events:none}.chat-notification{display:grid!important;grid-template-columns:42px minmax(0,1fr) auto;align-items:center;gap:11px;width:100%;padding:12px!important;border:1px solid #c9dcee!important;border-left:4px solid #e1323f!important;border-radius:14px!important;background:#fffffff2!important;color:#17324f!important;text-align:left;box-shadow:0 18px 45px #0a284529!important;backdrop-filter:blur(14px);pointer-events:auto;animation:chat-toast-in .22s ease-out}.chat-notification-avatar{display:grid;place-items:center;width:42px;height:42px;border-radius:13px;background:linear-gradient(145deg,#dcfaf6,#dceaff);color:#07587c;font-size:.72rem;font-weight:800}.chat-notification-copy{display:grid;gap:4px;min-width:0}.chat-notification-copy strong,.chat-notification-copy span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.chat-notification-copy strong{font-size:.78rem}.chat-notification-copy span{color:#62778d;font-size:.68rem}.chat-notification-action{color:#1c65b4;font-size:.67rem;font-weight:750}@keyframes chat-toast-in{from{opacity:0;transform:translateY(-9px) scale(.98)}to{opacity:1;transform:none}}
.chat-dialog{border-radius:20px;box-shadow:0 30px 85px #041a323d}.chat-dialog::backdrop{background:#071b326e;backdrop-filter:blur(5px)}.chat-dialog form{gap:17px;padding:25px}.chat-dialog-head>button{width:40px;height:40px;padding:0;border-radius:50%;font-size:1.1rem}.chat-dialog fieldset{border-radius:12px;background:#fbfdff}.chat-member-option{padding:9px;border-radius:9px}.chat-member-option:hover{background:#edf5fd}
@media(max-width:800px){.chat-workspace{height:max(540px,calc(100dvh - 245px));min-height:540px}.chat-shell{grid-template-columns:112px minmax(0,1fr);border-radius:14px}.chat-rail-head{padding:10px}.chat-rail-head .primary{padding:7px;font-size:.67rem}.chat-thread-list{padding:6px}.chat-thread{grid-template-columns:38px minmax(0,1fr);min-height:61px;padding:7px 6px}.chat-avatar{width:38px;height:38px;border-radius:12px}.chat-thread-line time,.chat-thread-copy small{display:none}.chat-thread-copy strong{font-size:.68rem}.chat-unread{position:absolute;top:3px;left:32px;min-width:18px;height:18px;padding:0 4px;font-size:.58rem}.chat-header{min-height:64px;padding:10px 12px}.chat-header h2{font-size:.9rem}.chat-header p{max-width:150px}.chat-header-actions button{min-height:31px;padding:5px 7px;font-size:.62rem}.chat-messages{padding:13px 10px}.chat-message{max-width:88%;padding:9px 11px}.chat-compose{padding:9px}.chat-compose textarea{min-height:58px}.chat-selected-file{max-width:82px}.chat-compose .primary[type=submit]{min-width:58px;padding-inline:10px}.chat-emoji-panel{left:7px;bottom:64px;width:calc(100% - 14px)}.chat-emoji-grid{grid-template-columns:repeat(6,minmax(32px,1fr))}.chat-notifications{top:70px;right:14px}.chat-notification{grid-template-columns:38px minmax(0,1fr)}.chat-notification-avatar{width:38px;height:38px}.chat-notification-action{display:none}}
@media(max-width:480px){.chat-shell{grid-template-columns:92px minmax(0,1fr)}.chat-thread{grid-template-columns:34px minmax(0,1fr)}.chat-avatar{width:34px;height:34px}.chat-thread-copy strong{font-size:.62rem}.chat-header p{max-width:110px}.chat-message{max-width:93%}.chat-emoji-grid{grid-template-columns:repeat(5,minmax(32px,1fr))}}
@media(prefers-reduced-motion:reduce){.chat-notification{animation:none}}
.chat-emoji-panel:not([hidden]){grid-template-columns:1fr;gap:0}
