/* === RESET & BASE === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #1a56db;
    --primary-dark: #1041a3;
    --primary-light: #e1effe;

    --bg: #f0f4f8;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);

    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    font-family: var(--font);
    line-height: 1.6;
    background-color: var(--bg);
    color: var(--text);
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px 60px;
    -webkit-font-smoothing: antialiased;
}

/* === HEADER === */
.app-header {
    text-align: center;
    padding: 40px 0 32px;
}

.app-header .logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    border-radius: 16px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(26, 86, 219, 0.3);
}

.app-header .logo-icon i {
    font-size: 24px;
    color: #fff;
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.02em;
}

.app-header .subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* === FLASH MESSAGES === */
ul.flashes {
    list-style: none;
    margin-bottom: 16px;
}

ul.flashes li {
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

ul.flashes li.error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

ul.flashes li.warning {
    background-color: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

ul.flashes li.info {
    background-color: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid #bfdbfe;
}

ul.flashes li.success {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.init-error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 14px 18px;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
}

/* === SEARCH CARD === */
.search-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 24px;
    margin-bottom: 32px;
}

/* === FORM === */
.search-row {
    display: flex;
    gap: 12px;
    align-items: stretch;
    margin-bottom: 16px;
}

.search-row .input-wrapper {
    flex: 1;
}

.search-row button[type="submit"] {
    white-space: nowrap;
    min-width: auto;
}

.input-wrapper {
    position: relative;
    display: block;
    width: 100%;
}

#query {
    width: 100%;
    padding: 14px 44px 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    line-height: 1.5;
}

#query::placeholder {
    color: var(--text-light);
}

#query:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.12);
    background: #fff;
}

#query:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.clear-input-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--text-light);
    display: none;
    font-size: 0.95rem;
    line-height: 1;
    padding: 4px;
    border-radius: 50%;
    transition: color var(--transition), background var(--transition);
}

.clear-input-btn:hover {
    color: var(--text);
    background: rgba(0,0,0,0.05);
}

/* === FILTER PILLS === */
.filter-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 16px 0;
}

.filter-radio {
    cursor: pointer;
}

.filter-radio input[type="radio"] {
    display: none;
}

.filter-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 2px solid var(--border);
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all var(--transition);
    color: var(--text-muted);
    background: var(--bg);
    user-select: none;
}

.filter-label i {
    font-size: 0.8rem;
}

.filter-radio input[type="radio"]:checked + .filter-label {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(26, 86, 219, 0.25);
}

.filter-label:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-radio input[type="radio"]:checked + .filter-label:hover {
    color: #fff;
}

/* === SEARCH BUTTON === */
button[type="submit"] {
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white;
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font);
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(26, 86, 219, 0.25);
    min-width: 160px;
}

button[type="submit"]:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26, 86, 219, 0.35);
    filter: brightness(1.05);
}

button[type="submit"]:active {
    transform: translateY(0);
}

button[type="submit"]:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
    opacity: 0.65;
    filter: none;
}

.btn-icon {
    font-size: 0.9rem;
    color: white;
}

.button-info {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-light);
}

/* === RESULTS SECTION === */
.results-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.results-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.results-header h2 span {
    color: var(--primary);
}

.execution-time {
    font-size: 0.8rem;
    color: var(--text-light);
    font-style: normal;
    font-weight: 500;
}

.results-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* === RESULT CARDS === */
.results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-item {
    background: var(--bg-card);
    padding: 18px 20px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition), transform var(--transition);
}

.result-item:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.result-item h4 {
    margin: 0 0 10px 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.result-item .text {
    margin: 0;
    line-height: 1.7;
    font-size: 0.93rem;
    color: #334155;
}

.text-clamp {
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-clamp.text-expanded {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
}

.expand-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    padding: 6px 0 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color var(--transition);
}

.expand-btn:hover {
    color: var(--primary-dark);
}

.expand-btn i {
    font-size: 0.7rem;
}

.score-display {
    font-size: 0.75rem;
    color: var(--text-light);
    font-weight: 500;
    margin-left: auto;
}

/* === TYPE BADGES === */
.type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: 100px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.type-verse {
    background-color: #eff6ff;
    color: #1d4ed8;
}

.type-commentary {
    background-color: #fff7ed;
    color: #c2410c;
}

/* === MARK / HIGHLIGHT === */
mark {
    background: linear-gradient(120deg, rgba(254, 240, 138, 0.5) 0%, rgba(253, 224, 71, 0.45) 100%);
    padding: 1px 4px;
    border-radius: 3px;
    color: inherit;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

mark.stem {
    background: linear-gradient(120deg, rgba(254, 249, 195, 0.35) 0%, rgba(254, 240, 138, 0.3) 100%);
    filter: blur(0.3px);
    padding: 1px 4px;
}

/* === LOADING OVERLAY === */
#loading {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(240, 244, 248, 0.85);
    backdrop-filter: blur(4px);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loader {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading p {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* === EMPTY STATE === */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    color: var(--text-light);
    margin-bottom: 12px;
    display: block;
}

.empty-state p {
    font-size: 0.95rem;
}

/* === FOOTER === */
.app-footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.app-footer i {
    color: var(--primary);
}

/* === PAGINATION === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 28px;
    flex-wrap: wrap;
}

.page-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--primary);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.page-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.page-num {
    min-width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 600;
}

.page-num.current {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
}

.page-ellipsis {
    color: var(--text-light);
    padding: 0 4px;
    font-size: 0.88rem;
}

/* === RESPONSIVE === */
@media (max-width: 640px) {
    body {
        padding: 16px 12px 40px;
    }

    .app-header {
        padding: 24px 0 20px;
    }

    .app-header h1 {
        font-size: 1.35rem;
    }

    .search-card {
        padding: 18px 16px;
        border-radius: var(--radius-sm);
    }

    #query {
        padding: 12px 40px 12px 14px;
        font-size: 0.95rem;
    }

    .search-row {
        flex-direction: column;
    }

    .search-row button[type="submit"] {
        width: 100%;
    }

    .result-item {
        padding: 14px 16px;
    }

    .result-item h4 {
        font-size: 0.88rem;
    }

    .results-header {
        flex-direction: column;
        gap: 4px;
    }
}
