:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #1a1a25;
  --border: #2a2a3a;
  --text: #e0e0e8;
  --text-dim: #8888a0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
}

header {
  padding: 32px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
}

.section {
  margin-bottom: 24px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.stat-card.highlight {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Charts */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-card h3 {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 12px;
  font-weight: 500;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.bar-label {
  width: 60px;
  text-align: right;
  color: var(--text-dim);
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 20px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  min-width: 2px;
  transition: width 0.3s ease;
}

.bar-count {
  width: 40px;
  text-align: left;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.filter-group input,
.filter-group select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--accent);
}

.filter-group input { width: 240px; }

.filter-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn-secondary:hover { background: var(--border); }

/* Results */
#results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

#results-header h2 {
  font-size: 18px;
  font-weight: 600;
}

#results-count {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 400;
}

#results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.patent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: grid;
  grid-template-columns: 48px 1fr 200px;
  gap: 16px;
  align-items: start;
}

.patent-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.score-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.score-high { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.score-mid { background: rgba(234, 179, 8, 0.15); color: var(--yellow); }
.score-low { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.score-none { background: var(--surface-2); color: var(--text-dim); }

.patent-info {
  min-width: 0;
}

.patent-info h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.3;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.patent-info .patent-desc {
  font-size: 13px;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.patent-meta {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-dim);
}

.tag-type {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
}

.patent-right {
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
  min-width: 0;
  overflow: hidden;
}

.patent-right .bom {
  font-size: 13px;
  color: var(--green);
  font-weight: 600;
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.3;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 20px 0;
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.pagination button:hover { border-color: var(--accent); }
.pagination button.active { background: var(--accent); border-color: var(--accent); }
.pagination button:disabled { opacity: 0.3; cursor: default; }

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  overflow-y: auto;
  padding: 40px 20px;
}

.modal.open { display: flex; justify-content: center; align-items: flex-start; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 720px;
  width: 100%;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px; right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
}

.modal-close:hover { color: var(--text); }

.detail-header {
  margin-bottom: 24px;
}

.detail-header h2 {
  font-size: 20px;
  margin-bottom: 4px;
}

.detail-header .patent-num {
  font-size: 14px;
  color: var(--accent);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.detail-field {
  padding: 12px;
  background: var(--bg);
  border-radius: 6px;
}

.detail-field.full { grid-column: 1 / -1; }

.detail-field label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 4px;
}

.detail-field .value {
  font-size: 14px;
  line-height: 1.5;
}

.detail-actions {
  display: flex;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.detail-actions a {
  text-decoration: none;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

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

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.loading::after {
  content: '...';
  animation: pulse 1.5s infinite;
}

@media (max-width: 768px) {
  .chart-row { grid-template-columns: 1fr; }
  .filters { flex-direction: column; }
  .filter-group input { width: 100%; }
  .filter-actions { margin-left: 0; width: 100%; }
  .patent-card { grid-template-columns: 40px 1fr; }
  .patent-right { display: none; }
  .patent-info h3 { font-size: 14px; }
  .detail-grid { grid-template-columns: 1fr; }
}
