:root {
    --primary-color: #4f6b82;
    --primary-dark: #3e5669;
    --secondary-color: #6f7b84;
    --danger-color: #dc3545;
    --danger-dark: #a71d2a;
    --success-color: #4d7a5f;
    --light-gray: #f7f8f9;
    --medium-gray: #dde2e7;
    --dark-gray: #4f5b66;
    --white: #ffffff;
    --text-color: #1f2933;
    --border-radius: 12px;
    --box-shadow: 0 2px 8px rgba(31, 41, 51, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background: #f5f6f7;
    min-height: 100vh;
    color: var(--text-color);
}

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

.exelearning body {
    background: #efeff1;
}

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

.header {
    margin-bottom: 14px;
    position: relative;
    background: var(--white);
    border: 1px solid var(--medium-gray);
    border-radius: var(--border-radius);
    padding: 12px 16px;
    box-shadow: var(--box-shadow);
}

.header-main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.header-copy {
    min-width: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.45rem;
    margin: 0 0 6px 0;
    text-align: left;
}

.header p {
    font-size: 0.95rem;
    color: var(--dark-gray);
    margin: 0;
    text-align: left;
}

.language-selector {
    display: none; /* Hidden by default, shown by JS if not in eXe */
    align-items: center;
    justify-content: flex-end;
    gap: 0;
    margin-top: 0;
    position: relative;
}

#language-toggle {
    border: 1px solid transparent;
    background: transparent;
    color: var(--dark-gray);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}

#language-toggle:hover,
#language-toggle:focus {
    outline: none;
    background-color: #f1f4f6;
    border-color: #d4dbe2;
    color: var(--text-color);
}

.language-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 20;
    display: none;
    padding: 6px;
    border-radius: 8px;
    border: 1px solid var(--medium-gray);
    background: var(--white);
    box-shadow: 0 2px 8px rgba(31, 41, 51, 0.12);
    min-width: 56px;
    flex-direction: column;
    gap: 4px;
}

.language-dropdown.open {
    display: flex;
}

.language-option {
    border: 1px solid transparent;
    background: transparent;
    color: var(--dark-gray);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: left;
    width: 100%;
}

.language-option:hover {
    background-color: #f1f4f6;
    border-color: #d4dbe2;
    color: var(--text-color);
}

.language-option:focus {
    outline: none;
    border-color: #c4ccd5;
    background-color: #f1f4f6;
}

.language-option.active {
    border-color: #c4ccd5;
    background-color: #edf2f6;
    color: var(--text-color);
}

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

.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;
}

#maximize-btn img {
    width: 24px;
    height: 24px;
    display: block;
}

#settings-btn img {
    width: 24px;
    height: 24px;
    display: block;
}

#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: 13px 18px;
    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: #eef2f5;
    color: var(--text-color);
}

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

#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 1px 2px rgba(31, 41, 51, 0.06);
    overflow: hidden;
    font-size: 0.85rem;
}

.toolbar-btn:hover {
    border-color: var(--primary-color);
    background: #f4f7fa;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(31, 41, 51, 0.1);
}

.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);
    border: 1px solid var(--medium-gray);
    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: #66737d;
    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 1px 3px rgba(31, 41, 51, 0.12);
}

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

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 7px rgba(31, 41, 51, 0.16);
}

.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: var(--dark-gray);
    font-size: 0.9rem;
}

.footer a {
    color: var(--dark-gray);
    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-main {
        flex-direction: column;
        align-items: stretch;
    }
    .header-actions {
        justify-content: flex-end;
    }
    .header h1 {
        font-size: 1.25rem;
    }
    .tab-btn {
        padding: 12px 15px;
        font-size: 14px;
    }
    .container {
        padding: 10px;
    }
    .modal-content {
        padding: 20px;
    }
    .matrix-builder {
        justify-content: flex-start;
    }
}
