/* 
 * Reader Mode Styles for Amjad Smart Hub
 */
@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400;1,700&display=swap');

.reader-mode {
    max-width: 100%;
    background: #eef1f5;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    font-family: 'Amiri', serif;
    position: relative;
    overflow-x: hidden;
}

.reader-mode.flipbook-mode {
    background: #dcdcdc;
    background-image: radial-gradient(#c1c1c1 1px, transparent 1px);
    background-size: 20px 20px;
}

.reader-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 40px;
    background: #ffffff;
    border-bottom: 1px solid #d1d5db;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.reader-progress-container {
    width: 100%;
    height: 4px;
    background: transparent;
    position: fixed;
    top: 55px;
    left: 0;
    z-index: 1001;
}

.reader-progress-bar {
    height: 4px;
    background: #3498db;
    width: 0%;
    transition: width 0.1s;
}

.reader-nav {
    display: flex;
    align-items: center;
    gap: 25px;
}

.back-btn {
    text-decoration: none;
    color: #555;
    font-weight: 600;
    font-size: 14px;
    transition: color 0.2s;
}

.back-btn:hover {
    color: #3498db;
}

.book-title {
    font-size: 20px;
    margin: 0;
    color: #1a1a1a;
    font-weight: 700;
}

.reader-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f3f4f6;
    padding: 4px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
}

.font-size-badge {
    font-size: 13px;
    font-weight: 700;
    color: #4b5563;
    min-width: 45px;
    text-align: center;
}

.control-btn {
    background: #ffffff;
    border: 1px solid #d1d5db;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #374151;
}

.control-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.dark-mode .control-group {
    background: #333;
    border-color: #444;
}

.dark-mode .control-btn {
    background: #222;
    border-color: #444;
    color: #eee;
}

.dark-mode .font-size-badge {
    color: #ccc;
}

.reader-main {
    padding: 60px 20px;
    display: flex;
    justify-content: center;
    position: relative;
}

.book-page {
    background: #ffffff;
    width: 100%;
    max-width: 900px;
    padding: 80px 100px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.1);
    border-radius: 8px;
    min-height: 85vh;
    position: relative;
    border: 1px solid #e5e7eb;
}

.book-page::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 40px;
    width: 1px;
    background: rgba(0,0,0,0.05);
    box-shadow: 2px 0 5px rgba(0,0,0,0.02);
}

.reader-content {
    font-size: 22px;
    color: #2c3e50;
    line-height: 2.2;
    text-align: justify;
    direction: rtl;
}

.reader-content p {
    margin-bottom: 25px;
}

.reader-content h2, .reader-content h3 {
    color: #1a1a1a;
    margin-top: 40px;
    margin-bottom: 20px;
    font-weight: 700;
}

@media print {
    .reader-header, .floating-tools, .reader-progress-container, .back-btn, .reader-controls {
        display: none !important;
    }
    .reader-main {
        padding: 0;
    }
    .book-page {
        box-shadow: none;
        padding: 0;
        width: 100%;
        max-width: 100%;
    }
    body {
        background: #fff !important;
    }
}

.floating-tools {
    position: fixed;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 10001;
    background: #3c4043;
    padding: 20px 12px;
    border-radius: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
}

.reader-ai-tool-btn {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background: #ffffff;
    color: #2c3e50;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.reader-ai-tool-btn[data-tool="chat"] { background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%); color: #fff; }
.reader-ai-tool-btn[data-tool="translate"] { background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); color: #fff; }
.reader-ai-tool-btn[data-tool="audio"] { background: linear-gradient(135deg, #ff9966 0%, #ff5e62 100%); color: #fff; }
.reader-ai-tool-btn[data-tool="scholar"] { background: linear-gradient(135deg, #6a11cb 0%, #a445b2 100%); color: #fff; }
.reader-ai-tool-btn[data-tool="deepseek"] { background: linear-gradient(135deg, #2193b0 0%, #6dd5ed 100%); color: #fff; }
.reader-ai-tool-btn[data-tool="summarize"] { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: #fff; }

.reader-ai-tool-btn:hover {
    transform: scale(1.15) rotate(5deg);
    filter: brightness(1.1);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

/* Selection Toolbar */
.selection-toolbar {
    position: absolute;
    display: none;
    background: #2c3e50;
    padding: 8px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 10000;
    gap: 8px;
    animation: toolbarPop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.selection-tool-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.selection-tool-btn:hover {
    background: #3498db;
    transform: translateY(-2px);
}

/* Modal Styles */
.amjad-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #fff;
    margin: 8% auto;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    position: relative;
    box-shadow: 0 25px 60px rgba(0,0,0,0.4);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.close-modal {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    transition: color 0.3s;
}

.close-modal:hover {
    color: #e74c3c;
}

.modal-content h2 {
    margin-top: 0;
    font-size: 24px;
    color: #2c3e50;
    margin-bottom: 20px;
}

.modal-content textarea,
.modal-content input,
.modal-content select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 14px;
}

.modal-content textarea {
    min-height: 100px;
    resize: vertical;
}

.action-btn {
    width: 100%;
    background: #3498db;
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
    margin: 10px 0;
    transition: background 0.3s;
}

.action-btn:hover {
    background: #2980b9;
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.result-box {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-right: 4px solid #3498db;
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.6;
}

.error-box {
    background: #fff5f5;
    color: #c62828;
    padding: 15px;
    border-radius: 8px;
    border-right: 4px solid #c62828;
    margin: 10px 0;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #666;
}

.loading:after {
    content: "...";
    animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

.original-text {
    background: #f0f0f0;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 13px;
    max-height: 150px;
    overflow-y: auto;
}

/* Chat Styles */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 450px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 15px;
}

.chat-msg {
    margin-bottom: 12px;
    padding: 10px 15px;
    border-radius: 12px;
    line-height: 1.5;
    max-width: 90%;
}

.chat-msg.user {
    background: #3498db;
    color: white;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-msg.ai {
    background: #eef2f3;
    color: #333;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.chat-msg.system {
    background: #fff9c4;
    text-align: center;
    font-size: 0.9em;
    margin: 10px auto;
}

.chat-msg.error {
    background: #ffebee;
    color: #c62828;
    text-align: center;
}

.chat-controls {
    display: flex;
    gap: 10px;
}

.chat-controls input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.chat-send-btn-inline {
    width: auto !important;
    padding: 0 20px !important;
    margin: 0 !important;
}

.tool-textarea {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    min-height: 80px;
}

/* Dark Mode */
.dark-mode {
    background: #1a1a1a !important;
    color: #eee !important;
}

.dark-mode .reader-header {
    background: #222;
    border-color: #333;
}

.dark-mode .book-title, .dark-mode .back-btn {
    color: #eee;
}

.dark-mode .reader-content {
    color: #ccc;
}

.dark-mode .reader-content h2, .dark-mode .reader-content h3 {
    color: #fff;
}

.dark-mode .modal-content {
    background: #2c2c2c;
    color: #eee;
}

.dark-mode .result-box {
    background: #3a3a3a;
}

.dark-mode .chat-history {
    background: #2c2c2c;
}

/* ==========================================================================
   FlipBook Specific Styles
   ========================================================================== */
.flipbook-mode .reader-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 70px);
    background: #dcdcdc;
    padding: 40px 20px;
    overflow-y: auto;
    background-image: radial-gradient(#c0c0c0 1px, transparent 1px);
    background-size: 20px 20px;
}

.flipbook-container {
    width: 1000px;
    height: calc(100vh - 160px);
    margin: 0 auto;
    position: relative;
    box-shadow: 0 30px 60px rgba(0,0,0,0.4);
    border-radius: 4px;
    background: #fff;
}

#flipbook {
    width: 100%;
    height: 100%;
}

.page {
    background-color: #fdf8e7; /* Paper color */
    box-shadow: inset 0 0 50px rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.1);
}

/* Spine effect */
.page-content::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 5;
}

/* Left page spine shadow */
.page:nth-child(even) .page-content::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0) 100%);
}

/* Right page spine shadow */
.page:nth-child(odd) .page-content::after {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0) 100%);
}

.page-content {
    padding: 50px 60px;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-y: auto;
    font-family: 'Amiri', serif;
    line-height: 2;
    color: #2c3e50;
    font-size: 20px;
    text-align: justify;
    direction: rtl;
}

.page-number {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    color: #999;
    font-family: 'Amiri', serif;
    font-weight: bold;
}

/* Cover Styles */
.page.cover {
    background: #2c3e50 !important;
    color: #fff !important;
    box-shadow: inset -10px 0 20px rgba(0,0,0,0.5);
}

.page.cover .page-content {
    color: #fff;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

.book-cover-inner {
    border: 4px double rgba(255,255,255,0.3);
    padding: 40px 20px;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.cover-title {
    font-size: 42px;
    margin-bottom: 30px;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.cover-decoration {
    width: 100px;
    height: 2px;
    background: #3498db;
    margin-bottom: 30px;
}

.cover-author {
    font-size: 24px;
    font-style: italic;
    opacity: 0.9;
}

/* Back Cover */
.page.cover-back {
    background: #34495e !important;
    color: #fff !important;
}

.back-cover-inner h2 {
    color: #fff !important;
    font-size: 36px;
}

.back-cover-inner .divider {
    width: 60px;
    height: 3px;
    background: #3498db;
    margin: 20px auto;
}

.end-page {
    justify-content: center;
    align-items: center;
    text-align: center;
    background: #f5f5f5 !important;
}

.end-page h2 {
    margin-bottom: 20px;
    color: #2c3e50;
    font-size: 32px;
}

.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-screen::after {
    content: 'جاري تحضير الكتاب...';
    margin-top: 20px;
    font-family: 'Amiri', serif;
    font-size: 18px;
    color: #3498db;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #f3f3f3;
    border-top: 6px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#voice-visualizer {
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.03);
    transition: all 0.3s ease;
    border: 1px solid rgba(226, 232, 240, 0.5);
}

.voice-chat-container {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.voice-chat-container:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.voice-record-btn:active {
    transform: scale(0.9);
}

.voice-record-btn:hover {
    filter: brightness(1.1);
}

.voice-manual-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    width: 100%;
}

.voice-manual-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.3);
    filter: brightness(1.05);
}

.voice-manual-btn:active {
    transform: translateY(0);
}

@keyframes voice-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Dark Mode for FlipBook */
.dark-mode .flipbook-mode .reader-layout {
    background: #121212;
    background-image: radial-gradient(#222 1px, transparent 1px);
}

.dark-mode .page {
    background-color: #242424;
    color: #e0e0e0;
    border-color: #333;
}

.dark-mode .page-content {
    color: #e0e0e0;
}

.dark-mode .page-number {
    color: #555;
}

.dark-mode .loading-screen {
    background: #1a1a1a;
}

.dark-mode .page:nth-child(even) .page-content::after {
    background: linear-gradient(to left, rgba(0,0,0,0.4) 0%, rgba(0,0,0,0) 100%);
}

.dark-mode .page:nth-child(odd) .page-content::after {
    background: linear-gradient(to right, rgba(0,0,0,0.4) 0%, rgba(0,0,0,0) 100%);
}

/* Selection Toolbar Adjustments */
.selection-toolbar {
    z-index: 10000; /* Ensure it's above the flipbook */
}

/* Floating Tools Adjustments */
.floating-tools {
    z-index: 10001;
}

/* Autoplay Warning */
.autoplay-warning {
    animation: fadeIn 0.3s ease;
}

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

.autoplay-warning-box {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: 15px;
    margin: 10px 0;
    text-align: center;
}

.autoplay-warning-text {
    margin: 0 0 10px 0;
    color: #856404;
}

.manual-play-btn {
    background: #ffc107;
    color: #856404;
    border: none;
    padding: 8px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

/* Tool UI Helpers */
.tool-ui-box label {
    display: block;
    margin-bottom: 8px;
}

.tool-field-group {
    margin-bottom: 15px;
}

.tool-field-label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}

.tool-select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.tool-help-text {
    font-size: 12px;
    color: #666;
    margin-top: 8px;
}

.audio-player {
    width: 100%;
    margin-top: 15px;
    border-radius: 30px;
}

.download-btn {
    margin-top: 10px;
    background: #27ae60 !important;
}

/* Audio Controls */
audio {
    border-radius: 30px;
    background: #f0f0f0;
}

audio::-webkit-media-controls-panel {
    background: #f0f0f0;
}

/* Dark Mode Audio */
.dark-mode audio {
    background: #3a3a3a;
}

.dark-mode audio::-webkit-media-controls-panel {
    background: #3a3a3a;
}

.dark-mode .autoplay-warning-box {
    background: #2c2c2c !important;
    border-color: #ffc107 !important;
}

.dark-mode .autoplay-warning-text {
    color: #ffc107 !important;
}
