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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --surface3: #2d333b;
  --border: #30363d;
  --border-strong: #444c56;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-subtle: #6e7681;
  --accent: #58a6ff;
  --accent-dim: rgba(88, 166, 255, 0.15);
  --green: #3fb950;
  --green-dim: rgba(63, 185, 80, 0.15);
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App Shell ─────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header .logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.app-header .logo span { color: var(--accent); }

.app-header .header-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}

.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 49px);
}

/* ─── Form Panel ─────────────────────────────────────────── */
.form-panel {
  width: 380px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.form-panel::-webkit-scrollbar { width: 4px; }
.form-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── Collapsible Sections ───────────────────────────────── */
.form-section {
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.section-header:hover { background: var(--surface); }

.section-header .section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.toggle-icon {
  font-size: 0.65rem;
  color: var(--text-subtle);
  transition: transform 0.2s;
}

.section-body {
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.section-body.collapsed { display: none; }

/* ─── Form Elements ──────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.3rem; }

label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"],
input[type="email"],
textarea,
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  width: 100%;
  transition: border-color 0.15s, background 0.15s;
  outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  background: var(--surface);
}

input::placeholder,
textarea::placeholder { color: var(--text-subtle); }

textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.5;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
  cursor: pointer;
}

/* ─── Skills Panel ───────────────────────────────────────── */
.skills-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.skills-search {
  position: relative;
}

.skills-search input {
  padding-left: 1.75rem;
}

.skills-search::before {
  content: '🔍';
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  pointer-events: none;
}

.cat-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.cat-filter {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
}

.cat-filter:hover { border-color: var(--accent); color: var(--accent); }
.cat-filter.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.skills-category-header {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  padding: 0.5rem 0 0.25rem;
  width: 100%;
}

#skills-grid {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding-right: 2px;
}

#skills-grid::-webkit-scrollbar { width: 3px; }
#skills-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.skill-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
}

.skill-item:hover { background: var(--surface2); }
.skill-item.checked { background: var(--accent-dim); }

.skill-item input[type="checkbox"] { display: none; }

.skill-item img {
  height: 20px;
  flex-shrink: 0;
}

.skill-item span {
  font-size: 0.8rem;
  color: var(--text-muted);
  user-select: none;
}

.skill-item.checked span { color: var(--text); }

.no-results {
  color: var(--text-subtle);
  font-size: 0.8rem;
  padding: 1rem;
  text-align: center;
}

/* ─── Social Inputs ──────────────────────────────────────── */
.social-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.social-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.social-icon-badge {
  height: 16px;
}

/* ─── Stats Options ──────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}

.toggle-row:hover { background: var(--surface2); border-color: var(--border); }

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

.toggle-row span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ─── Preview Panel ──────────────────────────────────────── */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.preview-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: var(--font);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  transition: all 0.15s;
}

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

.tab-btn.active {
  background: var(--surface2);
  border-color: var(--border-strong);
  color: var(--text);
}

.toolbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#char-count {
  font-size: 0.72rem;
  color: var(--text-subtle);
  font-family: var(--mono);
}

.action-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font);
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.action-btn:hover { background: var(--surface3); border-color: var(--border-strong); color: var(--text); }

.action-btn.primary {
  background: var(--green-dim);
  border-color: var(--green);
  color: var(--green);
}

.action-btn.primary:hover { background: rgba(63, 185, 80, 0.25); }

.preview-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

.hidden { display: none !important; }

/* ─── Raw Output ─────────────────────────────────────────── */
#output-raw {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: #79c0ff;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  padding: 1rem;
  white-space: pre;
  overflow: auto;
}

/* ─── Markdown Preview ───────────────────────────────────── */
#md-preview {
  padding: 1.5rem 2rem;
  max-width: 860px;
  margin: 0 auto;
  color: var(--text);
}

#md-preview h1 {
  font-size: 1.8rem;
  font-weight: 700;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

#md-preview h2, #md-preview h3 {
  margin: 1.25rem 0 0.5rem;
  font-weight: 600;
}

#md-preview h2 { font-size: 1.3rem; }
#md-preview h3 { font-size: 1.1rem; }

#md-preview p { margin: 0.5rem 0; }

#md-preview ul {
  padding-left: 1.25rem;
  margin: 0.5rem 0;
}

#md-preview li { margin: 0.25rem 0; }

#md-preview img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  margin: 0.15rem;
}

#md-preview a { color: var(--accent); }

#md-preview code {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.35em;
  font-family: var(--mono);
  font-size: 0.85em;
}

#md-preview pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  margin: 0.75rem 0;
}

#md-preview pre code {
  background: none;
  border: none;
  padding: 0;
}

#md-preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

#md-preview blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 0.75rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
}

/* ─── HTML iframe Preview ────────────────────────────────── */
#html-preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #0d1117;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; height: auto; overflow: visible; }
  .form-panel { width: 100%; border-right: none; border-bottom: 1px solid var(--border); overflow: visible; }
  .app-header .header-meta { display: none; }
  #output-raw { min-height: 300px; }
  #html-preview-frame { min-height: 500px; }
}
