
/*
 * Advanced Search Modal Theme Styles (Blue Mock-up)
 * Version: 1.8.1
 * Overrides styles from book-filter.css specifically for the advanced search modal.
 */

/* ==========================================================================
   Variables (Step 6a)
   ========================================================================== */
:root {
  --wbg-brand-blue: #4a90e2; /* Primary blue from mock-up */
  --wbg-brand-blue-dark: #3a7bc8; /* Darker blue for hover/active */
  --wbg-light-blue-bg: #f0f8ff; /* Light blue background for rows/sections */
  --wbg-border-color: #d1e3f8; /* Border color for sections/inputs */
  --wbg-text-color: #333;
  --wbg-text-color-light: #555;
  --wbg-text-color-lighter: #777;
  --wbg-white: #fff;
  --wbg-modal-bg: var(--wbg-white);
  --wbg-input-bg: var(--wbg-white);
  --wbg-disabled-bg: #f8f9fa;
  --wbg-disabled-text: #adb5bd;
  --wbg-secondary-button-bg: #e9ecef;
  --wbg-secondary-button-text: #495057;
  --wbg-secondary-button-border: #ced4da;
  --wbg-secondary-button-hover-bg: #dee2e6;
}

/* ==========================================================================
   Modal Base Styles
   ========================================================================== */
#wbg-advanced-search-modal .wbg-modal-content {
  background-color: var(--wbg-modal-bg);
  border: 1px solid var(--wbg-border-color);
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  max-width: 850px; /* Adjusted width */
  padding: 20px 30px 30px 30px; /* Adjusted padding */
}

#wbg-advanced-search-modal .wbg-modal-header {
  border-bottom: 1px solid var(--wbg-border-color);
  padding-bottom: 15px;
  margin-bottom: 25px;
}

#wbg-advanced-search-modal .wbg-modal-header h2 {
  color: var(--wbg-text-color);
  font-size: 1.5em; /* Slightly larger title */
  font-weight: 600;
}

#wbg-advanced-search-modal .wbg-modal-close {
  color: var(--wbg-text-color-lighter);
  font-size: 1.8em;
  font-weight: bold;
  opacity: 0.7;
}
#wbg-advanced-search-modal .wbg-modal-close:hover {
  color: var(--wbg-brand-blue);
  opacity: 1;
}

#wbg-advanced-search-modal .wbg-modal-body {
  margin-bottom: 25px;
}

/* Search Type Toggle CSS removed (Plan Step 1.c) */

/* ==========================================================================
   Precision Builder (Step 7 Styling)
   ========================================================================== */
#wbg-precision-builder {
  margin-bottom: 25px;
  padding-bottom: 0; /* Remove padding/border from base style */
  border-bottom: none;
}

#wbg-precision-rows-container {
  display: flex;
  flex-direction: column;
  gap: 8px; /* Space between rows */
  margin-bottom: 15px;
}

.wbg-precision-row {
  display: grid;
  /* Grid layout matching HTML structure: Logic | Field | Value | Remove */
  grid-template-columns: 90px 180px 1fr auto; /* Adjusted widths */
  gap: 10px;
  align-items: center;
  padding: 10px 15px;
  background-color: var(--wbg-light-blue-bg);
  border: 1px solid var(--wbg-border-color);
  border-radius: 4px;
}

/* Step 7b: Hide logic operator for the first row via CSS only */
#wbg-precision-rows-container .wbg-precision-row:first-child .wbg-precision-row-logic {
  visibility: hidden; /* Keep space, hide content */
}

/* Hide remove button only if it's the first AND only row */
#wbg-precision-rows-container .wbg-precision-row:first-child:last-child .wbg-precision-row-remove {
  display: none;
}

/* Style inputs and selects within precision rows */
.wbg-precision-row select,
.wbg-precision-row input[type="text"] {
  width: 100%;
  padding: 8px 10px; /* Slightly smaller padding */
  border: 1px solid var(--wbg-border-color);
  border-radius: 4px;
  font-size: 0.9em;
  box-sizing: border-box;
  height: 38px; /* Match mock-up */
  background-color: var(--wbg-input-bg);
  color: var(--wbg-text-color);
}
.wbg-precision-row select:focus,
.wbg-precision-row input[type="text"]:focus {
  outline: none;
  border-color: var(--wbg-brand-blue);
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2); /* Blue focus ring */
}

/* Style remove button */
.wbg-precision-row .wbg-remove-precision-row {
  background: none;
  border: none;
  color: var(--wbg-text-color-lighter);
  font-size: 1.5em; /* Larger 'x' */
  line-height: 1;
  padding: 0 5px;
  cursor: pointer;
  opacity: 0.7;
  transition: all 0.2s ease;
}
.wbg-precision-row .wbg-remove-precision-row:hover {
  color: var(--wbg-brand-blue);
  opacity: 1;
}

/* Style Add Row button */
#wbg-precision-builder-controls {
  text-align: left;
  margin-top: 10px;
}
#wbg-add-precision-row {
  /* Uses .wbg-modal-button styles defined later */
  padding: 6px 15px; /* Smaller padding */
  font-size: 0.9em;
}
#wbg-add-precision-row span {
  margin-right: 5px;
}
#wbg-add-precision-row:disabled {
  background-color: var(--wbg-disabled-bg) !important;
  border-color: var(--wbg-border-color) !important;
  color: var(--wbg-disabled-text) !important;
  cursor: not-allowed;
  opacity: 0.7;
}

/* ==========================================================================
   Collapsible Quick Filters Panel (Step 8 Styling)
   ========================================================================== */
.wbg-quick-filters-panel {
  border: 1px solid var(--wbg-border-color);
  border-radius: 4px;
  margin-bottom: 25px;
  background-color: var(--wbg-light-blue-bg); /* Light blue background */
}

.wbg-collapse-toggle {
  background-color: transparent; /* Use panel background */
  border: none;
  border-bottom: 1px solid var(--wbg-border-color); /* Separator line */
  padding: 12px 15px;
  width: 100%;
  text-align: left;
  font-size: 1.1em;
  font-weight: 600;
  color: var(--wbg-text-color);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.wbg-collapse-toggle:hover {
  /* background-color: rgba(74, 144, 226, 0.05); Subtle hover */
}
.wbg-collapse-toggle[aria-expanded="false"] + .wbg-collapse-content {
  display: none;
}

/* Chevron Icon */
.wbg-chevron {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-style: solid;
  border-color: var(--wbg-text-color-light);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg); /* Down arrow */
  transition: transform 0.3s ease;
}
.wbg-collapse-toggle[aria-expanded="true"] .wbg-chevron {
  transform: rotate(-135deg); /* Up arrow */
}

.wbg-collapse-content {
  padding: 20px 15px 15px 15px;
}

/* ==========================================================================
   Quick Filter Groups Styling (Inside Collapse Panel)
   ========================================================================== */
.wbg-modal-field-group {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px dashed var(--wbg-border-color); /* Dashed separator */
}
.wbg-modal-field-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.wbg-modal-field-group label.wbg-modal-section-title {
  display: block; /* Make title take full width */
  font-weight: bold;
  margin-bottom: 12px;
  font-size: 1em; /* Match mock-up */
  color: var(--wbg-text-color);
  padding-left: 0; /* Reset padding if any */
  border-bottom: none; /* Remove border from base style */
}

.wbg-modal-options-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 15px; /* Row gap, Column gap */
}

.wbg-modal-options-group label.wbg-filter-option {
  display: inline-flex; /* Align checkbox and text */
  align-items: center;
  font-size: 0.9em;
  color: var(--wbg-text-color-light);
  cursor: pointer;
  margin-bottom: 5px; /* Spacing for wrapping */
}

.wbg-modal-options-group input[type="checkbox"],
.wbg-modal-options-group input[type="radio"] {
  margin-right: 6px;
  accent-color: var(--wbg-brand-blue); /* Step 6a: Blue checkbox/radio */
}
.wbg-modal-options-group input[type="checkbox"]:disabled + span, /* Style disabled label text */
.wbg-modal-options-group input[type="radio"]:disabled + span {
    color: var(--wbg-disabled-text);
    cursor: not-allowed;
}
.wbg-modal-options-group input[type="checkbox"]:disabled,
.wbg-modal-options-group input[type="radio"]:disabled {
    cursor: not-allowed;
}


/* Specific styling for date options layout */
.wbg-modal-options-group.date-options {
    align-items: center; /* Align items vertically */
}
.wbg-modal-options-group label.custom-date-label {
    margin-right: 5px; /* Reduce space before inputs */
}
.wbg-custom-date-range.modal-custom-date {
    margin-left: 0; /* Align with radio button */
    padding: 0;
    margin-top: 0; /* Reset margin */
}
.wbg-custom-date-range .wbg-date-inputs {
    display: inline-flex; /* Keep inputs inline */
    align-items: center;
    gap: 5px;
    margin-bottom: 0; /* Reset margin */
}
.wbg-custom-date-range .wbg-date-start,
.wbg-custom-date-range .wbg-date-end {
    width: 80px; /* Fixed width */
    padding: 6px 8px;
    border: 1px solid var(--wbg-border-color);
    border-radius: 3px;
    font-size: 0.9em;
    height: 32px; /* Smaller height */
    box-sizing: border-box;
    background-color: var(--wbg-input-bg);
    color: var(--wbg-text-color);
}
.wbg-custom-date-range .wbg-date-start:focus,
.wbg-custom-date-range .wbg-date-end:focus {
    outline: none;
    border-color: var(--wbg-brand-blue);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}
.wbg-custom-date-range .wbg-date-separator {
    margin: 0 3px;
    color: var(--wbg-text-color-light);
}

/* Styling for the static "Exclude..." checkbox */
.wbg-exclude-option {
    border-bottom: none; /* No separator needed */
    padding-bottom: 0;
    margin-bottom: 15px;
}
.wbg-exclude-option label.wbg-filter-option {
    font-size: 0.9em;
}

/* Region-specific CSS removed (Plan Step 3.b - No specific styles found) */

/* ==========================================================================
   Modal Footer & Buttons (Step 6a)
   ========================================================================== */
#wbg-advanced-search-modal .wbg-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 20px;
  border-top: 1px solid var(--wbg-border-color);
  margin-top: 0; /* Reset margin if any */
}

/* Base button style */
#wbg-advanced-search-modal .wbg-modal-button {
  padding: 10px 25px; /* More padding */
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1em; /* Larger font */
  font-weight: 600; /* Bolder */
  transition: all 0.2s ease;
  height: 40px;
  box-sizing: border-box;
  line-height: 1.5; /* Adjust line height for vertical centering */
}

/* Primary Button (查詢) */
#wbg-advanced-search-modal .wbg-modal-button-primary {
  background-color: var(--wbg-brand-blue);
  color: var(--wbg-white);
  border-color: var(--wbg-brand-blue);
}
#wbg-advanced-search-modal .wbg-modal-button-primary:hover {
  background-color: var(--wbg-brand-blue-dark);
  border-color: var(--wbg-brand-blue-dark);
}

/* Secondary Button (重置, 添加一行) */
#wbg-advanced-search-modal .wbg-modal-button-secondary {
  background-color: var(--wbg-secondary-button-bg);
  color: var(--wbg-secondary-button-text);
  border: 1px solid var(--wbg-secondary-button-border);
}
#wbg-advanced-search-modal .wbg-modal-button-secondary:hover {
  background-color: var(--wbg-secondary-button-hover-bg);
  border-color: #adb5bd;
}

/* ==========================================================================
   Responsive Adjustments (Basic)
   ========================================================================== */
@media (max-width: 768px) {
  #wbg-advanced-search-modal .wbg-modal-content {
    padding: 15px;
    max-width: 95%;
  }
  #wbg-advanced-search-modal .wbg-modal-header h2 {
    font-size: 1.3em;
  }

  /* Search Type Toggle responsive CSS removed (Plan Step 1.c) */

  /* Stack precision row elements */
  .wbg-precision-row {
    grid-template-columns: 1fr; /* Stack all elements */
    gap: 8px;
    padding: 10px;
  }
  .wbg-precision-row > div {
    width: 100%; /* Ensure elements take full width */
  }
  .wbg-precision-row .wbg-precision-row-logic {
    /* JS no longer handles visibility, rely on CSS */
     order: 1; /* Logic first */
  }
   /* Explicitly hide logic on first row on mobile via CSS */
   #wbg-precision-rows-container .wbg-precision-row:first-child .wbg-precision-row-logic {
       visibility: hidden; /* Keep space */
       display: block; /* Ensure it takes space if needed, or use display: none if space not needed */
       /* If display: none is preferred:
       display: none;
       */
   }

  .wbg-precision-row .wbg-precision-row-field { order: 2; }
  .wbg-precision-row .wbg-precision-row-value { order: 3; }
  .wbg-precision-row .wbg-precision-row-remove {
      order: 4;
      text-align: right; /* Align remove button right */
      margin-top: 5px;
  }
   /* Hide remove button on first AND only row on mobile */
  #wbg-precision-rows-container .wbg-precision-row:first-child:last-child .wbg-precision-row-remove {
      display: none;
  }

  .wbg-collapse-toggle {
      padding: 10px 12px;
      font-size: 1em;
  }
  .wbg-collapse-content {
      padding: 15px 12px 10px 12px;
  }
  .wbg-modal-field-group {
      margin-bottom: 15px;
      padding-bottom: 10px;
  }
  .wbg-modal-options-group {
      gap: 5px 10px;
  }
  .wbg-modal-options-group.date-options {
      flex-direction: column; /* Stack date options */
      align-items: flex-start;
  }
   .wbg-custom-date-range.modal-custom-date {
      margin-top: 5px;
  }

  #wbg-advanced-search-modal .wbg-modal-footer {
    padding-top: 15px;
    /* Spread buttons on small screens */
    /* justify-content: space-between; */ /* Keep right-aligned */
  }
  #wbg-advanced-search-modal .wbg-modal-button {
      padding: 8px 15px;
      font-size: 0.9em;
  }
}