:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --warn: #dc2626;
  --warn-soft: #fef2f2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  padding: 20px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 16px;
}

.topbar h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.topbar-title { flex: 1 1 auto; min-width: 200px; }

.meta-box {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
  margin-left: auto;
}

.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.home-btn:hover { background: var(--accent); color: #fff; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
}

button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

main {
  padding: 24px 32px 60px;
  max-width: 1400px;
  margin: 0 auto;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.card.highlight {
  background: var(--warn-soft);
  border-color: #fecaca;
}

.card-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.card-value { font-size: 26px; font-weight: 700; }
.card.highlight .card-value { color: var(--warn); }

.card-clickable {
  display: block;
  width: 100%;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}
.card-clickable:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}
.card-clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.card-hint { margin-top: 8px; font-size: 11px; color: var(--warn); }

.active-filter-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--warn-soft);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--warn);
  font-weight: 600;
}
.active-filter-badge button {
  background: transparent;
  border: 1px solid #fecaca;
  color: var(--warn);
  padding: 4px 10px;
  font-size: 12px;
}
.active-filter-badge button:hover { background: var(--warn); color: #fff; }
.active-filter-badge[hidden] { display: none; }

.charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.chart-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  height: 320px;
}

.chart-box h3 { margin: 0 0 12px; font-size: 14px; color: var(--text); }
.chart-box canvas { max-height: 250px; }

.search-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-row input {
  flex: 1;
  min-width: 240px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.search-row select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.table-wrap { overflow-x: auto; }

.table-scroll-top {
  overflow-x: auto;
  overflow-y: hidden;
  height: 16px;
  margin-bottom: 6px;
}
.table-scroll-top-spacer { height: 1px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: var(--accent-soft);
  color: var(--accent);
  position: sticky;
  top: 0;
}

tbody tr:hover { background: #fafafa; }

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.hub-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 22px 20px;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, transform 0.15s;
}

.hub-card:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.hub-card .hub-icon { font-size: 28px; margin-bottom: 12px; display: block; }
.hub-card .hub-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.hub-card .hub-desc { font-size: 13px; color: var(--muted); line-height: 1.5; }

.hub-card.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.hub-badge {
  display: inline-block;
  margin-top: 12px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.hub-card.disabled .hub-badge {
  background: #f3f4f6;
  color: var(--muted);
}

.hub-progress {
  color: var(--muted);
  font-size: 13px;
}

.pill-thumb {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 6px;
  background: #fafafa;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.img-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  z-index: 1000;
}
.img-modal-overlay[hidden] { display: none; }

.img-modal-body {
  background: var(--panel);
  border-radius: 12px;
  padding: 20px;
  max-width: min(90vw, 480px);
  max-height: 90vh;
  overflow: auto;
  text-align: center;
}
.img-modal-body img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fafafa;
}
.img-modal-caption {
  margin-top: 12px;
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}
.img-modal-close {
  position: fixed;
  top: 16px;
  right: 16px;
  background: #fff;
  color: var(--text);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.img-modal-close:hover { background: #f3f4f6; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 0;
  text-decoration: underline;
}
.link-btn:hover { color: #1e40af; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--panel);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: min(90vw, 640px);
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box h3 { margin: 0 0 6px; font-size: 17px; }
.modal-meta { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.modal-content { white-space: pre-wrap; line-height: 1.6; font-size: 14px; }
.modal-attach { margin-top: 18px; }
.modal-attach a {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.modal-attach a:hover { text-decoration: underline; }

.modal-dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 9px 16px;
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
}
.modal-dl dt { color: var(--muted); font-weight: 600; white-space: nowrap; }
.modal-dl dd { margin: 0; word-break: break-word; }
.modal-dl dd.long-text { white-space: pre-wrap; }

.resizable-table th, .resizable-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  user-select: none;
  touch-action: none;
}
.col-resize-handle:hover, .col-resize-handle.resizing {
  background: var(--accent);
  opacity: 0.6;
}

.sortable-th { cursor: pointer; user-select: none; }
.sortable-th:hover { background: #dbeafe; }
.sortable-th::after {
  content: '\2195';
  margin-left: 5px;
  font-size: 11px;
  opacity: 0.35;
  display: inline-block;
}
.sortable-th.sort-asc::after { content: '\25B2'; opacity: 1; }
.sortable-th.sort-desc::after { content: '\25BC'; opacity: 1; }

.modal-close {
  position: fixed;
  top: 16px;
  right: 16px;
  background: #fff;
  color: var(--text);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.modal-close:hover { background: #f3f4f6; }
