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

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #273347;
  --border:    #334155;
  --border2:   #3f526b;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --text-dim:  #64748b;
  --accent:    #6366f1;
  --accent-h:  #818cf8;
  --cyan:      #22d3ee;
  --green:     #4ade80;
  --yellow:    #fbbf24;
  --red:       #f87171;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
}

html, body { height: 100%; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 16px;
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.tagline {
  color: var(--text-muted);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 260px 1fr;
  gap: 16px;
  height: calc(100vh - 110px);
  min-height: 480px;
  flex-shrink: 0;
}

/* ── Panels ───────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}

.panel-head h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.input-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
}

/* ── Input Panel ──────────────────────────────────────────── */
#inputText {
  flex: 1;
  resize: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.7;
  padding: 14px 16px;
  width: 100%;
}

#inputText::placeholder { color: var(--text-dim); }

/* ── Extractor Panel ──────────────────────────────────────── */
.panel-extractors { overflow-y: auto; }

.extractor-groups {
  padding: 8px 0;
  overflow-y: auto;
  flex: 1;
}

.extractor-group {
  padding: 6px 0;
}

.group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 6px 16px 4px;
}

.extractor-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background .12s;
  user-select: none;
}

.extractor-item:hover { background: var(--surface2); }

.extractor-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.extractor-icon { font-size: 14px; flex-shrink: 0; }

.extractor-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.extractor-item--custom { padding-bottom: 2px; }

.custom-input-area {
  padding: 4px 16px 10px 41px;
  display: none;
  flex-direction: column;
  gap: 4px;
}

.custom-input-area.active { display: flex; }

.custom-text-input {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: monospace;
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  width: 100%;
  transition: border-color .15s;
}

.custom-text-input:focus { border-color: var(--accent); }
.custom-text-input.error  { border-color: var(--red); }
.custom-text-input.valid  { border-color: var(--green); }

.custom-hint {
  font-size: 11px;
  color: var(--text-dim);
}
.custom-hint.error { color: var(--red); }
.custom-hint.valid { color: var(--green); }

/* ── Profile Bar ──────────────────────────────────────────── */
.profile-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px 6px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.profile-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-right: 2px;
}

.profile-btn {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  transition: border-color .12s, color .12s, background .12s;
  white-space: nowrap;
}

.profile-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.profile-btn--active {
  background: rgba(99,102,241,.18);
  border-color: var(--accent);
  color: var(--accent-h);
}

/* ── Group Note ───────────────────────────────────────────── */
.group-note {
  font-size: 10px;
  color: var(--yellow);
  padding: 2px 16px 6px 41px;
  opacity: .75;
}

/* ── Collapsible Groups ───────────────────────────────────── */
.extractor-group { padding: 0; }

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 16px 6px;
  text-align: left;
}

.group-chevron {
  font-size: 10px;
  color: var(--text-dim);
  transition: transform .15s;
  width: 10px;
}

.extractor-group.collapsed .group-chevron { transform: rotate(-90deg); }

.group-name {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  flex: 1;
}

.group-count {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-h);
  background: rgba(99,102,241,.18);
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}

.group-header:hover .group-name { color: var(--text); }

.extractor-group.collapsed .group-body { display: none; }

/* New label class used by dynamic panel */
.extractor-label {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

/* Inline custom input area (dynamic) */
.custom-area {
  padding: 4px 16px 10px 41px;
  display: none;
  flex-direction: column;
  gap: 4px;
}
.custom-area.active { display: flex; }

/* ── Extractor Search ─────────────────────────────────────── */
.extractor-search {
  position: relative;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#extractorSearch {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  padding: 6px 28px 6px 10px;
  outline: none;
  transition: border-color .15s;
}

#extractorSearch:focus { border-color: var(--accent); }

.search-clear {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12px;
  user-select: none;
}
.search-clear:hover { color: var(--text); }

/* ── Output Panel ─────────────────────────────────────────── */
.panel-output {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.result-count {
  font-size: 12px;
  color: var(--text-dim);
  margin-right: 4px;
}

.results-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 40px 20px;
}

/* ── Result Cards ─────────────────────────────────────────── */
.result-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.result-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.result-card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

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

.card-copy-btn {
  opacity: 0;
  transition: opacity .15s;
}

.result-card:hover .card-copy-btn:not(:disabled) {
  opacity: 1;
}

.card-copy-btn:focus-visible {
  opacity: 1;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
}

.result-badge.zero { background: var(--border2); color: var(--text-dim); }

.result-items {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.result-item {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  color: var(--cyan);
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  word-break: break-all;
}

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

.result-item--context {
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
}

.result-item mark {
  background: rgba(250, 204, 21, .25);
  color: var(--yellow);
  border-radius: 2px;
  padding: 0 2px;
}

.result-empty {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  padding: 4px 0;
}

/* ── Status bar ───────────────────────────────────────────── */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-bar.hidden { display: none; }
.perf-msg { color: var(--text-dim); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 10px;
  transition: border-color .12s, color .12s, background .12s;
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(99,102,241,.08);
}

.btn-ghost:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  transition: background .12s;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-sm { height: 26px; }

/* ── Scrollbars ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── SEO / Content Section ────────────────────────────────── */
.content {
  margin-top: 8px;
  padding: 8px 0 48px;
  color: var(--text-muted);
}

.content-block { margin-bottom: 36px; }

.content h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  letter-spacing: -.01em;
}

.content h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.content p {
  font-size: 14px;
  line-height: 1.7;
  max-width: 820px;
}

.content strong { color: var(--text); font-weight: 600; }

.content code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--cyan);
  white-space: nowrap;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.content-card p { font-size: 13px; }

.content-list {
  list-style: none;
  display: grid;
  gap: 8px;
  max-width: 820px;
}

.content-list li {
  font-size: 14px;
  line-height: 1.6;
  padding-left: 22px;
  position: relative;
}

.content-list li::before {
  content: '▸';
  position: absolute;
  left: 4px;
  color: var(--accent);
}

.faq {
  display: grid;
  gap: 10px;
  max-width: 820px;
}

.faq details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  transition: border-color .15s;
}

.faq details[open] { border-color: var(--border2); }

.faq summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  padding: 13px 0;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq summary::-webkit-details-marker { display: none; }

.faq summary::after {
  content: '+';
  font-size: 18px;
  color: var(--text-dim);
  font-weight: 400;
  transition: transform .15s;
}

.faq details[open] summary::after { transform: rotate(45deg); }

.faq details p {
  padding: 0 0 14px;
  font-size: 13px;
}

.content-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.content-footer p { font-size: 12px; color: var(--text-dim); margin: 0 auto; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 320px auto 480px;
    height: auto;
  }
}
