.templates-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.templates-stack,
.templates-detail-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.templates-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.templates-toolbar-meta {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: #64748b;
  font-size: 13px;
}

.templates-toolbar-meta strong {
  color: #0f172a;
  font-size: 20px;
}

.templates-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.template-card {
  position: relative;
  padding: 14px;
}

.template-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.template-card-main,
.template-card-preview {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.template-card-title {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.template-card-date {
  margin-top: 4px;
  font-size: 12px;
  color: #64748b;
}

.template-card-actions {
  position: relative;
  flex: 0 0 auto;
}

.template-actions-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 170px;
  padding: 6px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

.template-actions-menu-btn {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  color: #334155;
  cursor: pointer;
}

.template-actions-menu-btn.danger {
  color: #b91c1c;
}

.template-card-preview {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.45;
  color: #475569;
  white-space: pre-wrap;
}

.template-card-file {
  margin-top: 10px;
  font-size: 12px;
  color: #64748b;
}

.template-detail-card,
.template-targets-card {
  padding: 14px;
}

.template-detail-meta {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 10px;
}

.template-detail-file {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
}

.template-detail-file-title {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #334155;
}

.template-detail-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.template-full-text {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: #f8fafc;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: #0f172a;
  white-space: pre-wrap;
  word-break: break-word;
}

.template-detail-actions,
.template-targets-actions,
.template-send-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-lang-filters {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-lang-filters .btn.active {
  border-color: #2563eb;
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.12);
}

.template-detail-actions {
  margin-top: 12px;
}

.template-targets-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.template-targets-head h3 {
  margin: 0 0 4px;
}

.template-selection-meta {
  font-size: 13px;
  color: #64748b;
}

.template-company-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-company-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: #ffffff;
}

.template-company-row input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.template-company-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.template-company-name {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
}

.template-company-meta {
  font-size: 12px;
  color: #64748b;
}

.template-send-actions {
  margin-top: 14px;
}

#templateTextInput {
  min-height: 220px;
  resize: vertical;
  overflow-y: auto;
}

.template-file-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-file-upload-btn {
  align-self: flex-start;
}

.template-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: #475569;
}

.template-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-weight: 600;
}

.template-file-size {
  color: #64748b;
}

.template-file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 1200px) {
  .template-targets-head {
    flex-direction: column;
  }
}

@media (max-width: 900px) {
  .templates-toolbar,
  .template-detail-actions,
  .template-targets-actions,
  .template-send-actions {
    flex-direction: column;
  }

  .templates-toolbar .btn,
  .template-detail-actions .btn,
  .template-targets-actions .btn,
  .template-send-actions .btn {
    width: 100%;
  }

  .template-lang-filters {
    width: 100%;
  }

  .template-lang-filters .btn {
    flex: 1 1 0;
    width: auto;
  }

  .template-card-head {
    align-items: flex-start;
  }

  .template-actions-menu {
    right: 0;
    left: auto;
    min-width: 150px;
  }

  .template-company-row {
    grid-template-columns: 20px minmax(0, 1fr);
    align-items: flex-start;
  }
}
