/* ============================================
   LawTalk - Internal Communication
   Dark navy + gold theme
   ============================================ */
:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-elevated: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #d4a017;
    --accent-hover: #b8860b;
    --primary: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

html, body {
    height: 100%;
    font-family: 'Segoe UI', 'Tahoma', 'Cairo', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

#app { height: 100vh; }

/* Loading & Login */
.loading-screen, .error-screen, .login-screen {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100vh; padding: 20px; text-align: center; gap: 16px;
}
.spinner {
    width: 50px; height: 50px; border: 4px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen h2 { color: var(--accent); }

.login-card {
    background: var(--bg-card); padding: 40px; border-radius: 16px;
    box-shadow: var(--shadow); width: 100%; max-width: 400px;
    border: 1px solid var(--border);
}
.login-card .logo { font-size: 3.5rem; margin-bottom: 8px; }
.login-card h1 { color: var(--accent); margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 0.9rem; }
.form-group { margin-bottom: 16px; text-align: right; }
.form-group label { display: block; margin-bottom: 6px; font-size: 0.9rem; color: var(--text-muted); }
.form-group input {
    width: 100%; padding: 12px 16px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: 1rem; font-family: inherit;
    transition: border-color 0.2s;
}
.form-group input:focus { outline: none; border-color: var(--accent); }
.login-card button {
    width: 100%; padding: 12px; background: var(--accent);
    color: #000; border: none; border-radius: 8px; font-size: 1.05rem;
    font-weight: 700; cursor: pointer; margin-top: 8px; font-family: inherit;
    transition: background 0.2s;
}
.login-card button:hover { background: var(--accent-hover); }
.demo-info {
    margin-top: 20px; padding: 16px; background: var(--bg);
    border-radius: 8px; font-size: 0.85rem; line-height: 1.8;
    border: 1px solid var(--border); text-align: right;
}
.demo-info code { background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px; font-family: monospace; }

.error-screen { background: var(--bg); }
.error-box { background: var(--bg-card); padding: 40px; border-radius: 16px; max-width: 400px; }
.btn-retry { background: var(--accent); color: #000; padding: 10px 24px; border: none; border-radius: 8px; cursor: pointer; margin-top: 16px; font-weight: 700; }

/* App Layout */
.app-layout {
    display: grid; grid-template-columns: 320px 1fr 280px;
    height: 100vh; gap: 0;
}
.sidebar, .right-sidebar {
    background: var(--bg-card); display: flex; flex-direction: column;
    border-left: 1px solid var(--border);
}
.sidebar-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px; border-bottom: 1px solid var(--border);
}
.user-avatar, .avatar {
    width: 44px; height: 44px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: white; flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; display: inline-block; margin-top: 2px; background: var(--bg-elevated); }
.role-admin { background: rgba(220, 38, 38, 0.2); color: #fca5a5; }
.role-supervisor { background: rgba(124, 58, 237, 0.2); color: #c4b5fd; }
.logout-btn {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-muted); width: 36px; height: 36px;
    border-radius: 8px; cursor: pointer; transition: all 0.2s;
}
.logout-btn:hover { background: var(--danger); color: white; border-color: var(--danger); }

.sidebar-search { padding: 12px; }
.sidebar-search input {
    width: 100%; padding: 8px 12px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: 0.9rem;
}
.sidebar-search input:focus { outline: none; border-color: var(--accent); }

.conversations-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conversation-item {
    display: flex; align-items: center; gap: 12px; padding: 12px;
    border-radius: 8px; cursor: pointer; transition: background 0.15s;
    margin-bottom: 4px;
}
.conversation-item:hover { background: var(--bg-elevated); }
.conversation-item.active { background: var(--bg-elevated); border-right: 3px solid var(--accent); }
.conversation-item .info { flex: 1; min-width: 0; }
.conversation-item .name { font-weight: 700; font-size: 0.9rem; margin-bottom: 2px; }
.conversation-item .preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-item .meta { text-align: left; font-size: 0.75rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.unread { background: var(--accent); color: #000; padding: 2px 8px; border-radius: 10px; font-weight: 700; font-size: 0.7rem; }

.btn-new-chat {
    width: 100%; padding: 10px; background: var(--accent);
    color: #000; border: none; border-radius: 8px; font-weight: 700;
    cursor: pointer; transition: background 0.2s;
}
.btn-new-chat:hover { background: var(--accent-hover); }

/* Right Sidebar */
.right-sidebar-header { padding: 16px; font-weight: 700; border-bottom: 1px solid var(--border); }
.user-list { flex: 1; overflow-y: auto; padding: 8px; }
.user-list-item {
    display: flex; align-items: center; gap: 10px; padding: 8px;
    border-radius: 6px; cursor: pointer; transition: background 0.15s;
}
.user-list-item:hover { background: var(--bg-elevated); }
.user-list-item .name { flex: 1; font-size: 0.85rem; min-width: 0; }
.role-badge { width: 24px; text-align: center; font-size: 0.9rem; }

/* Chat Area */
.chat-area { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }
.chat-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px; background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}
.chat-header .name { font-weight: 700; font-size: 1.05rem; }
.chat-header .status { font-size: 0.8rem; color: var(--text-muted); }
.live-indicator {
    display: flex; align-items: center; gap: 6px;
    color: var(--success); font-size: 0.8rem; font-weight: 600;
}
.live-indicator .dot {
    width: 8px; height: 8px; background: var(--success);
    border-radius: 50%; animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.no-chat {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex: 1; color: var(--text-muted); gap: 8px;
}
.no-chat i { font-size: 4rem; opacity: 0.3; }

.messages-area {
    flex: 1; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 8px;
}
.empty-chat {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex: 1; color: var(--text-muted); gap: 8px; text-align: center; padding: 20px;
}
.empty-chat i { font-size: 3.5rem; opacity: 0.4; }

.message {
    max-width: 70%; padding: 10px 14px; border-radius: 12px;
    word-wrap: break-word; position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.message.own { align-self: flex-end; background: var(--accent); color: #000; border-bottom-left-radius: 4px; }
.message.other { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); border-bottom-right-radius: 4px; }
.message .sender { font-size: 0.8rem; font-weight: 700; margin-bottom: 4px; color: var(--accent); }
.message.own .sender { color: rgba(0, 0, 0, 0.7); }
.message .content { line-height: 1.5; }
.message .time { font-size: 0.7rem; opacity: 0.7; margin-top: 4px; text-align: left; }

/* File Attachments */
.message-image { position: relative; }
.message-image img { display: block; }
.view-only-img { -webkit-user-select: none; user-select: none; }
.file-attachment {
    display: flex; align-items: center; gap: 10px; margin-top: 6px;
    padding: 10px; background: rgba(0, 0, 0, 0.2); border-radius: 8px;
}
.message.own .file-attachment { background: rgba(0, 0, 0, 0.15); }
.file-icon { font-size: 1.8rem; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 0.9rem; font-weight: 600; word-break: break-word; }
.file-size { font-size: 0.75rem; opacity: 0.7; margin-top: 2px; }
.btn-save-file {
    background: var(--success); color: white; border: none;
    padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 700;
}

/* File Preview */
.file-preview {
    display: flex; align-items: center; gap: 10px; padding: 10px 20px;
    background: var(--bg-card); border-top: 1px solid var(--border);
}
.file-preview .file-info { flex: 1; font-size: 0.9rem; }
.btn-remove-file {
    background: var(--danger); color: white; border: none;
    width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-weight: 700;
}

/* Message Input */
.message-input {
    display: flex; gap: 8px; padding: 12px 20px;
    background: var(--bg-card); border-top: 1px solid var(--border);
    align-items: flex-end;
}
.attach-btn, .send-btn {
    background: var(--bg-elevated); color: var(--text);
    border: none; width: 40px; height: 40px;
    border-radius: 50%; cursor: pointer; font-size: 1rem;
    transition: all 0.2s; flex-shrink: 0;
}
.send-btn { background: var(--accent); color: #000; }
.attach-btn:hover { background: var(--primary); }
.send-btn:hover { background: var(--accent-hover); }
#messageInput {
    flex: 1; padding: 10px 14px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 20px;
    color: var(--text); font-size: 0.95rem; resize: none;
    max-height: 100px; font-family: inherit;
}
#messageInput:focus { outline: none; border-color: var(--accent); }

/* Lightbox */
.lightbox {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.95);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 85vh; border-radius: 8px; }
.lightbox .close, .lightbox .download {
    position: absolute; background: rgba(255, 255, 255, 0.1);
    color: white; border: none; padding: 10px 16px;
    border-radius: 8px; cursor: pointer; font-weight: 700;
    backdrop-filter: blur(10px);
}
.lightbox .close { top: 20px; right: 20px; font-size: 1.5rem; }
.lightbox .download { bottom: 20px; left: 50%; transform: translateX(-50%); }
.lightbox .download:disabled { opacity: 0.5; cursor: not-allowed; }
.watermark {
    position: absolute; top: 20px; left: 20px;
    background: rgba(220, 38, 38, 0.9); color: white;
    padding: 8px 14px; border-radius: 8px; font-size: 0.85rem; font-weight: 600;
}

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 999; padding: 20px; backdrop-filter: blur(4px);
}
.modal {
    background: var(--bg-card); border-radius: 12px;
    max-width: 500px; width: 100%; max-height: 80vh;
    overflow: hidden; display: flex; flex-direction: column;
    box-shadow: var(--shadow);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { color: var(--accent); }
.modal-header button {
    background: transparent; border: none; color: var(--text);
    font-size: 1.5rem; cursor: pointer; line-height: 1;
}
.modal-body { padding: 20px; overflow-y: auto; }

/* Toast */
.toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 9999;
    display: flex; flex-direction: column; gap: 8px; max-width: 350px;
}
.toast {
    background: var(--bg-card); color: var(--text); padding: 12px 16px;
    border-radius: 8px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 10px; font-size: 0.9rem;
    border-right: 3px solid var(--primary);
    animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { border-right-color: var(--success); }
.toast.error { border-right-color: var(--danger); }
.toast.warning { border-right-color: var(--warning); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================
   MOBILE - position:fixed full-screen panels
   ============================================ */
@media (max-width: 900px) {
    html, body { height: 100%; overflow: hidden; }
    .app-layout {
        display: block !important;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        position: relative;
        overflow: hidden;
    }
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        z-index: 100;
        display: flex !important;
        flex-direction: column;
        background: var(--bg-card);
        border-left: none !important;
    }
    .sidebar.hidden-mobile { display: none !important; }
    .right-sidebar { display: none !important; }
    .chat-area {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 200;
        display: none !important;
        flex-direction: column;
        background: var(--bg);
    }
    .chat-area.active-mobile { display: flex !important; }
    .chat-header {
        flex-shrink: 0;
        padding: 10px 12px !important;
    }
    .chat-header .back-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: var(--accent);
        color: #000;
        border: none;
        width: 40px;
        height: 40px;
        min-width: 40px;
        border-radius: 50%;
        cursor: pointer;
        font-size: 1rem;
        margin-left: 8px;
        flex-shrink: 0;
    }
    .chat-header .name { font-size: 1rem !important; }
    .chat-header .status { font-size: 0.75rem !important; }
    .live-indicator { display: none !important; }
    .messages-area {
        flex: 1 1 auto !important;
        overflow-y: auto;
        min-height: 0;
        padding: 12px !important;
    }
    .message-input {
        flex-shrink: 0;
        padding: 8px 10px !important;
        background: var(--bg-card);
        border-top: 1px solid var(--border);
        display: flex !important;
        gap: 8px;
        align-items: flex-end;
    }
    #messageInput {
        font-size: 16px !important;
        padding: 10px 14px !important;
        flex: 1;
    }
    .conversation-item {
        padding: 14px 12px !important;
        min-height: 64px;
    }
    .user-avatar, .avatar { width: 48px !important; height: 48px !important; font-size: 1rem; }
    .message {
        max-width: 85% !important;
        padding: 10px 14px !important;
        font-size: 0.95rem;
    }
    .attach-btn, .send-btn {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px;
        font-size: 1rem;
    }
    .btn-new-chat { padding: 12px !important; font-size: 0.95rem; }
    .sidebar-header { padding: 12px !important; }
    .sidebar-search { padding: 10px !important; }
    .user-name { font-size: 0.9rem; }
    .conversation-item .name { font-size: 0.9rem; }
    .conversation-item .preview { font-size: 0.8rem; }
    .modal { max-height: 90vh !important; }
    .login-card { padding: 28px 20px !important; }
    .login-card h1 { font-size: 1.6rem !important; }
    .file-preview { flex-shrink: 0; }
    input, textarea, select { font-size: 16px !important; }
}

@media (min-width: 901px) {
    .chat-header .back-btn { display: none !important; }
}

@media (max-width: 380px) {
    .user-avatar, .avatar { width: 42px !important; height: 42px !important; }
    .conversation-item { padding: 12px 10px !important; }
    .sidebar-header { padding: 10px !important; }
    .user-name { font-size: 0.85rem; }
    .conversation-item .name { font-size: 0.85rem; }
}

/* ============================================
   USER MANAGEMENT - Admin features
   ============================================ */
.btn-manage-users {
    width: 100%; padding: 10px; background: var(--bg-elevated);
    color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; font-weight: 600;
    transition: all 0.2s; font-size: 0.9rem;
}
.btn-manage-users:hover { background: var(--primary); border-color: var(--primary); }

.btn-primary {
    background: var(--accent); color: #000; border: none;
    padding: 12px 20px; border-radius: 8px; font-weight: 700;
    cursor: pointer; font-size: 0.95rem; transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
    background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
    padding: 12px 20px; border-radius: 8px; font-weight: 600;
    cursor: pointer; font-size: 0.95rem;
}
.btn-secondary:hover { background: var(--bg); }

.color-picker {
    display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0;
}
.color-dot {
    width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
    border: 3px solid transparent; transition: all 0.2s;
}
.color-dot:hover { transform: scale(1.1); }
.color-dot.selected {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--bg-card);
}

.manage-user-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 8px;
    background: var(--bg); margin-bottom: 6px;
    border: 1px solid var(--border);
    transition: background 0.2s;
}
.manage-user-item:hover { background: var(--bg-elevated); }
.manage-user-item .name { font-weight: 700; font-size: 0.95rem; }
.manage-user-item .preview { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.btn-icon {
    background: var(--bg-elevated); color: var(--text); border: none;
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    font-size: 1rem; transition: all 0.2s;
}
.btn-icon:hover { background: var(--primary); }
.btn-icon.btn-danger:hover { background: var(--danger); }

select {
    width: 100%; padding: 10px 12px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: 0.95rem; cursor: pointer;
    font-family: inherit;
}
select:focus { outline: none; border-color: var(--accent); }

/* Admin Header Button - Always visible */
.add-user-header-btn {
    background: var(--success);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.add-user-header-btn:hover { background: #059669; transform: scale(1.05); }

/* Big Create User Button */
.btn-create-user {
    width: 100%;
    padding: 12px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s;
    font-size: 0.95rem;
}
.btn-create-user:hover { background: #059669; }
