/**
 * WRENN Search Widget Styles
 *
 * Design system:
 * - Font: Palatino Linotype (serif)
 * - Primary color: #EC0505 (WRENN red)
 * - Border radius: 6px (inputs), 8px (containers)
 */

/* ============================================
   CONTAINER
   ============================================ */

.wrenn-search-widget {
    font-family: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
    max-width: 100%;
    padding: 20px;
    box-sizing: border-box;
    color: #1a1a1a;
    line-height: 1.7;
}

.wrenn-search-widget * {
    box-sizing: border-box;
}

/* ============================================
   HEADER
   ============================================ */

.wrenn-search-header h2 {
    margin: 0 0 20px 0;
    color: #1a1a1a;
    font-size: 1.4rem;
    font-weight: normal;
}

/* ============================================
   FORM LAYOUT
   ============================================ */

.wrenn-search-form {
    background: #fafafa;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.wrenn-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}

.wrenn-form-row:last-child {
    margin-bottom: 0;
}

.wrenn-button-row {
    padding-top: 8px;
}

.wrenn-form-group {
    flex: 1;
    min-width: 150px;
    position: relative;
}

.wrenn-form-group-wide {
    flex: 2;
    min-width: 300px;
}

.wrenn-form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: #6b7280;
    font-weight: normal;
}

/* ============================================
   INPUTS AND SELECTS
   ============================================ */

.wrenn-input,
.wrenn-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    background: white;
    transition: border-color 0.15s;
}

.wrenn-input:focus,
.wrenn-select:focus {
    outline: none;
    border-color: #EC0505;
    box-shadow: 0 0 0 3px rgba(236, 5, 5, 0.1);
}

.wrenn-input::placeholder {
    color: #999;
}

.wrenn-multi-select {
    height: auto;
    min-height: 100px;
}

.wrenn-form-group small {
    display: block;
    margin-top: 4px;
    color: #888;
    font-size: 0.75rem;
}

/* ============================================
   CHECKBOXES
   ============================================ */

.wrenn-checkbox-group {
    display: flex;
    align-items: center;
}

.wrenn-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.wrenn-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #EC0505;
}

/* ============================================
   AUTOCOMPLETE DROPDOWN
   ============================================ */

.wrenn-autocomplete-wrapper {
    position: relative;
}

.wrenn-autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.wrenn-autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.wrenn-autocomplete-item:last-child {
    border-bottom: none;
}

.wrenn-autocomplete-item:hover {
    background: #f5f5f5;
}

.wrenn-autocomplete-name {
    font-weight: 500;
}

.wrenn-autocomplete-count {
    font-size: 0.8rem;
    color: #888;
}

/* ============================================
   COLLAPSIBLE SECTIONS
   ============================================ */

.wrenn-collapsible {
    width: 100%;
}

.wrenn-collapsible summary {
    cursor: pointer;
    padding: 12px 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-weight: normal;
    color: #6b7280;
    list-style: none;
    display: flex;
    align-items: center;
}

.wrenn-collapsible summary::-webkit-details-marker {
    display: none;
}

.wrenn-collapsible summary::before {
    content: '\25B6';
    display: inline-block;
    margin-right: 10px;
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.wrenn-collapsible[open] summary::before {
    transform: rotate(90deg);
}

.wrenn-collapsible summary:hover {
    background: #f3f4f6;
}

.wrenn-collapsible[open] summary {
    border-radius: 6px 6px 0 0;
}

.wrenn-collapsible-content {
    padding: 16px;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 6px 6px;
    background: white;
}

/* ============================================
   BUTTONS
   ============================================ */

.wrenn-search-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    background: #EC0505;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: normal;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
}

.wrenn-search-btn:hover {
    opacity: 0.9;
}

.wrenn-search-btn .wrenn-icon {
    width: 18px;
    height: 18px;
}

.wrenn-clear-btn {
    padding: 12px 20px;
    background: white;
    color: #6b7280;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
}

.wrenn-clear-btn:hover {
    background: #f5f5f5;
}

/* ============================================
   RESULTS CONTAINER
   ============================================ */

.wrenn-results-container {
    background: white;
    border-radius: 8px;
    border: 1px solid #eee;
    overflow: hidden;
}

.wrenn-results-header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    color: #6b7280;
    font-size: 0.9rem;
    background: #fafafa;
}

.wrenn-results-list {
    max-height: 600px;
    overflow-y: auto;
}

/* ============================================
   RESULT ITEMS
   ============================================ */

.wrenn-result-item {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    transition: background 0.2s;
}

.wrenn-result-item:last-child {
    border-bottom: none;
}

.wrenn-result-item:hover {
    background: #fafafa;
}

.wrenn-result-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
}

.wrenn-result-title {
    font-size: 1.05rem;
    font-weight: normal;
    color: #EC0505;
    text-decoration: none;
    flex: 1;
    line-height: 1.4;
}

.wrenn-result-title:hover {
    text-decoration: underline;
}

/* ============================================
   GRADE BADGES
   ============================================ */

.wrenn-result-grade {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.wrenn-grade-I {
    background: #fef3c7;
    color: #92400e;
}

.wrenn-grade-IIstar {
    background: #dbeafe;
    color: #1e40af;
}

.wrenn-grade-II {
    background: #f3f4f6;
    color: #374151;
}

/* ============================================
   DECISION BADGES
   ============================================ */

.wrenn-result-decision {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.wrenn-decision-granted,
.wrenn-decision-approved,
.wrenn-decision-approved---conditions {
    background: #d1fae5;
    color: #065f46;
}

.wrenn-decision-refused {
    background: #fee2e2;
    color: #991b1b;
}

.wrenn-decision-withdrawn {
    background: #f3f4f6;
    color: #374151;
}

.wrenn-decision-pending {
    background: #fef3c7;
    color: #92400e;
}

/* ============================================
   METADATA
   ============================================ */

.wrenn-result-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 8px;
}

.wrenn-meta-sep {
    color: #ccc;
}

.wrenn-pending-days {
    color: #dc2626;
    font-weight: 500;
}

/* ============================================
   ATTRIBUTE TAGS
   ============================================ */

.wrenn-result-attributes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.wrenn-attr-tag {
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 12px;
    background: #e5e7eb;
    color: #374151;
    white-space: nowrap;
}

.wrenn-attr-period {
    background: #dbeafe;
    color: #1e40af;
}

.wrenn-attr-material {
    background: #fef3c7;
    color: #92400e;
}

.wrenn-attr-more {
    font-size: 0.75rem;
    padding: 3px 8px;
    color: #6b7280;
    font-style: italic;
}

/* ============================================
   LISTING INDICATORS
   ============================================ */

.wrenn-listing-badge {
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 500;
    white-space: nowrap;
    vertical-align: middle;
    margin-left: 6px;
}

.wrenn-listing-group {
    background: #ede9fe;
    color: #5b21b6;
}

.wrenn-listing-compound {
    background: #fef3c7;
    color: #92400e;
}

.wrenn-result-parent {
    font-size: 0.8rem;
    color: #6b7280;
    font-style: italic;
    margin-bottom: 4px;
}

.wrenn-result-note {
    font-size: 0.8rem;
    color: #9ca3af;
    font-style: italic;
}

/* ============================================
   DESCRIPTION
   ============================================ */

.wrenn-result-description {
    font-size: 0.9rem;
    color: #6b7280;
    line-height: 1.5;
}

/* ============================================
   PAGINATION
   ============================================ */

.wrenn-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-top: 1px solid #eee;
    background: #fafafa;
}

.wrenn-page-btn {
    padding: 8px 16px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
}

.wrenn-page-btn:hover:not(:disabled) {
    background: #f5f5f5;
}

.wrenn-page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.wrenn-page-info {
    color: #6b7280;
    font-size: 0.9rem;
}

/* ============================================
   LOADING STATE
   ============================================ */

.wrenn-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: #6b7280;
}

.wrenn-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #eee;
    border-top-color: #EC0505;
    border-radius: 50%;
    animation: wrenn-spin 0.8s linear infinite;
}

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

/* ============================================
   ERROR STATE
   ============================================ */

.wrenn-error {
    padding: 16px 20px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 8px;
    margin-top: 16px;
}

.wrenn-no-results {
    padding: 40px;
    text-align: center;
    color: #6b7280;
}

/* ============================================
   DATE RANGE FILTER
   ============================================ */

.wrenn-date-custom {
    width: 100%;
}

.wrenn-date-range-inputs {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.wrenn-date-input-wrapper {
    flex: 1;
    min-width: 130px;
}

.wrenn-date-input-wrapper label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.8rem;
    color: #6b7280;
}

.wrenn-date-input {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.9rem;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .wrenn-search-widget {
        padding: 16px;
    }

    .wrenn-search-form {
        padding: 16px;
    }

    .wrenn-form-group {
        min-width: 100%;
    }

    .wrenn-form-group-wide {
        min-width: 100%;
    }

    .wrenn-result-header {
        flex-direction: column;
        gap: 8px;
    }

    .wrenn-result-grade,
    .wrenn-result-decision {
        align-self: flex-start;
    }

    .wrenn-result-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .wrenn-meta-sep {
        display: none;
    }

    .wrenn-button-row {
        flex-direction: column;
    }

    .wrenn-search-btn,
    .wrenn-clear-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .wrenn-search-header h2 {
        font-size: 1.25rem;
    }

    .wrenn-result-title {
        font-size: 1rem;
    }

    .wrenn-pagination {
        flex-direction: column;
        gap: 12px;
    }
}
