:root {
  --teal: #0f8173;
  --teal-dark: #0b665a;
  --mint: #eaf7f4;
  --ink: #172c2a;
  --muted: #71807e;
  --line: #e7eeec;
  --panel: #ffffff;
  --page: #dfe9e8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
  font-family: "DM Sans", "Noto Sans Thai", sans-serif;
  color: var(--ink);
  background: var(--page);
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  background: var(--page);
  transition: grid-template-columns 180ms ease;
}

.app-shell.panel-hidden { grid-template-columns: 0 minmax(0, 1fr); }
.app-shell.panel-hidden .sidebar { opacity: 0; pointer-events: none; transform: translateX(-100%); }

.sidebar {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  transition: 180ms ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 64px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 1.5px solid var(--teal);
  border-radius: 50%;
  color: var(--teal);
  font-size: 13px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 16px 8px;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
}

.search-box svg {
  width: 16px;
  fill: none;
  stroke: #8b9996;
  stroke-width: 1.8;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.system-tabs {
  display: flex;
  gap: 5px;
  padding: 8px 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}

.system-tabs::-webkit-scrollbar { display: none; }

.system-tab {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: #6d7d7a;
  font-size: 11px;
  font-weight: 600;
}

.system-tab.active {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

.anatomy-list {
  flex: 1;
  padding: 10px 12px 84px;
  overflow-y: auto;
}

.anatomy-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  width: 100%;
  margin-bottom: 7px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  color: var(--ink);
}

.anatomy-card:hover { background: #f7faf9; }
.anatomy-card.active { border-color: #bfddd7; background: var(--mint); }

.anatomy-icon {
  display: grid;
  place-items: center;
  height: 58px;
  border-radius: 7px;
  background: #edf3f2;
  color: var(--teal);
  font-size: 24px;
}

.anatomy-card.active .anatomy-icon { background: #d7ece7; }

.anatomy-copy { align-self: center; min-width: 0; }
.anatomy-copy strong { display: block; margin-bottom: 3px; font-size: 12px; }
.anatomy-copy span { display: block; overflow: hidden; color: var(--muted); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }

.load-more-button {
  width: calc(100% - 16px);
  height: 36px;
  margin: 8px;
  border: 1px solid #bfddd7;
  border-radius: 8px;
  background: white;
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
}

.sidebar-footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: space-between;
  height: 58px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #8da09d;
}

.icon-button:hover { background: var(--mint); color: var(--teal); }
.icon-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.viewer-area {
  position: relative;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,.55), rgba(223,233,232,0) 44%),
    #dfe9e8;
}

.viewer-toolbar {
  position: absolute;
  z-index: 3;
  top: 16px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  color: #71827f;
  font-size: 12px;
}

.toolbar-actions {
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.view-button {
  height: 32px;
  padding: 0 11px;
  border: 1px solid rgba(127,150,146,.25);
  border-radius: 7px;
  background: rgba(255,255,255,.88);
  color: #71827f;
  font-size: 11px;
}

.view-button.active { border-color: var(--teal); background: var(--teal); color: white; }

.canvas-container { position: absolute; inset: 0; }
.canvas-container canvas { display: block; width: 100%; height: 100%; }

.model-credit {
  position: absolute;
  z-index: 3;
  bottom: 12px;
  left: 20px;
  color: #7b8d89;
  font-size: 10px;
  pointer-events: auto;
}

.model-credit a {
  color: var(--teal);
  font-weight: 700;
  text-decoration: none;
}

.loading-state {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(223,233,232,.75);
  color: #71827f;
  font-size: 12px;
  transition: opacity 200ms ease;
}

.loading-state.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 28px; height: 28px; border: 3px solid #bfd0cd; border-top-color: var(--teal); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.detail-card {
  position: absolute;
  z-index: 4;
  right: 24px;
  bottom: 24px;
  width: 270px;
  padding: 18px;
  border: 1px solid rgba(127,150,146,.14);
  border-radius: 12px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 16px 50px rgba(53,82,76,.12);
  backdrop-filter: blur(12px);
  transition: 180ms ease;
}

.detail-card.closed { opacity: 0; transform: translateY(12px); pointer-events: none; }
.detail-heading { display: flex; justify-content: space-between; gap: 12px; }
.detail-system { color: var(--teal); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.detail-heading h1 { margin: 4px 0 0; font-size: 18px; }
.close-button { width: 28px; height: 28px; border: 0; border-radius: 50%; background: #f0f5f3; color: #82918f; font-size: 18px; line-height: 1; }
.detail-card p { margin: 12px 0; color: #6f807d; font-size: 11px; line-height: 1.6; }

.detail-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 12px;
}

.detail-card dl div { padding: 8px; border-radius: 7px; background: #f5f8f7; }
.detail-card dt { color: #93a09e; font-size: 9px; }
.detail-card dd { margin: 2px 0 0; font-size: 11px; font-weight: 700; }

.primary-button {
  width: 100%;
  height: 38px;
  border: 0;
  border-radius: 7px;
  background: var(--teal);
  color: white;
  font-size: 12px;
  font-weight: 700;
}
.primary-button:hover { background: var(--teal-dark); }

@media (max-width: 760px) {
  body { overflow: hidden; }
  .app-shell { grid-template-columns: 224px minmax(0, 1fr); }
  .detail-card { right: 10px; bottom: 10px; width: 240px; }
  .viewer-toolbar { top: 10px; left: 10px; right: 10px; }
  .toolbar-actions { display: none; }
}

