.msg-screen,
.msg-desktop,
.msg-thread-screen,
.msg-thread-pane{
  --msg-bg:#f2f2f7;
  --msg-panel:#fff;
  --msg-panel-alt:#f9f9f9;
  --msg-border:#e0e0e0;
  --msg-border-soft:#f0f0f0;
  --msg-text:#1a1a2e;
  --msg-muted:#8e8e93;
  --msg-subtle:#636366;
  --msg-patient-bubble:#fff;
  --msg-doctor-bubble:var(--c-primary);
  --msg-category-bg:#f0f6ff;
  --msg-category-text:#0043a8;
  --msg-date-bg:rgba(0,0,0,.12);
  --msg-date-text:#fff;
  --msg-shadow:0 1px 2px rgba(0,0,0,.08);
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]) .msg-screen,
  :root:not([data-theme="light"]) .msg-desktop,
  :root:not([data-theme="light"]) .msg-thread-screen,
  :root:not([data-theme="light"]) .msg-thread-pane{
    --msg-bg:var(--c-bg-2);
    --msg-panel:var(--c-bg);
    --msg-panel-alt:var(--c-bg-3);
    --msg-border:var(--c-border);
    --msg-border-soft:var(--c-border-light);
    --msg-text:var(--c-text);
    --msg-muted:var(--c-text-3);
    --msg-subtle:var(--c-text-2);
    --msg-patient-bubble:#222736;
    --msg-doctor-bubble:#0a66d1;
    --msg-category-bg:#18345f;
    --msg-category-text:#9fc7ff;
    --msg-date-bg:rgba(255,255,255,.12);
    --msg-date-text:#cfd6e6;
    --msg-shadow:none;
    color-scheme:dark;
  }
}
:root[data-theme="dark"] .msg-screen,
:root[data-theme="dark"] .msg-desktop,
:root[data-theme="dark"] .msg-thread-screen,
:root[data-theme="dark"] .msg-thread-pane{
  --msg-bg:var(--c-bg-2);
  --msg-panel:var(--c-bg);
  --msg-panel-alt:var(--c-bg-3);
  --msg-border:var(--c-border);
  --msg-border-soft:var(--c-border-light);
  --msg-text:var(--c-text);
  --msg-muted:var(--c-text-3);
  --msg-subtle:var(--c-text-2);
  --msg-patient-bubble:#222736;
  --msg-doctor-bubble:#0a66d1;
  --msg-category-bg:#18345f;
  --msg-category-text:#9fc7ff;
  --msg-date-bg:rgba(255,255,255,.12);
  --msg-date-text:#cfd6e6;
  --msg-shadow:none;
  color-scheme:dark;
}


.msg-screen{background:var(--msg-bg);margin:0 -12px 0;padding:0 0 80px;min-height:calc(100dvh - 120px);color:var(--msg-text)}
.msg-thread-screen{position:fixed!important;inset:0!important;z-index:1001!important;width:100vw!important;height:100vh!important;min-height:100vh!important;background:var(--msg-bg);margin:0!important;padding:0!important;display:flex!important;flex-direction:column;overflow:hidden!important;color:var(--msg-text)}
.msg-thread-screen.in-pane{position:relative!important;inset:auto!important;z-index:1!important;width:100%!important;height:100%!important;min-height:0!important;margin:0!important}
.msg-thread-header{background:var(--msg-panel);border-bottom:.5px solid var(--msg-border);padding:7px 12px;display:flex;align-items:center;gap:8px;flex-shrink:0}
.msg-chat-area{flex:1;overflow-y:auto;padding:10px 10px 6px;display:flex;flex-direction:column;gap:2px;background:var(--msg-bg)}
.msg-input-bar{background:var(--msg-panel);border-top:.5px solid var(--msg-border);padding:6px 10px;padding-bottom:max(env(safe-area-inset-bottom),6px);display:flex;align-items:flex-end;gap:8px;flex-shrink:0}
.msg-reply-input{flex:1;padding:8px 14px;border:1px solid var(--msg-border);border-radius:20px;font-size:15px;resize:none;font-family:inherit;line-height:1.4;outline:none;max-height:120px;overflow-y:auto;background:var(--msg-panel-alt);color:var(--msg-text)}
.msg-reply-input::placeholder{color:var(--msg-muted)}
.msg-reply-input:focus{border-color:rgba(0,122,255,.4);box-shadow:none}
.msg-scroll-down{position:absolute;bottom:calc(52px + env(safe-area-inset-bottom,0px) + 8px);right:12px;min-width:36px;height:36px;padding:0 10px;border-radius:18px;background:var(--msg-panel);border:1px solid var(--msg-border);color:var(--msg-text);font-size:13px;font-weight:700;display:flex;align-items:center;justify-content:center;cursor:pointer;box-shadow:0 2px 8px rgba(0,0,0,.15);z-index:2;gap:3px;-webkit-tap-highlight-color:transparent}
.msg-send-btn{width:38px;height:38px;border-radius:50%;background:var(--c-primary);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:opacity .15s;-webkit-tap-highlight-color:transparent}

/* Desktop split view */
.msg-desktop{display:flex;margin:0 -12px 0;height:calc(100dvh - 96px);overflow:hidden;background:var(--msg-bg);color:var(--msg-text)}
.msg-list-pane{width:300px;flex-shrink:0;border-right:1px solid var(--msg-border);display:flex;flex-direction:column;overflow:hidden;background:var(--msg-panel)}
.msg-thread-pane{flex:1;display:flex;flex-direction:column;overflow:hidden;min-width:0;background:var(--msg-bg)}
.msg-list-items{overflow-y:auto;flex:1;background:var(--msg-panel)}

.msg-list-header{padding:12px 14px 10px;border-bottom:.5px solid var(--msg-border);flex-shrink:0;background:var(--msg-panel)}
.msg-list-header-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
.msg-list-title{font-size:13px;font-weight:700;color:var(--msg-text)}
.msg-list-new{background:var(--c-danger);color:#fff;font-size:12px;font-weight:700;padding:2px 9px;border-radius:12px}
.msg-list-tools{display:flex;align-items:center;gap:6px}
.msg-search-input{flex:1;min-width:0;padding:7px 11px;border-radius:10px;border:.5px solid var(--msg-border);background:var(--msg-bg);color:var(--msg-text);font-size:13px;outline:none;-webkit-appearance:none}
.msg-search-input:focus{border-color:var(--c-primary)}
.msg-search-input::placeholder{color:var(--msg-muted)}
.msg-filter-btn{padding:7px 12px;font-size:12px;font-weight:600;border-radius:10px;border:.5px solid var(--msg-border);background:var(--msg-bg);color:var(--msg-muted);cursor:pointer;white-space:nowrap;flex-shrink:0}
.msg-filter-btn.active{background:var(--c-primary);border-color:var(--c-primary);color:#fff}
.msg-thread-item{width:100%;display:flex;align-items:center;gap:12px;padding:12px 14px;background:var(--msg-panel);border:0;border-bottom:.5px solid var(--msg-border-soft);cursor:pointer;text-align:left;font:inherit;color:var(--msg-text);-webkit-tap-highlight-color:rgba(0,0,0,.05)}
.msg-thread-item.active{background:var(--msg-panel-alt)}
.msg-thread-item:hover{background:var(--msg-panel-alt)}
.msg-avatar{width:44px;height:44px;border-radius:50%;display:flex;align-items:center;justify-content:center;flex-shrink:0;color:#fff;font-size:18px;font-weight:700}
.msg-thread-main{flex:1;min-width:0}
.msg-thread-top{display:flex;align-items:baseline;justify-content:space-between;gap:6px;margin-bottom:1px}
.msg-thread-name{font-size:14px;font-weight:600;color:var(--msg-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex-shrink:1;min-width:0}
.msg-thread-name.unread{font-weight:700}
.msg-thread-time{font-size:10px;color:var(--msg-muted);flex-shrink:0;white-space:nowrap}
.msg-thread-doctor{font-size:10px;font-weight:600;margin-bottom:1px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.msg-thread-meta{font-size:11px;color:var(--msg-subtle);margin-bottom:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.msg-preview-row{display:flex;align-items:center;justify-content:space-between;gap:6px}
.msg-preview{font-size:12px;color:var(--msg-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;font-weight:400}
.msg-preview.unread{color:var(--msg-text);font-weight:500}
.msg-unread-badge{min-width:18px;height:18px;border-radius:9px;background:var(--c-danger);color:#fff;font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;padding:0 4px;flex-shrink:0}

.msg-empty,.msg-placeholder{display:flex;flex-direction:column;align-items:center;justify-content:center;color:var(--msg-muted);gap:12px;text-align:center}
.msg-empty{padding:60px 20px}
.msg-placeholder{height:100%}
.msg-empty svg,.msg-placeholder svg{opacity:.22}
.msg-empty-title,.msg-placeholder-title{font-size:15px;font-weight:600}
.msg-empty-sub{font-size:13px}
.msg-loading{text-align:center;padding:40px;color:var(--msg-muted);font-size:14px}

.msg-back-btn{background:none;border:none;cursor:pointer;color:var(--c-primary);font-size:16px;font-weight:600;padding:4px 10px 4px 0;display:flex;align-items:center;gap:4px;white-space:nowrap}
.msg-header-avatar{width:36px;height:36px;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-size:15px;font-weight:700;flex-shrink:0}
.msg-thread-heading{flex:1;min-width:0}
.msg-thread-title-btn{background:none;border:none;padding:0;cursor:pointer;font-size:15px;font-weight:700;color:var(--c-primary);text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block;max-width:100%}
.msg-thread-subline{font-size:11px;color:var(--msg-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:1px}
.msg-phone-btn{width:36px;height:36px;border-radius:50%;background:var(--c-success);display:flex;align-items:center;justify-content:center;color:#fff;text-decoration:none;flex-shrink:0}

.msg-date-separator{text-align:center;margin:8px 0}
.msg-date-pill{background:var(--msg-date-bg);color:var(--msg-date-text);font-size:11px;font-weight:600;padding:3px 10px;border-radius:10px}
.msg-bubble-row{display:flex;margin-bottom:2px}
.msg-bubble-row.patient{justify-content:flex-start}
.msg-bubble-row.doctor{justify-content:flex-end}
.msg-bubble-wrap{max-width:82%}
.msg-bubble{border-radius:18px;padding:9px 13px}
.msg-bubble.patient{background:var(--msg-patient-bubble);border-radius:18px 18px 18px 4px;box-shadow:var(--msg-shadow)}
.msg-bubble.doctor{background:var(--msg-doctor-bubble);border-radius:18px 18px 4px 18px}
.msg-category{display:inline-block;background:var(--msg-category-bg);color:var(--msg-category-text);font-size:10px;font-weight:700;padding:2px 7px;border-radius:6px;margin-bottom:6px}
.msg-text{font-size:14px;line-height:1.5;word-break:break-word}
.msg-text.patient{color:var(--msg-text)}
.msg-text.doctor{color:#fff}
.msg-time{font-size:10px;color:var(--msg-muted);margin:2px 6px}
.msg-time.doctor{text-align:right}
.msg-sender{font-size:10px;font-weight:700;color:rgba(255,255,255,.85);margin-bottom:3px;letter-spacing:.02em}
.msg-ticks{margin-left:4px;font-size:10px;color:var(--msg-muted);letter-spacing:-.08em}
.msg-ticks--read{color:var(--c-primary);font-weight:700}

.msg-thread-error{display:flex;flex-direction:column;align-items:center;justify-content:center;flex:1;gap:12px;color:var(--msg-muted);padding:40px 20px}
.msg-thread-error-text{font-size:14px;font-weight:500}
.msg-thread-retry-btn{padding:9px 22px;font-size:14px;font-weight:600;background:var(--msg-doctor-bubble);color:#fff;border:none;border-radius:20px;cursor:pointer}

@media(min-width:1000px){.msg-list-pane{width:340px}}

/* Constrain thread width on large screens */
@media(min-width:1200px){
  .msg-thread-pane{align-items:center}
  .msg-thread-pane>.msg-thread-screen{max-width:760px;width:100%;margin:0}
  .msg-chat-area{max-width:760px;width:100%}
}
