/* ============================================================
   Profs Classrooms — WhatsApp-inspired Chat UI
   Clean, warm, professional — built for learning
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800&display=swap');

:root {
    --cr-sidebar-bg:    #111b21;
    --cr-sidebar-item:  #202c33;
    --cr-sidebar-hover: #2a3942;
    --cr-sidebar-active:#2a3942;
    --cr-panel-bg:      #0b141a;

    --cr-header-bg:     #202c33;
    --cr-input-bg:      #202c33;
    --cr-messages-bg:   #0b141a;

    --cr-bubble-mine:   #005c4b;
    --cr-bubble-theirs: #202c33;

    --cr-accent:        #00a884;
    --cr-accent-light:  #00cf9d;
    --cr-text:          #e9edef;
    --cr-text-muted:    #8696a0;
    --cr-border:        #2a3942;

    --cr-font: 'Nunito', system-ui, sans-serif;
    --cr-radius-bubble: 7.5px;
    --cr-radius-mine: 7.5px 0 7.5px 7.5px;
    --cr-radius-theirs: 0 7.5px 7.5px 7.5px;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.cr-app {
    display: flex;
    height: 94vh;
    max-height: 900px;
    border-radius: 12px;
    overflow: hidden;
    font-family: var(--cr-font);
    box-shadow: 0 16px 48px rgba(0,0,0,.4);
    background: var(--cr-panel-bg);
    border: 1px solid rgba(255,255,255,.06);
    position: relative;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.cr-sidebar {
    width: 360px;
    min-width: 360px;
    background: var(--cr-sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--cr-border);
    z-index: 10;
}

.cr-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--cr-header-bg);
}

.cr-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cr-brand-icon { font-size: 22px; }
.cr-brand-name {
    font-size: 18px;
    font-weight: 800;
    color: var(--cr-text);
    letter-spacing: -.01em;
}

.cr-sidebar-action {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--cr-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    text-decoration: none;
    line-height: 1;
    transition: background .2s;
}

.cr-sidebar-action:hover { background: var(--cr-accent-light); color: #fff; }

.cr-sidebar-search {
    padding: 8px 12px;
    background: var(--cr-sidebar-bg);
}

.cr-sidebar-search input {
    width: 100%;
    background: var(--cr-sidebar-item);
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    color: var(--cr-text);
    font-family: var(--cr-font);
    font-size: 14px;
    outline: none;
}

.cr-sidebar-search input::placeholder { color: var(--cr-text-muted); }

.cr-rooms-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--cr-border) transparent;
}

/* Room Item */
.cr-room-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    transition: background .12s;
    border-bottom: 1px solid rgba(255,255,255,.04);
    cursor: pointer;
}

.cr-room-item:hover   { background: var(--cr-sidebar-hover); }
.cr-room-item.active  { background: var(--cr-sidebar-active); }

.cr-room-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.cr-room-info { flex: 1; min-width: 0; }

.cr-room-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 3px;
}

.cr-room-item-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--cr-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.cr-room-item-time { font-size: 11px; color: var(--cr-text-muted); flex-shrink: 0; }

.cr-room-item-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cr-room-item-preview {
    font-size: 13px;
    color: var(--cr-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.cr-unread-badge {
    background: var(--cr-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.cr-sidebar-empty {
    padding: 32px 20px;
    text-align: center;
    color: var(--cr-text-muted);
    font-size: 14px;
}

.cr-sidebar-empty a { color: var(--cr-accent); text-decoration: none; }

/* ============================================================
   MAIN CHAT AREA
   ============================================================ */

.cr-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--cr-messages-bg);
    position: relative;
    overflow: hidden;
}

.cr-main.no-room { align-items: center; justify-content: center; }

/* Welcome state */
.cr-welcome-state {
    text-align: center;
    color: var(--cr-text-muted);
}

.cr-welcome-icon { font-size: 64px; margin-bottom: 16px; opacity: .5; }
.cr-welcome-state h2 { font-size: 22px; color: var(--cr-text); margin-bottom: 8px; }
.cr-welcome-state p  { font-size: 14px; }

/* Chat Header */
.cr-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--cr-header-bg);
    border-bottom: 1px solid var(--cr-border);
    flex-shrink: 0;
    z-index: 10;
}

.cr-back-btn {
    background: none;
    border: none;
    color: var(--cr-text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    display: none; /* shown on mobile */
}

.cr-chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.cr-chat-header-info { flex: 1; }
.cr-chat-name    { display: block; font-size: 16px; font-weight: 700; color: var(--cr-text); }
.cr-chat-members { display: block; font-size: 12px; color: var(--cr-text-muted); }

.cr-chat-actions { display: flex; gap: 4px; }
.cr-header-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--cr-text-muted);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background .15s;
}
.cr-header-btn:hover { background: rgba(255,255,255,.08); color: var(--cr-text); }

/* Members Panel */
.cr-members-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: var(--cr-sidebar-bg);
    border-left: 1px solid var(--cr-border);
    z-index: 20;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform .25s ease;
}

.cr-members-panel.open { transform: translateX(0); }

.cr-members-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--cr-header-bg);
    border-bottom: 1px solid var(--cr-border);
}

.cr-members-panel-header h3 { color: var(--cr-text); font-size: 16px; margin: 0; }
.cr-members-panel-header button { background:none; border:none; color:var(--cr-text-muted); cursor:pointer; font-size:18px; }

.cr-members-list { flex:1; overflow-y:auto; padding:8px 0; }
.cr-member-item  { display:flex; align-items:center; gap:12px; padding:10px 16px; }
.cr-member-avatar { width:36px; height:36px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:14px; font-weight:700; color:#fff; flex-shrink:0; }
.cr-member-info strong { display:block; font-size:14px; color:var(--cr-text); }
.cr-member-info span   { display:block; font-size:11px; color:var(--cr-text-muted); }
.cr-member-badge { margin-left:auto; background:var(--cr-accent); color:#fff; font-size:10px; font-weight:700; padding:2px 8px; border-radius:10px; }

/* ============================================================
   MESSAGES
   ============================================================ */

.cr-messages-wrap {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--cr-border) transparent;
    /* WhatsApp-style background pattern */
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.025'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.cr-messages {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 100%;
}

.cr-load-older {
    text-align: center;
    margin-bottom: 12px;
}

.cr-load-older button {
    background: rgba(0,168,132,.15);
    border: 1px solid var(--cr-accent);
    color: var(--cr-accent);
    padding: 6px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-family: var(--cr-font);
    font-size: 12px;
    font-weight: 600;
    transition: background .15s;
}

.cr-load-older button:hover { background: rgba(0,168,132,.25); }

/* System message */
.cr-msg-system {
    display: flex;
    justify-content: center;
    margin: 8px 0;
}

.cr-msg-system span {
    background: rgba(0,0,0,.35);
    color: var(--cr-text-muted);
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 8px;
    text-align: center;
}

/* Message row */
.cr-msg-row {
    display: flex;
    gap: 8px;
    max-width: 75%;
    margin-bottom: 2px;
    animation: msgIn .15s ease;
}

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

.cr-msg-row.mine   { align-self: flex-end; flex-direction: row-reverse; }
.cr-msg-row.theirs { align-self: flex-start; }

.cr-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    align-self: flex-end;
}

.cr-msg-content { display: flex; flex-direction: column; }

.cr-msg-name {
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 3px;
    margin-left: 4px;
}

.cr-msg-bubble {
    background: var(--cr-bubble-theirs);
    border-radius: var(--cr-radius-theirs);
    padding: 7px 10px 5px;
    position: relative;
    cursor: pointer;
    transition: filter .15s;
}

.cr-msg-row.mine .cr-msg-bubble {
    background: var(--cr-bubble-mine);
    border-radius: var(--cr-radius-mine);
}

.cr-msg-bubble:hover { filter: brightness(1.1); }

/* Reply quote */
.cr-msg-reply-quote {
    background: rgba(255,255,255,.1);
    border-left: 3px solid var(--cr-accent);
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--cr-text-muted);
}

.cr-msg-text {
    color: var(--cr-text);
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    word-break: break-word;
    white-space: pre-wrap;
}

/* Image message */
.cr-msg-image-wrap { display: block; }
.cr-msg-image {
    max-width: 260px;
    max-height: 260px;
    border-radius: 6px;
    display: block;
    object-fit: cover;
}

/* File message */
.cr-msg-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    text-decoration: none;
    color: var(--cr-text);
    min-width: 180px;
}

.cr-file-icon { font-size: 24px; }
.cr-file-name { flex: 1; font-size: 13px; font-weight: 600; word-break: break-all; }
.cr-file-dl   { color: var(--cr-accent); font-weight: 700; }

.cr-msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 3px;
}

.cr-msg-time { font-size: 10px; color: var(--cr-text-muted); }

.cr-msg-delete {
    background: none;
    border: none;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    padding: 0;
    transition: opacity .15s;
    color: var(--cr-text-muted);
}

.cr-msg-bubble:hover .cr-msg-delete { opacity: 1; }

.cr-no-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--cr-text-muted);
    font-size: 14px;
    padding: 40px;
}

.cr-no-messages span { font-size: 36px; opacity: .5; }

/* ============================================================
   REPLY BAR
   ============================================================ */

.cr-reply-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--cr-header-bg);
    border-top: 1px solid var(--cr-border);
    border-left: 4px solid var(--cr-accent);
    flex-shrink: 0;
}

.cr-reply-preview { flex: 1; }
.cr-reply-label   { font-size: 11px; color: var(--cr-accent); font-weight: 700; display: block; }
.cr-reply-preview p { font-size: 13px; color: var(--cr-text-muted); margin: 2px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 400px; }
.cr-reply-cancel  { background:none; border:none; color:var(--cr-text-muted); cursor:pointer; font-size:16px; transition:color .15s; }
.cr-reply-cancel:hover { color: var(--cr-text); }

/* ============================================================
   INPUT AREA
   ============================================================ */

.cr-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px;
    background: var(--cr-input-bg);
    border-top: 1px solid var(--cr-border);
    flex-shrink: 0;
}

.cr-attach-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--cr-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color .15s;
}

.cr-attach-btn:hover { color: var(--cr-accent); }

.cr-input-box {
    flex: 1;
    background: var(--cr-sidebar-item);
    border: 1px solid var(--cr-border);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--cr-text);
    font-family: var(--cr-font);
    font-size: 14px;
    line-height: 1.5;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    transition: border-color .15s;
    word-break: break-word;
}

.cr-input-box:focus { border-color: var(--cr-accent); }
.cr-input-box:empty::before {
    content: attr(data-placeholder);
    color: var(--cr-text-muted);
    pointer-events: none;
}

.cr-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--cr-accent);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .2s;
    transform: scale(0.9);
}

.cr-send-btn:not(:disabled) { transform: scale(1); }
.cr-send-btn:not(:disabled):hover { background: var(--cr-accent-light); }
.cr-send-btn:disabled { background: var(--cr-border); cursor: not-allowed; transform: scale(0.85); }

/* Login prompt */
.cr-login-prompt { text-align:center; padding:40px; color:#64748b; }
.cr-login-prompt a { color:#1a3a5c; font-weight:600; }

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 768px) {
    .cr-app      { height: 100vh; border-radius: 0; }
    .cr-sidebar  { width: 100%; min-width: 0; border-right: none; }
    .cr-sidebar.mobile-hidden { display: none; }
    .cr-back-btn { display: flex !important; }
    .cr-msg-row  { max-width: 88%; }
    .cr-members-panel { width: 100%; }
}
