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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
}

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

/* 로그인 페이지 */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  width: 100%;
  max-width: 380px;
}

.login-box h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  text-align: center;
}

.login-box p {
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.login-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.login-box input:focus {
  border-color: var(--primary);
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  display: none;
}

/* 레이아웃 */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
}

/* 팀 탭 */
.team-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.team-tab {
  flex: 1;
  padding: 0.6rem 0.25rem;
  border: none;
  background: none;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

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

.team-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.team-tab[data-team="bookthief"].active {
  color: #d97706;
  border-bottom-color: #d97706;
}

.team-tab[data-team="kindai"].active {
  color: #7c3aed;
  border-bottom-color: #7c3aed;
}

.team-tab[data-team="ranchat"].active {
  color: #059669;
  border-bottom-color: #059669;
}

.sidebar-actions {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}

.page-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.page-item {
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.page-item:hover {
  background: var(--bg);
}

.page-item.active {
  background: #eff6ff;
  color: var(--primary);
}

.page-item-title {
  font-size: 0.9rem;
  font-weight: 500;
}

.page-item-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.page-list-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* 사이드바 하단 */
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* 히스토리 뷰 */
.history-view {
  max-width: 800px;
  margin: 0 auto;
}

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 0.5rem;
  transition: background 0.15s;
}

.history-item:hover {
  background: var(--bg);
}

.history-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}

.history-badge.created {
  background: #dcfce7;
  color: #166534;
}

.history-badge.updated {
  background: #dbeafe;
  color: #1e40af;
}

.history-badge.deleted {
  background: #fee2e2;
  color: #991b1b;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-title a {
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.history-title a:hover {
  color: var(--primary);
}

.history-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-actions {
  flex-shrink: 0;
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

/* 변경 비교 (diff) */
.diff-container {
  display: flex;
  gap: 0.75rem;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.diff-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.diff-pane-header {
  padding: 0.4rem 0.75rem;
  border-radius: 6px 6px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  flex-shrink: 0;
}

.diff-pane-before {
  background: #fee2e2;
  color: #991b1b;
}

.diff-pane-after {
  background: #dcfce7;
  color: #166534;
}

.diff-pane-content {
  flex: 1;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  padding: 0.75rem;
  font-size: 0.82rem;
  line-height: 1.65;
  margin: 0;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

@media (max-width: 768px) {
  .diff-container {
    flex-direction: column;
  }
}

/* 메인 콘텐츠 */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.main-header h2 {
  font-size: 1.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.main-header-actions-dynamic {
  display: flex;
  gap: 0.5rem;
}

.content-area {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

/* 뷰 모드 - 마크다운 렌더링 */
.view-content {
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.8;
}

.view-content h1 { font-size: 1.8rem; margin: 1.5rem 0 0.75rem; }
.view-content h2 { font-size: 1.5rem; margin: 1.25rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.view-content h3 { font-size: 1.25rem; margin: 1rem 0 0.5rem; }
.view-content p { margin-bottom: 0.75rem; }
.view-content ul, .view-content ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.view-content li { margin-bottom: 0.25rem; }
.view-content code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.9em; }
.view-content pre { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: 8px; overflow-x: auto; margin-bottom: 1rem; }
.view-content pre code { background: none; padding: 0; color: inherit; }
.view-content blockquote { border-left: 3px solid var(--primary); padding-left: 1rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.view-content table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.view-content th, .view-content td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; }
.view-content th { background: var(--bg); font-weight: 600; }
.view-content a { color: var(--primary); }
.view-content hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* 편집 모드 */
.edit-area {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.edit-title {
  width: 100%;
  padding: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
  outline: none;
}

.edit-title:focus {
  border-color: var(--primary);
}

.edit-content {
  width: 100%;
  min-height: 500px;
  padding: 1rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.9rem;
  line-height: 1.7;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  outline: none;
}

.edit-content:focus {
  border-color: var(--primary);
}

/* 버튼 */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

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

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* 환영 화면 */
.welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
}

.welcome h2 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.welcome p {
  font-size: 0.95rem;
}

/* 모달 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal h3 {
  margin-bottom: 1rem;
}

.modal input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 1rem;
  outline: none;
}

.modal input:focus {
  border-color: var(--primary);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* 검색 */
.search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  margin-bottom: 0.5rem;
}

.search-input:focus {
  border-color: var(--primary);
}

/* 전체 보기 */
.all-pages-view {
  max-width: 800px;
  margin: 0 auto;
}

.all-pages-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.all-pages-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  gap: 0.5rem;
}

.all-pages-card-title {
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.all-pages-card-title:hover {
  color: var(--primary);
}

.all-pages-card-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.all-pages-card-body {
  padding: 1rem 1.25rem;
}

.all-pages-card-body.view-content {
  max-width: none;
}

.all-pages-empty,
.all-pages-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

/* 반응형 */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 50;
    transition: left 0.25s;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 49;
    display: none;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .content-area {
    padding: 1rem;
  }
}

@media (min-width: 769px) {
  .menu-toggle {
    display: none;
  }

  .sidebar-backdrop {
    display: none !important;
  }
}

/* 유틸리티 */
.hidden {
  display: none !important;
}

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

.mt-1 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
