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

:root {
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --text:         #111827;
  --text-muted:   #6b7280;
  --text-light:   #9ca3af;
  --bg:           #ffffff;
  --bg-sidebar:   #f9fafb;
  --bg-hover:     #f3f4f6;
  --border:       #e5e7eb;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --radius:       10px;
  --sidebar-w:    240px;
  --header-h:     60px;
}

html { font-size: 16px; }

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

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
  text-decoration: none;
}

.logo-icon {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.search-wrap {
  flex: 1;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 8px 12px 8px 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--bg-sidebar);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

#search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  background: var(--bg);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
  color: var(--text-muted);
  background: transparent;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 24px 12px;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-light);
  padding: 0 8px;
  margin-bottom: 8px;
}

#category-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cat-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: left;
  transition: background .12s, color .12s;
}
.cat-btn:hover { background: var(--bg-hover); color: var(--text); }
.cat-btn.active { background: #eff6ff; color: var(--primary); font-weight: 600; }

.cat-count {
  background: var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 22px;
  text-align: center;
}
.cat-btn.active .cat-count { background: #dbeafe; color: var(--primary); }

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 32px 36px;
  min-width: 0;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.content-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

#result-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Card Grid ────────────────────────────────────────────────────────────── */
#sop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.sop-card {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s, border-color .15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.sop-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: #d1d5db;
}

.card-header { margin-bottom: 10px; }

.cat-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.4;
}

.card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-light);
}

.meta-author { font-weight: 500; color: var(--text-muted); }

/* ── Skeleton ─────────────────────────────────────────────────────────────── */
.card-skeleton {
  height: 160px;
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 1.1rem; margin-bottom: 6px; color: var(--text); }

/* ── Error Banner ─────────────────────────────────────────────────────────── */
.error-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 16px 20px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  grid-column: 1 / -1;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal {
  background: var(--bg);
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(0,0,0,.18);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.05rem; font-weight: 700; }
.modal-close { color: var(--text-muted); font-size: 1.2rem; padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg-hover); color: var(--text); }

.modal-body { padding: 20px 24px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; letter-spacing: .02em; }

input[type=text], input[type=password] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.field-hint { font-size: 0.75rem; color: var(--text-light); margin-top: 4px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
}

.cfg-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}

/* ── Drop Zone ────────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-bottom: 16px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}
.drop-zone p { color: var(--text-muted); font-size: 0.9rem; }
.drop-zone strong { color: var(--primary); }

.upload-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.upload-item:last-child { border-bottom: none; }
.upload-filename { font-size: 0.85rem; font-weight: 500; }
.upload-title-preview { font-size: 0.8rem; color: var(--text-muted); margin-left: 4px; }
.warn-tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 20px; background: #fef3c7; color: #92400e; font-weight: 600; }
.upload-item-info { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

#upload-progress { font-size: 0.85rem; color: var(--text-muted); padding: 8px 0; }

/* ── SOP Detail Page ──────────────────────────────────────────────────────── */
.detail-layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  gap: 40px;
}

.detail-sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 32px 0;
  position: sticky;
  top: var(--header-h);
  height: fit-content;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 28px;
  padding: 6px 10px;
  border-radius: 7px;
  transition: background .12s, color .12s;
}
.back-link:hover { background: var(--bg-hover); color: var(--text); }

#toc { border-top: 1px solid var(--border); padding-top: 16px; }
.toc-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 10px;
}
#toc ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }
#toc a {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: block;
  padding: 4px 8px;
  border-radius: 5px;
  line-height: 1.4;
  transition: background .1s, color .1s;
}
#toc a:hover { background: var(--bg-hover); color: var(--text); }
.toc-h3 > a { padding-left: 18px; font-size: 0.78rem; }

/* ── SOP Article ──────────────────────────────────────────────────────────── */
.detail-article {
  flex: 1;
  min-width: 0;
  padding: 40px 0;
}

.breadcrumb {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--primary); }
.breadcrumb a:hover { text-decoration: underline; }
.crumb-sep { color: var(--text-light); }
.crumb-current { color: var(--text-muted); }

.sop-header { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }

#sop-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 10px;
}

#sop-desc {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

#sop-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── Markdown Body ────────────────────────────────────────────────────────── */
#sop-body { font-size: 1rem; line-height: 1.75; color: var(--text); }

#sop-body h1 { font-size: 1.75rem; font-weight: 800; margin: 40px 0 16px; }
#sop-body h2 { font-size: 1.35rem; font-weight: 700; margin: 36px 0 12px; padding-top: 8px; border-top: 1px solid var(--border); }
#sop-body h3 { font-size: 1.1rem; font-weight: 600; margin: 24px 0 8px; color: var(--text); }
#sop-body h4 { font-size: 0.95rem; font-weight: 600; margin: 18px 0 6px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

#sop-body p { margin-bottom: 14px; }
#sop-body strong { font-weight: 700; }
#sop-body em { font-style: italic; }

#sop-body ul, #sop-body ol { margin: 14px 0 14px 24px; }
#sop-body li { margin-bottom: 6px; }

/* Styled step list */
#sop-body ol.step-list { list-style: none; margin-left: 0; counter-reset: step-counter; }
#sop-body ol.step-list > li {
  counter-increment: step-counter;
  position: relative;
  padding: 14px 16px 14px 56px;
  margin-bottom: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color .15s;
}
#sop-body ol.step-list > li:hover { border-color: #d1d5db; }
#sop-body ol.step-list > li::before {
  content: counter(step-counter);
  position: absolute;
  left: 14px;
  top: 14px;
  width: 26px;
  height: 26px;
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#sop-body a { color: var(--primary); text-decoration: underline; }
#sop-body a:hover { color: var(--primary-dark); }

#sop-body blockquote {
  border-left: 3px solid var(--primary);
  padding: 10px 16px;
  margin: 18px 0;
  background: #eff6ff;
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
}

#sop-body code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.85em;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  color: #be123c;
}

#sop-body pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 18px 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 18px 0;
  font-size: 0.875rem;
  line-height: 1.6;
}
#sop-body pre code { background: none; padding: 0; color: inherit; font-size: inherit; }

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,.12);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background .15s;
}
.copy-btn:hover { background: rgba(255,255,255,.22); }

#sop-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 0.9rem;
}
#sop-body th {
  background: var(--bg-sidebar);
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  color: var(--text);
}
#sop-body td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
#sop-body tr:hover td { background: var(--bg-sidebar); }

/* ── Screenshots ──────────────────────────────────────────────────────────── */
figure.sop-screenshot {
  margin: 24px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
figure.sop-screenshot img {
  width: 100%;
  height: auto;
  display: block;
}
figure.sop-screenshot figcaption {
  padding: 8px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
}

/* Inline images not in figures */
#sop-body img:not(figure img) {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
  margin: 12px 0;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { padding: 24px 20px; }
  .detail-layout { padding: 0 16px; }
  .detail-sidebar { display: none; }
}

@media (max-width: 600px) {
  .logo span { display: none; }
  .search-wrap { max-width: none; }
  .header-actions .btn span { display: none; }
  #sop-grid { grid-template-columns: 1fr; }
  #sop-title { font-size: 1.5rem; }
  .main-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
}
