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

:root {
  --blue-600: #0077cc;
  --blue-500: #00a8e8;
  --blue-50: #e0f4ff;
  --blue-100: #b3e0ff;
  --blue-hover: #cceaff;
  --bg: #f0f2f5;
  --bg-white: #fff;
  --bg-subtle: #f8f9fb;
  --text: #333;
  --text-secondary: #555;
  --text-muted: #888;
  --text-light: #999;
  --border: #d9d9d9;
  --border-light: #eee;
  --danger: #e53e3e;
  --danger-bg: #fef2f2;
  --star: #f59e0b;
  --star-bg: #fffbeb;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

button {
  font-family: var(--font-display);
  cursor: pointer;
}

/* ---- Header ---- */
.header {
  width: 100%;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-600));
  padding: 12px 16px;
  text-align: center;
  color: #fff;
  animation: fadeSlideDown 0.5s ease-out;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header h1 .sep {
  opacity: 0.5;
  margin: 0 8px;
  font-weight: 400;
}

.header h1 .subtitle {
  font-weight: 400;
  font-size: 14px;
  opacity: 0.9;
}

/* ---- Main Layout ---- */
.main-layout {
  display: flex;
  width: 100%;
  max-width: 1020px;
  flex: 1;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-white);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  max-height: 100vh;
  animation: fadeSlideUp 0.5s ease-out;
}

.sidebar-header {
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--text);
  background: var(--bg-subtle);
}

.sidebar-header .history-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

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

.btn-favorites {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--star);
  transition: opacity 0.15s;
}

.btn-favorites:hover {
  opacity: 0.75;
}

.btn-favorites span {
  font-weight: 400;
  color: var(--text-muted);
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 13px;
  color: var(--blue-600);
  font-weight: 600;
}

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-search input {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  font-family: var(--font-display);
  color: var(--text);
}

.sidebar-search input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.sidebar-search input:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(0, 168, 232, 0.15);
}

.sidebar-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}

.sidebar-item:hover {
  background: #f8fafc;
}

.sidebar-item.active {
  background: var(--blue-50);
  border-left: 3px solid var(--blue-500);
  padding-left: 13px;
}

.sidebar-item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.item-icons {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  border: none;
  background: none;
  color: var(--text-light);
  border-radius: 4px;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.sidebar-item .btn-icon {
  opacity: 0;
}

.sidebar-item:hover .btn-icon,
.sidebar-item .btn-favorite.favorited,
.sidebar-item.favorited .btn-favorite {
  opacity: 1;
}

.btn-delete:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.btn-favorite:hover {
  color: var(--star);
  background: var(--star-bg);
}

.favorited .btn-favorite,
.btn-favorite.favorited {
  color: var(--star);
}

.favorited .btn-favorite svg,
.btn-favorite.favorited svg {
  fill: currentColor;
}

.sidebar-item .domain {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

.sidebar-item .meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.sidebar-item .stats {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  font-family: var(--font-mono);
}

.sidebar-item .actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  color: var(--text-muted);
}

.btn-sm:hover {
  background: var(--blue-50);
  border-color: var(--blue-500);
  color: var(--blue-600);
}

.btn-sm.btn-requery {
  color: var(--blue-600);
  border-color: var(--blue-100);
  background: var(--blue-50);
}

.btn-sm.btn-requery:hover {
  background: var(--blue-hover);
}

.sidebar-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border-light);
}

.btn-clear {
  width: 100%;
  padding: 8px;
  font-size: 13px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-clear:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

/* ---- Container ---- */
.container {
  width: 100%;
  max-width: 720px;
  padding: 24px 16px;
  flex: 1;
}

/* ---- Form ---- */
.form-group {
  margin-bottom: 20px;
  animation: fadeSlideUp 0.5s ease-out both;
}

.form-group:nth-child(2) { animation-delay: 0.15s; }

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input::placeholder {
  font-family: var(--font-mono);
  color: var(--text-muted);
  opacity: 0.7;
}

.form-group input:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(0, 168, 232, 0.15);
}

.form-group .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group .hint a {
  color: var(--blue-600);
  text-decoration: none;
}

.form-group .hint a:hover {
  text-decoration: underline;
}

/* ---- Button ---- */
.btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-600));
  border: none;
  border-radius: 6px;
  transition: transform 0.15s, box-shadow 0.25s, opacity 0.2s;
  animation: fadeSlideUp 0.5s ease-out 0.25s both;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 119, 204, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ---- Status ---- */
.status {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: #666;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
}

.status.visible { display: flex; }
.status.error { color: var(--danger); }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--blue-500);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.status.error .spinner { display: none; }

.status-contact {
  display: none;
  flex-basis: 100%;
  font-size: 13px;
  color: var(--text-muted);
}

.status-contact a { color: #6366f1; }

.status.error .status-contact { display: block; }

/* ---- Results ---- */
.results {
  margin-top: 24px;
  display: none;
}

.results.visible {
  display: block;
  animation: fadeSlideUp 0.4s ease-out;
}

/* Summary Cards */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.summary-card {
  background: var(--bg-white);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: fadeSlideUp 0.4s ease-out both;
}

.summary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.summary-card.highlight {
  background: linear-gradient(135deg, var(--blue-500), var(--blue-600));
}

.summary-card .value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--blue-600);
  letter-spacing: -0.5px;
}

.summary-card.highlight .value {
  color: #fff;
}

.summary-card .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.summary-card .subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.summary-card.highlight .label {
  color: rgba(255, 255, 255, 0.85);
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar .count {
  font-size: 14px;
  color: #666;
}

.btn-export {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue-600);
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: 6px;
  transition: background 0.2s, box-shadow 0.2s;
}

.btn-export:hover {
  background: var(--blue-hover);
  box-shadow: 0 2px 8px rgba(0, 119, 204, 0.1);
}

/* Table */
.table-wrap {
  overflow-x: auto;
  background: var(--bg-white);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead { background: #f5f7fa; }

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--text-secondary);
}

tbody tr {
  transition: background 0.15s;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child td {
  border-bottom: none;
}

td a {
  color: var(--blue-600);
  text-decoration: none;
  max-width: 320px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
}

td a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

td .dr-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  min-width: 32px;
  text-align: center;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--blue-50);
  color: var(--blue-600);
}

/* ---- Favorites Dialog ---- */
.dialog {
  margin: auto;
  border: none;
  border-radius: 10px;
  padding: 0;
  width: calc(100% - 32px);
  max-width: 520px;
  box-shadow: var(--shadow-md);
  color: var(--text);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.dialog-panel {
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-subtle);
}

.dialog-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.dialog-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.dialog-close:hover {
  color: var(--text);
  background: var(--border-light);
}

.dialog-body {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.dialog-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.fav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}

.fav-item:hover {
  background: #f8fafc;
}

.fav-item:last-child {
  border-bottom: none;
}

.fav-main {
  flex: 1;
  min-width: 0;
}

.fav-item .domain {
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
}

.fav-item .meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  font-family: var(--font-mono);
}

.fav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ---- Footer ---- */
.footer {
  width: 100%;
  text-align: center;
  padding: 20px 16px;
  font-size: 12px;
  color: var(--text-light);
}

.footer a { color: var(--blue-600); text-decoration: none; }

/* ---- Animations ---- */
@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }

  .sidebar.collapsed .sidebar-search,
  .sidebar.collapsed .sidebar-list,
  .sidebar.collapsed .sidebar-footer {
    display: none;
  }

  .sidebar-toggle {
    display: block;
  }

  .fav-item {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .header { padding: 10px 12px; }
  .header h1 { font-size: 15px; }
  .header h1 .subtitle { font-size: 12px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  td a { max-width: 180px; }
}
