
.templates-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
}

.templates-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-secondary, #6b7280);
}

[data-theme='dark'] .templates-sort {
  color: #a1a1a0;
}

.templates-sort-label {
  letter-spacing: 0.02em;
}

.templates-sort-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 0.375rem 1.75rem 0.375rem 0.625rem;
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text-primary, #111827);
  background-color: transparent;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 0.5rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%239ca3af' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  transition: border-color 0.15s, background-color 0.15s;
}

.templates-sort-select:hover {
  border-color: var(--text-secondary, #9ca3af);
}

.templates-sort-select:focus {
  outline: none;
  border-color: var(--accent-color, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

[data-theme='dark'] .templates-sort-select {
  color: #fafaf9;
  border-color: #404040;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%23a1a1a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/></svg>");
}

[data-theme='dark'] .templates-sort-select:hover {
  border-color: #525252;
}

[data-theme='dark'] .templates-sort-select:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

.templates-sort-select option {
  background-color: var(--bg-secondary, #ffffff);
  color: var(--text-primary, #111827);
}

[data-theme='dark'] .templates-sort-select option {
  background-color: #262625;
  color: #fafaf9;
}

.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
}

.template-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 0.5rem;
  background-color: var(--bg-secondary, #ffffff);
  transition: border-color 0.15s, box-shadow 0.15s;
  height: 100%;
}

.template-card:hover {
  border-color: var(--accent-color, #3b82f6);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

[data-theme='dark'] .template-card {
  background-color: #262625;
  border-color: #404040;
}

[data-theme='dark'] .template-card:hover {
  border-color: #60a5fa;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.template-card-header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.template-name {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary, #000000);
}

[data-theme='dark'] .template-name {
  color: #fafaf9;
}

.template-author {
  font-size: 0.8125rem;
  color: var(--text-secondary, #6b7280);
}

[data-theme='dark'] .template-author {
  color: #a1a1a0;
}

.template-cost {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent-color, #3b82f6);
  margin-top: 0.25rem;
}

[data-theme='dark'] .template-cost {
  color: #60a5fa;
}

.template-description {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text-secondary, #6b7280);
}

[data-theme='dark'] .template-description {
  color: #a1a1a0;
}

.template-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background-color: var(--bg-tertiary, #f9fafb);
  border-radius: 0.375rem;
  font-size: 0.875rem;
}

[data-theme='dark'] .template-stack {
  background-color: #1a1a19;
}

.template-layer {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.layer-label {
  font-weight: 500;
  color: var(--text-primary, #000000);
  white-space: nowrap;
}

[data-theme='dark'] .layer-label {
  color: #d4d4d3;
}

.layer-items {
  color: var(--text-secondary, #6b7280);
  word-break: break-word;
}

[data-theme='dark'] .layer-items {
  color: #a1a1a0;
}

.template-use-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #ffffff;
  background-color: var(--accent-color, #3b82f6);
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background-color 0.15s;
  margin-top: auto;
  width: 100%;
}

.template-use-btn:hover {
  background-color: var(--accent-hover, #2563eb);
}

.template-use-btn:active {
  background-color: var(--accent-active, #1d4ed8);
}

[data-theme='dark'] .template-use-btn {
  background-color: #60a5fa;
}

[data-theme='dark'] .template-use-btn:hover {
  background-color: #3b82f6;
}


@media (max-width: 640px) {
  .templates-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}
