:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --danger: #f43f5e;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
}

.sync-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.nav-tabs {
  display: flex;
  gap: 6px;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

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

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
}

.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--accent-strong); border-color: var(--accent); color: #fff; }
.btn-danger { background: rgba(244, 63, 94, 0.15); border-color: var(--danger); color: #fda4af; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px;
}

.view { display: none; }
.view.active { display: block; }

/* 대분류 탭 + 하위 섹터 칩 바 */
.category-bar, .sector-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}

.sector-bar {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-items: center;
}

.sector-bar-label {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  margin-right: 4px;
}

.chip {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip.active {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #fff;
}

.chip-count {
  font-size: 0.74rem;
  opacity: 0.85;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
}

.input, .select, .textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.toolbar .input { flex: 1; min-width: 180px; }

/* 책장 그리드 */
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.card:hover { transform: translateY(-2px); border-color: var(--accent); }

.cover-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--surface-2);
  display: flex;
  align-items: flex-end;
  padding: 12px;
  overflow: hidden;
}

.cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-fallback {
  position: relative;
  z-index: 1;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.rating-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 3px 7px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  color: #fbbf24;
}

.cat-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
}

.card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.card-title {
  font-weight: 700;
  font-size: 0.94rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.card-sector {
  display: inline-block;
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: #cbd5e1;
  width: fit-content;
}

.card-actions {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.st-badge { font-size: 0.7rem; padding: 2px 6px; border-radius: 5px; font-weight: 600; }
.st-done { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
.st-progress { background: rgba(56, 189, 248, 0.18); color: #7dd3fc; }
.st-wish { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }
.st-drop { background: rgba(244, 63, 94, 0.18); color: #fda4af; }

/* 통계 대시보드 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.kpi-label { font-size: 0.78rem; color: var(--muted); }
.kpi-value { font-size: 1.4rem; font-weight: 800; margin-top: 4px; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.chart-box { position: relative; height: 260px; margin-top: 8px; }

/* AI 추천 & 2-Pane 레이아웃 */
.two-pane {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.prompt-box {
  width: 100%;
  min-height: 280px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  resize: vertical;
}

.rec-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
}

/* 모달 */
dialog {
  width: min(560px, calc(100% - 24px));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.65); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

.meta-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
}

.meta-item:hover { border-color: var(--accent); }
.meta-item img { width: 32px; height: 44px; object-fit: cover; border-radius: 4px; }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* 768px 브레이크포인트 (폴더블 펼침 / 태블릿 / 데스크톱 2-pane) */
@media (min-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .charts-grid { grid-template-columns: repeat(2, 1fr); }
  .two-pane { grid-template-columns: 360px 1fr; align-items: start; }
}
