 
    :root {
      --primary: #2563eb;
      --primary-light: #eff6ff;
      --accent: #0ea5e9;
      --sidebar-bg: #f8fafc;
      --chat-bg: #ffffff;
      --border: #e2e8f0;
      --text-main: #1e293b;
      --text-muted: #94a3b8;
      --text-sub: #64748b;
      --bubble-in: #f1f5f9;
      --radius: 14px;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: 'DM Sans', sans-serif;
      background: #e9eef6;
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .chat-shell {
      width: 100%;
      max-width: 98vw;
      height: 98vh;
      background: var(--chat-bg);
      border-radius: 20px;
      box-shadow: 0 20px 60px rgba(37,99,235,0.10), 0 2px 8px rgba(0,0,0,0.06);
      display: flex;
      overflow: hidden;
    }

    /* ---- SIDEBAR ---- */
    .sidebar {
      width: 340px;
      min-width: 280px;
      background: var(--sidebar-bg);
      border-right: 1.5px solid var(--border);
      display: flex;
      flex-direction: column;
      height: 100%;
    }

    .sidebar-header {
      padding: 22px 22px 14px;
      border-bottom: 1.5px solid var(--border);
      background: #fff;
    }

    .sidebar-header h5 {
      font-family: 'Playfair Display', serif;
      font-size: 1.25rem;
      color: var(--text-main);
      margin-bottom: 14px;
      letter-spacing: -0.01em;
    }

    .search-by-row {
      display: flex;
      flex-wrap: wrap;   /* 👈 important */
      align-items: center;
      gap: 6px;
      margin-bottom: 12px;
      font-size: 0.82rem;
      color: var(--text-sub);
      font-weight: 500;
    }

    .search-by-row .radio-option {
      width: calc(50% - 6px);  /* 👈 2 columns */
      display: flex;
      align-items: center;
      gap: 4px;
      cursor: pointer;
    }

    .search-by-row input[type="radio"] {
      accent-color: var(--primary);
    }

    .search-input-wrap {
      position: relative;
    }

    .search-input-wrap .bi-search {
      position: absolute;
      left: 11px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-muted);
      font-size: 0.85rem;
    }

    .search-input-wrap input {
      width: 100%;
      padding: 9px 12px 9px 34px;
      border: 1.5px solid var(--border);
      border-radius: 10px;
      font-size: 0.85rem;
      color: var(--text-main);
      background: #f1f5f9;
      outline: none;
      transition: border-color 0.2s;
    }

    .search-input-wrap input:focus {
      border-color: var(--primary);
      background: #fff;
    }

    /* Tabs */
    .msg-tabs {
      display: flex;
      gap: 0;
      padding: 12px 18px 0;
      background: #fff;
      border-bottom: 1.5px solid var(--border);
    }

    .msg-tab {
      padding: 8px 16px;
      font-size: 0.85rem;
      font-weight: 600;
      color: var(--text-sub);
      border: none;
      background: none;
      cursor: pointer;
      border-bottom: 2.5px solid transparent;
      transition: all 0.18s;
    }

    .msg-tab.active {
      color: var(--primary);
      border-bottom-color: var(--primary);
    }

    /* Teacher list */
    .chat-list {
      flex: 1;
      overflow-y: auto;
      padding: 6px 0;
    }

    .teacher-list::-webkit-scrollbar { width: 4px; }
    .teacher-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

    .teacher-item {
      padding: 13px 20px;
      border-bottom: 1px solid #f1f5f9;
      cursor: pointer;
      transition: background 0.15s;
      position: relative;
    }

    

    .teacher-item:hover { background: #f0f6ff; }
    .teacher-item.active { background: #eff6ff; }

    .teacher-item .t-name {
      font-weight: 600;
      font-size: 0.88rem;
      color: var(--text-main);
      margin-bottom: 2px;
    }

    .teacher-item .t-role {
      font-size: 0.76rem;
      color: var(--text-muted);
    }

    .teacher-item .chevron {
      position: absolute;
      right: 16px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-muted);
      font-size: 0.95rem;
    }

    /* Student sub-panel */
    .student-panel {
      background: #f8fafc;
      border-top: 1px solid var(--border);
      padding: 10px 14px 12px;
    }

    .student-search-wrap {
      position: relative;
      margin-bottom: 8px;
    }

    .student-search-wrap .bi-search {
      position: absolute;
      left: 10px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-muted);
      font-size: 0.8rem;
    }

    .student-search-wrap input {
      width: 100%;
      padding: 7px 10px 7px 30px;
      border: 1.5px solid var(--border);
      border-radius: 9px;
      font-size: 0.8rem;
      background: #fff;
      outline: none;
    }

    .student-card {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 9px 10px;
      border-radius: 10px;
      background: #fff;
      border: 1.5px solid var(--border);
      cursor: pointer;
      transition: box-shadow 0.18s, border-color 0.18s;
    }

    .student-card:hover {
      border-color: var(--primary);
      box-shadow: 0 2px 10px rgba(37,99,235,0.08);
    }

    .student-card img {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      object-fit: cover;
      border: 2px solid var(--primary-light);
    }

    .student-card .s-name {
      font-weight: 600;
      font-size: 0.83rem;
      color: var(--text-main);
    }

    .student-card .s-tap {
      font-size: 0.73rem;
      color: var(--text-muted);
    }

    .badge-tag {
      margin-left: auto;
      background: var(--primary);
      color: #fff;
      font-size: 0.68rem;
      font-weight: 600;
      border-radius: 20px;
      padding: 3px 8px;
      white-space: nowrap;
    }

    .badge-time {
      margin-left: auto;
      color: var(--secondary);
      font-size: 0.68rem;
      font-weight: 600;
      padding: 3px 8px;
      white-space: nowrap;
    }

    /* ---- CHAT AREA ---- */
    .chat-area {
      flex: 1;
      display: flex;
      flex-direction: column;
      height: 100%;
      background: #fff;
    }

    .chat-topbar {
      display: flex;
      align-items: center;
      gap: 13px;
      padding: 16px 24px;
      border-bottom: 1.5px solid var(--border);
      background: #fff;
    }

    .chat-topbar img {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      object-fit: cover;
      border: 2px solid var(--primary-light);
    }

    .chat-topbar .ct-name {
      font-weight: 700;
      font-size: 0.98rem;
      color: var(--text-main);
      letter-spacing: -0.01em;
    }

    .chat-topbar .ct-class {
      font-size: 0.77rem;
      color: var(--primary);
      font-weight: 600;
      letter-spacing: 0.04em;
      text-transform: uppercase;
    }

    .chat-topbar .topbar-actions {
      margin-left: auto;
      display: flex;
      gap: 8px;
    }

    .topbar-actions button {
      background: var(--primary-light);
      border: none;
      border-radius: 8px;
      padding: 7px 10px;
      color: var(--primary);
      font-size: 1rem;
      cursor: pointer;
      transition: background 0.15s;
    }

    .topbar-actions button:hover { background: #dbeafe; }

    /* Messages */
    .chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: 24px 28px;
      display: flex;
      flex-direction: column;
      gap: 14px;
      background: #f8fafc;
    }

    .chat-messages::-webkit-scrollbar { width: 4px; }
    .chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

    .msg-row {
      display: flex;
      align-items: flex-end;
      gap: 10px;
      animation: fadeUp 0.3s ease both;
    }

    @keyframes fadeUp {
      from { opacity: 0; transform: translateY(10px); }
      to   { opacity: 1; transform: translateY(0); }
    }

    .msg-row.incoming { flex-direction: row; }
    .msg-row.outgoing { flex-direction: row-reverse; }

    .msg-avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      object-fit: cover;
      border: 2px solid #e2e8f0;
      flex-shrink: 0;
    }

    .msg-bubble {
      /* max-width: 100%; */
      padding: 11px 15px;
      border-radius: 16px;
      font-size: 0.87rem;
      line-height: 1.55;
      color: var(--text-main);
      position: relative;
    }

    .msg-row.incoming .msg-bubble {
      background: #fff;
      border-bottom-left-radius: 4px;
      box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    }

    .msg-row.outgoing .msg-bubble {
      background: var(--primary);
      color: #fff;
      border-bottom-right-radius: 4px;
      box-shadow: 0 2px 8px rgba(37,99,235,0.18);
    }

    .msg-time {
      font-size: 0.68rem;
      color: #CFCFCF;
      margin-top: 4px;
      display: block;
    }

    .msg-row.outgoing .msg-time {
      text-align: right;
      color: #CFCFCF;
    }

    .date-divider {
      text-align: center;
      font-size: 0.73rem;
      color: var(--text-muted);
      font-weight: 500;
      margin: 4px 0;
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .date-divider::before,
    .date-divider::after {
      content: '';
      flex: 1;
      height: 1px;
      background: var(--border);
    }

    /* Input bar */
    .chat-inputbar {
      padding: 14px 20px;
      border-top: 1.5px solid var(--border);
      background: #fff;
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .chat-inputbar input {
      flex: 1;
      padding: 10px 16px;
      border: 1.5px solid var(--border);
      border-radius: 24px;
      font-size: 0.87rem;
      outline: none;
      background: #f8fafc;
      color: var(--text-main);
      transition: border-color 0.2s;
    }

    .chat-inputbar input:focus {
      border-color: var(--primary);
      background: #fff;
    }

    .chat-inputbar input::placeholder { color: var(--text-muted); }

    .chat-inputbar .btn-send {
      background: var(--primary);
      border: none;
      border-radius: 50%;
      width: 40px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      font-size: 1rem;
      cursor: pointer;
      transition: background 0.18s, transform 0.15s;
      flex-shrink: 0;
    }

    .chat-inputbar .btn-send:hover {
      background: #1d4ed8;
      transform: scale(1.07);
    }

    .chat-inputbar .btn-attach {
      background: none;
      border: none;
      color: var(--text-muted);
      font-size: 1.1rem;
      cursor: pointer;
      padding: 4px 6px;
      border-radius: 8px;
      transition: color 0.15s;
    }

    .chat-inputbar .btn-attach:hover { color: var(--primary); }

    /* Empty chat state */
    .chat-empty {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: var(--text-muted);
      gap: 12px;
      background: #f8fafc;
    }

    .chat-empty .bi { font-size: 2.8rem; color: #cbd5e1; }
    .chat-empty p { font-size: 0.9rem; }

    /* ---- MOBILE HAMBURGER BUTTON ---- */
    .btn-menu {
      display: none;
      background: var(--primary-light);
      border: none;
      border-radius: 9px;
      padding: 7px 10px;
      color: var(--primary);
      font-size: 1.15rem;
      cursor: pointer;
      margin-right: 4px;
      transition: background 0.15s;
      flex-shrink: 0;
    }
    .btn-menu:hover { background: #dbeafe; }

    /* ---- SIDEBAR CLOSE BUTTON (mobile only) ---- */
    .sidebar-close-btn {
      display: none;
      background: none;
      border: none;
      color: var(--text-sub);
      font-size: 1.2rem;
      cursor: pointer;
      padding: 2px 4px;
      border-radius: 6px;
      margin-left: auto;
      transition: color 0.15s;
    }
    .sidebar-close-btn:hover { color: var(--primary); }

    /* ---- OVERLAY (mobile) ---- */
    .sidebar-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.45);
      z-index: 99;
      backdrop-filter: blur(2px);
      animation: fadeOverlay 0.22s ease;
    }
    @keyframes fadeOverlay {
      from { opacity: 0; } to { opacity: 1; }
    }
    .sidebar-overlay.show { display: block; }

    /* ---- RESPONSIVE ---- */
    @media (max-width: 768px) {
      body { align-items: stretch; }

      .chat-shell {
        border-radius: 0;
        height: 100vh;
        height: 100dvh;
        max-width: 100%;
      }

      /* Sidebar becomes a slide-in drawer */
      .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        height: 100dvh;
        width: 85%;
        max-width: 320px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(37,99,235,0.12);
      }

      .sidebar.show {
        transform: translateX(0);
      }

      /* Show hamburger & sidebar close button */
      .btn-menu { display: flex; align-items: center; }
      .sidebar-close-btn { display: inline-flex; align-items: center; }

      /* Sidebar header: title row with close btn */
      .sidebar-header-row {
        display: flex;
        align-items: center;
        margin-bottom: 14px;
      }
      .sidebar-header-row h5 { margin-bottom: 0; flex: 1; }

      /* Chat area always full width on mobile */
      .chat-area { width: 100%; }

      /* Slightly tighter topbar on mobile */
      .chat-topbar { padding: 12px 14px; }
      .topbar-actions button { padding: 6px 8px; }

      /* Wider bubbles on small screens */
      .msg-bubble { max-width: 100%; }

      /* Tighter message padding */
      .chat-messages { padding: 16px 14px; }
      .chat-inputbar { padding: 10px 12px; }
    }

    @media (max-width: 400px) {
      .sidebar { width: 92%; }
      .ct-name { font-size: 0.85rem; }
      .badge-tag { font-size: 0.62rem; padding: 2px 6px; }
    }
  