:root {
  --bg-dark: #090c15;
  --bg-card: #121826;
  --bg-card-hover: #182033;
  --bg-input: #1a2235;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);

  --accent-emerald: #10b981;
  --accent-cyan: #06b6d4;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --shadow-main: 0 12px 32px rgba(0, 0, 0, 0.4);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: #1f293d;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #374151;
}

/* Header */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: rgba(18, 24, 38, 0.7);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 1.6rem;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-text .title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge-pro {
  font-size: 0.65rem;
  font-weight: 700;
  background: linear-gradient(90deg, #6366f1, #ec4899);
  color: #fff;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.brand-text .subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  box-shadow: 0 4px 16px var(--primary-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-large {
  padding: 0.85rem 1.8rem;
  font-size: 1rem;
  border-radius: var(--radius-md);
  width: 100%;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.btn-icon:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* App Layout */
.app-layout {
  display: flex;
  flex: 1;
  position: relative;
}

/* History Drawer */
.history-drawer {
  width: 320px;
  background: var(--bg-dark);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 73px);
  position: sticky;
  top: 73px;
  z-index: 90;
  flex-shrink: 0;
  transition: var(--transition);
}

.history-drawer.closed {
  margin-left: -320px;
}

.drawer-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
}

.history-list {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 0.85rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.history-item:hover {
  border-color: var(--primary);
  background: var(--bg-card-hover);
  transform: translateX(3px);
}

.history-item.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.15);
}

.history-item .item-kw {
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  margin-bottom: 2px;
}

.history-item .item-url {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.btn-delete-item {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-delete-item:hover {
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.15);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-main);
}

.card-header {
  margin-bottom: 1.5rem;
}
.card-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
}
.card-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}
.form-group.full-width {
  grid-column: span 2;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}
.required {
  color: var(--accent-rose);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-with-action {
  position: relative;
  display: flex;
  align-items: center;
}
.btn-icon-inside {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0.7;
}

.help-text {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}
.help-text a {
  color: var(--accent-cyan);
  text-decoration: none;
}

.form-actions {
  margin-top: 1.5rem;
}

/* Loading state */
.loading-status {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  margin-bottom: 2rem;
}
.pulse-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid var(--primary);
  border-top-color: transparent;
  animation: spin 1s linear infinite;
  margin: 0 auto 1.5rem auto;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Metrics Dashboard */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.tag-keyword {
  display: inline-block;
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 6px;
}

.results-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
}
.res-url {
  font-size: 0.9rem;
  color: var(--accent-cyan);
  text-decoration: none;
}

.timestamp-badge {
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
}
.metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.15);
}

.metric-icon {
  font-size: 1.6rem;
  width: 46px;
  height: 46px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.metric-data {
  display: flex;
  flex-direction: column;
}
.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}
.metric-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* Tabs */
.tabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: var(--transition);
}
.tab-btn:hover {
  color: #fff;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}

/* Gaps List & Pills */
.gaps-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.gap-detail-card h3 {
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 4px;
}
.card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.gaps-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.gap-item {
  background: var(--bg-input);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-left: 3px solid var(--accent-rose);
}

.gap-item .gap-title {
  font-size: 0.9rem;
  font-weight: 500;
}

.badge-urr {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 700;
}
.badge-urr.ROOT {
  background: rgba(244, 63, 94, 0.2);
  color: var(--accent-rose);
}
.badge-urr.RARE {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent-amber);
}

/* Pills cloud */
.pills-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.term-pill {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.term-pill .comp-badge {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary);
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.card.full-width {
  grid-column: span 2;
}

.subgaps-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.subhead {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.simple-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.simple-list li {
  font-size: 0.85rem;
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent-cyan);
}

/* Code box & Markdown Renderer */
.code-box {
  background: #080b12;
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  font-family: monospace;
  font-size: 0.85rem;
  color: #e5e7eb;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 450px;
  overflow-y: auto;
}

.card-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.markdown-body {
  color: #e5e7eb;
  line-height: 1.7;
  font-size: 0.95rem;
}

.markdown-body h1 {
  font-size: 1.6rem;
  color: #fff;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
}

.markdown-body h2 {
  font-size: 1.3rem;
  color: var(--primary);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.markdown-body h3 {
  font-size: 1.1rem;
  color: var(--accent-cyan);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.markdown-body h4 {
  font-size: 0.95rem;
  color: var(--accent-emerald);
  margin-top: 1rem;
  margin-bottom: 0.4rem;
}

.markdown-body p {
  margin-bottom: 1rem;
}

.markdown-body ul, .markdown-body ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.markdown-body li {
  margin-bottom: 0.3rem;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
}

.markdown-body th, .markdown-body td {
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.markdown-body th {
  background: var(--bg-input);
  color: #fff;
}

.markdown-body code {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85rem;
}

.markdown-body pre {
  background: #080b12;
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 1rem 0;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: #e5e7eb;
}

.content-preview-box {
  max-height: 600px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

/* Data table */
.table-container {
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}
.data-table th {
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
}
.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.status-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}
.status-badge.ok {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-emerald);
}
.status-badge.fail {
  background: rgba(244, 63, 94, 0.2);
  color: var(--accent-rose);
}
