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

/* ── Dark Theme (default) ───────────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2129;
  --bg-card: #161b22;
  --bg-card-hover: #1c2129;
  --bg-card-selected: #0d1926;
  --bg-input: #0d1117;
  --bg-modal-overlay: rgba(1, 4, 9, 0.7);

  --border-default: #30363d;
  --border-muted: #21262d;
  --border-accent: #58a6ff;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --text-accent: #58a6ff;
  --text-on-accent: #ffffff;
  --text-code: #e6edf3;
  --text-comment: #8b949e;

  --accent: #58a6ff;
  --accent-emphasis: #1f6feb;
  --accent-muted: rgba(56, 139, 253, 0.15);

  --cat-language: #79c0ff;
  --cat-language-bg: rgba(121, 192, 255, 0.12);
  --cat-framework: #7ee787;
  --cat-framework-bg: rgba(126, 231, 135, 0.12);
  --cat-tool: #ffa657;
  --cat-tool-bg: rgba(255, 166, 87, 0.12);

  --tooltip-bg: #1c2129;
  --tooltip-border: #30363d;
  --tooltip-text: #e6edf3;
}

/* ── Light Theme ────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --bg-card: #ffffff;
  --bg-card-hover: #f3f4f6;
  --bg-card-selected: #eff6ff;
  --bg-input: #ffffff;
  --bg-modal-overlay: rgba(110, 118, 129, 0.4);

  --border-default: #d0d7de;
  --border-muted: #d8dee4;
  --border-accent: #0969da;

  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8c959f;
  --text-accent: #0969da;
  --text-on-accent: #ffffff;
  --text-code: #1f2328;
  --text-comment: #656d76;

  --accent: #0969da;
  --accent-emphasis: #0969da;
  --accent-muted: rgba(9, 105, 218, 0.1);

  --cat-language: #0550ae;
  --cat-language-bg: rgba(9, 105, 218, 0.08);
  --cat-framework: #1a7f37;
  --cat-framework-bg: rgba(26, 127, 55, 0.08);
  --cat-tool: #953800;
  --cat-tool-bg: rgba(149, 56, 0, 0.08);

  --tooltip-bg: #1f2328;
  --tooltip-border: #30363d;
  --tooltip-text: #ffffff;
}

/* ── Shared Variables ───────────────────────────────────────── */
:root {
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-tooltip: 0 4px 16px rgba(0, 0, 0, 0.3);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;

  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  transition: background-color var(--transition), color var(--transition);
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  border-bottom: 1px solid var(--border-default);
  padding: 1.25rem 2rem;
  transition: border-color var(--transition);
  flex-shrink: 0;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  flex-direction: column;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

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

.subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.125rem;
}

/* ── Layout ──────────────────────────────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: background-color var(--transition), border-color var(--transition);
}

/* ── Presets ─────────────────────────────────────────────────── */
.presets-section {
  border-bottom: 1px solid var(--border-muted);
}

.presets-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
}

.presets-row .section-label {
  flex-shrink: 0;
}

.presets-select-wrapper {
  position: relative;
  flex: 1;
  max-width: 260px;
}

.presets-select {
  width: 100%;
  padding: 0.4rem 1.75rem 0.4rem 0.625rem;
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.presets-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.presets-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.presets-chevron {
  position: absolute;
  right: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* ── Controls Row ────────────────────────────────────────────── */
.controls-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-muted);
}

.search-wrapper {
  flex: 1;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

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

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.selected-count {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Bulk Actions ────────────────────────────────────────────── */
.bulk-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-muted);
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}

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

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.btn-primary {
  background: var(--accent-emphasis);
  border-color: var(--accent-emphasis);
  color: var(--text-on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-icon {
  flex-shrink: 0;
}

.btn-icon-only {
  padding: 0.375rem;
}

.btn-copied {
  background: rgba(46, 160, 67, 0.15) !important;
  border-color: #2ea043 !important;
  color: #3fb950 !important;
}

[data-theme="light"] .btn-copied {
  background: rgba(26, 127, 55, 0.1) !important;
  border-color: #1a7f37 !important;
  color: #1a7f37 !important;
}

/* ── Tech Grid ───────────────────────────────────────────────── */
.tech-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.625rem;
  padding: 1rem 1.25rem 1.25rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.tech-grid::-webkit-scrollbar {
  width: 6px;
}

.tech-grid::-webkit-scrollbar-track {
  background: transparent;
}

.tech-grid::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

/* ── Tech Card ───────────────────────────────────────────────── */
.tech-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.tech-card:hover {
  border-color: var(--border-default);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.tech-card.selected {
  border-color: var(--accent);
  background: var(--bg-card-selected);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.tech-card.selected .tech-name {
  color: var(--text-accent);
}

.tech-card.hidden {
  display: none;
}

.tech-card input[type="checkbox"] {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  pointer-events: none;
}

.tech-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  padding-right: 1.25rem;
}

.tech-category {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  width: fit-content;
  text-transform: capitalize;
}

.tech-category[data-category="Language"] {
  color: var(--cat-language);
  background: var(--cat-language-bg);
}

.tech-category[data-category="Framework"] {
  color: var(--cat-framework);
  background: var(--cat-framework-bg);
}

.tech-category[data-category="Tool"] {
  color: var(--cat-tool);
  background: var(--cat-tool-bg);
}

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

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-muted);
  background: var(--bg-tertiary);
  transition: background-color var(--transition);
}

.output-filename {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.output-actions {
  display: flex;
  gap: 0.5rem;
}

.output-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.output-area::-webkit-scrollbar {
  width: 6px;
}

.output-area::-webkit-scrollbar-track {
  background: transparent;
}

.output-area::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

.output-code {
  padding: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.65;
  color: var(--text-code);
  white-space: pre;
  overflow-x: auto;
  min-height: 100%;
  tab-size: 2;
}

.output-code .empty-state {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  gap: 0.5rem;
  text-align: center;
}

.output-code .empty-state svg {
  opacity: 0.3;
}

.output-line {
  position: relative;
  display: block;
  line-height: 1.65;
}

.output-line.comment {
  color: var(--text-comment);
  font-weight: 600;
}

.output-line.pattern {
  cursor: help;
  border-radius: 2px;
  transition: background-color var(--transition);
}

.output-line.pattern:hover {
  background: var(--accent-muted);
}

/* ── Tooltip ─────────────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 1000;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  line-height: 1.4;
  color: var(--tooltip-text);
  background: var(--tooltip-bg);
  border: 1px solid var(--tooltip-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-tooltip);
  pointer-events: none;
  max-width: 280px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(4px);
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay:not([hidden]) {
  opacity: 1;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-desc {
  padding: 1rem 1.25rem 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-desc code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: var(--bg-tertiary);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
}

.import-textarea {
  display: block;
  margin: 1rem 1.25rem;
  width: calc(100% - 2.5rem);
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}

.import-textarea::placeholder {
  color: var(--text-muted);
}

.import-textarea:focus {
  border-color: var(--accent);
}

.import-detect-result {
  margin: 0 1.25rem;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  border-radius: var(--radius-md);
  background: var(--accent-muted);
  border: 1px solid var(--accent);
  color: var(--text-primary);
}

.import-detect-result[hidden] {
  display: none;
}

.import-detect-result .detected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.import-detect-result .detected-tag {
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 999px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-muted);
}

/* ── Copied Toast ────────────────────────────────────────────── */
.btn-copied {
  background: rgba(46, 160, 67, 0.15) !important;
  border-color: #2ea043 !important;
  color: #3fb950 !important;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 1rem;
  }

  .tech-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .output-area {
    max-height: none;
  }

  .output-actions .btn span {
    display: none;
  }

  .output-actions .btn {
    padding: 0.375rem 0.5rem;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 1rem;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .header-right {
    width: 100%;
    justify-content: flex-end;
  }

  .container {
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .selected-count {
    text-align: center;
  }

  .bulk-actions {
    padding: 0.5rem 1rem;
  }

  .tech-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    padding: 0.75rem 1rem 1rem;
  }

  .presets-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .presets-select-wrapper {
    max-width: none;
  }

  .output-header {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .output-actions {
    width: 100%;
  }

  .output-actions .btn {
    flex: 1;
    justify-content: center;
    padding: 0.5rem 0.75rem;
  }

  .output-actions .btn span {
    display: inline;
  }
}

/* ── Focus Visible ───────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible {
  outline-offset: 2px;
}

/* ── Print ───────────────────────────────────────────────────── */
@media print {
  .header,
  .selectors,
  .output-header {
    display: none;
  }

  .panel {
    border: none;
    background: #fff;
  }

  .output-code {
    color: #000;
    background: #fff;
  }
}
