/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #18181b;
  --bg-secondary: #1f1f23;
  --bg-tertiary: #27272a;
  --bg-elevated: #2d2d32;
  --violet: #8b5cf6;
  --violet-dark: #7c3aed;
  --violet-light: #a78bfa;
  --violet-glow: rgba(139, 92, 246, 0.15);
  --amber: #fbbf24;
  --amber-dark: #f59e0b;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border: #3f3f46;
  --border-light: #52525b;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --yellow: #fbbf24;
  --yellow-bg: rgba(251, 191, 36, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --orange: #f97316;
  --orange-bg: rgba(249, 115, 22, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
}

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

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

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

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--violet);
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-accent {
  color: var(--violet);
}

.tagline {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* === Search Section === */
.search-section {
  padding: 48px 0 32px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

.search-form {
  max-width: 720px;
  margin: 0 auto;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px 4px 4px 16px;
  transition: border-color 0.2s;
}

.search-input-wrap:focus-within {
  border-color: var(--violet);
  box-shadow: 0 0 0 4px var(--violet-glow);
}

.search-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

#keywordInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  padding: 12px;
  outline: none;
}

#keywordInput::placeholder {
  color: var(--text-muted);
}

.btn-primary {
  background: var(--violet);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.btn-primary:active {
  transform: scale(0.97);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--border-light);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8125rem;
}

.spinner {
  width: 18px;
  height: 18px;
  animation: spin 1s linear infinite;
}

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

/* === Loading State === */
.loading-state {
  padding: 64px 0;
}

.loading-inner {
  text-align: center;
}

.loading-inner h3 {
  margin-top: 20px;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.loading-inner p {
  color: var(--text-secondary);
  margin-top: 8px;
}

.loading-spinner-lg {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--violet);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

/* === Error State === */
.error-state {
  padding: 20px 0;
}

.error-inner {
  background: var(--red-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.error-inner p {
  color: var(--red);
  font-size: 0.9375rem;
}

/* === Summary Cards === */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.summary-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.summary-card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.summary-card .value {
  font-size: 1.5rem;
  font-weight: 700;
}

.summary-card .value.violet { color: var(--violet); }
.summary-card .value.amber { color: var(--amber); }
.summary-card .value.green { color: var(--green); }

/* === Toolbar === */
.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

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

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

.filter-group select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 28px 6px 10px;
  font-size: 0.8125rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--violet);
}

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

.result-count {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* === Domains Table === */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
}

.domains-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.domains-table thead {
  background: var(--bg-tertiary);
}

.domains-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: relative;
}

.domains-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.domains-table th.sortable:hover {
  color: var(--violet-light);
}

.domains-table th.sort-asc .sort-arrow::after { content: ' \2191'; color: var(--violet); }
.domains-table th.sort-desc .sort-arrow::after { content: ' \2193'; color: var(--violet); }

.domains-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.domains-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.domains-table tbody tr:hover {
  background: var(--violet-glow);
}

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

.domain-name {
  font-weight: 600;
  color: var(--violet-light);
}

.tld-badge {
  display: inline-block;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.6875rem;
  margin-left: 4px;
}

.da-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 24px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.8125rem;
}

.da-high { background: var(--green-bg); color: var(--green); }
.da-medium { background: var(--yellow-bg); color: var(--yellow); }
.da-low { background: var(--orange-bg); color: var(--orange); }
.da-very-low { background: var(--red-bg); color: var(--red); }

.rebuild-score {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rebuild-bar {
  width: 60px;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
}

.rebuild-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.rebuild-bar-fill.high { background: var(--green); }
.rebuild-bar-fill.medium { background: var(--amber); }
.rebuild-bar-fill.low { background: var(--red); }

.spam-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.spam-low { background: var(--green-bg); color: var(--green); }
.spam-medium { background: var(--yellow-bg); color: var(--yellow); }
.spam-high { background: var(--red-bg); color: var(--red); }

/* === Chart Section === */
.chart-section {
  margin-top: 32px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.chart-section h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.chart-container {
  max-width: 600px;
  margin: 0 auto;
}

/* === Deep Dive Panel === */
.deep-dive-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
  display: none;
  backdrop-filter: blur(4px);
}

.deep-dive-overlay.active { display: block; }

.deep-dive-panel {
  position: fixed;
  top: 0;
  right: -500px;
  width: 480px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 100;
  overflow-y: auto;
  transition: right 0.3s ease;
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}

.deep-dive-panel.active { right: 0; }

.deep-dive-content {
  padding: 32px 24px;
}

.deep-dive-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.deep-dive-close:hover {
  background: var(--bg-elevated);
}

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

.dd-domain-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--violet-light);
  margin-bottom: 4px;
  word-break: break-all;
}

.dd-previous-use {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.dd-score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.dd-stat {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 14px;
}

.dd-stat .label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.dd-stat .value {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 2px;
}

.dd-section {
  margin-bottom: 20px;
}

.dd-section h4 {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.dd-rebuild-score {
  text-align: center;
  padding: 20px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.dd-rebuild-number {
  font-size: 3rem;
  font-weight: 800;
}

.dd-rebuild-number.high { color: var(--green); }
.dd-rebuild-number.medium { color: var(--amber); }
.dd-rebuild-number.low { color: var(--red); }

.dd-rebuild-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.dd-rebuild-explanation {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-primary);
  border-radius: var(--radius);
}

.dd-backlink-list {
  list-style: none;
}

.dd-backlink-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  margin-bottom: 6px;
}

.dd-backlink-source {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.875rem;
}

.dd-backlink-anchor {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.dd-backlink-da {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--violet);
  background: var(--violet-glow);
  padding: 2px 8px;
  border-radius: 4px;
}

.dd-recommendation {
  background: var(--violet-glow);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-primary);
}

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

.dd-meta-item {
  font-size: 0.8125rem;
}

.dd-meta-item .meta-label {
  color: var(--text-muted);
}

.dd-meta-item .meta-value {
  color: var(--text-primary);
  font-weight: 600;
}

/* === History Section === */
.history-section {
  padding: 48px 0;
}

.section-title {
  font-size: 1.25rem;
  margin-bottom: 20px;
  color: var(--text-secondary);
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.history-empty {
  color: var(--text-muted);
  font-size: 0.875rem;
  grid-column: 1 / -1;
}

.history-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.history-card:hover {
  border-color: var(--violet);
  background: var(--violet-glow);
}

.history-keyword {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 4px;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* === Signup Section === */
.signup-section {
  padding: 0 0 64px;
}

.signup-card {
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  max-width: 560px;
  margin: 0 auto;
}

.signup-card h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.signup-card > p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.signup-form {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.signup-form input {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 12px 16px;
  font-size: 0.9375rem;
  flex: 1;
  max-width: 320px;
  outline: none;
}

.signup-form input:focus {
  border-color: var(--violet);
}

.signup-message {
  margin-top: 12px;
  font-size: 0.875rem;
}

.signup-message.success { color: var(--green); }
.signup-message.error { color: var(--red); }

/* === Footer === */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* === Results Section === */
.results-section {
  padding: 0 0 32px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-input-wrap {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }

  .search-icon { display: none; }

  #keywordInput {
    width: 100%;
    padding: 12px;
  }

  .btn-primary {
    width: 100%;
    justify-content: center;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .filters {
    flex-direction: column;
  }

  .summary-cards {
    grid-template-columns: 1fr 1fr;
  }

  .dd-score-grid {
    grid-template-columns: 1fr;
  }

  .deep-dive-panel {
    width: 100vw;
    max-width: 100vw;
  }

  .domains-table {
    font-size: 0.8125rem;
  }

  .domains-table th,
  .domains-table td {
    padding: 8px 10px;
  }

  .signup-form {
    flex-direction: column;
    align-items: stretch;
  }

  .signup-form input {
    max-width: none;
  }

  .history-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .container {
    padding: 0 12px;
  }

  .search-section {
    padding: 32px 0 24px;
  }
}
