:root {
  --bg: #ffffff;
  --surface: #f7f5fa;
  --surface-hover: #efeaf6;
  --border: #e5dfee;
  --text: #16131d;
  --muted: #6c647a;
  --accent: #ca51f9;
  --accent-hover: #b338e3;
  --accent-soft: rgba(202, 81, 249, 0.12);
  --shadow: 0 10px 30px rgba(202, 81, 249, 0.10), 0 2px 8px rgba(0, 0, 0, 0.04);
  --modal-bg: #ffffff;
  --link-color: #6b21a8;
  --url-color: #059669;
}

body.dark {
  --bg: #0e0c14;
  --surface: #171422;
  --surface-hover: #211c30;
  --border: #2b253d;
  --text: #f5f3fa;
  --muted: #9c93ad;
  --accent: #d268fc;
  --accent-hover: #df8aff;
  --accent-soft: rgba(210, 104, 252, 0.16);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --modal-bg: #171422;
  --link-color: #d8b4fe;
  --url-color: #34d399;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

mark {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  padding: 0 2px;
  border-radius: 3px;
}

/* 상단 바 */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  font-size: 14px;
  border-bottom: 1px solid transparent;
}

body.view-serp .topbar {
  border-bottom-color: var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eisha-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  transition: border-color 0.15s, background-color 0.15s;
}

.eisha-pill:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.index-badge {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: 999px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: border-color 0.15s, background-color 0.15s;
}

.icon-btn:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.icon-btn.accent-outline {
  border-color: rgba(202, 81, 249, 0.4);
  color: var(--accent);
  font-weight: 600;
}

/* 메인 컨테이너: 홈 뷰 vs 검색 결과(SERP) 뷰 */
.main-wrap {
  flex: 1;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

body.view-home .main-wrap {
  max-width: 680px;
  padding: 20px 18px 64px;
  align-items: center;
  justify-content: center;
}

body.view-home .search-header-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

body.view-home .search-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

body.view-home .serp-section {
  display: none;
}

body.view-home .home-widgets {
  display: block;
  width: 100%;
}

/* SERP 뷰 레이아웃 */
body.view-serp .main-wrap {
  max-width: 860px;
  padding: 20px 20px 64px;
}

body.view-serp .search-header-area {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

body.view-serp .brand-hero {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  padding-top: 6px;
  flex-shrink: 0;
}

body.view-serp .logo-wrap {
  margin-bottom: 0;
}

body.view-serp .brand-logo {
  height: 32px;
}

body.view-serp .brand-title {
  font-size: 24px;
  margin-bottom: 0;
}

body.view-serp .brand-slogan {
  display: none;
}

body.view-serp .search-controls {
  flex: 1;
  min-width: 0;
}

body.view-serp .category-tabs {
  justify-content: flex-start;
  margin-top: 10px;
  margin-bottom: 0;
}

body.view-serp .home-widgets {
  display: none;
}

body.view-serp .serp-section {
  display: block;
}

/* 브랜드 히어로 */
.brand-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
  text-align: center;
  cursor: pointer;
}

.logo-wrap {
  margin-bottom: 10px;
}

.brand-logo {
  height: 66px;
  width: auto;
  display: block;
  object-fit: contain;
  user-select: none;
}

.brand-title {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -1.4px;
  line-height: 1.1;
  margin-bottom: 6px;
}

.brand-title .accent {
  color: var(--accent);
}

.brand-slogan {
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}

/* 검색 입력창 */
.search-wrapper {
  position: relative;
  width: 100%;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 18px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  background: var(--bg);
}

.search-leading-icon {
  display: flex;
  align-items: center;
  color: var(--accent);
  margin-right: 10px;
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15.5px;
  outline: none;
}

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

.clear-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 15px;
  display: none;
}

.clear-btn:hover {
  color: var(--text);
}

.search-submit {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.search-submit:hover {
  background: var(--accent-hover);
}

/* 카테고리 탭 */
.category-tabs {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s ease;
}

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

.tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

/* 드롭다운 */
.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 30;
  display: none;
}

.dropdown.open {
  display: block;
}

.dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.dropdown-header button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.dropdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 18px;
  cursor: pointer;
  font-size: 14px;
}

.dropdown-item:hover,
.dropdown-item.selected {
  background: var(--surface);
}

.del-item {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 6px;
}

/* 홈 위젯 (바로가기 & 최근 문서) */
.home-widgets {
  margin-top: 28px;
}

.section-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 0 4px;
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
  margin-bottom: 26px;
}

.shortcut-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 12px 6px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.shortcut-card:hover {
  background: var(--surface);
  border-color: var(--border);
}

.shortcut-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 17px;
  color: var(--accent);
}

.shortcut-title {
  font-size: 12px;
  font-weight: 500;
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shortcut-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.shortcut-card:hover .shortcut-remove {
  display: flex;
}

/* 최근 색인 문서 카드 */
.recent-docs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-doc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, transform 0.1s;
}

.recent-doc-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.recent-doc-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.recent-doc-url {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 480px;
}

.cat-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

/* SERP 검색 결과 화면 */
.serp-meta-bar {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
}

.serp-results {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.serp-card {
  padding: 16px 18px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}

.serp-card:hover {
  border-color: var(--accent);
}

.serp-source-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12.5px;
}

.serp-favicon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.serp-domain {
  color: var(--url-color);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.serp-title-link {
  display: inline-block;
  font-size: 18px;
  font-weight: 700;
  color: var(--link-color);
  text-decoration: none;
  margin-bottom: 6px;
  line-height: 1.35;
}

.serp-title-link:hover {
  text-decoration: underline;
}

.serp-desc {
  font-size: 14px;
  color: var(--text);
  line-height: 1.55;
  opacity: 0.9;
}

.serp-keywords {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.kw-tag {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
}

/* 안내 / 빈 상태 / SQL 셋업 박스 */
.empty-box {
  padding: 28px 22px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

.empty-box h3 {
  font-size: 17px;
  margin-bottom: 8px;
}

.empty-box p {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.sql-helper {
  text-align: left;
  margin-top: 14px;
}

.sql-helper pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  overflow-x: auto;
  margin-bottom: 10px;
  color: var(--text);
}

/* 푸터 */
.footer {
  text-align: center;
  padding: 18px 16px;
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* 모달 공통 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 16, 0.58);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal-card.modal-sm {
  max-width: 360px;
}

.modal-card.modal-lg {
  max-width: 600px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-subtitle {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
}

.modal-desc {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  padding: 4px;
}

.modal-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 16px;
}

.m-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 13px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.m-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.m-tab-panel {
  display: none;
}

.m-tab-panel.active {
  display: block;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  flex: 1;
}

.field input,
.field textarea,
.field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
}

.inline-input-group {
  display: flex;
  gap: 8px;
}

.inline-input-group input {
  flex: 1;
  min-width: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.checkbox-row input {
  accent-color: var(--accent);
}

.preview-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px dashed var(--accent);
}

.crawl-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text);
  max-height: 130px;
  overflow-y: auto;
  line-height: 1.5;
}

.error-text {
  color: #ef4444;
  font-size: 12.5px;
  min-height: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.btn-secondary,
.btn-primary {
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

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

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 문서 관리 리스트 */
.manage-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.manage-toolbar input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}

.manage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
}

.manage-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.manage-item-info {
  min-width: 0;
}

.manage-item-title {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manage-item-url {
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-danger-sm {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-danger-sm:hover {
  background: #ef4444;
  color: #ffffff;
}

@media (max-width: 640px) {
  body.view-serp .search-header-area {
    flex-direction: column;
    gap: 12px;
  }
  .field-row {
    grid-template-columns: 1fr;
  }
  .index-badge {
    display: none;
  }
  .topbar {
    padding: 12px 14px;
  }
}
