:root {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #3d3d3d;
  --text-primary: #ffffff;
  --text-secondary: #b3b3b3;
  --text-muted: #666666;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #404040;
  --border-light: #525252;
  --shadow: rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 400px;
  min-height: 400px;
  max-height: 800px;
  overflow-y: auto;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 400px;
  max-height: 800px;
  height: auto;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 16px;
  flex-shrink: 0;
  max-height: 200px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  border-radius: 6px;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

#appBrand {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.current-tab-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.tab-favicon {
  width: 16px;
  height: 16px;
  border-radius: 2px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Main Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-label {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  cursor: pointer;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary, #3d3d3d);
  transition: all 0.3s ease;
  border-radius: 24px;
  border: 1px solid var(--border, #404040);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  background-color: var(--text-muted, #999999);
  transition: all 0.3s ease;
  border-radius: 50%;
}

.toggle-input:checked + .toggle-label .toggle-slider {
  background-color: var(--accent, #3b82f6);
  border-color: var(--accent, #3b82f6);
}

.toggle-input:checked + .toggle-label .toggle-slider:before {
  transform: translateX(20px) translateY(-50%);
  background-color: white;
}

.toggle-switch:hover .toggle-slider {
  opacity: 0.9;
}

/* Settings Button */
.settings-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.settings-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Tabs Navigation */
.tabs-nav {
  display: flex;
  gap: 2px;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
}

.tab-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.tab-btn.active {
  background: var(--accent);
  color: white;
}

.tab-btn svg {
  width: 14px;
  height: 14px;
}

/* Main Content */
.main {
  flex: 1;
  min-height: 300px;
  overflow-y: auto;
  padding: 0;
  background: var(--bg-primary);
}

.tab-content {
  display: none;
  padding: 2px 16px 16px 16px;
  min-height: 200px;
  background: var(--bg-primary);
}

.tab-content.active {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  height: auto !important;
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 16px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--bg-tertiary);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 16px;
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 16px;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.4;
}

/* Detection Results */
.detection-results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.results-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detection-title-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detection-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-logo {
  border-radius: 4px;
}

#detectionLabel {
  font-size: 14px;
  font-weight: 500;
}

.count-badge {
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

/* Stats Grid */
.detection-overview {
  margin-top: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stat-icon-compact {
  font-size: 16px;
}

.stat-content-compact {
  display: flex;
  flex-direction: column;
}

.stat-label-compact {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.stat-value-compact {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Search */
.search-filter-section {
  margin-top: 12px;
}

.search-filter-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.search-container {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 5px 10px 5px 28px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 400;
  height: 26px;
  box-sizing: border-box;
}

.search-input::placeholder {
  color: var(--text-muted);
  font-size: 10px;
}

.search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 12px;
  height: 12px;
}

/* Results List */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detection-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.detection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.detection-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detection-icon {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.detection-details h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.detection-category {
  font-size: 12px;
  color: var(--text-muted);
}

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

.confidence-high { background: var(--success); color: white; }
.confidence-medium { background: var(--warning); color: white; }
.confidence-low { background: var(--danger); color: white; }

.detection-matches {
  margin-top: 8px;
}

.detection-matches p {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.matches-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.match-tag {
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  font-size: 10px;
  color: var(--text-secondary);
}

.more-matches {
  padding: 2px 6px;
  background: var(--accent);
  border-radius: 12px;
  font-size: 10px;
  color: white;
}

/* Refresh Button */
.refresh-btn-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.refresh-btn-bottom:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* History */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.clear-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--danger);
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s;
}

.clear-btn:hover {
  background: #dc2626;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-light);
}

.history-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.history-favicon {
  width: 16px;
  height: 16px;
  border-radius: 2px;
}

.history-url {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-timestamp {
  font-size: 11px;
  color: var(--text-muted);
}

.history-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-detections {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.history-detection-tag {
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  font-size: 10px;
  color: var(--text-secondary);
}


/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  max-height: 80%;
  overflow: hidden;
  box-shadow: 0 20px 40px var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.header-content h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.header-content p {
  font-size: 14px;
  color: var(--text-muted);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  max-height: 400px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px;
  border-top: 1px solid var(--border);
}

/* Settings */
.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.setting-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.setting-group:last-child {
  border-bottom: none;
}

.setting-label {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.setting-label span:first-child {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.setting-description {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-tertiary);
  transition: 0.2s;
  border-radius: 12px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background: var(--text-secondary);
  transition: 0.2s;
  border-radius: 50%;
}

input:checked + .slider {
  background: var(--accent);
}

input:checked + .slider:before {
  transform: translateX(20px);
  background: white;
}

/* Form Elements */
.input-field {
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  width: 100px;
}

.range-field {
  width: 120px;
  margin-right: 8px;
}

.range-value {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 40px;
}

.action-group {
  display: flex;
  gap: 8px;
  padding-top: 16px;
}

.primary-btn {
  padding: 10px 16px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.secondary-btn {
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.warning-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--danger);
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}

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

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}