* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f5f5f5;
  color: #333;
  margin: 0;
  padding: 0;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 280px;
  background: white;
  padding: 20px;
  box-shadow: 2px 0 4px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.main-content {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
}

header {
  background: white;
  padding: 15px 20px;
  border-radius: 8px;
  margin-bottom: 15px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
  font-size: 18px;
  margin-bottom: 12px;
}

.stats-bar {
  display: flex;
  gap: 30px;
  margin-bottom: 12px;
}

#geoStat .stat-value {
  display: flex;
  align-items: center;
  gap: 4px;
}

.geo-indicator {
  font-size: 14px;
  line-height: 1;
  cursor: default;
  color: #ccc;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stat-label {
  font-size: 10px;
  color: #666;
  text-transform: uppercase;
}

.stat-value {
  font-size: 16px;
  font-weight: bold;
  color: #4CAF50;
}

.filters {
  background: white;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 15px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.filters h2 {
  font-size: 14px;
  margin-bottom: 12px;
}

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

.filter-hint {
  font-size: 11px;
  color: #ff9800;
  margin-bottom: 10px;
  padding: 5px 10px;
  background: #fff3e0;
  border-radius: 4px;
  border-left: 3px solid #ff9800;
}

.filter-row input[type="text"],
.filter-row input[type="number"] {
  flex: 1;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.filter-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  transition: all 0.2s;
}

.sort-btn {
  padding: 4px 12px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: #555;
  transition: all 0.15s;
}
.sort-btn:hover { background: #f0f0f0; border-color: #bbb; }
.sort-btn.active { background: #4CAF50; color: white; border-color: #4CAF50; }

.btn-primary {
  background: #4CAF50;
  color: white;
}

.btn-primary:hover {
  background: #45a049;
}

.btn-secondary {
  background: #2196F3;
  color: white;
}

.btn-secondary:hover {
  background: #0b7dda;
}

.btn-warning {
  background: #ff9800;
  color: white;
}

.btn-warning:hover {
  background: #e68900;
}

.settings-section {
  background: transparent;
  padding: 0;
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 2px solid #eee;
}

.settings-section h3 {
  font-size: 14px;
  margin-bottom: 10px;
  font-weight: bold;
}

.settings-summary {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: #666;
}

.settings-form {
  margin-top: 8px;
}

.settings-form label {
  display: block;
  font-size: 11px;
  color: #666;
  margin-bottom: 6px;
}

.settings-form input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  margin-top: 2px;
}

.settings-form button {
  margin-top: 8px;
  width: 100%;
}

.home-city-section {
  background: transparent;
  padding: 0;
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 2px solid #eee;
}

.home-city-section h3 {
  font-size: 14px;
  margin-bottom: 10px;
  font-weight: bold;
}

.home-city-section input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 8px;
}

.home-city-section button {
  width: 100%;
}

.home-city-display {
  margin-top: 10px;
  padding: 8px;
  background: #e3f2fd;
  border-radius: 4px;
  font-size: 11px;
  color: #1976d2;
  text-align: center;
  font-weight: bold;
  display: none;
}

.home-city-display.active {
  display: block;
}

.quick-filters {
  background: transparent;
  padding: 0;
}

.quick-filters h3 {
  font-size: 14px;
  margin-bottom: 15px;
  font-weight: bold;
}

.quick-filters-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 15px;
}

.quick-filter-btn {
  width: 100%;
  padding: 10px 12px;
  background: #2196F3;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.2s;
  position: relative;
  padding-right: 30px;
  text-align: left;
}

.quick-filter-btn:hover {
  background: #0b7dda;
}

.quick-filter-btn .remove-btn {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.3);
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 12px;
  margin-left: 8px;
}

.quick-filter-btn .remove-btn:hover {
  background: rgba(255,255,255,0.5);
}

.quick-filter-add {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 15px;
  border-top: 1px solid #eee;
}

.quick-filter-add input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 11px;
}

.quick-filter-add button {
  width: 100%;
}

.btn-small {
  padding: 8px 16px;
  font-size: 13px;
}

.btn-similar {
  background: #9c27b0;
  color: white;
  border: none;
  white-space: nowrap;
}

.btn-similar:hover {
  background: #7b1fa2;
}

.items-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  font-size: 18px;
  color: #666;
}

.item-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  height: 520px;
}

.item-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.item-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: #f0f0f0;
  flex-shrink: 0;
}

.item-content {
  padding: 15px;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.item-title {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 10px;
  color: #333;
  line-height: 1.4;
  word-wrap: break-word;
  word-spacing: 2px;
  white-space: normal;
  max-height: 40px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.item-price {
  font-size: 20px;
  font-weight: bold;
  color: #4CAF50;
  margin-bottom: 10px;
  display: block;
}

.item-location {
  font-size: 13px;
  color: #666;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-distance {
  background: #4CAF50;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: bold;
  white-space: nowrap;
}

.item-description {
  font-size: 13px;
  color: #666;
  margin-bottom: 15px;
  max-height: 60px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}

.item-meta {
  font-size: 11px;
  color: #999;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-badges {
  display: flex;
  gap: 5px;
  margin-bottom: auto;
  flex-wrap: wrap;
  min-height: 25px;
}

.badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
}

.badge-seen {
  background: #e0e0e0;
  color: #666;
}

.badge-saved {
  background: #4CAF50;
  color: white;
}

.badge-new {
  background: #2196F3;
  color: white;
}

.item-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-shrink: 0;
}

.item-actions button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.2s;
}

.btn-save {
  background: #4CAF50;
  color: white;
}

.btn-save:hover {
  background: #45a049;
}

.btn-hide {
  background: #f44336;
  color: white;
}

.btn-hide:hover {
  background: #da190b;
}

.btn-view {
  background: #2196F3;
  color: white;
}

.btn-view:hover {
  background: #0b7dda;
}

.btn-delete {
  background: #9e9e9e;
  color: white;
}

.btn-delete:hover {
  background: #757575;
}

/* Auto-scroll controls */
.autoscroll-controls {
  display: flex !important;
  align-items: center;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid #e0e0e0;
  margin-top: 10px;
  flex-wrap: wrap;
}

.autoscroll-controls label {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  margin: 0;
  flex-shrink: 0;
  display: inline-block !important;
  visibility: visible !important;
}

.autoscroll-controls select {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  background: white;
  cursor: pointer;
  min-width: 150px;
  flex-shrink: 0;
  display: inline-block !important;
  visibility: visible !important;
}

.autoscroll-controls select:hover {
  border-color: #2196F3;
}

#toggleAutoScroll {
  flex-shrink: 0;
}

#toggleAutoScroll.active {
  background: #f44336;
  border-color: #f44336;
}

#toggleAutoScroll.active:hover {
  background: #d32f2f;
}

/* Search Jobs */
.search-pages-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.search-pages-row label {
  font-size: 12px;
  white-space: nowrap;
}

.search-pages-row input[type="number"] {
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
}

.btn-search-all {
  flex: 1;
  background: #ff9800;
  color: white;
  font-weight: bold;
}

.btn-search-all:hover {
  background: #e68900;
}

.quick-filter-row {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.quick-filter-row .quick-filter-btn {
  flex: 1;
}

.quick-filter-search-btn {
  padding: 6px 10px;
  background: #ff9800;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.quick-filter-search-btn:hover {
  background: #e68900;
}
.filter-check {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid rgba(255,255,255,0.5);
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.filter-check:hover {
  border-color: rgba(255,255,255,0.8);
}
.filter-check.checked {
  background: rgba(255,255,255,0.9);
  border-color: rgba(255,255,255,0.9);
}
.filter-check.checked::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 0px;
  width: 3px;
  height: 6px;
  border: solid #2196F3;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.quick-filter-btn.excluded {
  background: #90a4ae;
}
.quick-filter-btn.excluded:hover {
  background: #78909c;
}

/* Search Panel (fixed overlay, below header) */
.search-panel {
  position: fixed;
  top: 90px;
  right: 15px;
  width: 680px;
  background: white;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  z-index: 100;
  padding: 8px 10px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}

/* Collapsed: narrow strip, no body */
.search-panel.collapsed {
  width: auto;
  max-height: none;
  overflow: visible;
  padding: 4px 10px;
}

.search-panel.collapsed .search-panel-body {
  display: none;
}

.search-panel.collapsed .search-panel-buttons .btn-clear-log:not(#toggleSearchPanel) {
  display: none;
}

/* Expanded log: taller log area */
.search-panel.expanded .search-log {
  max-height: 500px;
}

.search-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.search-panel:not(.collapsed) .search-panel-header {
  margin-bottom: 8px;
}

.search-panel-title {
  font-size: 13px;
  font-weight: bold;
}

.search-panel-buttons {
  display: flex;
  gap: 6px;
}

.search-jobs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.search-jobs-empty {
  font-size: 12px;
  color: #999;
  text-align: center;
  padding: 10px;
}

.search-job-item {
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px;
}

.search-job-item.clickable {
  cursor: pointer;
}

.search-job-item.clickable:hover {
  outline: 2px solid #2196F3;
  outline-offset: -2px;
}

.search-job-item .job-label {
  font-weight: bold;
  margin-bottom: 2px;
}

.search-job-item .job-meta {
  font-size: 11px;
  opacity: 0.8;
}

.search-job-item .job-error {
  font-size: 10px;
  color: #c62828;
  margin-top: 2px;
}

/* Search running indicator */
.search-running-indicator {
  font-size: 13px;
  font-weight: 500;
  color: #e65100;
  margin-left: 10px;
  vertical-align: middle;
}

.btn-stop-jobs {
  font-size: 11px;
  padding: 2px 8px;
  background: #f44336;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 6px;
  vertical-align: middle;
}

.btn-stop-jobs:hover {
  background: #c62828;
}

.pulse-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: #ff9800;
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

.pages-complete {
  color: #2e7d32;
  font-weight: bold;
}

.pages-empty {
  color: #c62828;
  font-weight: bold;
}

.pages-partial {
  color: #e65100;
}

.job-status-pending {
  background: #fff3e0;
  color: #e65100;
}

.job-status-running {
  background: #e3f2fd;
  color: #0d47a1;
}

.job-status-completed {
  background: #e8f5e9;
  color: #1b5e20;
}

.job-status-failed {
  background: #fce4ec;
  color: #b71c1c;
}

.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid #0d47a1;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

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

/* Search Log */
.btn-clear-log {
  font-size: 10px;
  padding: 2px 8px;
  background: #9e9e9e;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

.btn-clear-log:hover {
  background: #757575;
}

.search-panel .search-log {
  margin-top: 8px;
}

.search-log {
  max-height: 250px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  line-height: 1.5;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 4px;
  padding: 8px;
}

.search-log-empty {
  color: #666;
  text-align: center;
  padding: 10px;
  font-family: -apple-system, sans-serif;
  font-size: 12px;
}

.log-entry {
  padding: 1px 0;
  word-break: break-word;
}

.log-time {
  color: #6a9955;
}

.log-label {
  color: #569cd6;
}

.log-info {
  color: #d4d4d4;
}

.log-error {
  color: #f44747;
}

.log-warn {
  color: #ce9178;
}

.sidebar-toggle-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sidebar-toggle {
  padding: 4px 10px;
  background: #2196F3;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.sidebar-toggle:hover {
  background: #1976D2;
}

.sidebar.collapsed {
  display: none;
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

/* Tablet */
@media (max-width: 1024px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    max-height: none;
    border-bottom: 2px solid #eee;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }

  .sidebar-toggle {
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
  }

  .main-content {
    padding: 10px;
  }

  .items-container {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
  }

  .stats-bar {
    flex-wrap: wrap;
    gap: 15px;
  }

  .filter-row {
    flex-wrap: wrap;
  }

  .search-panel {
    position: static;
    width: 100%;
    max-height: none;
    margin-bottom: 10px;
  }

  .search-panel.collapsed {
    width: 100%;
  }
}

/* Mobile */
@media (max-width: 640px) {
  .main-content {
    padding: 8px;
  }

  header {
    padding: 10px 12px;
  }

  header h1 {
    font-size: 15px;
  }

  .items-container {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .item-card {
    height: auto;
  }

  .item-image {
    height: 180px;
  }

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

  .filter-row input[type="text"],
  .filter-row input[type="number"] {
    width: 100%;
  }

  .tabs {
    flex-wrap: wrap;
    gap: 6px;
  }

  .tab-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  .btn {
    padding: 8px 14px;
    font-size: 13px;
  }

}
