* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, sans-serif;
}

body {
    background: #f5f7fa;
    direction: rtl;
}

.app-container {
    max-width: 480px;
    margin: 0 auto;
    background: #fff;
    min-height: 100vh;
    position: relative;
    padding-bottom: 70px;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/* Header */
.app-header {
    background: #4A90D9;
    color: #fff;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}
.header-title {
    font-size: 20px;
    font-weight: bold;
}
.header-user {
    font-size: 14px;
}
.logout-btn, .login-btn {
    color: #fff;
    text-decoration: none;
    background: rgba(255,255,255,0.2);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-around;
    padding: 8px 0 12px;
    max-width: 480px;
    margin: 0 auto;
    z-index: 20;
}
.nav-item {
    text-decoration: none;
    color: #888;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 12px;
    transition: 0.2s;
}
.nav-item.active {
    color: #4A90D9;
}
.nav-icon {
    font-size: 22px;
}
.nav-label {
    margin-top: 2px;
}

/* Cards & Grid */
.books-grid {
    padding: 16px;
}
.book-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.book-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: 0.2s;
    text-align: center;
}
.book-card a {
    text-decoration: none;
    color: #333;
    display: block;
    padding: 12px;
}
.book-card img, .book-cover-placeholder {
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: #eef2f7;
    border-radius: 8px;
}
.book-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 50px;
}
.book-card h4 {
    font-size: 15px;
    margin: 8px 0 4px;
}
.book-card p {
    font-size: 13px;
    color: #777;
}

/* Search */
.search-form {
    display: flex;
    padding: 12px 16px;
    gap: 8px;
    background: #f8f9fa;
}
.search-form input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 24px;
    font-size: 14px;
}
.search-form button {
    padding: 10px 20px;
    background: #4A90D9;
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    cursor: pointer;
}

/* Auth Forms */
.page-auth {
    padding: 40px 20px;
    max-width: 360px;
    margin: 0 auto;
}
.auth-form input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
}
.auth-form button {
    width: 100%;
    padding: 12px;
    background: #4A90D9;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
}
.alert {
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 12px;
}
.alert.error {
    background: #fce4e4;
    color: #c0392b;
}
.alert.success {
    background: #e4fce4;
    color: #27ae60;
}

/* Upload */
.page-upload {
    padding: 20px;
}
.upload-form input, .upload-form textarea {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
}
.upload-form textarea {
    height: 100px;
}
.file-input {
    margin: 12px 0;
}
.file-input input[type="file"] {
    border: none;
    padding: 8px 0;
}

/* Book Detail */
.page-book-detail {
    padding: 20px;
    text-align: center;
}
.book-cover-large img {
    max-width: 200px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.book-cover-placeholder-large {
    font-size: 80px;
}
.btn-read {
    display: inline-block;
    padding: 12px 30px;
    background: #4A90D9;
    color: #fff;
    border-radius: 30px;
    text-decoration: none;
    margin-top: 16px;
}

/* Reader */
.page-reader {
    padding: 16px;
}
.reader-content {
    background: #fafafa;
    padding: 20px;
    border-radius: 12px;
    min-height: 400px;
    margin: 12px 0;
}
.reader-content iframe {
    border: none;
    min-height: 500px;
}
.btn-back {
    display: inline-block;
    margin-top: 12px;
    color: #4A90D9;
    text-decoration: none;
}

/* Admin */
.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 20px;
}
.admin-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    text-decoration: none;
    color: #333;
    border: 1px solid #eee;
}
.admin-card .icon {
    font-size: 40px;
    display: block;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.admin-table th, .admin-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #eee;
    text-align: center;
}
.admin-table th {
    background: #f0f4f8;
}
.btn-small {
    padding: 4px 10px;
    background: #4A90D9;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
.btn-danger {
    background: #e74c3c;
}
.btn-add, .btn-cancel {
    display: inline-block;
    padding: 8px 16px;
    background: #4A90D9;
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    margin: 8px 0;
}

/* Profile */
.page-profile {
    padding: 20px;
    text-align: center;
}
.profile-header .avatar {
    font-size: 60px;
}
.badge-admin {
    background: #f39c12;
    color: #fff;
    padding: 2px 12px;
    border-radius: 20px;
    font-size: 12px;
}
.btn-logout {
    display: inline-block;
    margin-top: 20px;
    padding: 10px 24px;
    background: #e74c3c;
    color: #fff;
    border-radius: 30px;
    text-decoration: none;
}
.profile-books ul {
    list-style: none;
    text-align: right;
    padding: 0;
}
.profile-books li {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
}
.book-status {
    font-size: 12px;
    color: #888;
}

/* Chat Secret */
.page-secret-chat, .page-chat {
    padding: 16px;
}
.chat-users-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 10px;
    text-decoration: none;
    color: #333;
}
.chat-user-item .user-avatar {
    font-size: 28px;
}
.chat-user-item .user-name {
    font-weight: bold;
}
.chat-user-item .user-phone {
    color: #888;
    font-size: 13px;
}

/* Chat Messages */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}
.chat-messages {
    height: 380px;
    overflow-y: auto;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.message {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 15px;
    word-wrap: break-word;
}
.message.sent {
    align-self: flex-end;
    background: #4A90D9;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message.received {
    align-self: flex-start;
    background: #e9ecef;
    color: #333;
    border-bottom-left-radius: 4px;
}
.msg-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}
.chat-input {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid #eee;
}
.chat-input input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 24px;
    font-size: 15px;
}
.chat-input button {
    padding: 10px 20px;
    background: #4A90D9;
    color: #fff;
    border: none;
    border-radius: 24px;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 480px) {
    .book-list {
        grid-template-columns: repeat(2, 1fr);
    }
    .admin-grid {
        grid-template-columns: 1fr;
    }
}







/* ===== صفحة الشات ===== */
.page-chat {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    background: #e5ddd5;
    padding: 0;
    margin: 0;
}

.chat-header {
    background: #075e54;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 5;
}
.chat-header .back-btn {
    color: #fff;
    text-decoration: none;
    font-size: 24px;
    line-height: 1;
}
.chat-partner {
    font-size: 18px;
    font-weight: 500;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #e5ddd5;
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MCIgaGVpZ2h0PSI4MCIgdmlld0JveD0iMCAwIDQwMCA0MDAiPjxwYXRoIGQ9Ik0wIDBoNDAwdjQwMEgweiIgZmlsbD0iI2U1ZGRkNSIvPjwvc3ZnPg==');
    background-size: cover;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 80%;
}
.message-wrapper.sent {
    align-self: flex-end;
    align-items: flex-end;
}
.message-wrapper.received {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble {
    background: #fff;
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
    word-wrap: break-word;
    cursor: pointer;
    transition: 0.2s;
    max-width: 100%;
}
.message-bubble.selected {
    background: #e0f0ff;
    border: 1px solid #4A90D9;
}
.message-wrapper.sent .message-bubble {
    background: #dcf8c6;
    border-top-right-radius: 4px;
}
.message-wrapper.received .message-bubble {
    background: #fff;
    border-top-left-radius: 4px;
}

.reply-quote {
    background: rgba(0,0,0,0.05);
    border-right: 3px solid #4A90D9;
    padding: 4px 8px;
    margin-bottom: 4px;
    border-radius: 4px;
    font-size: 13px;
    color: #555;
}
.reply-quote .reply-name {
    font-weight: bold;
    color: #075e54;
    margin-left: 4px;
}
.reply-quote .reply-text {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.msg-text {
    font-size: 15px;
    line-height: 1.4;
}
.msg-time {
    font-size: 11px;
    color: #888;
    text-align: left;
    margin-top: 4px;
    display: flex;
    justify-content: flex-end;
    gap: 4px;
}
.message-wrapper.sent .msg-time {
    color: #666;
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #f0f0f0;
    gap: 6px;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
}
.chat-input-wrapper .input-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: 0.2s;
}
.chat-input-wrapper .input-btn:hover {
    background: rgba(0,0,0,0.05);
}
.chat-input-wrapper input {
    flex: 1;
    padding: 10px 14px;
    border: none;
    border-radius: 24px;
    font-size: 16px;
    outline: none;
    background: #fff;
}
.chat-input-wrapper button#sendBtn {
    padding: 10px 18px;
    background: #075e54;
    color: #fff;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-size: 16px;
}

#replyBar {
    background: #e8f0fe;
    padding: 6px 12px;
    border-top: 1px solid #ccc;
    font-size: 14px;
    display: none;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
#replyBar span:first-child {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
#replyBar button {
    background: none;
    border: none;
    color: #d32f2f;
    font-size: 20px;
    cursor: pointer;
}

/* ===== تحسينات للإيموجي ===== */
#emojiPicker {
    background: #fff;
    border-top: 1px solid #ddd;
    padding: 8px;
    max-height: 150px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.emoji-item {
    cursor: pointer;
    font-size: 24px;
    padding: 2px;
    transition: transform 0.1s;
}
.emoji-item:hover {
    transform: scale(1.3);
}

/* ===== صور الشات ===== */
.chat-image {
    max-width: 200px;
    border-radius: 8px;
    cursor: pointer;
}

/* ===== تنسيق الصوت ===== */
.chat-messages audio {
    width: 200px;
    max-width: 100%;
}