/* ============================================================
   CSS Variables & Reset
   ============================================================ */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-sm: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Header
   ============================================================ */
.site-header {
  background: var(--primary);
  color: #fff;
  padding: 1.5rem 1rem;
  box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}
.header-inner { max-width: 1200px; margin: 0 auto; }
.site-header h1 { font-size: 1.5rem; font-weight: 700; }
.header-sub { font-size: 0.9rem; opacity: 0.85; margin-top: 0.25rem; }

/* ============================================================
   Main Layout
   ============================================================ */
.main-container {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  width: 100%;
}

/* ============================================================
   Search Section
   ============================================================ */
.search-section { margin-bottom: 1rem; }

.search-bar-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
  outline: none;
}
#search-input:focus { border-color: var(--primary); }
#search-input::placeholder { color: var(--text-muted); }

.search-hint {
  position: absolute;
  right: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  min-height: 1.2em;
}

/* ============================================================
   Filter Section
   ============================================================ */
.filter-section {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 140px;
  flex: 1;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-group select {
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}
.filter-group select:focus { border-color: var(--primary); }

.btn-clear {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  align-self: flex-end;
}
.btn-clear:hover { background: var(--bg); color: var(--text); border-color: var(--primary); }

/* ============================================================
   Loading Indicator
   ============================================================ */
.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ============================================================
   Results Grid
   ============================================================ */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ============================================================
   Device Card
   ============================================================ */
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.device-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.protocol-badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  background: #dbeafe;
  color: #1e40af;
  text-transform: uppercase;
}
.protocol-badge.snmp { background: #dcfce7; color: #166534; }
.protocol-badge.ssh { background: #fef9c3; color: #854d0e; }
.protocol-badge.telnet { background: #ffedd5; color: #9a3412; }
.protocol-badge.wmi { background: #f3e8ff; color: #6b21a8; }
.protocol-badge.agent { background: #fce7f3; color: #9d174d; }

.card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.card-sub span + span::before { content: " · "; }

.card-metrics {
  font-size: 0.78rem;
  color: var(--primary);
  margin-top: 0.2rem;
}

.card-oid {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.2rem;
}

/* ============================================================
   No Results
   ============================================================ */
.no-results {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ============================================================
   Modal
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.modal-title-wrap { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-header-actions { display: flex; align-items: center; gap: 0.5rem; }

.btn-copy-yaml {
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-copy-yaml:hover { background: #dcfce7; border-color: #16a34a; }
.btn-copy-yaml.copied { background: #16a34a; color: #fff; border-color: #16a34a; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-meta {
  padding: 0.6rem 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  transition: opacity 0.2s;
}

/* 弹窗内加载动画 */
.modal-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  z-index: 10;
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: var(--text-muted);
}
.modal-loading.hidden { display: none; }

.modal-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ============================================================
   Metric Table (inside modal)
   ============================================================ */
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.metrics-table th {
  position: sticky;
  top: 0;
  background: var(--bg);
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}
.metrics-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.metrics-table tr:hover td { background: #f8fafc; }
.metrics-table tr:last-child td { border-bottom: none; }

.td-oid {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.78rem;
  color: #7c3aed;
  word-break: break-all;
}
.td-name { font-weight: 500; }
.td-unit { color: var(--text-muted); white-space: nowrap; }
.td-threshold { font-size: 0.8rem; }
.td-threshold .warn { color: #d97706; }
.td-threshold .crit { color: #dc2626; }

.btn-copy-oid {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-copy-oid:hover { background: #ddd6fe; }

.metric-group-header {
  background: var(--bg);
  font-weight: 600;
  color: var(--primary);
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  margin: 0.75rem 0 0.25rem;
}
.metric-group-header:first-child { margin-top: 0; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  font-size: 0.85rem;
  padding: 0.6rem 1.25rem;
  border-radius: 20px;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* ============================================================
   Pagination Buttons
   ============================================================ */
.btn-page {
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-page:hover:not(:disabled) { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-page:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   Thanks Section
   ============================================================ */
.thanks-section {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1rem;
  margin: 2rem 0 0;
}
.thanks-inner {
  max-width: 680px;
  margin: 0 auto;
  text-align: center;
}
.thanks-section p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.7;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .filter-section { flex-direction: column; }
  .filter-group { min-width: 100%; }
  .btn-clear { width: 100%; }
  .results-grid { grid-template-columns: 1fr; }
  .modal-content { max-height: 90vh; }
}
