:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e6ec;
  --text: #1f2733;
  --text-muted: #6b7684;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eaf1ff;
  --success: #1a9c6b;
  --danger: #d64545;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 1px 2px rgba(20, 30, 50, 0.06);
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef1f6; padding: 1px 6px; border-radius: 5px; font-size: 0.9em; color: #3a4250; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--accent); }

.topnav { display: flex; gap: 4px; }
.topnav a {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: 8px;
}
.topnav a:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; }

.quick-search {
  display: flex;
  flex: 1;
  min-width: 220px;
  max-width: 480px;
  gap: 6px;
}
.quick-search input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
}
.quick-search input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.quick-search button {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.quick-search button:hover { background: var(--accent-dark); }

.topbar-meta { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
}
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; }

/* Layout */
.content { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.footer { text-align: center; color: var(--text-muted); font-size: 0.85rem; padding: 30px 20px; }

.hero { margin-bottom: 24px; }
.hero h1 { margin: 0 0 6px; font-size: 1.7rem; }
.hero p { color: var(--text-muted); margin: 0; }

.breadcrumb { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 14px; }

/* badges */
.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-error { background: #fde8e8; color: var(--danger); }
.count-badge {
  display: inline-block;
  background: #eef1f6;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  margin-left: 6px;
}

/* Group / cards */
.group-section { margin-bottom: 30px; }
.group-section h2 {
  font-size: 1.05rem;
  color: var(--text-muted);
  border-left: 4px solid var(--accent);
  padding-left: 10px;
  margin-bottom: 14px;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.table-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform .1s ease, box-shadow .1s ease;
}
.table-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(20, 30, 50, 0.12);
  border-color: var(--accent);
}
.table-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.table-name { font-weight: 700; font-family: Consolas, "Courier New", monospace; font-size: 0.95rem; }
.table-card-desc { color: var(--text-muted); font-size: 0.85rem; }

/* Table header section */
.table-header, .detail-header { margin-bottom: 16px; }
.table-header h1, .detail-header h1 { margin: 0 0 4px; font-family: Consolas, "Courier New", monospace; font-size: 1.5rem; }
.desc { color: var(--text-muted); margin: 2px 0; }
.pk-info { font-size: 0.85rem; color: var(--text-muted); }
.model-name { font-family: "Segoe UI", sans-serif; font-size: 1rem; color: var(--text-muted); font-weight: 400; margin-left: 8px; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 12px 0;
}
.info-grid > div, .option-grid > div { display: flex; flex-direction: column; gap: 2px; }
.label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.value { font-size: 0.95rem; }
.option-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 10px; }

.options-details { margin-top: 10px; }
.options-details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.88rem; }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filter-bar input[type=text] {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.filter-bar select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.filter-bar button {
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.filter-bar button:hover { background: var(--accent-dark); }

.result-summary { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 10px; }

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-wrap-scroll { overflow-x: auto; }

table.data-table, table.mini-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
  white-space: nowrap;
}
table.mini-table { white-space: normal; }

.data-table thead th, .mini-table thead th {
  background: #f7f9fc;
  border-bottom: 2px solid var(--border);
  text-align: left;
  padding: 9px 12px;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sort-link { color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.sort-link:hover { color: var(--accent); text-decoration: none; }
.sort-arrow { color: var(--accent); }
.pk-star { font-size: 0.75em; }

.data-table tbody td, .mini-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table tbody tr:nth-child(even), .mini-table tbody tr:nth-child(even) { background: #fafbfd; }
.data-table tbody tr:hover, .mini-table tbody tr:hover { background: var(--accent-soft); }
td.has-tip { border-bottom-style: dashed; cursor: help; }
.tip-hint { color: var(--text-muted); font-size: 0.85em; }
.null-val { color: #c3c9d3; }
.empty { text-align: center; color: var(--text-muted); padding: 24px !important; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 10px; margin-top: 16px; justify-content: center; }
.pagination a {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.pagination a.disabled { pointer-events: none; opacity: 0.4; }
.page-indicator { font-size: 0.85rem; color: var(--text-muted); }

/* Detail sections */
.detail-section { margin: 26px 0; }
.detail-section h2 { font-size: 1.05rem; margin-bottom: 10px; }
.detail-section h2 small { color: var(--text-muted); font-weight: 400; font-size: 0.78rem; margin-left: 6px; }

/* Union collapsible */
.union-details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  padding: 10px 14px;
}
.union-details summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.union-details summary:hover { color: var(--accent); }
.union-details .mini-table { margin-top: 10px; }
.muted { color: var(--text-muted); font-size: 0.82rem; }
.action-context { font-size: 0.78rem; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert-error { background: #fde8e8; color: var(--danger); border: 1px solid #f5b8b8; }

/* ERD page */
.erd-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.erd-tabs { display: flex; gap: 8px; }
.erd-tab {
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}
.erd-tab:hover { border-color: var(--accent); color: var(--accent-dark); }
.erd-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.erd-legend { display: flex; flex-wrap: wrap; gap: 12px; }
.erd-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); }
.erd-legend-item i { width: 12px; height: 12px; border-radius: 3px; border: 1.5px solid; display: inline-block; }

.erd-canvas-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  overflow: auto;
}
.erd-canvas { min-height: 320px; }
.erd-canvas svg { max-width: none; display: block; margin: 0 auto; }
.erd-canvas a { cursor: pointer; }
.erd-hint { margin-top: 10px; }

/* Union editor-style viewer */
.editor-view-link { margin-left: auto; font-size: 0.82rem; font-weight: 600; }
tr.current-row { background: #1f2733 !important; color: #fff; }
tr.current-row td { border-bottom-color: #1f2733; }
tr.current-row a { color: #9ec1ff; }
tr.current-row code { background: #33404f; color: #cfe0ff; }

.code-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  padding: 3px 7px;
  border-radius: 6px;
  font-family: Consolas, "Courier New", monospace;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid transparent;
}
.code-badge small { font-family: "Segoe UI", sans-serif; font-weight: 500; font-size: 0.68rem; }
.code-badge.code-confirmed { background: #e8f9f0; color: #0b6b45; border-color: #12a86a; }
.code-badge.code-inferred { background: #fff6e5; color: #8a5a10; border-color: #d98a1f; border-style: dashed; }
.code-badge.code-unknown { background: #f2f4f7; color: #6b7684; border-color: #b7bfc9; border-style: dotted; }

.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.legend-confirmed { background: #12a86a; }
.legend-inferred { background: #d98a1f; }
.legend-unknown { background: #b7bfc9; }

/* Write guide page */
.guide-steps { padding-left: 22px; }
.guide-steps > li { margin-bottom: 14px; line-height: 1.7; }
.guide-steps ul { margin: 6px 0; padding-left: 20px; }
.guide-steps ul li { margin-bottom: 4px; }

.codec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 16px 0 24px;
}
.codec-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.codec-card h3 { margin: 0 0 12px; font-size: 0.98rem; }
.codec-card input[type=text] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: Consolas, monospace;
  font-size: 1rem;
  margin-bottom: 12px;
}
.codec-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; margin-bottom: 12px; }
.codec-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--text-muted); }
.codec-form select, .codec-form input[type=number] {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.85rem;
}
.codec-output { min-height: 20px; }
.codec-result { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 0.9rem; }
.big-code { font-size: 1.3rem; font-weight: 700; background: var(--accent-soft); color: var(--accent-dark); padding: 4px 10px; border-radius: 8px; }
.ref-title { margin-top: 24px; font-size: 0.95rem; }

@media (max-width: 720px) {
  .topbar-inner { flex-direction: column; align-items: stretch; }
  .quick-search { max-width: none; }
  .topbar-meta { margin-left: 0; justify-content: space-between; }
}
