/* General Styles */
body, html {
    margin: 0;
    padding: 0;
    font-family: 'Cairo', sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
    /* Direction will be set by JS */
}

/* Header and Navigation */
header {
    background-color: #252525;
    padding: 15px 30px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    position: sticky;
    top: 0;
    z-index: 100;
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.logo { 
    font-size: 24px; 
    font-weight: bold; 
    color: #4a90e2; 
    text-decoration: none; /* Prevents underline on link */
    cursor: pointer;
}
.nav-links { list-style: none; display: flex; gap: 25px; margin: 0; padding: 0; }
.nav-links a { color: #e0e0e0; text-decoration: none; font-size: 16px; transition: color 0.3s; cursor: pointer; }
.nav-links a:hover { color: #4a90e2; }

.right-nav { display: flex; align-items: center; gap: 20px; }

/* Language Switcher Styles */
.language-switcher { position: relative; }
.lang-btn { background: none; border: none; cursor: pointer; padding: 5px; display: flex; align-items: center; gap: 8px; color: #e0e0e0; font-family: 'Cairo', sans-serif; }
.lang-btn img { width: 20px; height: 15px; object-fit: cover; border-radius: 3px; }
.current-lang { background-color: #333; border-radius: 5px; padding: 5px 10px; }
.lang-dropdown { display: none; position: absolute; top: 110%; right: 0; background-color: #333; border-radius: 5px; box-shadow: 0 4px 8px rgba(0,0,0,0.3); z-index: 110; overflow: hidden; min-width: 120px; }
html[dir="ltr"] .lang-dropdown { right: auto; left: 0; }
.language-switcher:hover .lang-dropdown { display: block; }
.lang-dropdown .lang-btn { width: 100%; padding: 10px 15px; text-align: right; }
html[dir="ltr"] .lang-dropdown .lang-btn { text-align: left; }
.lang-dropdown .lang-btn:hover { background-color: #4a90e2; }

/* Auth Section */
.auth-section { position: relative; }
#user-profile { display: flex; align-items: center; cursor: pointer; }
#user-pic { width: 40px; height: 40px; border-radius: 50%; margin-left: 10px; border: 2px solid #444; }
html[dir="ltr"] #user-pic { margin-left: 0; margin-right: 10px; }
#user-name { font-weight: bold; }
.dropdown-content { display: none; position: absolute; background-color: #333; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; border-radius: 5px; right: 0; margin-top: 5px; }
html[dir="ltr"] .dropdown-content { right: auto; left: 0; }
.dropdown-content a { color: #e0e0e0; padding: 12px 16px; text-decoration: none; display: block; text-align: right; }
html[dir="ltr"] .dropdown-content a { text-align: left; }
.dropdown-content a:hover { background-color: #4a90e2; }
#user-profile:hover .dropdown-content { display: block; }

/* Main Content & Page Switching */
main { padding: 20px; }
#translator-page, #history-page {
    width: 90%;
    max-width: 1200px;
    margin: 20px auto;
}

.translation-mode-selector { display: flex; justify-content: center; margin-bottom: 30px; background-color: #252525; border-radius: 8px; padding: 5px; width: fit-content; margin-left: auto; margin-right: auto; }
.translation-mode-selector button { background: none; border: none; color: #aaa; padding: 10px 20px; font-size: 16px; font-family: 'Cairo', sans-serif; cursor: pointer; border-radius: 6px; transition: background-color 0.3s, color 0.3s; }
.translation-mode-selector button.active { background-color: #4a90e2; color: white; }

.main-content { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.translator-box { flex: 1; background-color: #252525; border-radius: 8px; padding: 15px; display: flex; flex-direction: column; min-height: 250px; }
.box-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.box-header select { width: 100%; padding: 10px; background-color: #333; color: #e0e0e0; border: 1px solid #444; border-radius: 5px; font-family: 'Cairo', sans-serif; flex-grow: 1; }

.text-area-container { position: relative; flex-grow: 1; display: flex; flex-direction: column; }
textarea, .output-box { width: 100%; box-sizing: border-box; flex-grow: 1; min-height: 150px; padding: 10px; padding-bottom: 40px; background-color: #1a1a1a; border: 1px solid #444; border-radius: 5px; color: #e0e0e0; font-size: 16px; resize: none; }
.output-box { white-space: pre-wrap; overflow-y: auto; word-wrap: break-word; }

.control-button { background: none; border: none; color: #aaa; cursor: pointer; padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: color 0.3s, background-color 0.3s; }
.control-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.control-button:hover { color: #e0e0e0; background-color: #3a3a3a; }
#source-tts-btn { position: absolute; bottom: 10px; left: 10px; }
html[dir="rtl"] #source-tts-btn { left: auto; right: 10px; }
.output-controls { position: absolute; bottom: 10px; left: 10px; display: flex; gap: 5px; }
html[dir="rtl"] .output-controls { left: auto; right: 10px; }

#swap-languages { background: none; border: 1px solid #444; color: #e0e0e0; border-radius: 50%; width: 40px; height: 40px; cursor: pointer; display: flex; align-items: center; justify-content: center; align-self: center; transition: background-color 0.3s, transform 0.3s; flex-shrink: 0; }
#swap-languages:hover { background-color: #333; transform: rotate(180deg); }
#swap-languages svg { stroke: #aaa; transition: stroke 0.3s; }
#swap-languages:hover svg { stroke: #e0e0e0; }

#translate-btn { display: block; width: 200px; padding: 15px; background-color: #4a90e2; color: white; border: none; border-radius: 8px; font-size: 18px; font-family: 'Cairo', sans-serif; cursor: pointer; margin: 20px auto 0; transition: background-color 0.3s; }
#translate-btn:hover { background-color: #357abd; }
#translate-btn:disabled { background-color: #555; cursor: not-allowed; }

/* History Page Styles */
#history-page { background-color: #252525; border-radius: 8px; padding: 20px; }
#history-page h2 { color: #e0e0e0; margin-top: 0; margin-bottom: 20px; text-align: center; border-bottom: 1px solid #444; padding-bottom: 10px; }
#back-to-translator-btn { display: block; width: fit-content; margin: 0 auto 20px auto; padding: 10px 20px; background-color: #333; color: #e0e0e0; border: 1px solid #555; border-radius: 6px; cursor: pointer; transition: background-color 0.3s; }
#back-to-translator-btn:hover { background-color: #4a90e2; }
.history-items { max-height: 60vh; overflow-y: auto; padding-left: 15px; }
html[dir="rtl"] .history-items { padding-left: 0; padding-right: 15px; }
.history-item { background-color: #2d2d2d; padding: 15px; border-radius: 6px; margin-bottom: 10px; border-right: 4px solid #4a90e2; transition: background-color 0.3s; }
html[dir="ltr"] .history-item { border-right: none; border-left: 4px solid #4a90e2; }
.history-item:hover { background-color: #3a3a3a; }
.history-item p { margin: 0 0 10px 0; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.history-item .source-text { font-weight: bold; color: #e0e0e0; }
.history-item .translated-text { color: #b0b0b0; }
.history-item .meta { font-size: 12px; color: #888; text-align: left; }
html[dir="rtl"] .history-item .meta { text-align: right; }
.no-history { color: #888; text-align: center; padding: 20px; }

/* Edit Name Modal Styles */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-content { background-color: #2d2d2d; padding: 25px; border-radius: 8px; width: 90%; max-width: 400px; box-shadow: 0 5px 15px rgba(0,0,0,0.5); text-align: center; }
.modal-content h3 { margin-top: 0; }
.modal-content input { width: calc(100% - 20px); padding: 10px; margin-top: 10px; margin-bottom: 20px; border: 1px solid #555; background-color: #252525; color: #e0e0e0; border-radius: 5px; }
.modal-buttons button { padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; font-family: 'Cairo', sans-serif; font-size: 16px; margin: 0 5px; }
#save-name-btn { background-color: #4a90e2; color: white; }
#save-name-btn:hover { background-color: #357abd; }
#cancel-name-btn { background-color: #555; color: #e0e0e0; }
#cancel-name-btn:hover { background-color: #666; }

/* Scrollbar styles */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #2d2d2d; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #666; }

/* Utility */
.hidden { display: none !important; }

/* Responsive Design */
@media (max-width: 768px) {
    nav { flex-direction: column; gap: 15px; }
    .right-nav { width: 100%; justify-content: space-between; }
    .nav-links { justify-content: center; flex-wrap: wrap; }
    .main-content { flex-direction: column; align-items: center; }
    .translator-box { width: 100%; }
    #swap-languages { transform: rotate(90deg); margin: 10px 0; }
    #swap-languages:hover { transform: rotate(270deg); }
}