/* Search: a dialog on top of the reader, which stays visible (dimmed) behind it.
   The search box stays at the top of the dialog; the results scroll under it.
   It closes with the X, the Esc key, a click outside it, or the browser's Back button (js/search.js). */

/* The dimmed layer over the whole page; the dialog sits on it */
#search-page {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.32);
    z-index: 1100;                      /* above the reader's fixed header and footer */
}

/* while search is open, the reader underneath can't scroll */
body.search-open {
    overflow: hidden;
}

#search-dialog {
    position: absolute;
    top: 14px;                          /* near the top: it covers the toolbar, so the results aren't mistaken for the surah's */
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    width: min(780px, 100% - 32px);
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

#search-header {
    padding: 26px 22px 8px;
}

#search-form {
    display: flex;
    align-items: center;
}

/* The search box: the magnifier inside it on the left, the clear button inside it on the right.
   (No search button: results show as you type, and Enter works too.) */
#search-box {
    position: relative;
    flex-grow: 1;
    display: flex;
}

#search-input {
    flex-grow: 1;
    box-sizing: border-box;
    height: 46px;
    margin: 0;
    padding: 0 40px 0 44px;             /* room for the magnifier (left) and the clear button (right) */
    font-size: 18px;
    border: 1px solid #bfcbd5;
    border-radius: 10px;
    background-color: #ecf0f3;
    color: #222;
    -webkit-appearance: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#search-input:focus {
    border-color: #3775dd;
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(55, 117, 221, 0.15);     /* a soft blue ring while typing */
}

.search-box-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    fill: #7d8992;
    pointer-events: none;
}

#search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;           /* the browser's own clear button: ours is below */
    display: none;
}

input:focus {
    outline: none;
}

/* Clear: a white x in a gray circle, so it doesn't look like the X that closes search */
#search-clear {
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: #9aa5ae;
    color: #ffffff;
    font-size: 12px;
    line-height: 22px;
    text-align: center;
    cursor: pointer;
}

#search-clear:hover {
    background-color: #7d8992;
}

/* Close: a plain X at the right end */
#search-close {
    margin-left: 12px;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #666666;
    font-size: 24px;
    line-height: 36px;
    cursor: pointer;
}

#search-close:hover {
    background-color: #eef1f4;
}

button:focus:not(:focus-visible) {     /* no outline after a mouse click; keyboard focus shows one (reader.css) */
    outline: 0;
}

/* The results: they scroll inside the dialog */
#search-page-search-container {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;       /* scrolling past the end doesn't pass through to the reader */
    padding: 12px 20px 20px;            /* room under the search box, also when there is no status line (2:255) */
}

#search-status {
    color: #767676;                     /* the lightest gray that is still easy to read on white (4.5:1) */
    padding-top: 2px;
    padding-bottom: 12px;
}

#search-results {
    text-align: left;
}

.search-result {
    margin: 0 -8px;                     /* keeps the text aligned with the search box */
    padding: 12px 8px;
    border-bottom: 1px solid #eeeeee;   /* a line between results */
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.search-result:hover {
    background-color: #f4f7fd;          /* a soft blue tint over the whole result */
}

.search-result-text {
    display: inline;
    font-size: 17px;
    line-height: 140%;
    color: #111;
}

.search-result-info-a {
    display: inline;
    font-weight: 500;
}

.search-result-text b {
    font-weight: normal;                /* the words found: a highlighter background, not bold */
    background-color: #fff1a8;
    border-radius: 3px;
    padding: 0 2px;
    margin: 0 -2px;
}

.not-visited {
    color: #3775dd;
}

.visited {
    color: #609;
}

/* A line and a label where each new batch of results starts (after See More) */
.search-batch-divider {
    padding: 8px 8px;
    border-top: 2px solid #333;
    border-bottom: 2px solid #333;
    color: #333;
    font-size: 16px !important;         /* stays small; the script sets the result text sizes */
    font-weight: 700;
    background-color: #e0e0e0;
}

.search-btn {
    width: max-content;             /* its own size (the script shows it as a block) */
    margin: 16px 0 12px;            /* room above and below (with the dialog's own 20px below) */
    padding: 8px 12px;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 1px rgba(0,0,0,0.24);
    background: #3775dd;
    color: #fafafa;
    font-size: 14px;
    cursor: pointer;
}

.search-noselect {
    user-select: none;
}

/* The spinner, while the text downloads (the first search only) */
.search-spinner-container {
    padding-top: 10px;
    padding-left: 10px;
}

.search-spinner {
    border: 3px solid #f3f3f3;
    border-radius: 50%;
    border-top: 3px solid #3775dd;
    width: 30px;
    height: 30px;
    animation: spin 0.4s linear infinite;
}

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


/*-------- Night mode (the class "night" on the page, set from the Aa panel) --------*/
html.night #search-page {
    background-color: rgba(0, 0, 0, 0.55);
}
html.night #search-dialog {
    background-color: #1b2025;
    border: 1px solid #3a434b;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.6);
}
html.night #search-input {
    background-color: #22282e;
    border-color: #3a434b;
    color: #e6e9ec;
}
html.night #search-input::placeholder {
    color: #8f9aa3;
}
html.night #search-input:focus {
    border-color: #4a9bb8;
    background-color: #22282e;
    box-shadow: 0 0 0 3px rgba(74, 155, 184, 0.2);
}
html.night .search-box-icon {
    fill: #8f9aa3;
}
html.night #search-clear {
    background-color: #5d6870;
    color: #15191d;
}
html.night #search-clear:hover {
    background-color: #77838c;
}
html.night .search-btn {
    background-color: #2f6f88;
    border-color: #2f6f88;
}
html.night #search-close {
    color: #aab4bd;
}
html.night #search-close:hover {
    background-color: #2c343b;
}
html.night #search-status {
    color: #8f9aa3;
}
html.night .search-result {
    border-bottom-color: #2c343b;
}
html.night .search-result:hover {
    background-color: #232a31;
}
html.night .search-result-text {
    color: #c9cfd5;                     /* the same as the verses in the reader */
}
html.night .search-result-text b {
    background-color: #5a4d1c;          /* the words found: a dark golden highlight */
    color: #fff7d6;
}
html.night .not-visited {
    color: #7fb3e0;
}
html.night .visited {
    color: #b493d6;
}
html.night .search-batch-divider {
    background-color: #22282e;
    border-color: #3a434b;
    color: #d6dbe0;
}
html.night .search-spinner {
    border-color: #2c343b;
    border-top-color: #7fb3e0;
}

#search-dialog:focus {                  /* focused only to move keyboard focus into search; no outline */
    outline: none;
}
