:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6c757d;
  --primary: #4361ee;
  --primary-hover: #3a56d4;
  --border: #dee2e6;
  --error-bg: #fff5f5;
  --error-text: #c92a2a;
  --code-bg: #f1f3f5;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --primary: #58a6ff;
    --primary-hover: #79b8ff;
    --border: #30363d;
    --error-bg: #3d1a1a;
    --error-text: #f87171;
    --code-bg: #1c2128;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

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

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

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* Input bar */
.input-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.input-bar input[type="url"] {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.input-bar input[type="url"]:focus {
  border-color: var(--primary);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
}

#extractBtn {
  padding: 0.6rem 1.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

#extractBtn:hover {
  background: var(--primary-hover);
}

#extractBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Error */
.error {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  color: var(--text-secondary);
}

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

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

/* Tabs */
.results {
  margin-top: 1.5rem;
}

.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  gap: 0;
}

.tab {
  padding: 0.5rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

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

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
  padding: 1.25rem 0;
}

.tab-panel.active {
  display: block;
}

.panel-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

/* Content toggle */
.content-toggle {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.toggle-btn {
  padding: 0.3rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.toggle-btn:hover {
  color: var(--text);
}

.toggle-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Metadata card */
.meta-card {
  display: grid;
  gap: 0.75rem;
}

.meta-row {
  display: flex;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.meta-label {
  flex-shrink: 0;
  width: 120px;
  font-weight: 600;
  color: var(--text-secondary);
}

.meta-value {
  flex: 1;
  word-break: break-word;
}

.meta-value a {
  color: var(--primary);
  text-decoration: none;
}

.meta-value a:hover {
  text-decoration: underline;
}

.meta-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
  margin-top: 0.5rem;
}

.meta-section-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* Prose (markdown content) */
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.prose p {
  margin-bottom: 0.75rem;
}

.prose img {
  max-width: 100%;
  border-radius: var(--radius);
}

.prose pre {
  background: var(--code-bg);
  padding: 0.75rem;
  border-radius: var(--radius);
  overflow-x: auto;
}

.prose code {
  background: var(--code-bg);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  font-size: 0.85em;
}

.prose pre code {
  background: none;
  padding: 0;
}

.prose a {
  color: var(--primary);
}

.prose blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--text-secondary);
  margin: 0.75rem 0;
}

.prose ul, .prose ol {
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
}

.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
}

/* Raw JSON */
#rawContent pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.82rem;
  line-height: 1.5;
}

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 1rem 0.75rem;
  }

  header h1 {
    font-size: 1.35rem;
  }

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

  .input-bar input[type="url"] {
    min-width: 0;
  }

  .checkbox-label {
    align-self: flex-start;
  }

  #extractBtn {
    width: 100%;
  }

  .meta-row {
    flex-direction: column;
    gap: 0.15rem;
  }

  .meta-label {
    width: auto;
  }
}
