/* ============================================================================
   ADVANCED SEARCH — extra query rows combined with the main box

   Each row is: [و|أو|بدون] [text] [جذور][تصريف] [×]
   The main search box is the anchor and has no row here: there is nothing
   before it to combine with.
   ============================================================================ */

/* The «سطر زائد» toggle now lives inside .search-options in the search bar,
   between the two morphology checkboxes, so it no longer needs its own row
   wrapper. Its button styling follows. */

/* A real bordered button, matching the white/amber .filter-button-footer look
   used elsewhere, rather than the ghost link it started as. */
.advanced-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: relative;
    padding: 8px 16px;
    background: var(--color-white);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    font-family: var(--font-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.advanced-toggle:hover {
    background: var(--color-sand-light);
    border-color: var(--color-primary-dark);
}

/* Filled while the panel is open, so the button reads as "on". */
.advanced-toggle.open {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
}

.advanced-toggle__caret {
    font-size: 0.8em;
    color: var(--color-primary);
}

/* On the filled (open) state the caret needs to invert too. */
.advanced-toggle.open .advanced-toggle__caret {
    color: var(--color-white);
}

/* The row-count badge floats at the corner like the filter button's. */
.advanced-toggle .filter-badge {
    position: absolute;
    top: -8px;
    inset-inline-end: -8px;
    background: var(--color-danger);
    color: var(--color-white);
    border-radius: var(--radius-full);
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: var(--font-weight-bold);
    min-width: 20px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

/* ---- panel ---- */

.advanced-search {
    max-width: 1000px;
    margin: 8px auto 0;
    padding: 12px;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
}

.clause-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.clause-row:last-of-type {
    margin-bottom: 0;
}

/* ---- operator radios ---- */

.clause-ops {
    display: flex;
    flex: 0 0 auto;
    gap: 2px;
    padding: 2px;
    background: var(--color-surface-sunken, rgba(0, 0, 0, 0.2));
    border-radius: var(--radius-md);
}

.clause-op {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-family: var(--font-primary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
}

/* The native radio stays in the DOM for keyboard and screen-reader support;
   only its default rendering is hidden. */
.clause-op input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.clause-op:hover {
    color: var(--color-text-primary);
}

.clause-op.active {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-weight: 600;
}

/* بدون is an exclusion — colour it as one so a NOT row is never mistaken
   for an AND at a glance. */
.clause-op--n.active {
    background: var(--color-error, #b91c1c);
}

.clause-op input:focus-visible + span {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---- text ---- */

.clause-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-md);
    background: var(--color-surface-secondary);
    color: var(--color-text-primary);
    font-family: var(--font-primary);
    font-size: var(--font-size-base);
    direction: rtl;
}

.clause-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.clause-input::placeholder {
    color: var(--color-text-muted);
}

/* ---- per-row morphology ---- */

.clause-toggles {
    display: flex;
    flex: 0 0 auto;
    gap: 4px;
}

.clause-toggle {
    padding: 5px 10px;
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    font-family: var(--font-primary);
    font-size: var(--font-size-xs);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.clause-toggle:hover {
    color: var(--color-text-primary);
    border-color: var(--color-border-secondary);
}

.clause-toggle.on {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-text-inverse);
}

/* ---- remove ---- */

.clause-remove {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--color-text-muted);
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.clause-remove:hover {
    background: rgba(185, 28, 28, 0.15);
    color: var(--color-error, #b91c1c);
}

/* ---- actions ---- */

.advanced-search__actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--color-border-subtle);
}

.clause-add {
    padding: 6px 14px;
    border: 1px dashed var(--color-border-primary);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-secondary);
    font-family: var(--font-primary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.clause-add:hover:not(:disabled) {
    border-color: var(--color-primary);
    border-style: solid;
    color: var(--color-primary);
}

.clause-add:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.clause-count {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}
