/* LawComm - Internal Communication System */
:root {
    --primary: #3b82f6;
    --primary-dark: #1d4ed8;
    --bg: #f1f5f9;
    --sidebar-bg: #1e293b;
    --header-bg: #ffffff;
    --chat-bg: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --msg-own: #3b82f6;
    --msg-other: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Cairo', sans-serif;
    background: var(--chat-bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* Login Screen */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    padding: 20px;
}
.login-card {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    width: 100%;
    max-width: 420px;
}
.login-card .logo {
    text-align: center;
    font-size: 3rem;
    margin-bottom: 12px;
}
.login-card h1 {
    text-align: center;
    margin: 0 0 4px;
    color: var(--text);
    font-size: 1.5rem;
}
.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 24px;
}
.login-card .form-group {
    margin-bottom: 16px;
}
.login-card label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text);
    font-size: 0.85rem;
}
.login-card input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    text-align: center;
    letter-spacing: 4px;
}
.login-card input:focus {
    outline: none;
    border-color: var(--primary);
}
.login-card .btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    margin-top: 8px;
}
.login-card .btn:hover { background: var(--primary-dark); }
.login-card .demo-info {
    margin-top: 16px;
    padding: 12px;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.6;
}
.login-card .demo-info strong { color: var(--text); }

/* App Layout */
.app-layout {
    display: grid;
    grid-template-columns: 320px 1fr 280px;
    height: 100vh;
}

/* Sidebar - Conversations List */
.sidebar {
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #334155;
}
.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-header .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
}
.sidebar-header .user-info {
    flex: 1;
    min-width: 0;
}
.sidebar-header .user-name {
    font-weight: 700;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-header .user-role {
    font-size: 0.7rem;
    color: #94a3b8;
    background: rgba(255,255,255,0.1);
    padding: 1px 6px;
    border-radius: 4px;
    display: inline-block;
}
.sidebar-header .role-supervisor {
    background: rgba(245,158,11,0.3);
    color: #fbbf24;
}
.sidebar-header .role-admin {
    background: rgba(220,38,38,0.3);
    color: #fca5a5;
}
.sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    color: white;
    font-size: 0.85rem;
    font-family: inherit;
}
.sidebar-search input::placeholder { color: #94a3b8; }
.sidebar-search input:focus { outline: none; border-color: var(--primary); }
.conversations-list {
    flex: 1;
    overflow-y: auto;
}
.conversation-item {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background 0.2s;
}
.conversation-item:hover {
    background: rgba(255,255,255,0.05);
}
.conversation-item.active {
    background: rgba(59,130,246,0.2);
    border-right: 3px solid var(--primary);
}
.conversation-item .avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    flex-shrink: 0;
}
.conversation-item .info { flex: 1; min-width: 0; }
.conversation-item .name {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conversation-item .preview {
    font-size: 0.78rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conversation-item .meta {
    text-align: left;
    font-size: 0.7rem;
    color: #94a3b8;
}
.conversation-item .unread {
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 700;
    margin-top: 4px;
    display: inline-block;
}

/* Chat Area */
.chat-area {
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    overflow: hidden;
}
.chat-header {
    background: white;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
}
.chat-header .name { font-weight: 700; font-size: 1rem; }
.chat-header .status { font-size: 0.75rem; color: var(--text-muted); }
.chat-header .actions {
    margin-right: auto;
    display: flex;
    gap: 8px;
}
.chat-header .actions button {
    background: transparent;
    border: none;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
}
.chat-header .actions button:hover { background: var(--bg); }

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    position: relative;
    word-wrap: break-word;
}
.message.own {
    align-self: flex-end;
    background: var(--msg-own);
    color: white;
    border-bottom-right-radius: 4px;
}
.message.other {
    align-self: flex-start;
    background: var(--msg-other);
    border-bottom-left-radius: 4px;
}
.message .sender {
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--primary);
}
.message.own .sender { color: rgba(255,255,255,0.8); }
.message .content {
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
}
.message .time {
    font-size: 0.65rem;
    color: rgba(0,0,0,0.4);
    margin-top: 4px;
    text-align: left;
}
.message.own .time { color: rgba(255,255,255,0.7); }
.message .file-attachment {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(0,0,0,0.05);
    border-radius: 10px;
    margin-top: 6px;
}
.message.own .file-attachment { background: rgba(255,255,255,0.15); }
.message .file-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}
.message .file-info { flex: 1; min-width: 0; }
.message .file-name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message .file-size { font-size: 0.7rem; opacity: 0.7; }
.message .image-msg {
    max-width: 100%;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 4px;
}

/* View-only protection for non-supervisors */
.view-only-img {
    position: relative;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}
.view-only-img::after {
    content: "👁 عرض فقط - " attr(data-user);
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
}

/* Message Input */
.message-input {
    background: white;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.message-input .attach-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg);
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
}
.message-input .attach-btn:hover { background: var(--border); }
.message-input textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    min-height: 40px;
}
.message-input textarea:focus { outline: none; border-color: var(--primary); }
.message-input .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    cursor: pointer;
    color: white;
    font-size: 1.1rem;
}
.message-input .send-btn:hover { background: var(--primary-dark); }
.message-input .send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.file-preview {
    background: white;
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.file-preview .file-info { flex: 1; }
.file-preview button {
    background: var(--danger);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}

/* Right Sidebar - Users */
.right-sidebar {
    background: white;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.right-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: var(--text);
}
.user-list { padding: 12px; }
.user-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
}
.user-list-item:hover { background: var(--bg); }
.user-list-item .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.user-list-item .name {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-list-item .role-badge {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-muted);
}
.user-list-item .role-supervisor {
    background: rgba(245,158,11,0.2);
    color: #d97706;
}
.user-list-item .role-admin {
    background: rgba(220,38,38,0.2);
    color: #dc2626;
}
.user-list-item .online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    margin-right: 4px;
}
.user-list-item.offline .online-dot {
    background: var(--text-muted);
}

.no-chat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}
.no-chat i { font-size: 5rem; opacity: 0.3; margin-bottom: 20px; }

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}
.lightbox .close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.1);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
}
.lightbox .download {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}
.lightbox .download:disabled {
    background: var(--danger);
    cursor: not-allowed;
    opacity: 0.7;
}
.lightbox .watermark {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: #1e293b;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: slideIn 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 200px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Empty states */
.empty-chat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    flex-direction: column;
    gap: 12px;
}
.empty-chat i { font-size: 4rem; opacity: 0.2; }

/* Responsive - Mobile */
@media (max-width: 900px) {
    body { overflow: auto; height: auto; }
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        max-height: 50vh;
        border-left: none;
        border-bottom: 1px solid #334155;
    }
    .sidebar .conversations-list { max-height: 35vh; }
    .right-sidebar { display: none; }
    .chat-area { height: 60vh; min-height: 400px; }
    .login-card { padding: 24px; }
    .login-card h1 { font-size: 1.2rem; }
}

@media (max-width: 480px) {
    .sidebar-header .user-info .user-name { font-size: 0.8rem; }
    .chat-header .name { font-size: 0.9rem; }
    .message { max-width: 85%; }
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-header button {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
}
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.btn-secondary {
    background: var(--border);
    color: var(--text);
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
}
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
}
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.85rem;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); }
