@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap');

/* ===== Design Tokens ===== */
:root {
  /* Backgrounds & Surfaces */
  --bg: #F8F7F5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #64605a;
  --text-muted: #9b958d;
  --border: #E8E5E0;
  --border-strong: #DDD9D3;

  /* Accent (editorial warm) */
  --accent: #2d2d2d;
  --accent-soft: #555;

  /* Focus */
  --focus-ring: rgba(59, 130, 246, 0.18);

  /* Radii */
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);

  /* Domain Colors */
  --domain-blue: #3B82F6;
  --domain-red: #EF4444;
  --domain-amber: #F59E0B;
  --domain-teal: #14B8A6;
  --domain-violet: #8B5CF6;
  --domain-emerald: #10B981;
  --domain-cyan: #06B6D4;
  --domain-indigo: #6366F1;
  --domain-orange: #F97316;
  --domain-pink: #EC4899;

  /* Transition */
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

button {
  font: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

/* ===== Base ===== */
html,
body {
  font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
}

/* Subtle grain texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

body.modal-open {
  overflow: hidden;
}

/* ===== Page Shell ===== */
.page-shell {
  width: min(1180px, 92vw);
  margin: 32px auto 48px;
  display: grid;
  gap: 16px;
}

/* ===== Hero Block (Editorial Header) ===== */
.hero-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--domain-blue);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 36px 32px 28px;
  display: grid;
  gap: 24px;
}

.hero-title {
  display: grid;
  gap: 6px;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.8vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.hero-subtitle {
  margin: 0;
  font-size: clamp(0.88rem, 1.2vw, 1rem);
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* ===== Search ===== */
.search-wrap {
  position: relative;
}

.search-wrap::before {
  content: '';
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  opacity: 0.4;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%231a1a1a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 1;
}

.search-input {
  width: 100%;
  height: 52px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 0 120px 0 44px;
  font-size: 0.95rem;
  color: var(--text);
  transition: border-color 200ms var(--ease), box-shadow 200ms var(--ease);
}

.search-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.search-input:focus {
  outline: none;
  border-color: var(--domain-blue);
  box-shadow: 0 0 0 4px var(--focus-ring), 0 2px 8px rgba(59, 130, 246, 0.1);
}

.search-hint {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.78rem;
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity 200ms var(--ease);
  user-select: none;
}

.search-input:focus ~ .search-hint {
  opacity: 0;
}

/* ===== Main Grid ===== */
.main-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 260px minmax(0, 1fr);
  align-items: start;
}

/* ===== Panels (shared) ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head {
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--domain-blue);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.mono {
  font-family: 'SF Mono', ui-monospace, SFMono-Regular, 'Cascadia Code', 'Fira Code', Menlo, Monaco, Consolas, monospace;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
}

/* ===== Index Panel (Sidebar) ===== */
.index-panel {
  position: sticky;
  top: 16px;
}

.domain-index {
  padding: 10px;
  display: grid;
  gap: 4px;
}

.index-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  transition: all 200ms var(--ease);
  border-left: 3px solid transparent;
}

.index-item strong {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}

.index-item small {
  color: var(--text-muted);
  font-size: 0.72rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.index-item svg {
  flex-shrink: 0;
  color: var(--domain-color, var(--text-muted));
  opacity: 0.7;
}

.index-item:hover {
  background: rgba(0, 0, 0, 0.025);
  transform: translateY(-1px);
}

.index-item:focus {
  outline: none;
  background: rgba(0, 0, 0, 0.035);
  box-shadow: 0 0 0 3px var(--focus-ring);
  border-left-color: var(--domain-color, var(--domain-blue));
}

.index-item:focus-visible {
  outline: none;
  background: rgba(0, 0, 0, 0.035);
  box-shadow: 0 0 0 3px var(--focus-ring);
  border-left-color: var(--domain-color, var(--domain-blue));
}

.index-item.active svg {
  opacity: 1;
}

.index-item.active {
  background: color-mix(in srgb, var(--domain-color, var(--domain-blue)) 6%, transparent);
  border-left-color: var(--domain-color, var(--domain-blue));
  font-weight: 600;
}

.index-item.active strong {
  font-weight: 600;
}

/* Domain Dot */
.domain-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  /* color set via inline style: background-color */
}

/* ===== Result Panel ===== */
.result-panel {
  min-height: 400px;
}

.result-groups {
  padding: 16px;
  display: grid;
  gap: 24px;
}

/* ===== Domain Group ===== */
.domain-group {
  display: grid;
  gap: 12px;
}

.group-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  color: var(--text);
}

.group-title::before {
  content: '';
  display: block;
  width: 3px;
  height: 18px;
  border-radius: 2px;
  background: var(--domain-color, var(--domain-blue));
  flex-shrink: 0;
}

.group-title svg {
  flex-shrink: 0;
  color: var(--domain-color, var(--text-secondary));
}

.group-title .mono {
  margin-left: auto;
}

/* ===== System List Grid ===== */
.system-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

/* ===== Item Card ===== */
.item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  text-align: left;
  padding: 14px;
  cursor: pointer;
  display: grid;
  gap: 10px;
  transition: transform 200ms var(--ease), box-shadow 200ms var(--ease), border-color 200ms var(--ease);
}

.item-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--domain-blue) 40%, var(--border));
}

.item-card.active {
  border-color: var(--domain-blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.item-top h3 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
}

.tag {
  white-space: nowrap;
  border-radius: 6px;
  background: color-mix(in srgb, var(--tag-color, #9b958d) 8%, #ffffff);
  color: color-mix(in srgb, var(--tag-color, #9b958d) 55%, #64605a);
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 500;
  border: 1px solid color-mix(in srgb, var(--tag-color, #9b958d) 15%, #E8E5E0);
  flex-shrink: 0;
}

.item-meta {
  display: grid;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.5;
}

.item-meta strong {
  color: var(--text-secondary);
  font-weight: 500;
}

.item-meta span:last-child {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Search Highlight ===== */
mark {
  background: #FEF3C7;
  color: inherit;
  border-radius: 3px;
  padding: 1px 3px;
}

/* ===== Empty State ===== */
.empty {
  border: 1px dashed var(--domain-amber);
  border-radius: var(--radius-md);
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--domain-amber) 3%, var(--surface));
  font-size: 0.9rem;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  animation: modalFadeIn 200ms var(--ease);
}

.modal[hidden] {
  display: none;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(920px, 92vw);
  max-height: min(88vh, 860px);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 300ms var(--ease);
}

.modal-head {
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.modal-close {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms var(--ease);
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  overflow-y: auto;
  padding: 24px 28px;
  display: grid;
  gap: 28px;
  overscroll-behavior: contain;
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ===== Summary Grid (KV items) ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px 28px;
}

.kv-item {
  display: grid;
  align-content: start;
  gap: 3px;
}

.kv-item strong {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kv-item p {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
  font-size: 0.88rem;
}

/* ===== Detail Sections ===== */
.detail-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.detail-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 16px 18px;
  display: grid;
  gap: 10px;
}

.detail-section h4 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.section-list {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 5px;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.5;
}

.section-list li::marker {
  color: var(--text-muted);
}

.section-empty {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .page-shell {
    width: min(96vw, 760px);
    margin: 16px auto 28px;
    gap: 12px;
  }

  .hero-block {
    padding: 24px 20px 20px;
    gap: 18px;
  }

  .main-grid {
    grid-template-columns: 1fr;
  }

  .index-panel {
    position: static;
  }

  .domain-index {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .index-item {
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    border-radius: var(--radius-sm);
  }

  .index-item.active {
    border-left-color: var(--domain-color, var(--domain-blue));
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-sections {
    grid-template-columns: 1fr;
  }

  .result-groups {
    padding: 12px;
    gap: 20px;
  }
}

@media (max-width: 620px) {
  .page-shell {
    margin: 10px auto 20px;
  }

  .hero-block {
    padding: 20px 16px 16px;
    gap: 14px;
  }

  .search-input {
    height: 46px;
    padding-left: 40px;
    padding-right: 16px;
    font-size: 0.9rem;
  }

  .search-hint {
    display: none;
  }

  .search-wrap::before {
    left: 14px;
    width: 16px;
    height: 16px;
  }

  .domain-index,
  .system-list {
    grid-template-columns: 1fr;
  }

  .modal-panel {
    width: 96vw;
    max-height: 92vh;
    border-radius: var(--radius-md);
  }

  .modal-head {
    padding: 12px 16px;
  }

  .modal-body {
    padding: 16px;
    gap: 12px;
  }

  .modal-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .result-groups {
    padding: 10px;
    gap: 16px;
  }

  .item-card {
    padding: 12px;
  }
}

/* ===== Scrollbar Styling ===== */
.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Selection ===== */
::selection {
  background: rgba(59, 130, 246, 0.15);
  color: inherit;
}
