:root {
  color-scheme: light dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

body {
  margin: 0;
  background-color: #f6f7f8;
  color: #222;
}

.page-header,
.page-footer {
  padding: 1.5rem 1rem;
  text-align: center;
  background-color: #ffffff;
  border-bottom: 1px solid #d9dde2;
}

.page-header h1 {
  margin-bottom: 0.5rem;
}

.page-header p {
  margin: 0 auto;
  max-width: 48rem;
}

.page-footer {
  border-top: 1px solid #d9dde2;
  border-bottom: none;
  font-size: 0.9rem;
}

main {
  padding: 1rem 1.5rem 2rem 0;
  max-width: none;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
  max-width: 100vw;
  margin: 0;
}

.sidebar {
  background-color: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  padding: 1.5rem 1.25rem;
  position: sticky;
  top: 1rem;
}

.sidebar h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  color: #0f172a;
}

.sidebar__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar__button {
  all: unset;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border-radius: 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e293b;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar__button:hover,
.sidebar__button:focus-visible {
  background-color: rgba(59, 130, 246, 0.12);
  color: #0d6efd;
}

.sidebar__button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.sidebar__button[aria-current="true"] {
  background-color: #0d6efd;
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(13, 110, 253, 0.35);
}

.sidebar__badge {
  font-size: 0.8rem;
  background-color: rgba(15, 23, 42, 0.08);
  color: inherit;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
}

.sidebar__button[aria-current="true"] .sidebar__badge {
  background-color: rgba(255, 255, 255, 0.2);
}

.directory {
  min-width: 0;
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 260px) 1fr;
  gap: 1.5rem;
  align-items: start;
}

.sidebar {
  background-color: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  padding: 1.5rem 1.25rem;
  position: sticky;
  top: 1rem;
}

.sidebar h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  color: #0f172a;
}

.sidebar__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar__button {
  all: unset;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border-radius: 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e293b;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar__button:hover,
.sidebar__button:focus-visible {
  background-color: rgba(59, 130, 246, 0.12);
  color: #0d6efd;
}

.sidebar__button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.sidebar__button[aria-current="true"] {
  background-color: #0d6efd;
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(13, 110, 253, 0.35);
}

.sidebar__badge {
  font-size: 0.8rem;
  background-color: rgba(15, 23, 42, 0.08);
  color: inherit;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
}

.sidebar__button[aria-current="true"] .sidebar__badge {
  background-color: rgba(255, 255, 255, 0.2);
}

.directory {
  min-width: 0;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin: 0 0 1.25rem;
}

.filter-field {
  flex: 1 1 240px;
  min-width: 200px;
}

.filter-field--search {
  flex: 2 1 320px;   /* 검색창이 다른 것보다 더 넓게 */
  min-width: 260px;
}

.filter-field--narrow {
  flex: 0 0 200px;
}

.filter-field--toggle {
  flex: 0 0 auto;
}

.toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.9rem;         /* 검색 input padding 맞춰줌 */
  border-radius: 0.65rem;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
  color: #0f172a;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.toggle-button:hover {
  background-color: #e5edf9;
}

.toggle-button--active {
  /* .badge--ok 색감이랑 비슷하게 */
  background-color: rgba(34, 197, 94, 0.15);
  color: #15803d;
  border-color: rgba(34, 197, 94, 0.7);
}

.filter-bar label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: #334155;
}

.filter-bar input,
.filter-bar select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 0.65rem;
  padding: 0.6rem 0.75rem;
  font: inherit;
  background-color: #ffffff;
  color: inherit;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-bar select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% + 3px), calc(100% - 13px) calc(50% + 3px);
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.5rem;
}

.filter-bar input:focus,
.filter-bar select:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
  border-color: #0d6efd;
  box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.12);
}

.table-container {
  overflow-x: auto;
  background: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.table-container:focus-within,
.sidebar:focus-within {
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15), 0 12px 30px rgba(15, 23, 42, 0.12);
}

#instances-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

caption {
  text-align: left;
  font-weight: 600;
  padding: 1rem;
  font-size: 1.1rem;
}

thead {
  background-color: #f0f3f7;
}

th,
td {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e3e7ee;
  text-align: left;
  vertical-align: top;
}

.cell-name {
  min-width: 10rem;
  max-width: 25rem;
}

.cell-name__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
}

.cell-name__description {
  margin: 0.45rem 0 0;
  font-size: 0.85rem;
  color: #475569;
  opacity: 0.8;
}

th[data-sort-key] {
  white-space: nowrap;
}

th[data-sort-key] button {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-weight: inherit;
}

th[data-sort-key] button:hover,
th[data-sort-key] button:focus-visible {
  color: #0d6efd;
}

th[data-sort-key] button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

th[data-sort-key] button::after {
  content: "";
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  mask: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"%3E%3Cpath d="M7 10l5-5 5 5H7zm10 4l-5 5-5-5h10z"/%3E%3C/svg%3E') center / contain no-repeat;
  background-color: currentColor;
  opacity: 0.35;
}

th[data-sort-key][data-direction="asc"] button::after {
  mask: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"%3E%3Cpath d="M7 14l5-5 5 5H7z"/%3E%3C/svg%3E') center / contain no-repeat;
  opacity: 0.75;
}

th[data-sort-key][data-direction="desc"] button::after {
  mask: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"%3E%3Cpath d="M7 10l5 5 5-5H7z"/%3E%3C/svg%3E') center / contain no-repeat;
  opacity: 0.75;
}

tbody tr:last-child td {
  border-bottom: none;
}

a {
  color: #0d6efd;
}

a:hover,
a:focus {
  text-decoration: underline;
}

@media (max-width: 960px) {
  main {
    padding: 1rem;
  }

  .layout {
    grid-template-columns: 1fr;
    max-width: none;
  }

  .sidebar {
    position: static;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-field,
  .filter-field--narrow {
    flex: 1 1 auto;
    min-width: 0;
  }
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  vertical-align: middle;
  margin-left: 0.5rem;
}

.badge--ok {
  background-color: rgba(34, 197, 94, 0.15);
  color: #15803d;
}

.badge--warn {
  background-color: rgba(248, 113, 113, 0.18);
  color: #b91c1c;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sidebar__sublist {
  padding-left: 1rem;
  margin-top: 0.3rem;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.sidebar__button--child {
  font-weight: 500;
  font-size: 0.9rem;
  background: none;
}

.sidebar__section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0.6rem 0 0.2rem;
  padding: 0 0.2rem;
  color: #64748b;
}

.sidebar__button {
  position: relative;
}

.sidebar__toggle {
  margin-right: 0.35rem;
  font-size: 0.8rem;
  opacity: 0.7;
}

.sidebar__pin {
  margin-left: 0.4rem;
  font-size: 0.9rem;
  opacity: 0.7;
  cursor: pointer;
}

.sidebar__pin:hover {
  opacity: 1;
}

/* 접힌 상태에서 자식 리스트 숨김 */
.sidebar__item--collapsed > .sidebar__sublist {
  display: none;
}

@media (max-width: 640px) {
  .filter-field,
  .filter-field--narrow {
    flex: 1 1 100%;
  }
}

@media (prefers-color-scheme: dark) {
  body {
    background-color: #0f172a;
    color: #f8fafc;
  }

  .page-header,
  .page-footer,
  .table-container {
    background-color: #111827;
    color: inherit;
    border-color: #1f2937;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.45);
  }

  .filter-bar label {
    color: #cbd5f5;
  }

  .filter-bar input,
  .filter-bar select {
    background-color: #0f172a;
    border-color: #1f2937;
    color: inherit;
    box-shadow: inset 0 1px 2px rgba(148, 163, 184, 0.16);
  }

  thead {
    background-color: #1f2937;
  }

  th,
  td {
    border-color: #1f2937;
  }

  .cell-name__description {
    color: #cbd5f5;
    opacity: 0.65;
  }

  a {
    color: #60a5fa;
  }

  th[data-sort-key] button:hover,
  th[data-sort-key] button:focus-visible {
    color: #93c5fd;
  }

  .badge--ok {
    background-color: rgba(16, 185, 129, 0.22);
    color: #34d399;
  }

  .badge--warn {
    background-color: rgba(248, 113, 113, 0.25);
    color: #fca5a5;
  }
}
