:root {
    --primary-color: #007bff;
    --primary-dark: #0056b3;
    --secondary-color: #6c757d;
    --danger-color: #dc3545;
    --danger-dark: #a71d2a;
    --success-color: #28a745;
    --light-gray: #f8f9fa;
    --medium-gray: #e9ecef;
    --dark-gray: #495057;
    --white: #ffffff;
    --text-color: #212529;
    --border-radius: 12px;
    --box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-color);
}

a {
    color: var(--text-color);
}

.exelearning body {
    background: #efeff1;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    text-align: center;
    margin-bottom: 30px;
    color: var(--white);
    position: relative;
}

.header h1 {
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin: 0;
}

.language-selector {
    display: none; /* Hidden by default, shown by JS if not in eXe */
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.lang-btn {
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s;
    font-weight: 600;
}

.lang-btn:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.lang-btn.active {
    background-color: white;
    color: var(--primary-dark);
    border-color: var(--primary-dark);
}

.tabs-section {
    position: relative;
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin-bottom: 20px;
    overflow: hidden;
}

.search-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 20px 10px 20px;
    border-bottom: 1px solid var(--medium-gray);
}

.search-input-container {
    position: relative;
    flex-grow: 1;
}

#search-input {
    width: 100%;
    padding: 12px 40px 12px 12px;
    border-radius: 8px;
    border: 2px solid var(--medium-gray);
    font-size: 1rem;
    transition: all 0.3s ease;
}

#search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

#clear-search-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    font-size: 1.8rem;
    color: var(--secondary-color);
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
    display: none;
}

#clear-search-btn:hover {
    color: var(--dark-gray);
}

#settings-btn, #maximize-btn, #menu-toggler-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--dark-gray);
    transition: transform 0.3s, color 0.3s;
    padding: 0 5px;
    flex-shrink: 0;
}

#maximize-btn {
    margin-top: -3px;
}

#settings-btn:hover, #maximize-btn:hover {
    color: var(--primary-color);
    transform: rotate(45deg);
}

#menu-toggler-btn {
    transform: scale(.9);
}

#menu-toggler-btn:hover {
    color: var(--primary-color);
    transform: scale(1);
}

#maximize-btn:hover {
     transform: scale(1.1);
}

.search-results-view .tabs-container {
    display: none;
}

.search-results-view .tab-content {
    display: grid !important;
}

.tabs-container {
    display: flex;
    flex-wrap: wrap;
    background: var(--light-gray);
    border-bottom: 3px solid var(--medium-gray);
}

.tab-btn {
    padding: 15px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: var(--dark-gray);
    transition: all 0.3s ease;
    position: relative;
    border-bottom: 3px solid transparent;
}

.tab-btn:hover {
    background: var(--medium-gray);
    color: var(--text-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

#toolbar-wrapper {
    padding: 20px;
    background: var(--white);
}

.tab-content {
    display: none;
    gap: 10px;
}

.tab-content.active {
    display: grid;
}

.toolbar-btn {
    background: var(--white);
    border: 2px solid var(--medium-gray);
    border-radius: 8px;
    padding: 15px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    font-size: 0.85rem;
}

.toolbar-btn:hover {
    border-color: var(--primary-color);
    background: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.2);
}

.toolbar-btn svg {
    max-width: 100%;
    height: auto;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.panel {
    background: var(--white);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    display: flex;
    flex-direction: column;
}

.panel-title-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 0 15px 0;
    border-bottom: 2px solid var(--medium-gray);
    padding-bottom: 10px;
}

.panel-title-container h2 {
    margin: 0;
    padding: 0;
    border: none;
    color: #333;
    font-size: 1.3rem;
}

#ask-ai-btn {
    padding: 6px 12px;
    background: linear-gradient(45deg, #6c757d, #343a40);
    color: white;
    font-size: 0.9em;
}

#latex-input {
    width: 100%;
    height: 200px;
    border: 2px solid var(--medium-gray);
    border-radius: 8px;
    padding: 15px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: vertical;
    transition: all 0.3s ease;
    flex-grow: 1;
}

#latex-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.preview-container {
    min-height: 200px;
    border: 2px dashed var(--medium-gray);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--light-gray);
    flex-grow: 1;
}

#preview {
    font-size: 24px;
    color: var(--text-color);
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    text-align: center;
}

.copy-options-container {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.copy-options-container label {
    font-size: 0.9rem;
    color: var(--dark-gray);
    font-weight: 500;
}

#delimiter-selector {
    font-family: inherit;
    padding: 5px 8px;
    border-radius: 8px;
    border: 2px solid var(--medium-gray);
    background-color: white;
    transition: border-color 0.2s ease-in-out;
}

#delimiter-selector:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.panel-actions {
    margin-top: 15px;
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
}

.btn-primary {
    background: linear-gradient(45deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.btn-secondary {
    background: linear-gradient(45deg, var(--secondary-color), #495057);
    color: white;
}

.btn-danger {
    background: linear-gradient(45deg, var(--danger-color), var(--danger-dark));
    color: white;
}

.btn-success {
    background: linear-gradient(45deg, var(--success-color), #1e7e34);
    color: white;
}

.btn:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}

.copy-feedback {
    color: var(--primary-color);
    font-weight: 600;
    margin-top: 10px;
    height: 20px;
    opacity: 0;
    transition: opacity 0.5s ease;
    text-align: center;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--white);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    max-width: 90vw;
    max-height: 90vh;
    text-align: left;
    transform: scale(0.9);
    transition: transform 0.3s;
    width: 600px;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-content h2,
.modal-content h3 {
    text-align: center;
    margin-top: 0;
    color: var(--text-color);
}

.modal-content h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    border-top: 1px solid var(--medium-gray);
    padding-top: 20px;
    font-size: 1.1rem;
}

#modal-message {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    line-height: 1.5;
    text-align: center;
}

#modal-message img {
    display: block;
    margin: 0 auto;
}

#alert-modal-message p {
    margin: 0 0 10px 0;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 25px;
}

.modal-content .form-group {
    margin-bottom: 20px;
}

.modal-content .form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}

.modal-content .form-group input,
.modal-content .form-group textarea {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid var(--medium-gray);
    font-size: 1rem;
}

#ai-modal .form-group textarea {
    resize: vertical;
    font-family: 'Segoe UI', sans-serif;
}

#ai-modal .form-group textarea[readonly] {
    background-color: var(--light-gray);
    cursor: text;
}

#modal-feedback {
    font-size: 0.9em;
    height: 20px;
    text-align: center;
}

.modal-body {
    overflow-y: auto;
    padding-right: 15px;
    margin-right: -15px;
}

.menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu-list li {
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.menu-list li:nth-child(odd) {
    background-color: var(--light-gray);
}

.menu-list-item-name {
    font-weight: 500;
    margin-left: 10px;
}

.footer {
    text-align: center;
    padding: 30px 20px;
    color: white;
    opacity: 0.9;
    font-size: 0.9rem;
}

.footer a {
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

#clear-recents-btn-container {
    text-align: right;
    margin-top: 10px;
}

.matrix-builder {
    border: 2px solid var(--medium-gray);
    border-radius: var(--border-radius);
    padding: 10px;
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 15px;
    background-color: var(--light-gray);
}

.matrix-builder-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.matrix-builder-group label {
    font-size: 0.9em;
    font-weight: 500;
    color: var(--dark-gray);
    white-space: nowrap;
}

.matrix-builder-group input,
.matrix-builder-group select {
    padding: 6px;
    border-radius: 8px;
    border: 2px solid var(--medium-gray);
    font-size: 0.9rem;
    width: 65px;
}

.matrix-builder-group select {
    width: auto;
    min-width: 140px;
}

.matrix-builder-delimiters {
    display: flex;
    align-items: center;
    gap: 8px;
}

.matrix-builder-delimiters .btn {
    padding: 6px 14px;
    font-size: 1.1rem;
}

#maximize-btn {
    position: static !important;
    margin-left: 6px;
}

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .header h1 {
        font-size: 2rem;
    }
    .tab-btn {
        padding: 12px 15px;
        font-size: 14px;
    }
    .container {
        padding: 10px;
    }
    .modal-content {
        padding: 20px;
    }
    .matrix-builder {
        justify-content: flex-start;
    }
}