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

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #212529;
  --text-secondary: #6c757d;
  --primary: #3366cc;
  --primary-hover: #2952a3;
  --danger: #dc3545;
  --danger-hover: #b02a37;
  --tag-bg: #e8f0fe;
  --tag-text: #1a56db;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ======= Navbar ======= */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .6rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.logo { font-weight: 700; font-size: 1.15rem; color: var(--primary); white-space: nowrap; }
.search-form { flex: 1; max-width: 400px; display: flex; gap: .4rem; }
.search-form input {
  flex: 1;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
}
.search-form input:focus { outline: none; border-color: var(--primary); }
.search-form button {
  padding: .45rem .9rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .9rem;
}
.search-form button:hover { background: var(--primary-hover); }

/* ======= Buttons ======= */
.btn {
  display: inline-block;
  padding: .4rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  cursor: pointer;
  text-decoration: none;
  transition: .15s;
}
.btn:hover { background: #f0f0f0; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: transparent; }
.btn-new { background: var(--primary); color: #fff; border-color: var(--primary); white-space: nowrap; }
.btn-new:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: .25rem .55rem; font-size: .8rem; }

/* ======= Container ======= */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
  width: 100%;
}

/* ======= Flash Messages ======= */
.flash {
  padding: .65rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
}
.flash-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.flash-error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* ======= Home ======= */
.home-header { margin-bottom: 1.5rem; }
.home-header h1 { font-size: 1.8rem; margin-bottom: .25rem; }
.subtitle { color: var(--text-secondary); }

.tag-filter { margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 2rem;
}

.page-items { list-style: none; }
.page-items li {
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}
.page-title { font-weight: 600; }
.meta { color: var(--text-secondary); font-size: .82rem; }

.sidebar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; align-self: start; }
.sidebar h3 { font-size: 1rem; margin-bottom: .6rem; }

.empty { color: var(--text-secondary); font-style: italic; }

/* ======= Tags ======= */
.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: .78rem;
  padding: .15rem .5rem;
  border-radius: 999px;
  text-decoration: none;
}
.tag:hover { background: #cde; text-decoration: none; }
.tag-active { background: var(--primary); color: #fff; }

/* ======= Wiki Page ======= */
.wiki-page { background: var(--surface); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow); }

.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.7rem; margin-bottom: .3rem; }
.page-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }

.page-actions { display: flex; gap: .5rem; align-items: center; }

.page-content { line-height: 1.75; }
.page-content h1 { font-size: 1.5rem; margin: 1.5rem 0 .5rem; border-bottom: 2px solid var(--border); padding-bottom: .25rem; }
.page-content h2 { font-size: 1.3rem; margin: 1.3rem 0 .4rem; }
.page-content h3 { font-size: 1.1rem; margin: 1rem 0 .3rem; }
.page-content p { margin: .6rem 0; }
.page-content ul, .page-content ol { margin: .5rem 0 .5rem 1.5rem; }
.page-content code { background: #f0f0f0; padding: .15rem .35rem; border-radius: 3px; font-size: .88em; }
.page-content pre { background: #f5f5f5; padding: 1rem; border-radius: var(--radius); overflow-x: auto; margin: .8rem 0; }
.page-content blockquote { border-left: 4px solid var(--border); padding: .3rem 1rem; color: var(--text-secondary); margin: .8rem 0; }
.page-content hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.page-content .wiki-link { color: var(--primary); }
.page-content .wiki-link:hover { text-decoration: underline; }

/* wiki table */
.page-content .wiki-table,
.history-table {
  border-collapse: collapse;
  width: 100%;
  margin: .8rem 0;
}
.page-content .wiki-table th,
.page-content .wiki-table td,
.history-table th,
.history-table td {
  border: 1px solid var(--border);
  padding: .4rem .7rem;
  font-size: .9rem;
}
.page-content .wiki-table th,
.history-table th {
  background: #f0f4fa;
  font-weight: 600;
}
.history-table td { font-size: .85rem; }

/* ======= Edit ======= */
.edit-page { background: var(--surface); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.edit-page h1 { margin-bottom: 1.2rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .9rem; }
.form-group small { color: var(--text-secondary); }

.form-group input[type="text"] {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
}
.form-group input:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(51,102,204,.15); }

.form-group textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: .88rem;
  line-height: 1.55;
  resize: vertical;
}

.form-actions { display: flex; gap: .5rem; margin-top: 1.2rem; }

/* ======= Not Found ======= */
.not-found {
  text-align: center;
  padding: 4rem 1rem;
}
.not-found h1 { font-size: 1.6rem; margin-bottom: .6rem; }
.not-found p { color: var(--text-secondary); margin-bottom: 1rem; }

/* ======= Footer ======= */
.footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-secondary);
  font-size: .82rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ======= Responsive ======= */
@media (max-width: 768px) {
  .two-col { grid-template-columns: 1fr; }
  .sidebar { order: -1; }
  .navbar { flex-wrap: wrap; }
  .search-form { order: 3; max-width: 100%; width: 100%; }
}