*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
  background: #111827;
  color: #f3f4f6;
}

body.light {
  background: #f3f4f6;
  color: #111827;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  min-width: 1100px;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  background: #0f172a;
  border-right: 1px solid #1e293b;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

body.light .sidebar {
  background: #ffffff;
  border-right-color: #d1d5db;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-bottom: 8px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #9ca3af;
}

body.light .brand p {
  color: #4b5563;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}

.nav-link {
  display: block;
  text-decoration: none;
}

.nav-item:hover {
  background: #1e293b;
}

.nav-item.active {
  background: #2563eb;
  border-color: #60a5fa;
  color: #ffffff;
}

body.light .nav-item:hover {
  background: #e5e7eb;
}

.theme-toggle {
  margin-top: auto;
}

.main-content {
  flex: 1;
  padding: 28px;
  overflow: auto;
}

.section {
  display: none;
  max-width: 980px;
}

.cluster-section {
  max-width: 1320px;
}

.section.active {
  display: block;
}

h2 {
  margin-top: 0;
  margin-bottom: 16px;
}

label {
  display: block;
  margin: 10px 0 6px;
  font-size: 13px;
  color: #9ca3af;
}

body.light label {
  color: #4b5563;
}

select,
textarea,
button {
  font: inherit;
}

select,
textarea {
  width: 100%;
  max-width: 760px;
  background: #1f2937;
  color: inherit;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 10px 12px;
}

body.light select,
body.light textarea {
  background: #ffffff;
  border-color: #d1d5db;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

button {
  border: 1px solid #1d4ed8;
  background: #2563eb;
  color: #ffffff;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.counts,
.result,
.embed-stats {
  max-width: 760px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 10px;
}

body.light .counts,
body.light .result,
body.light .embed-stats {
  background: #ffffff;
  border-color: #d1d5db;
}

.counts {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 12px;
  margin-top: 12px;
}

.view-toggle {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.toggle-btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #4b5563;
  cursor: pointer;
}

.toggle-btn.active {
  background: #2563eb;
  border-color: #60a5fa;
  color: #ffffff;
}

.result {
  min-height: 60px;
  margin-top: 12px;
  padding: 12px;
  font-family: Consolas, monospace;
  word-break: break-word;
}

.token {
  display: inline-block;
  margin: 2px;
  padding: 2px 6px;
  border-radius: 6px;
}

.embed-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 760px;
}

.embed-controls {
  margin-top: 14px;
  max-width: 760px;
}

.embed-controls button {
  margin-top: 10px;
  margin-right: 10px;
}

.cosine-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  max-width: 900px;
  margin-top: 12px;
}

.cosine-card {
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px 12px;
  background: #0f172a;
}

body.light .cosine-card {
  background: #ffffff;
  border-color: #d1d5db;
}

.card-label {
  font-size: 12px;
  opacity: 0.8;
}

.card-model {
  font-size: 11px;
  opacity: 0.75;
  margin-top: 2px;
}

.card-value {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.card-openai .card-value {
  color: #60a5fa;
}

.card-nomic .card-value {
  color: #34d399;
}

.card-minilm .card-value {
  color: #f59e0b;
}

.card-bge .card-value {
  color: #a78bfa;
}

.embed-stats {
  margin-top: 14px;
  padding: 12px;
}

.embed-meta-wrap {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  max-width: 900px;
  margin-top: 14px;
}

.meta-card {
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 12px 14px;
  background: #0f172a;
  font-size: 13px;
}

body.light .meta-card {
  background: #ffffff;
  border-color: #d1d5db;
}

.meta-card-title {
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 13px;
  opacity: 0.9;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  opacity: 0.9;
}

.meta-row span:first-child {
  opacity: 0.65;
}

.meta-card-error {
  border-color: #ef4444;
}

.meta-error-text {
  margin-top: 6px;
  font-size: 12px;
  color: #f87171;
  word-break: break-word;
}

#varianceResult {
  white-space: pre-wrap;
  font-family: Consolas, monospace;
  font-size: 12px;
}

#embedHeatmap,
#embed2D,
#embedding3D {
  width: 100%;
  max-width: 760px;
  border: 1px solid #374151;
  border-radius: 10px;
  background: #0b1220;
}

#embed2D {
  height: 420px;
}

#embedding3D {
  height: 480px;
}

#cluster2D,
#cluster3D {
  width: 100%;
  max-width: 1200px;
  border: 1px solid #374151;
  border-radius: 10px;
  background: #0b1220;
  margin-top: 8px;
}

#cluster2D {
  height: 620px;
}

#cluster3D {
  height: 660px;
}

body.light #embedHeatmap,
body.light #embed2D,
body.light #embedding3D,
body.light #cluster2D,
body.light #cluster3D {
  background: #ffffff;
  border-color: #d1d5db;
}

.hint,
.dim-note,
.note {
  color: #9ca3af;
  font-size: 13px;
}

@media (max-width: 920px) {
  .embed-grid {
    grid-template-columns: 1fr;
  }

  .cosine-cards {
    grid-template-columns: 1fr;
  }
}
