:root {
    --primary-color: #4285f4;
    --primary-hover: #3367d6;
    --bg-color: #f9f9f9;
    --card-bg: #ffffff;
    --text-color: #333333;
    --border-color: #e0e0e0;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --loader-color: var(--primary-color);
    --transition-speed: 0.3s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Heebo', 'Noto Sans Hebrew', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* Support for RTL and LTR languages */
[dir="rtl"] {
    text-align: right;
    font-family: 'Noto Sans Hebrew', 'Heebo', Arial, sans-serif;
}

[dir="ltr"] {
    text-align: left;
    font-family: 'Heebo', 'Noto Sans Hebrew', Arial, sans-serif;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: 70px; /* Add padding to account for fixed footer */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Search Header Styles */
.search-header {
    padding: 40px 0 20px;
    width: 100%;
    position: sticky;
    top: 0;
    background-color: var(--bg-color);
    z-index: 100;
    transition: all var(--transition-speed) ease;
    box-shadow: 0 2px 8px var(--shadow-color);
}

.search-header.sticky {
    box-shadow: 0 4px 12px var(--shadow-color);
    padding: 12px 0;
    background-color: var(--card-bg);
}

.search-container {
    display: flex;
    justify-content: center;
    width: 100%;
}

.search-box {
    width: 100%;
    max-width: 800px;
    display: flex;
    background-color: var(--card-bg);
    border-radius: 50px;
    padding: 8px 20px;
    box-shadow: 0 2px 10px var(--shadow-color);
    position: relative;
    transition: all var(--transition-speed) ease;
}

.search-box:focus-within {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

#search-input {
    flex: 1;
    border: none;
    padding: 12px 16px;
    font-size: 18px;
    background: transparent;
    color: var(--text-color);
    font-family: inherit;
    outline: none;
}

/* Style input placeholder for both RTL and LTR */
#search-input::placeholder {
    color: #999;
    opacity: 0.8;
}

/* Auto-detect RTL content and adjust text alignment */
#search-input:placeholder-shown {
    text-align: center;
}


#search-button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0 15px;
    color: var(--primary-color);
    font-size: 20px;
    transition: color var(--transition-speed) ease;
}

#search-button:hover {
    color: var(--primary-hover);
}

/* Main content styles */
main {
    flex: 1;
    margin-top: 20px;
}

.loader-container {
    display: none;
    justify-content: center;
    padding: 30px 0;
}

.loader {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--loader-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.results-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 10px;
}

.no-results {
    text-align: center;
    padding: 40px 0;
    color: #333;
}

.example-queries {
    max-width: 800px;
    margin: 0 auto;
}

.example-queries h2 {
    margin-bottom: 20px;
    font-size: 1.5em;
    color: #555;
}

.example-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 30px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.example-btn {
    display: inline-block;
    background-color: rgba(66, 133, 244, 0.1);
    color: var(--primary-color);
    padding: 12px 20px;
    border-radius: 50px;
    text-decoration: none;
    font-size: 1.1em;
    font-weight: 500;
    transition: all var(--transition-speed) ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(66, 133, 244, 0.2);
    direction: rtl;
    text-align: center;
    margin: 5px;
    min-width: 150px;
}

.example-btn:hover {
    background-color: rgba(66, 133, 244, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Result card styles */
.result-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: transform var(--transition-speed) ease;
}

.result-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px var(--shadow-color);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.result-source {
    font-weight: bold;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.result-book {
    font-size: 1.1em;
    color: var(--primary-color);
}

.result-part {
    font-size: 0.9em;
    color: #666;
}

.result-score {
    background-color: rgba(66, 133, 244, 0.1);
    color: var(--primary-color);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: bold;
}

.result-content {
    line-height: 1.5;
    font-size: 1.4em;
}

.result-content p {
    margin-bottom: 12px;
}

/* RTL text will be right-aligned properly */
.result-content[dir="auto"] p {
    text-align: start;
}

/* Explicitly set RTL content to be right-aligned */
html[dir="rtl"] .result-content p,
.result-content[dir="rtl"] p,
[dir="rtl"] .result-content p {
    text-align: right;
}

/* Sefaria reference styling */
.sefaria-reference {
    text-align: center;
    margin: 20px 0;
    font-size: 1em;
    font-weight: bold;
}

.sefaria-reference a {
    color: var(--primary-color);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    background-color: rgba(66, 133, 244, 0.1);
    transition: all var(--transition-speed) ease;
}

.sefaria-reference a:hover {
    background-color: rgba(66, 133, 244, 0.2);
    box-shadow: 0 2px 6px var(--shadow-color);
}

/* Content may be in RTL or LTR depending on the text */
.result-content[lang="he"] p,
.result-content p[lang="he"] {
    font-family: 'Noto Sans Hebrew', 'Heebo', Arial, sans-serif;
    direction: rtl;
}

.result-content[lang="en"] p,
.result-content p[lang="en"] {
    font-family: 'Heebo', 'Noto Sans Hebrew', Arial, sans-serif;
    direction: ltr;
}

/* Footer styles */
.main-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 12px 0;
    background-color: var(--card-bg);
    color: #777;
    font-size: 0.9em;
    box-shadow: 0 -2px 10px var(--shadow-color);
    z-index: 100;
}

.main-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: bold;
    transition: color var(--transition-speed) ease;
}

.main-footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Responsive styles */
@media (max-width: 768px) {
    .search-box {
        max-width: 95%;
    }

    #search-input {
        font-size: 16px;
        padding: 10px;
    }

    .result-card {
        padding: 15px;
    }

    .result-content {
        font-size: 1.2em;
    }

    .result-book {
        font-size: 1em;
    }

    .result-part {
        font-size: 0.8em;
    }

    .example-btn {
        font-size: 1em;
        padding: 10px 15px;
    }

    .sefaria-reference {
        font-size: 1.1em;
    }
}

@media (max-width: 480px) {
    .search-box {
        padding: 5px 15px;
    }

    #search-input {
        font-size: 14px;
    }

    .result-header {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        flex-wrap: wrap;
    }

    .result-score {
        font-size: 0.75em;
        padding: 3px 6px;
        margin-left: auto;
    }

    .result-content {
        font-size: 1.1em;
        line-height: 1.4;
    }

    .example-btn {
        font-size: 0.9em;
        padding: 8px 12px;
        min-width: 120px;
    }

    .result-book {
        font-size: 0.9em;
    }

    .result-part {
        font-size: 0.75em;
    }

    .sefaria-reference {
        font-size: 1em;
        margin: 15px 0;
    }

    .result-content p {
        margin-bottom: 8px;
    }
}